]> git.ipfire.org Git - thirdparty/squid.git/blob - tools/purge/convert.hh
Merge from trunk
[thirdparty/squid.git] / tools / purge / convert.hh
1 //
2 // $Id: convert.hh,v 1.2 1999/01/19 11:00:50 voeckler Exp $
3 //
4 // Author: Jens-S. V?ckler <voeckler@rvs.uni-hannover.de>
5 //
6 // File: convert.hh
7 // Thu Oct 30 1997
8 //
9 // (c) 1997 Lehrgebiet Rechnernetze und Verteilte Systeme
10 // Universit?t Hannover, Germany
11 //
12 // Permission to use, copy, modify, distribute, and sell this software
13 // and its documentation for any purpose is hereby granted without fee,
14 // provided that (i) the above copyright notices and this permission
15 // notice appear in all copies of the software and related documentation,
16 // and (ii) the names of the Lehrgebiet Rechnernetze und Verteilte
17 // Systeme and the University of Hannover may not be used in any
18 // advertising or publicity relating to the software without the
19 // specific, prior written permission of Lehrgebiet Rechnernetze und
20 // Verteilte Systeme and the University of Hannover.
21 //
22 // THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND,
23 // EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY
24 // WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
25 //
26 // IN NO EVENT SHALL THE LEHRGEBIET RECHNERNETZE UND VERTEILTE SYSTEME OR
27 // THE UNIVERSITY OF HANNOVER BE LIABLE FOR ANY SPECIAL, INCIDENTAL,
28 // INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND, OR ANY DAMAGES
29 // WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER OR NOT
30 // ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF LIABILITY,
31 // ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
32 // SOFTWARE.
33 //
34 // Revision 1.2 1999/01/19 11:00:50 voeckler
35 // added bool type workaround.
36 //
37 // Revision 1.1 1998/08/13 21:38:04 voeckler
38 // Initial revision
39 //
40 //
41 #ifndef _CONVERT_HH
42 #define _CONVERT_HH
43
44 #if defined(__GNUC__) || defined(__GNUG__)
45 #pragma interface
46 #else
47 #ifndef HAS_BOOL
48 #define HAS_BOOL
49 typedef int bool;
50 #define false 0
51 #define true 1
52 #endif
53 #endif
54
55 #include <sys/types.h>
56 #include <sys/socket.h>
57
58 typedef char HostAddress[16]; // strlen("xxx.xxx.xxx.xxx\0") <= 16
59 typedef char SockAddress[24]; // strlen("xxx.xxx.xxx.xxx:xxxxx\0" ) < 24
60
61 const char*
62 my_inet_ntoa( const struct in_addr& a, HostAddress buffer );
63 // purpose: thread-safely convert IPv4 address -> ASCII representation
64 // paramtr: a (IN): networked representation of IPv4 address
65 // buffer (OUT): storage area to store representation into.
66 // returns: pointer to buffer
67 // goodies: INADDR_ANY will be converted to "*"
68
69 const char*
70 my_sock_ntoa( const struct sockaddr_in& a, SockAddress buffer );
71 // purpose: thread-safely convert IPv4 socket pair into ASCII rep.
72 // paramtr: a (IN): socket_in address
73 // buffer (OUT): storage area to store representation into.
74 // returns: pointer to buffer
75
76 const char*
77 my_sock_fd2a( int fd, SockAddress buffer, bool peer = true );
78 // purpose: thread-safely convert IPv4 socket FD associated address
79 // to ASCII representation
80 // paramtr: fd (IN): open socket FD
81 // buffer (OUT): storage area
82 // peer (IN): true, use peer (remote) socket pair
83 // false, use own (local) socket pair
84 // returns: NULL in case of error, or pointer to buffer otherwise
85 // Refer to errno in case of error (usually unconnected fd...)
86
87 int
88 convertHostname( const char* host, struct in_addr& dst );
89 // purpose: convert a numeric or symbolic hostname
90 // paramtr: host (IN): host description to convert
91 // dst (OUT): the internet address in network byteorder.
92 // returns: -1 in case of error, see h_errno; 0 otherwise.
93
94 int
95 convertPortname( const char* port, unsigned short& dst );
96 // purpose: convert a numeric or symbolic port number
97 // paramtr: port (IN): port description to convert
98 // dst (OUT): port number in network byteorder.
99 // returns: -1 in case of error, see errno; 0 otherwise.
100
101 #endif // _CONVERT_HH