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

poslib/socket.h File Reference

system-indepent socket functions More...

Go to the source code of this file.


Classes

class   smallset_t
  checks whether data is avaiable on sockets More...


Defines

#define  UDP_MSG_SIZE   512 /**< Maximum size of an UDP packet. */
#define  TCP_MSG_SIZE   65536 /**< Maximum size of a TCP packet. */
#define  DNS_PORT   53 /**< Default port for DNS. */
#define  T_UDP   1 /**< Constant for UDP connections. */
#define  T_TCP   2 /**< Constant for TCP connections. */

Typedefs

typedef sockaddr_storage  _addr
  address type


Functions

int  udpcreateserver (_addr *a)
void  udpclose (int sockid)
int  udpread (int sockid, char *buff, int len, _addr *addr)
void  udpsend (int sockid, char *buff, int len, _addr *addr)
int  tcpcreateserver (_addr *a)
int  tcpopen (_addr *a)
void  tcpclose (int sockid)
int  tcpaccept (int sockid, _addr *addr)
int  tcpsend (int sockid, char *buff, int len)
void  tcpsendall (int sockid, char *buff, int len, int maxtime)
int  tcpread (int sockid, char *buff, int len)
void  tcpreadall (int sockid, char *buff, int len, int maxtime)
bool  tcpisopen (int sockid)
void  getaddress_ip4 (_addr *res, const char *ipv4_data, int port=0)
void  getaddress_ip6 (_addr *res, const char *ipv6_data, int port=0)
void  getaddress (_addr *res, const char *data, int port=0)
bool  address_lookup (_addr *res, const char *name, int port)
void  addr_setport (_addr *addr, int port)
int  addr_getport (_addr *addr)
bool  address_matches (_addr *a1, _addr *a2)
bool  addrport_matches (_addr *a1, _addr *a2)
bool  sock_is_ipv6 (_addr *a)
bool  addr_is_ipv6 (_addr *a)
bool  sock_is_ipv4 (_addr *a)
bool  addr_is_ipv4 (_addr *a)
char *  get_ipv4_ptr (_addr *a)
char *  get_ipv6_ptr (_addr *a)
stl_string  addr_to_string (_addr *addr, bool include_port=true)
int  getprotocolbyname (const char *name)
  returns the internet protocol ID from name

int  getserviceportbyname (const char *name)
  returns the internet service port from name


Variables

bool  posclient_quitflag

Detailed Description

system-indepent socket functions

System-indepent socket functions.

Definition in file socket.h.


Define Documentation

#define DNS_PORT   53 /**< Default port for DNS. */
 

Default port for DNS.

Definition at line 44 of file socket.h.

#define T_TCP   2 /**< Constant for TCP connections. */
 

Constant for TCP connections.

Definition at line 47 of file socket.h.

#define T_UDP   1 /**< Constant for UDP connections. */
 

Constant for UDP connections.

Definition at line 46 of file socket.h.

#define TCP_MSG_SIZE   65536 /**< Maximum size of a TCP packet. */
 

Maximum size of a TCP packet.

Definition at line 42 of file socket.h.

#define UDP_MSG_SIZE   512 /**< Maximum size of an UDP packet. */
 

Maximum size of an UDP packet.

Definition at line 41 of file socket.h.


Typedef Documentation

typedef sockaddr_storage _addr
 

address type

This type offers a system-independent type representing an IPv4/IPv6 address. Internally, this is a typedef to sockaddr_storage.

Definition at line 39 of file socket.h.


Function Documentation

int addr_getport _addr addr  ) 
 

Gets the port of an _addr structure.

bool addr_is_ipv4 _addr a  ) 
 

Checks whether the address is an IPv6 address.

bool addr_is_ipv6 _addr a  ) 
 

Checks whether the address is an IPv4 address.

void addr_setport _addr addr,
int  port
 

Sets the port of an _addr structure.

stl_string addr_to_string _addr addr,
bool  include_port = true
 

Converts the _addr structure to a human-readable string.

bool address_lookup _addr res,
const char *  name,
int  port
 

Looks up the specified domain name using the system resolver, and creates an _addr structure.

bool address_matches _addr a1,
_addr a2
 

Checks whether both _addr structures point to the same address.

bool addrport_matches _addr a1,
_addr a2
 

Checks whether both _addr structures point to the same address and port.

char* get_ipv4_ptr _addr a  ) 
 

Returns pointer to the four bytes of the IPv4 address.

char* get_ipv6_ptr _addr a  ) 
 

Returns pointer to the sixteen bytes of the IPv6 address.

void getaddress _addr res,
const char *  data,
int  port = 0
 

Converts an textual address (either IPv4/IPv6) to an _addr structure.

void getaddress_ip4 _addr res,
const char *  ipv4_data,
int  port = 0
 

Converts an IPv4 textual address to an _addr structure.

void getaddress_ip6 _addr res,
const char *  ipv6_data,
int  port = 0
 

Converts an IPv6 textual address to an _addr structure.

int getprotocolbyname const char *  name  ) 
 

returns the internet protocol ID from name

Uses the system's getprotobyname() function to look up the service ID for a given protocol (usually, "udp" or "tcp"). Additionally, if the given string is a number, it will return that number.

Parameters:
name  The protocol name
Returns:
The internet protocol ID

int getserviceportbyname const char *  name  ) 
 

returns the internet service port from name

Uses the system's getservbyname() function to look up the port for a given service (for example, "http" or "ftp"). Additionally, if the given string is a number, it will return that number.

Parameters:
name  The service name
Returns:
The service port

bool sock_is_ipv4 _addr a  ) 
 

Checks whether the address is an IPv6 address (obsolete, use addr_is_ipv4).

bool sock_is_ipv6 _addr a  ) 
 

Checks whether the address is an IPv4 address (obsolete, use addr_is_ipv6).

int tcpaccept int  sockid,
_addr addr
 

Accepts a client connection on a TCP server connection.

void tcpclose int  sockid  ) 
 

Closes a TCP client/server connection.

int tcpcreateserver _addr a  ) 
 

Opens a TCP server at the specified address/port, returning the socket id.

bool tcpisopen int  sockid  ) 
 

Checks whether the TCP connection is still open.

int tcpopen _addr a  ) 
 

Opens a TCP client connection to the specified server.

int tcpread int  sockid,
char *  buff,
int  len
 

Reads data from the TCP connection. Doesn't guarantee all data is read, but returns immediately.

void tcpreadall int  sockid,
char *  buff,
int  len,
int  maxtime
 

Reads len bytes through the TCP connection. Take at most maxtime milliseconds.

int tcpsend int  sockid,
char *  buff,
int  len
 

Sends data through the TCP connection. Doesn't guarantee all data is sent, but returns immediately.

void tcpsendall int  sockid,
char *  buff,
int  len,
int  maxtime
 

Sends all data through the TCP connection. Take at most maxtime milliseconds.

void udpclose int  sockid  ) 
 

Closes an UDP connection, both server and client.

int udpcreateserver _addr a  ) 
 

Opens an UDP server at the specified address/port, returning the socket id.

int udpread int  sockid,
char *  buff,
int  len,
_addr addr
 

Reads data from an UDP connection. The address of the sender is put in addr.

void udpsend int  sockid,
char *  buff,
int  len,
_addr addr
 

Sends data to the specified server through UDP.


Variable Documentation

bool posclient_quitflag
 

Set to true if you want to close down your application when sockets might still be active.

Definition at line 51 of file socket.h.


Generated on Fri Dec 24 19:55:16 2004 for Poslib by doxygen 1.3.7