GSP
Quick Navigator

Search Site

Unix VPS
A - Starter
B - Basic
C - Preferred
D - Commercial
MPS - Dedicated
Previous VPSs
* Sign Up! *

Support
Contact Us
Online Help
Handbooks
Domain Status
Man Pages

FAQ
Virtual Servers
Pricing
Billing
Technical

Network
Facilities
Connectivity
Topology Map

Miscellaneous
Server Agreement
Year 2038
Credits
 

USA Flag

 

 

Man Pages
AG_NET(3) FreeBSD Library Functions Manual AG_NET(3)

AG_Netagar network interface

#include <agar/core.h>

AG_Net provides a cross-platform interface to network sockets, DNS and other network-related functions. Available backends include "bsd", "dummy", "winsock1" and "winsock2". The default backend is selected based on present platform capabilities.

AG_NetAddrList *
(const char *hostname, const char *port, Uint flags);


AG_NetAddrList *
(void);


AG_NetAddrList *
(void);


void
(AG_NetAddrList *list);


void
(AG_NetAddrList *list);


AG_NetAddr *
(void);


AG_NetAddr *
(const AG_NetAddr *a);


int
(const AG_NetAddr *a, const AG_NetAddr *b);


int
(const AG_NetAddr *a);


const char *
(AG_NetAddr *a);


void
(AG_NetAddr *a);

The () function looks up a specified host hostname and port number (or service name) port. If the lookup is successful, the results are returned as a list of addresses. Optional flags include:

Use IPv6 based on host interface status.
Require a hostname in numerical notation.
Require a numerical port number.

The () function returns the list of addresses associated with local network interfaces (i.e., the list of addresses that would be displayed by ifconfig(8) under Unix). If the call is unsupported on the present platform, the function returns NULL.

The AG_NetAddrList structure stores a list of network addresses. The () function returns an empty, newly allocated list, AG_NetAddrListClear() removes all addresses from the given list and AG_NetAddrListFree() releases all resources allocated by the list.

The AG_NetAddr structure stores a single network address and a port number. The () function returns a newly-allocated address. AG_NetAddrDup() returns a newly-allocated duplicate of a.

() evaluates to 0 if a and b represent the same address and port, otherwise a non-zero value (suitable for sorting) is returned. AG_NetAddrIsAny() returns 1 if the address represents "*" (any address).

The () function returns a pointer to an (internally-managed) string buffer containing a numerical representation of the address. The buffer will remains valid until the AG_NetAddr is freed.

The () routine destroys all resources allocated by a.

AG_NetSocket *
AG_NetSocketNew(enum ag_net_addr_family af, enum ag_net_socket_type type, int proto);


void
(AG_NetSocket *sock);


int
(AG_NetSocket *sock, const AG_NetAddrList *host);


int
(AG_NetSocket *sock, const AG_NetAddr *addr);


AG_NetSocket *
(AG_NetSocket *sock);


void
(AG_NetSocket *sock);


int
(AG_NetSocket *sock, void *data, AG_Size size, AG_Size *nRead);


int
(AG_NetSocket *sock, const void *data, AG_Size size, AG_Size *nWrote);


int
(AG_NetSocket *sock, enum ag_net_socket_option opt, void *data);


int
(AG_NetSocket *sock, enum ag_net_socket_option opt, int *data);


int
(AG_NetSocket *sock, enum ag_net_socket_option opt, const void *data);


int
(AG_NetSocket *sock, enum ag_net_socket_option opt, int data);

The () function creates an endpoint for communication, returning a socket descriptor on success. The af argument indicates the address family of the socket:

AG_NET_AF_NONE
Undefined address family.
AG_NET_LOCAL
Host-local protocols (e.g., Unix sockets)
AG_NET_INET4
Internet version 4 address.
AG_NET_INET6
Internet version 6 address.

The proto argument is an optional protocol number (see protocols(5)). The type argument may be set to:

AG_NET_SOCKET_NONE
Undefined
AG_NET_STREAM
Stream socket
AG_NET_DGRAM
Datagram socket
AG_NET_RAW
Raw-protocol interface
AG_NET_RDM
Reliably-delivered packet
AG_NET_SEQPACKET
Sequenced packet stream

The () function closes a socket, releasing all associated resources.

The () call establishes a connection between sock and a remote host (specified as a list containing one or more addresses to try).

The () call assigns a local protocol address addr, to the socket sock. The AG_NetAccept() function should be called on a socket that was previously assigned a local address. From the queue of pending connections, AG_NetAccept() extracts the first connection request and returns a newly-created socket for the connection.

The () routine closes the connection on sock (without destroying the socket).

The () and AG_NetWrite() routines move data between the socket and a specified buffer data of size bytes. On success, 0 is returned, and the number of bytes successfully read/written is returned in the nRead and nWrite argument (which can be NULL).

The () function returns the current value of the socket option opt into data. AG_NetSetOption() sets the specified socket option to the contents of data. The AG_NetGetOptionInt() and AG_NetSetOptionInt() shorthands accept integer arguments for int socket options. Available socket options are as follows (unless indicated otherwise, int is the data type).

Enable debugging on the socket
Reuse local addresses
Keep connections alive
Routing bypass for outgoing messages
Transmit broadcast messages
Allow binding to any address
Set buffer size for sending
Set buffer size for receiving
Set low watermark for sending
Set low watermark for receiving
Limit on incoming connection backlog
Receive out-of-band data inline (non-portable)
Allow address/port reuse (non-portable)
Receive datagram timestamps (non-portable)
Disable generation of SIGPIPE (non-portable)
Linger on () up to n seconds if data present (non-portable)
Kernel-based accept filter. The argument is a AG_NetAcceptFilter structure (non-portable)

The argument to AG_NET_ACCEPTFILTER is defined as follows:

typedef struct ag_net_accept_filter {
	char name[16];			/* Filter module name */
	char arg[240];			/* Argument */
} AG_NetAcceptFilter;

void
(AG_NetSocketSet *set);


void
(AG_NetSocketSet *set);


void
(AG_NetSocketSet *set);


int
(AG_NetSocketSet *nsInput, AG_NetSocketSet *nsRead, AG_NetSocketSet *nsWrite, AG_NetSocketSet *nsException, Uint32 timeout);

The
(); function initializes a new socket set.
AG_NetSocketSetClear(); resets a socket set to the empty set.
AG_NetSocketSetFree(); releases all resources allocated by a socket set.

The
(); function blocks the execution of the current thread until an event is reported on one or more of the sockets in the nsInput set. Sockets with data available for reading/writing are returned into the nsRead and nsWrite sets. Sockets with other exceptions (such as availability of out-of-band data) are returned into the nsExcept set. If the timeout argument is non-zero, the call will time out in the specified amount of time (given in milliseconds).

For the AG_NetAddr structure:

typedef struct ag_net_addr {
	enum ag_net_addr_family family;		/* Address family */
	int port;				/* Port number (if any) */
	union {
		struct {
			char  *path;		/* Unix socket path */
		} local;
		struct {
			Uint32 addr;		/* IPv4 address */
		} inet4;
		struct {
			Uint8  addr[16];	/* IPv6 address */
		} inet6;
	} data;
} AG_NetAddr;

For the AG_NetSocket structure:

enum ag_net_addr_family family
Address family
enum ag_net_socket_type type
Socket type
int proto
Socket protocol number
AG_Mutex lock
Exclusive access lock
AG_NetAddr *addrLocal
Bound local address
AG_NetAddr *addrRemote
Connected remote address
int fd
Socket file descriptor (non-portable)
void *p
Optional user-defined pointer

AG_Intro(3), AG_OpenNetSocket(3)

The AG_Net interface first appeared in Agar 1.5.0.

December 21, 2022 Agar 1.7

Search for    or go to Top of page |  Section 3 |  Main Index

Powered by GSP Visit the GSP FreeBSD Man Page Interface.
Output converted with ManDoc.