libusual  0.1
Defines | Functions
usual/socket.h File Reference

Socket compat, few utils. More...

Defines

#define INADDR_NONE
 Compat: Some systems (Solaris) does not define INADDR_NONE.

Functions

bool socket_setup (int sock, bool non_block)
 Usual socket setup.
bool socket_set_nonblocking (int sock, bool non_block)
 Flip sockets non-blocking flag.
bool socket_set_keepalive (int fd, int onoff, int keepidle, int keepintvl, int keepcnt)
 Set sockets keepalive flags.
const char * sa2str (const struct sockaddr *sa, char *buf, int buflen)
 Convert struct sockaddr to stirng.
const char * inet_ntop (int af, const void *src, char *dst, int cnt)
 Compat: inet_ntop()
int inet_pton (int af, const char *src, void *dst)
 Compat: inet_pton()
int getpeereid (int fd, uid_t *uid_p, gid_t *gid_p)
 Get user id of UNIX socket peer.
int getpeercreds (int fd, uid_t *uid_p, gid_t *gid_p, pid_t *pid_p)
 Get info of UNIX socket peer.
int poll (struct pollfd *fds, nfds_t nfds, int timeout_ms)
 Compat: select-based poll()

Detailed Description

Socket compat, few utils.

Socket headers included:


Define Documentation

#define INADDR_NONE

Compat: Some systems (Solaris) does not define INADDR_NONE.


Function Documentation

bool socket_setup ( int  sock,
bool  non_block 
)

Usual socket setup.

bool socket_set_nonblocking ( int  sock,
bool  non_block 
)

Flip sockets non-blocking flag.

bool socket_set_keepalive ( int  fd,
int  onoff,
int  keepidle,
int  keepintvl,
int  keepcnt 
)

Set sockets keepalive flags.

Parameters:
fdTCP socket
onoffWhether to set keepalive on or off.
keepidleHow long the socket must be idle before keepalive packets are sent
keepintvlHow big period between consecutive keepalive packets.
keepcntHow many keepalive packets to send before considering socket dead.
const char* sa2str ( const struct sockaddr *  sa,
char *  buf,
int  buflen 
)

Convert struct sockaddr to stirng.

Supports: ipv4, ipv5, unix sockets.

const char* inet_ntop ( int  af,
const void *  src,
char *  dst,
int  cnt 
)

Compat: inet_ntop()

int inet_pton ( int  af,
const char *  src,
void *  dst 
)

Compat: inet_pton()

int getpeereid ( int  fd,
uid_t *  uid_p,
gid_t *  gid_p 
)

Get user id of UNIX socket peer.

int getpeercreds ( int  fd,
uid_t *  uid_p,
gid_t *  gid_p,
pid_t *  pid_p 
)

Get info of UNIX socket peer.

int poll ( struct pollfd *  fds,
nfds_t  nfds,
int  timeout_ms 
)

Compat: select-based poll()