Dibbler - a portable DHCPv6  1.0.2RC1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
socket.h
Go to the documentation of this file.
1 /*
2  Posadis - A DNS Server
3  Socket functions
4  Copyright (C) 2002 Meilof Veeningen <meilof@users.sourceforge.net>
5 
6  This program is free software; you can redistribute it and/or modify
7  it under the terms of the GNU General Public License as published by
8  the Free Software Foundation; either version 2 of the License, or
9  (at your option) any later version.
10 
11  This program is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  GNU General Public License for more details.
15 
16  You should have received a copy of the GNU General Public License
17  along with this program; if not, write to the Free Software
18  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19 */
20 
21 #ifndef __POSLIB_SOCKET_H
22 #define __POSLIB_SOCKET_H
23 
24 #include "syssocket.h"
25 #include "sysstl.h"
26 
40 
41 #define UDP_MSG_SIZE 512
42 #define TCP_MSG_SIZE 65536
44 #define DNS_PORT 53
46 #define T_UDP 1
47 #define T_TCP 2
51 extern bool posclient_quitflag;
52 
53 /* udp socket functions */
54 
56 int udpcreateserver(_addr *a);
58 void udpclose(int sockid);
59 
61 int udpread(int sockid, const char *buff, int len, _addr *addr);
62 
64 void udpsend(int sockid, const char *buff, int len, _addr *addr);
65 
66 /* tcp socket functions */
67 
69 int tcpcreateserver(_addr *a);
71 int tcpopen(_addr *a);
73 int tcpopen_from(_addr *to, _addr *source);
75 void tcpclose(int sockid);
77 int tcpaccept(int sockid, _addr *addr);
78 
80 int tcpsend(int sockid, const char *buff, int len);
82 void tcpsendall(int sockid, const char *buff, int len, int maxtime);
84 int tcpread(int sockid, const char *buff, int len);
86 void tcpreadall(int sockid, const char *buff, int len, int maxtime);
87 
89 bool tcpisopen(int sockid);
90 
91 /* address functions */
92 
94 void getaddress_ip4(_addr *res, const unsigned char *ipv4_data, int port = 0);
95 
97 void getaddress_ip6(_addr *res, const unsigned char *ipv6_data, int port = 0);
99 void getaddress(_addr *res, const char *data, int port = 0);
101 bool address_lookup(_addr *res, const char *name, int port);
102 
104 void addr_setport(_addr *addr, int port);
106 int addr_getport(_addr *addr);
107 
109 bool address_matches(_addr *a1, _addr *a2);
111 bool addrport_matches(_addr *a1, _addr *a2);
112 
114 bool sock_is_ipv6(_addr *a);
116 bool addr_is_ipv6(_addr *a);
118 bool sock_is_ipv4(_addr *a);
120 bool addr_is_ipv4(_addr *a);
121 
123 unsigned char *get_ipv4_ptr(_addr *a);
124 
125 bool addr_is_any(_addr *addr);
126 bool addr_is_none(_addr *addr);
129 unsigned char* get_ipv6_ptr(_addr *a);
130 
132 stl_string addr_to_string(const _addr *addr, bool include_port = true);
133 
134 /* small watchset functions */
135 
143 class smallset_t {
144  public:
145  smallset_t();
146  ~smallset_t();
148  void init(int ix);
149  void set(int ix, int socket);
151  void check();
152  void waitwrite(int msecs);
153  void wait(int msecs);
155  bool canwrite(int ix);
156  bool isdata(int ix);
157  bool iserror(int ix);
158  bool ishup(int ix);
160  private:
161  void runpoll(int msecs);
162  void destroy();
163  int nitems;
165 };
166 
177 int getprotocolbyname(const char *name);
178 
189 int getserviceportbyname(const char *name);
190 
191 #endif /* __POSLIB_SOCKET_H */
192