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

poslib/socket.h

Go to the documentation of this file.

  
00001 /* 00002 Posadis - A DNS Server 00003 Socket functions 00004 Copyright (C) 2002 Meilof Veeningen <> 00005 00006 This program is free software; you can redistribute it and/or modify 00007 it under the terms of the GNU General Public License as published by 00008 the Free Software Foundation; either version 2 of the License, or 00009 (at your option) any later version. 00010 00011 This program is distributed in the hope that it will be useful, 00012 but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00014 GNU General Public License for more details. 00015 00016 You should have received a copy of the GNU General Public License 00017 along with this program; if not, write to the Free Software 00018 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 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 /* udp socket functions */ 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 /* tcp socket functions */ 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 /* address functions */ 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 /* small watchset functions */ 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 /* __POSLIB_SOCKET_H */

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