Next: Network Sockets and Communication, Previous: Network Databases, Up: Networking
A socket address object identifies a socket endpoint for
communication. In the case of AF_INET for instance, the socket
address object comprises the host address (or interface on the host)
and a port number which specifies a particular open socket in a
running client or server process. A socket address object can be
created with,
Return a new socket address object. The first argument is the address family, one of the
AFconstants, then the arguments vary according to the family.For
AF_INETthe arguments are an IPv4 network address number (see Network Address Conversion), and a port number.For
AF_INET6the arguments are an IPv6 network address number and a port number. Optional flowinfo and scopeid arguments may be given (both integers, default 0).For
AF_UNIXthe argument is a filename (a string).The C function
scm_make_socket_addresstakes the family and address arguments directly, then arglist is a list of further arguments, being the port for IPv4, port and optional flowinfo and scopeid for IPv6, or the empty listSCM_EOLfor Unix domain.
The following functions access the fields of a socket address object,
Return the address family from socket address object sa. This is one of the
AFconstants (eg.AF_INET).
For an
AF_INETorAF_INET6socket address object sa, return the network address number.
For an
AF_INETorAF_INET6socket address object sa, return the port number.
For an
AF_INET6socket address object sa, return the flowinfo value.
For an
AF_INET6socket address object sa, return the scope ID value.
The functions below convert to and from the C struct sockaddr
(see Address Formats).
That structure is a generic type, an application can cast to or from
struct sockaddr_in, struct sockaddr_in6 or struct
sockaddr_un according to the address family.
In a struct sockaddr taken or returned, the byte ordering in
the fields follows the C conventions (see Byte Order Conversion). This means
network byte order for AF_INET host address
(sin_addr.s_addr) and port number (sin_port), and
AF_INET6 port number (sin6_port). But at the Scheme
level these values are taken or returned in host byte order, so the
port is an ordinary integer, and the host address likewise is an
ordinary integer (as described in Network Address Conversion).
Return a newly-
mallocedstruct sockaddrcreated from arguments like those taken byscm_make_socket_addressabove.The size (in bytes) of the
struct sockaddrreturn is stored into*outsize. An application must callfreeto release the returned structure when no longer required.
Return a Scheme socket address object from the C address structure. address_size is the size in bytes of address.
Return a newly-
mallocedstruct sockaddrfrom a Scheme level socket address object.The size (in bytes) of the
struct sockaddrreturn is stored into*outsize. An application must callfreeto release the returned structure when no longer required.