Main Page | Class List | File List | Class Members | File Members | Related Pages

gi_sockapi.h File Reference

Simple, portable procedural wrappers for the BSD socket API. More...

#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <netdb.h>

Go to the source code of this file.

Defines

#define AF_UNIX   AF_INET
#define AF_LOCAL   AF_UNIX
#define gi_sockin_connect(fd, saddr, len)   gi_sock_connect(fd,(struct sockaddr*)saddr,len)
#define gi_sockun_connect(fd, saddr, len)   gi_sockin_connect(fd,saddr,len)
#define gi_sockin_accept(fd, saddr, len)   gi_sock_accept(fd,(struct sockaddr*)saddr,len)
#define gi_sockun_accept(fd, saddr, len)   gi_sockin_accept(fd,saddr,len)
#define gi_sockin_bind(fd, saddr, len)   gi_sock_bind(fd,(struct sockaddr*)saddr,len)
#define gi_sockun_bind(fd, saddr, len)   gi_sockin_bind(fd,saddr,len)
#define gi_sockin_peername(fd, name, len)   gi_sock_peername(fd,(struct sockaddr*)name,len)
#define gi_sockun_peername(fd, name, len)   gi_sockin_peername(fd,name,len)
#define gi_sockin_name(fd, name, len)   gi_sock_name(fd,(struct sockaddr*)name,len)
#define gi_sockun_name(fd, name, len)   gi_sockin_name(fd,name,len)
#define gi_sockin_recvfrom(fd, buf, buf_len, flags, src, src_len)   gi_sock_recvfrom(fd,buf,buf_len,flags,(struct sockaddr*)src,src_len)
#define gi_sockun_recvfrom(fd, buf, buf_len, flags, src, src_len)   gi_sockin_recvfrom(fd,buf,buf_len,flags,src,src_len)
#define gi_sockin_sendto(fd, buf, buf_len, flags, dst, dst_len)   gi_sock_sendto(fd,buf,buf_len,flags,(struct sockaddr*)dst,dst_len)

Functions

EXTERN_C_BEGIN LIBGIFT_EXPORT
int 
gi_sock_init (void)
LIBGIFT_EXPORT int gi_sock_finish (void)
LIBGIFT_EXPORT int gi_sock_errno (void)
LIBGIFT_EXPORT char * gi_sock_strerror (int errno_ish)
LIBGIFT_EXPORT char * gi_sock_strerrno (void)
LIBGIFT_EXPORT int gi_sock_close (int fd)
LIBGIFT_EXPORT int gi_sock_connect (int fd, struct sockaddr *saddr, size_t len)
LIBGIFT_EXPORT int gi_sock_accept (int fd, struct sockaddr *saddr, size_t *len)
LIBGIFT_EXPORT int gi_sock_bind (int fd, struct sockaddr *saddr, size_t len)
LIBGIFT_EXPORT int gi_sock_blocking (int fd, bool blocking)
LIBGIFT_EXPORT int gi_sock_getopt (int fd, int level, int name, void *opt, size_t *len)
LIBGIFT_EXPORT int gi_sock_setopt (int fd, int level, int name, const void *opt, size_t len)
LIBGIFT_EXPORT int gi_sock_peername (int fd, struct sockaddr *name, size_t *len)
LIBGIFT_EXPORT int gi_sock_name (int fd, struct sockaddr *name, size_t *len)
LIBGIFT_EXPORT int gi_sock_recvfrom (int fd, void *buf, size_t buf_len, int flags, struct sockaddr *src, size_t *src_len)
LIBGIFT_EXPORT int gi_sock_sendto (int fd, const void *buf, size_t buf_len, int flags, struct sockaddr *dst, size_t dst_len)
LIBGIFT_EXPORT int gi_sock_recv (int fd, void *buf, size_t buf_len, int flags)
LIBGIFT_EXPORT int gi_sock_send (int fd, const void *buf, size_t buf_len, int flags)
LIBGIFT_EXPORT int gi_inet_pton (int family, const char *src, void *dst)
LIBGIFT_EXPORT char * gi_inet_ntop (int family, const void *src, char *dst, size_t dst_len)
LIBGIFT_EXPORT int socketpair (int family, int type, int protocol, int sv[2])


Detailed Description

Simple, portable procedural wrappers for the BSD socket API.

The primary focus of these wrappers is for portability and type cleanliness in the places where the BSD standard disagrees with widely adopted implementations.


Function Documentation

LIBGIFT_EXPORT char* gi_inet_ntop int  family,
const void *  src,
char *  dst,
size_t  dst_len
 

Portable wrapper for inet_ntop() which also fudges calling parameters.

LIBGIFT_EXPORT int gi_inet_pton int  family,
const char *  src,
void *  dst
 

Portable wrapper for inet_pton().

LIBGIFT_EXPORT int gi_sock_accept int  fd,
struct sockaddr *  saddr,
size_t *  len
 

Wrapper for accept() which fudges calling parameters.

LIBGIFT_EXPORT int gi_sock_bind int  fd,
struct sockaddr *  saddr,
size_t  len
 

Wrapper for bind() which fudges calling parameters.

LIBGIFT_EXPORT int gi_sock_blocking int  fd,
bool  blocking
 

Explicit interface for switching blocking I/O on the supplied socket file descriptor. Currently supports fcntl() on POSIX systems and ioctlsocket() on Windows.

Returns:
On success, zero is returned; on error, -1.

LIBGIFT_EXPORT int gi_sock_close int  fd  ) 
 

Similar to the POSIX close(), but supports the WinSock API as well.

LIBGIFT_EXPORT int gi_sock_connect int  fd,
struct sockaddr *  saddr,
size_t  len
 

Wrapper for connect() which fudges calling parameters and the return value to clean up the POSIX socklen_t mess through an indirect wrapper. The third argument is actually supposed to be an int, but through POSIX confusion became size_t, then finally socklen_t.

It is this author's opinion that size_t was in fact the correct way to specify the size of `saddr', but we will need a wrapper to remain portable if that is indeed what we plan to use.

Returns:
Identical to connect() except that the error EINPROGRESS is translated to a successful return in the interest of portability.

LIBGIFT_EXPORT int gi_sock_errno void   ) 
 

Platfrom-independent accessor for errno assigned from socket operations. Windows uses an isolated set of errors for C89/POSIX than WinSock2.

LIBGIFT_EXPORT int gi_sock_finish void   ) 
 

Cleanup the socket subsystem. Again, this is only required for WinSock and has no effect whatsoever on UNIX machines.

Returns:
On success, 0 is returned; otherwise, -1 and the special socket errno will be set.

LIBGIFT_EXPORT int gi_sock_getopt int  fd,
int  level,
int  name,
void *  opt,
size_t *  len
 

Wrapper for getsockopt() which fudges the widely confused `opt' and `len' parameters in order to remain consistent with our own usage.

EXTERN_C_BEGIN LIBGIFT_EXPORT int gi_sock_init void   ) 
 

Initialize the socket subsystem. This is required for WinSock initialization.

Returns:
On success, 0 is returned; otherwise, -1 and the special socket errno will be set.

LIBGIFT_EXPORT int gi_sock_name int  fd,
struct sockaddr *  name,
size_t *  len
 

Wrapper for getsockname() which fudges calling paramters.

LIBGIFT_EXPORT int gi_sock_peername int  fd,
struct sockaddr *  name,
size_t *  len
 

Wrapper for getpeername() which fudges calling parameters.

LIBGIFT_EXPORT int gi_sock_recv int  fd,
void *  buf,
size_t  buf_len,
int  flags
 

Wrapper for recv() which fudges calling parameters and the return value on some platforms.

LIBGIFT_EXPORT int gi_sock_recvfrom int  fd,
void *  buf,
size_t  buf_len,
int  flags,
struct sockaddr *  src,
size_t *  src_len
 

Wrapper for recvfrom() which fudges calling parameters and the return value on some platforms.

LIBGIFT_EXPORT int gi_sock_send int  fd,
const void *  buf,
size_t  buf_len,
int  flags
 

Wrapper for send() which fudges calling parameters and the return value on some platforms.

LIBGIFT_EXPORT int gi_sock_sendto int  fd,
const void *  buf,
size_t  buf_len,
int  flags,
struct sockaddr *  dst,
size_t  dst_len
 

Wrapper for sendto() which fudges calling parameters and the return value on some platforms.

LIBGIFT_EXPORT int gi_sock_setopt int  fd,
int  level,
int  name,
const void *  opt,
size_t  len
 

Wrapper for setsockopt() which accomplishes the same goals as gi_sock_getopt.

LIBGIFT_EXPORT char* gi_sock_strerrno void   ) 
 

Wrapper for gi_sock_strerror (gi_sock_errno()). This convention is mirrored by gi_strerrno in gi_string.c

LIBGIFT_EXPORT char* gi_sock_strerror int  errno_ish  ) 
 

Platform-independent strerror() wrapper/replacement.

LIBGIFT_EXPORT int socketpair int  family,
int  type,
int  protocol,
int  sv[2]
 

Emulate BSD 4.4 socketpair().

Parameters:
family Protocol family. Currently only AF_LOCAL and AF_INET are supported by this implementation.
type Socket type. Currently only SOCK_STREAM and SOCK_DGRAM is supported.
sv Created end-point descriptors.


Generated on Sun Aug 22 07:56:40 2004 by doxygen 1.3.7