Protocol

Join provides protocol classes that encapsulate network protocol specifications for socket programming. Each protocol class defines the address family, socket type, and protocol number needed to create sockets.

Protocols are:

  • type‑safe — compile‑time protocol selection
  • lightweight — zero‑overhead abstractions
  • composable — work with endpoints, sockets, and streams

Available protocols span multiple network layers:

  • Unix domain (local IPC)
  • Internet protocols (TCP, UDP, ICMP)
  • Secure protocols (TLS, HTTPS, SMTPS)
  • Application protocols (HTTP, SMTP, DNS, DoT, mDNS)
  • Low‑level protocols (Netlink, Raw packets)

Unix domain protocols

Unix domain sockets provide local inter‑process communication with filesystem‑based addressing.

UnixDgram

Connectionless datagram protocol using AF_UNIX and SOCK_DGRAM.

// libjoin.
#include <join/protocol.hpp>

using namespace join;

UnixDgram::Socket socket;
UnixDgram::Endpoint endpoint("/tmp/socket");

UnixStream

Connection‑oriented stream protocol using AF_UNIX and SOCK_STREAM.

UnixStream::Socket   socket;
UnixStream::Stream   stream;
UnixStream::Acceptor acceptor;

Internet protocols

UDP

User Datagram Protocol for connectionless packet transmission.

Udp::Socket socket4(Udp::v4());
Udp::Socket socket6(Udp::v6());

TCP

Transmission Control Protocol for reliable stream communication.

Tcp::Socket   socket4(Tcp::v4());
Tcp::Stream   stream;
Tcp::Acceptor acceptor;

Tcp::Socket   socket6(Tcp::v6());

ICMP

Internet Control Message Protocol for network diagnostics (ping, traceroute).

Icmp::Socket icmp4(Icmp::v4());
Icmp::Socket icmp6(Icmp::v6());

⚠️ ICMP sockets typically require CAP_NET_RAW.


Secure protocols

TLS

Transport Layer Security for encrypted TCP connections.

Tls::Socket   socket(Tls::v4());
Tls::Stream   stream;
Tls::Acceptor acceptor;

Application protocols

HTTP / HTTPS

Http::Client  client;
Http::Server  server;
Http::Worker  worker;

Https::Client secureClient;
Https::Server secureServer;

SMTP / SMTPS

Smtp::Client  client(Smtp::v4());
Smtps::Client secureClient(Smtps::v4());

DNS (over UDP)

DNS protocol over UDP. Default port 53, max message size 8192 bytes.

Dns::Socket     socket(Dns::v4());
Dns::Resolver   resolver("8.8.8.8");      // BasicDatagramResolver<Dns>
Dns::NameServer nameServer;               // BasicDatagramNameServer<Dns>

Both IPv4 and IPv6 are supported via Dns::v4() / Dns::v6().

See Dns::Resolver and Dns::NameServer for full documentation.

DoT — DNS over TLS

DNS-over-TLS protocol. Default port 853, max message size 16384 bytes, RFC 7858 framing.

Dot::Socket   socket(Dot::v4());
Dot::Resolver resolver("1.1.1.1");        // BasicTlsResolver<Dot>

Dot uses SOCK_STREAM / IPPROTO_TCP under the hood. Both IPv4 and IPv6 are supported.

See Dot::Resolver for full documentation.

mDNS (Multicast DNS)

Multicast DNS protocol. Default port 5353, max message size 8192 bytes.

Mdns::Socket socket(Mdns::v4());
Mdns::Peer   peer("eth0");                // BasicDatagramPeer<Mdns>

// Multicast group addresses
IpAddress v4group = Mdns::multicastAddress(AF_INET);   // 224.0.0.251
IpAddress v6group = Mdns::multicastAddress(AF_INET6);  // ff02::fb

Both IPv4 and IPv6 multicast groups are supported via Mdns::v4() / Mdns::v6().

See Mdns::Peer for full documentation.


Low‑level protocols

Linux kernel communication protocol for routing, netfilter, and more.

Netlink::Socket routeSocket(Netlink::rt());   // NETLINK_ROUTE
Netlink::Socket nfSocket(Netlink::nf());      // NETLINK_NETFILTER

Netlink custom(NETLINK_USERSOCK);

Raw

Raw packet protocol using AF_PACKET for link‑layer access.

Raw::Socket   socket;
Raw::Endpoint endpoint;

⚠️ Raw sockets require CAP_NET_RAW and handle Ethernet frames directly.


IPv4 vs IPv6

Internet protocols support both address families through static factory methods:

Tcp::v4()   Tcp::v6()
Udp::v4()   Udp::v6()
Icmp::v4()  Icmp::v6()
Tls::v4()   Tls::v6()
Dns::v4()   Dns::v6()
Dot::v4()   Dot::v6()
Mdns::v4()  Mdns::v6()
Http::v4()  Http::v6()

Protocols can also be constructed with an explicit family:

Tcp  tcpv4(AF_INET);
Tcp  tcpv6(AF_INET6);
Dns  dnsv4(AF_INET);
Mdns mdnsv6(AF_INET6);

Protocol comparison

Protocols with family selection support == and !=:

assert(Tcp::v4() == Tcp::v4());
assert(Tcp::v4() != Tcp::v6());
assert(Dns::v4() != Dns::v6());
assert(Netlink::rt() != Netlink::nf());

Protocol properties

All protocol classes expose three core methods:

protocol.family();    // AF_INET, AF_UNIX, AF_NETLINK, AF_PACKET…
protocol.type();      // SOCK_STREAM, SOCK_DGRAM, SOCK_RAW
protocol.protocol();  // IPPROTO_TCP, IPPROTO_UDP, 0…

DNS and mDNS also expose protocol-level constants:

Dns::defaultPort   // 53
Dns::maxMsgSize    // 8192

Dot::defaultPort   // 853
Dot::maxMsgSize    // 16384

Mdns::defaultPort  // 5353
Mdns::maxMsgSize   // 8192

Associated types

Each protocol defines type aliases for related components:

ProtocolEndpointSocketStreamAcceptorResolverNameServerPeerClientServer
UnixDgram✅✅❌❌❌❌❌❌❌
UnixStream✅✅✅✅❌❌❌❌❌
Udp✅✅❌❌❌❌❌❌❌
Tcp✅✅✅✅❌❌❌❌❌
Tls✅✅✅✅❌❌❌❌❌
Dns✅✅❌❌✅✅❌❌❌
Dot✅✅❌❌✅❌❌❌❌
Mdns✅✅❌❌❌❌✅❌❌
Http✅✅✅✅❌❌❌✅✅
Https✅✅✅✅❌❌❌✅✅
Smtp✅✅✅❌❌❌❌✅❌
Smtps✅✅✅❌❌❌❌✅❌
Netlink✅✅❌❌❌❌❌❌❌
Raw✅✅❌❌❌❌❌❌❌

Summary

ProtocolFamilyTypeUse Case
UnixDgramAF_UNIXSOCK_DGRAMLocal datagram IPC
UnixStreamAF_UNIXSOCK_STREAMLocal stream IPC
UdpAF_INET*SOCK_DGRAMInternet datagrams
TcpAF_INET*SOCK_STREAMReliable internet streams
IcmpAF_INET*SOCK_RAWNetwork diagnostics
TlsAF_INET*SOCK_STREAMEncrypted TCP
DnsAF_INET*SOCK_DGRAMDNS over UDP
DotAF_INET*SOCK_STREAMDNS over TLS
MdnsAF_INET*SOCK_DGRAMMulticast DNS
HttpAF_INET*SOCK_STREAMWeb requests
HttpsAF_INET*SOCK_STREAMSecure web requests
SmtpAF_INET*SOCK_STREAMEmail transmission
SmtpsAF_INET*SOCK_STREAMSecure email transmission
NetlinkAF_NETLINKSOCK_RAWKernel communication
RawAF_PACKETSOCK_RAWLink‑layer packet access

* Supports both AF_INET (IPv4) and AF_INET6 (IPv6)