(chibi net)

(make-address-info family socktype proto [hints])

(get-address-info host service [addrinfo])

(get-address-info host service . o)

Create and return a new addrinfo structure for the given host and service. host should be a string and service a string or integer. The optional addrinfo defaults to a TCP/IP stream setting.

(open-net-io host service . o)

Opens a client net connection to host, a string, on port service, which can be a string such as "http" or an integer. Returns a list of three values on success - the socket, an input port, and an output port - or #f on failure.

(with-net-io host service proc)

Convenience wrapper around open-net-io, opens the connection then calls proc with two arguments, the input port and the output port connected to the service, then closes the connection. Returns the result of proc. Raises an error if a connection can't be made.

(make-listener-socket addrinfo [max-conn])

Convenience wrapper to call socket, bind and listen to return a socket suitable for accepting connections on the given addrinfo. max-conn is the maximum number of pending connections, and defaults to 128. Automatically specifies socket-opt/reuseaddr.

(get-socket-option socket level name)

Returns the socket option of the given name for socket. socket should be a file descriptor, level the constant level/socket, and name one of the constants beginning with "socket-opt/".

(send socket bv . o)

Sends the bytevector bv to socket with sendto and returns the number of bytes sent, or a negative value on error. If addrinfo is unspecified, socket must previously have had a default address specified with connect.

(send/non-blocking socket bv timeout [flags addrinfo])

Equivalent to send but gives up and returns false if the packet can't be sent within timeout seconds.

(receive! socket bv . o)

Recieves data from socket to fill the bytevector bv by calling recvfrom. Returns the number of bytes read, or a negative value on error. If addrinfo is unspecified, socket must previously have had a default address specified with connect.

(receive!/non-blocking socket bv timeout [flags addrinfo])

Equivalent to receive! but gives up and returns false if no packets are received within timeout seconds.

(receive socket n . o)

Shortcut for receive, returning a newly created bytevector of length n on success and #f on failure.

(receive/non-blocking socket n timeout . o)

Equivalent to receive but gives up and returns false if no packets are received within timeout seconds.

(make-sockaddr)
(sockaddr? obj)

(address-info? obj)
(address-info-family addrinfo)
(address-info-socket-type addrinfo)
(address-info-protocol addrinfo)
(address-info-flags addrinfo)
(address-info-address addrinfo)
(address-info-address-length addrinfo)
(address-info-canonname addrinfo)
(address-info-next addrinfo)

The addrinfo struct accessors.

(bind fileno sockaddr int)

Bind a name to a socket.

(listen sexp sexp)

Listen on a socket.

(accept fileno sockaddr int)

Accept a connection on a socket.

(socket int int int)

Create an endpoint for communication.

(connect fileno sockaddr int)

Initiate a connection on a socket.

(open-socket-pair int int int)

Returns a list of 2 new sockets, the input and output end of a new pipe, respectively.

(sockaddr-name sockaddr)

Return the IP address of a sockaddr as an "N.N.N.N" string.

(sockaddr-port sockaddr)

Return the port a sockaddr is connected on.

int: address-family/unspecified

int: address-family/unix

int: address-family/inet

int: address-family/inet6

int: socket-type/stream

int: socket-type/datagram

int: socket-type/raw

int: ip-proto/ip

int: ip-proto/icmp

int: ip-proto/tcp

int: ip-proto/udp

int: ai/passive

int: ai/canonname

int: ai/numeric-host

The constants for the addrinfo struct.

(get-peer-name fileno sockaddr)

(set-socket-option! fileno int int int)

Set an option for the given socket. For example, to make the address reusable: (set-socket-option! sock level/socket socket-opt/reuseaddr 1)

int: level/socket

int: socket-opt/debug

int: socket-opt/broadcast

int: socket-opt/reuseaddr

int: socket-opt/keepalive

int: socket-opt/oobinline

int: socket-opt/sndbuf

int: socket-opt/rcvbuf

int: socket-opt/dontroute

int: socket-opt/rcvlowat

int: socket-opt/sndlowat

The constants for the get-socket-option and set-socket-option!.