Posix_socketSourcePOSIX socket interface bindings.
This module provides OCaml bindings to the POSIX socket API defined in sys/socket.h and netdb.h.
It includes functions for address resolution, byte order conversion, and socket address manipulation.
Error codes returned by address resolution functions like getaddrinfo and getnameinfo.
type error = [ | `ADDRFAMILYAddress family not supported
*)| `AGAINTemporary failure in name resolution
*)| `BADFLAGSInvalid flags value
*)| `BADHINTSInvalid hints value
*)| `FAILNon-recoverable failure in name resolution
*)| `FAMILYAddress family not supported
*)| `MEMORYMemory allocation failure
*)| `NODATANo address associated with hostname
*)| `NONAMEName or service not known
*)| `PROTOCOLResolved protocol is unknown
*)| `SOCKTYPESocket type not supported
*)| `OVERFLOWArgument buffer overflow
*)| `SERVICEService not supported for socket type
*)| `SYSTEMSystem error, check errno
*)| `UNKNOWN of intUnknown error code
*) ]Address resolution error codes (EAI_* constants).
Returns true if this error code is natively defined on this platform.
Return a human-readable error message. See gai_strerror(3).
Functions for converting between network byte order (big-endian) and host byte order. See byteorder(3).
Convert 32-bit integer from network to host byte order.
Convert 16-bit integer from network to host byte order.
Convert 32-bit integer from host to network byte order.
Convert 16-bit integer from host to network byte order.
Socket type constants used when creating sockets. See socket(2).
Abstract type representing socket types.
Ctypes representation of socket_type.
Datagram socket (connectionless, unreliable). Used with UDP.
Stream socket (connection-oriented, reliable). Used with TCP.
Sequenced packet socket (connection-oriented, reliable, message boundaries preserved).
Socket address family constants. See sys/socket.h.
Module for the sa_family field type.
Type alias for address family.
Ctypes representation of sa_family_t.
IPv4 address family (AF_INET).
IPv6 address family (AF_INET6).
Unspecified address family (AF_UNSPEC). Used to request any address family.
Constants for getnameinfo(3).
Maximum length of a service name string.
Maximum length of a host name string.
Return numeric form of the host address.
Return numeric form of the service (port number).
IP protocol numbers for use with sockets. See netinet/in.h.
Internet Protocol (IP).
Internet Protocol version 6 (IPv6).
Internet Control Message Protocol (ICMP).
Raw IP packets.
Transmission Control Protocol (TCP).
User Datagram Protocol (UDP).
The socklen_t type used for socket address lengths. See sys/socket.h.
Unsigned module for socklen_t arithmetic.
Abstract socklen_t type.
Ctypes representation of socklen_t.
Generic socket address storage large enough to hold any socket address type. See sockaddr_storage.
Abstract type for socket address storage.
Allocate a new socket address storage structure.
Size of sockaddr_storage in bytes.
The generic sockaddr structure. See sockaddr.
Type alias for sockaddr structure.
Ctypes representation of sockaddr.
Return the actual length of a socket address based on its family.
The addrinfo structure used by getaddrinfo. See getaddrinfo(3).
Port number type (16-bit unsigned integer in network byte order).
Ctypes representation of in_port_t.
The sockaddr_in structure for IPv4 addresses. See netinet/in.h.
IPv4 socket address structure.
Type alias for IPv4 socket address.
Ctypes representation of sockaddr_in.
The sockaddr_in6 structure for IPv6 addresses. See netinet/in.h.
IPv6 socket address structure.
Type alias for IPv6 socket address.
Ctypes representation of sockaddr_in6.
Convert a socket address to a hostname and port number.
This is a wrapper around getnameinfo(3).
val getaddrinfo :
?hints:Addrinfo.t Ctypes.structure Ctypes.ptr ->
?port:[ `Int of int | `String of string ] ->
string ->
sockaddr Ctypes.ptr listResolve a hostname to a list of socket addresses.
This is a wrapper around getaddrinfo(3).
Example:
let addresses = getaddrinfo ~port:(`Int 443) "example.com" in
List.iter
(fun addr ->
let host, port = getnameinfo addr in
Printf.printf "%s:%d\n" host port)
addressesCalculate the length of a null-terminated string up to a maximum. See strnlen(3).
Functions for converting between Unix.sockaddr and POSIX socket addresses.
Convert a Unix.sockaddr to a POSIX socket address.
Convert a POSIX socket address to Unix.sockaddr.