Simple Socket


Detailed Description

Copyright (C) 2007-2008 Ola Lundqvist <ola@inguza.com>

All rights reserved.

Simple Socket is a library to simplify the handling of sockets.

All functions with a container (unless declared with const) will write data to the container parameter related to the other parameters in the same function call.

The following naming convention for the functions are used:


Data Structures

struct  socketContainer_t

Defines

#define IP_ERROR_NO_PROTO   -2
#define IP_ERROR_NULL_PROTO   -3
#define IP_ERROR_UNKNOWN_ADDRESS   0xffffffff

Functions

int ipv4_proto_s (char *proto)
int ipv4_dgram_socket_s (char *proto)
int ipv4_stream_socket_s (char *proto)
short ipv4_service_ss (char *proto, char *service)
short ipv4_service_h (short service)
long int ipv4_address_s (const char *address)
int ipv4_udp_bind_ss (struct socketContainer_t *container, char *service, char *address)
int ipv4_udp_bind_hs (struct socketContainer_t *container, short service, char *address)
int ipv4_udp_bind_ns (struct socketContainer_t *container, short service, char *address)
int ipv4_tcp_bind_ss (struct socketContainer_t *container, char *service, char *address)
int ipv4_tcp_bind_hs (struct socketContainer_t *container, short service, char *address)
int ipv4_tcp_bind_ns (struct socketContainer_t *container, short service, char *address)
int ipv4_tcp_listen_ss (struct socketContainer_t *container, char *service, char *address, int max)
int ipv4_tcp_listen_hs (struct socketContainer_t *container, short service, char *address, int max)
int ipv4_tcp_listen_ns (struct socketContainer_t *container, short service, char *address, int max)
int ipv4_tcp_connect_ss (struct socketContainer_t *container, char *service, char *address)
int ipv4_tcp_connect_hs (struct socketContainer_t *container, short service, char *address)
int ipv4_tcp_connect_ns (struct socketContainer_t *container, short service, char *address)
int ipv4_tcp_accept (const struct socketContainer_t *listen_cont, struct socketContainer_t *client_cont)


Define Documentation

#define IP_ERROR_NO_PROTO   -2

See also:
ipv4_proto_s

#define IP_ERROR_NULL_PROTO   -3

See also:
ipv4_proto_s

#define IP_ERROR_UNKNOWN_ADDRESS   0xffffffff

See also:
ipv4_address_s


Function Documentation

long int ipv4_address_s ( const char *  address  ) 

Get an IP number

Parameters:
address Host name or IP address as string
Returns:
  • IP address as long integer
  • IP_ERROR_UNKNOWN_ADDRESS if the address is unknown

int ipv4_dgram_socket_s ( char *  proto  ) 

Create a datagram socket.

Parameters:
proto Protocol string
Returns:
  • socket number
  • 0 if no match for string

int ipv4_proto_s ( char *  proto  ) 

Get IPv4 protocol number from name.

Parameters:
proto Protocol string
Returns:
  • protocol number
  • IP_ERROR_NULL_PROTO if the parameter is NULL
  • IP_ERROR_NO_PROTO if there are no match for the protocol string.

short ipv4_service_h ( short  service  ) 

Get a service port number

Parameters:
service Service number in host byte order.
Returns:
Service number in network byte order.

short ipv4_service_ss ( char *  proto,
char *  service 
)

Get a service port number

Parameters:
proto Protocol string
service Service name or number as string
Returns:
service number with network byte order

int ipv4_stream_socket_s ( char *  proto  ) 

Create a stream socket.

Parameters:
proto Protocol string
Returns:
socket number

int ipv4_tcp_accept ( const struct socketContainer_t listen_cont,
struct socketContainer_t client_cont 
)

Accept connection for a TCP port. The new socket is set in client_cont, so make sure to close appropriately.

Parameters:
listen_cont Socket container with socket to listen to.
client_cont Socket container with information of client. Make sure that this parameter is initialized to zero, or specified to a specific client that is allowed.
Returns:
  • 0 on success.
  • -1 on failure.

int ipv4_tcp_bind_hs ( struct socketContainer_t container,
short  service,
char *  address 
)

Bind to a TCP port A new socket is always created, so make sure that is closed appropriately.

See also:
ipv4_tcp_listen_hs
Parameters:
container Socket container.
service Service number in host byte order.
address Name or IP address as string (NULL gives 0.0.0.0).
Returns:
  • 0 on success.
  • -1 on failure.

int ipv4_tcp_bind_ns ( struct socketContainer_t container,
short  service,
char *  address 
)

Bind to a TCP port A new socket is always created, so make sure that is closed appropriately.

See also:
ipv4_tcp_listen_ns
Parameters:
container Socket container.
service Service number in network byte order.
address Name or IP address as string (NULL gives 0.0.0.0).
Returns:
  • 0 on success.
  • -1 on failure.

int ipv4_tcp_bind_ss ( struct socketContainer_t container,
char *  service,
char *  address 
)

Bind to a TCP port A new socket is always created, so make sure that is closed appropriately.

See also:
ipv4_tcp_listen_ss
Parameters:
container Socket container.
service Service name or number as string.
address Name or IP address as string (NULL gives 0.0.0.0).
Returns:
  • 0 on success.
  • -1 on failure.

int ipv4_tcp_connect_hs ( struct socketContainer_t container,
short  service,
char *  address 
)

Connect to a TCP port A new socket is always created, so make sure that is closed appropriately.

Parameters:
container Socket container.
service Service number in host byte order.
address Name or IP address as string.
Returns:
  • 0 on success.
  • -1 on failure.

int ipv4_tcp_connect_ns ( struct socketContainer_t container,
short  service,
char *  address 
)

Connect to a TCP port A new socket is always created, so make sure that is closed appropriately.

Parameters:
container Socket container.
service Service number in network byte order.
address Name or IP address as string.
Returns:
  • 0 on success.
  • -1 on failure.

int ipv4_tcp_connect_ss ( struct socketContainer_t container,
char *  service,
char *  address 
)

Connect to a TCP port A new socket is always created, so make sure that is closed appropriately.

Parameters:
container Socket container.
service Service name or number as string.
address Name or IP address as string.
Returns:
  • 0 on success.
  • -1 on failure.

int ipv4_tcp_listen_hs ( struct socketContainer_t container,
short  service,
char *  address,
int  max 
)

Listen to a TCP port A new socket is always created, so make sure that is closed appropriately.

Parameters:
container Socket container.
service Service number in host byte order.
address Name or IP address as string (NULL gives 0.0.0.0).
max Maximum number of clients to handle
Returns:
  • 0 on success.
  • -1 on failure.

int ipv4_tcp_listen_ns ( struct socketContainer_t container,
short  service,
char *  address,
int  max 
)

Listen to a TCP port A new socket is always created, so make sure that is closed appropriately.

Parameters:
container Socket container.
service Service number in network byte order.
address Name or IP address as string (NULL gives 0.0.0.0).
max Maximum number of clients to handle
Returns:
  • 0 on success.
  • -1 on failure.

int ipv4_tcp_listen_ss ( struct socketContainer_t container,
char *  service,
char *  address,
int  max 
)

Listen to a TCP port A new socket is always created, so make sure that is closed appropriately.

Parameters:
container Socket container.
service Service name or number as string.
address Name or IP address as string (NULL gives 0.0.0.0).
max Maximum number of clients to handle
Returns:
  • 0 on success.
  • -1 on failure.

int ipv4_udp_bind_hs ( struct socketContainer_t container,
short  service,
char *  address 
)

Bind to an UDP port A new socket is always created, so make sure that is closed appropriately.

Parameters:
container Socket container.
service Service number in host byte order.
address Name or IP address as string (NULL gives 0.0.0.0).
Returns:
  • 0 on success.
  • -1 on failure.

int ipv4_udp_bind_ns ( struct socketContainer_t container,
short  service,
char *  address 
)

Bind to an UDP port A new socket is always created, so make sure that is closed appropriately.

Parameters:
container Socket container.
service Service number in network byte order.
address Name or IP address as string (NULL gives 0.0.0.0).
Returns:
  • 0 on success.
  • -1 on failure.

int ipv4_udp_bind_ss ( struct socketContainer_t container,
char *  service,
char *  address 
)

Bind to an UDP port A new socket is always created, so make sure that is closed appropriately.

Parameters:
container Socket container.
service Service name or number as string.
address Name or IP address as string (NULL gives 0.0.0.0).
Returns:
  • 0 on success.
  • -1 on failure.


Generated on Mon Apr 7 22:13:48 2008 for SocketDispatcher by  doxygen 1.5.1