00001 00002 00003 00004 00005 00006 00007 00008 00009 00010 00011 00012 00013 00014 00015 00016 00017 00018 00019 00020 00021
#ifndef __POSLIB_SOCKET_H 00022
#define __POSLIB_SOCKET_H 00023
00024
#include "syssocket.h" 00025
#include "sysstl.h" 00026
00039 typedef sockaddr_storage
_addr; 00040
00041 #define UDP_MSG_SIZE 512 00042 #define TCP_MSG_SIZE 65536 00044 #define DNS_PORT 53 00046 #define T_UDP 1 00047 #define T_TCP 2 00051 extern bool posclient_quitflag; 00052
00053 00054 00056
int udpcreateserver(_addr *a); 00058
void udpclose(
int sockid); 00059 00061
int udpread(
int sockid,
char *buff,
int len, _addr *addr); 00062 00064
void udpsend(
int sockid,
char *buff,
int len, _addr *addr); 00065 00066 00067 00069
int tcpcreateserver(_addr *a); 00071
int tcpopen(_addr *a); 00073
void tcpclose(
int sockid); 00075
int tcpaccept(
int sockid, _addr *addr); 00076 00078
int tcpsend(
int sockid,
char *buff,
int len); 00080
void tcpsendall(
int sockid,
char *buff,
int len,
int maxtime); 00082
int tcpread(
int sockid,
char *buff,
int len); 00084
void tcpreadall(
int sockid,
char *buff,
int len,
int maxtime); 00085 00087
bool tcpisopen(
int sockid); 00088 00089 00090 00092
void getaddress_ip4(_addr *res,
const char *ipv4_data,
int port = 0); 00093
#ifdef HAVE_IPV6 00094
00095
void getaddress_ip6(_addr *res,
const char *ipv6_data,
int port = 0); 00096
#endif 00097
00098
void getaddress(_addr *res,
const char *data,
int port = 0); 00100
bool address_lookup(_addr *res,
const char *name,
int port); 00101 00103
void addr_setport(_addr *addr,
int port); 00105
int addr_getport(_addr *addr); 00106 00108
bool address_matches(_addr *a1, _addr *a2); 00110
bool addrport_matches(_addr *a1, _addr *a2); 00111 00113
bool sock_is_ipv6(_addr *a); 00115
bool addr_is_ipv6(_addr *a); 00117
bool sock_is_ipv4(_addr *a); 00119
bool addr_is_ipv4(_addr *a); 00120 00122
char *
get_ipv4_ptr(_addr *a); 00124
#ifdef HAVE_IPV6 00125
char *
get_ipv6_ptr(_addr *a); 00126
#endif 00127
00129 stl_string
addr_to_string(_addr *addr,
bool include_port =
true); 00130 00131 00132
00140 class smallset_t { 00141
public: 00142
smallset_t(); 00143
~smallset_t(); 00145
void init(
int ix); 00146
void set(
int ix,
int socket); 00148
void check(); 00149
void waitwrite(
int msecs); 00150
void wait(
int msecs); 00152
bool canwrite(
int ix); 00153
bool isdata(
int ix); 00154
bool iserror(
int ix); 00155
bool ishup(
int ix); 00157
private: 00158
void runpoll(
int msecs); 00159
void destroy(); 00160
int nitems; 00161 pollfd *items; 00162 }; 00163 00174
int getprotocolbyname(
const char *name); 00175 00186
int getserviceportbyname(
const char *name); 00187 00188
#endif