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