Donate

You can make a donation if you'd like to support my work:


Contact

I deactivated the rating mechanism for now due to excessive spamming; while I got some interesting comments when I started it the current ratio is several hundred spam comments for one useful comment. If you have anything to say, please write an email to bwachter-hp@lart.info

libaard_network.h

Functions

netaddrinfo()

int netaddrinfo(const char *node, const char *service, const struct addrinfo *hints, struct addrinfo **res);

netaddrinfo() is just a wrapper around getaddrinfo() on systems which support getaddrinfo(). On systems which don't support getaddrinfo we emulate it using traditional socket functions. On windows we try to load getaddrinfo() from DLL and fall back to the emulation code at runtime if we need to.

netnameinfo()

int netnameinfo(const struct sockaddr *sa, socklen_t salen, 
						char *hostname, size_t hostlen, 
						char *servname, size_t servlen, int flags);

netnameinfo() is just a wrapper around getnameinfo() on systems which support it. In systems which don't we emulate it by using traditional socket functions. On windows we try to load it from DLL and fall back if we need to (just like netaddrinfo())

netconnect()

int netconnect(char *hostname, char *servicename);

netconnect() opens a socket to the host:service given as arguments and returns the socked file descriptor.

netsslstart()

int netsslstart(int sd);

netsslstart() negotiates a SSL session on a given file descriptor (which can be obtained by netconnect, for example)

netread()

int netread(int sd, char *buf);

netread() reads up to MAXNETBUF bytes from a given file descriptor and returns the number of bytes read. The read bytes are stored (NULL-terminated) in the buffer specified by buf. You need to make sure that buf has enough space for MAXNETBUF + 1 bytes.

netread(), as well as the following functions netreadline() and netwriteline() can handle both plaintext and SSL. If there's an open SSL connection they'll use SSL, if not they'll read/write plaintext.

netreadline()

int netreadline(int sd, char *buf);

netreadline() reads up to MAXNETBUF bytes from a given file descriptor. It stops if either \r\n or a NULL byte occurs. It returns the number of bytes read (and stored). Since strlen() can't cope with NULL bytes (it will take the first NULL byte as end of string) always use the return value, never use strlen() on the returned string.

netwriteline()

int netwriteline(int sd, char *buf);

netwriteline() writes the content of the buffer pointed to by buf to a given file descriptor. Since netwriteline() needs to find the end of the buffer no NULL bytes (except for the terminating one) are allowed in the input. It returns the number of bytes written.

netsslread()

int netsslread(SSL *ssl_handle, char *buf, int len);

netsslread() reads up to len bytes from a given SSL handle and stores them in the buffer pointed to by buf. You usually don't need this function -- netreadline() handles both encrypted and unencrypted connections.

netsslread() and netsslwrite() can cope with a certificate request from the server. If you have set a certificate (global variable am_sslkey keeps the pathname to the key) they will try to re-negotiate the handshake using your certificate once the server requests it.

netsslwrite()

int netsslwrite(SSL *ssl_handle, char *buf, int len);

netsslwrite() writes up to len bytes from the buffer pointed to by buf to a given SSL handle. You usually don't need this function -- netwriteline() handles both entcrypted and unencrypted connections.

netsocket()

int netsocket(struct addrinfo *ai);

netlogportservice()

void netlogportservice(const struct sockaddr *sa, socklen_t salen, char *msg);

Types

ibaard_network.h defines some types for use with MatrixSSL. However, MatrixSSL support is currently far from beeing usable

Constants

#define MAXNETBUF 1024
#define AM_SSL_ALLOWPLAIN 1
#define AM_SSL_USETLS 2
#define AM_SSL_STARTTLS 4

EAI_ADDRFAMILY and EAI_SYSTEM

#define EAI_ADDRFAMILY   -9    /* Address family for NAME not supported.  */
#define EAI_SYSTEM       -11   /* System error returned in `errno'.  */

EAI_ADDRFAMILY and EAI_SYSTEM are usually not defined under Windows. We only define them for Win32