Skip to content

Instantly share code, notes, and snippets.

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <netdb.h>
#include <sys/socket.h>
#include <openssl/ssl.h>
#include <openssl/err.h>
#include <openssl/x509_vfy.h>
@masakielastic
masakielastic / tls-client.c
Last active March 11, 2026 06:20
Minimal TLS Client in C with Explicit Connection State (QUIC Preparation)
/*
Minimal TLS Client in C (Architecture Exercise for QUIC Preparation)
This program implements a small TLS + TCP client using OpenSSL.
The goal of this code is not merely to demonstrate how to perform
a TLS request, but to illustrate a connection-oriented design that
resembles modern network protocol libraries.
Instead of writing everything inside main(), the implementation
intentionally separates responsibilities into multiple functions:
@masakielastic
masakielastic / reactphp_https_rr_example.php
Last active March 10, 2026 23:43
Minimal ReactPHP example for querying and parsing HTTPS DNS records (type 65)
<?php
/*
Minimal ReactPHP example for querying HTTPS DNS Resource Records (type 65).
This script demonstrates how to:
1. Query HTTPS DNS records using ReactPHP DNS
2. Retrieve raw RDATA from the DNS response
3. Parse SVCB/HTTPS wire format
4. Extract ALPN values such as "h2" and "h3"
@masakielastic
masakielastic / https_rr_parser.php
Last active March 10, 2026 23:15
Minimal PHP parser for HTTPS DNS Resource Record (type 65)
<?php
/*
Minimal HTTPS RR (DNS type 65) parser for PHP.
Demonstrates how to parse HTTPS/SVCB records returned by:
dns_get_record($host, 65, ..., true)
Extracts ALPN values such as "h2" and "h3".
@masakielastic
masakielastic / http2-server.php
Last active March 7, 2026 05:42
Minimal HTTP/2 Server with ReactPHP Socket. The latest version is available at: https://github.com/masakielastic/http2-minimal-examples
<?php
/**
* Minimal HTTP/2 Server with ReactPHP Socket (educational demo)
*
* This example demonstrates a minimal HTTP/2 server implemented directly
* on top of ReactPHP's Socket component. It shows how HTTP/2 can be used
* at the frame level without relying on external HTTP/2 libraries.
*
* The implementation is intentionally incomplete and simplified for
@masakielastic
masakielastic / 01-http2-client.php
Last active March 7, 2026 05:42
Minimal HTTP/2 Client with ReactPHP Socket. The latest version is available at: https://github.com/masakielastic/http2-minimal-examples/tree/main
<?php
/**
* Minimal HTTP/2 Client with ReactPHP Socket (educational demo)
*
* This example demonstrates a minimal HTTP/2 client implemented directly
* on top of ReactPHP's Socket component. It shows how HTTP/2 can be used
* at the frame level without relying on external HTTP/2 libraries.
*
* The implementation is intentionally incomplete and simplified for
@masakielastic
masakielastic / README.md
Last active March 5, 2026 05:11
PHP 最小 HPACK:静的テーブル+表現パース/生成のみ

PHP 最小 HPACK:静的テーブル+表現パース/生成のみ

PHP で HTTP/2 の HPACK を最小実装。目的は HTTP/2 ヘッダーブロックの decode/encode を最小限に扱えるようにすることです。

スコープ(必須)

HPACK の静的テーブル(Static Table)だけを扱うこと

Dynamic Table は実装しない

@masakielastic
masakielastic / QuicInitialPacketParser.php
Created March 5, 2026 03:37
QUIC Initial Packet Parser (PHP)
<?php
declare(strict_types=1);
final class QuicInitialPacketParser
{
private string $buffer = '';
private int $offset = 0;
public function parse(string $packet): array
@masakielastic
masakielastic / README.md
Created March 4, 2026 06:58
Zig 0.15.2 で TCP クライアント

Zig 0.15.2 で TCP クライアント

zig run client.zig
@masakielastic
masakielastic / README.md
Last active March 4, 2026 06:33
Zig 0.15.2 で HTTP クライアント

Zig 0.15.2 で HTTP クライアント

zig run client.zig