jabberd2  2.3.1
Functions
inaddr.c File Reference

object like wrapper around struct sockaddr_storage More...

#include "util.h"

Go to the source code of this file.

Functions

int j_inet_pton (const char *src, struct sockaddr_storage *dst)
 set the address of a struct sockaddr_storage (modeled after the stdlib function inet_pton) More...
 
const char * j_inet_ntop (struct sockaddr_storage *src, char *dst, size_t size)
 get the string representation of an address in struct sockaddr_storage (modeled after the stdlib function inet_ntop) More...
 
int j_inet_getport (struct sockaddr_storage *sa)
 get the port number out of a struct sockaddr_storage More...
 
int j_inet_setport (struct sockaddr_storage *sa, in_port_t port)
 set the port number in a struct sockaddr_storage More...
 
socklen_t j_inet_addrlen (struct sockaddr_storage *sa)
 calculate the size of an address structure (on some unices the stdlibc functions for socket handling want to get the size of the address structure that is contained in the struct sockaddr_storage, not the size of struct sockaddr_storage itself) More...
 

Detailed Description

object like wrapper around struct sockaddr_storage

The functions in this file are used as a wrapper around struct sockaddr_storage to access this structure like an object. The structure is seen as an object that contains an IPv4 or an IPv6 address and these functions are the access methods to this object.

Warning
this is the same as mio/mio_inaddr.c - changes made here need to be made there too. is there anyway we can merge these without requiring mio to depend on util?

Definition in file inaddr.c.

Function Documentation

int j_inet_pton ( const char *  src,
struct sockaddr_storage dst 
)

set the address of a struct sockaddr_storage (modeled after the stdlib function inet_pton)

Parameters
srcthe address that should be assigned to the struct sockaddr_storage (either a dotted quad for IPv4 or a compressed IPv6 address)
dstthe struct sockaddr_storage that should get the new address
Returns
1 on success, 0 if address is not valid

Definition at line 46 of file inaddr.c.

References AF_INET6, sockaddr_in6::sin6_addr, and sockaddr_storage::ss_family.

Referenced by _mio_connect(), _mio_listen(), access_allow(), access_check(), and access_deny().

const char* j_inet_ntop ( struct sockaddr_storage src,
char *  dst,
size_t  size 
)

get the string representation of an address in struct sockaddr_storage (modeled after the stdlib function inet_ntop)

Parameters
srcthe struct sockaddr_storage where the address should be read
dstwhere to write the result
sizethe size of the result buffer
Returns
NULL if failed, pointer to the result otherwise

Definition at line 97 of file inaddr.c.

References AF_INET6, sockaddr_in6::sin6_addr, and sockaddr_storage::ss_family.

Referenced by _mio_accept().

int j_inet_getport ( struct sockaddr_storage sa)

get the port number out of a struct sockaddr_storage

Parameters
sathe struct sockaddr_storage where we want to read the port
Returns
the port number (already converted to host byte order!)

Definition at line 148 of file inaddr.c.

References AF_INET6, sockaddr_in6::sin6_port, and sockaddr_storage::ss_family.

Referenced by _c2s_client_mio_callback(), _mio_accept(), in_mio_callback(), and router_mio_callback().

int j_inet_setport ( struct sockaddr_storage sa,
in_port_t  port 
)

set the port number in a struct sockaddr_storage

Parameters
sathe struct sockaddr_storage where the port should be set
portthe port number that should be set (in host byte order)
Returns
1 on success, 0 if address family is not supported

Definition at line 173 of file inaddr.c.

References AF_INET6, sockaddr_in6::sin6_port, and sockaddr_storage::ss_family.

Referenced by _mio_connect(), and _mio_listen().

socklen_t j_inet_addrlen ( struct sockaddr_storage sa)

calculate the size of an address structure (on some unices the stdlibc functions for socket handling want to get the size of the address structure that is contained in the struct sockaddr_storage, not the size of struct sockaddr_storage itself)

Parameters
sathe struct sockaddr_storage for which we want to get the size of the contained address structure
Returns
the size of the contained address structure

Definition at line 203 of file inaddr.c.

References AF_INET6, and sockaddr_storage::ss_family.

Referenced by _mio_connect(), and _mio_listen().