1
/* ######################################################################
3
RFC 2553 Emulation - Provides emulation for RFC 2553 getaddrinfo,
4
freeaddrinfo and getnameinfo
6
These functions are necessary to write portable protocol independent
7
networking. They transparently support IPv4, IPv6 and probably many
8
other protocols too. This implementation is needed when the host does
9
not support these standards. It implements a simple wrapper that
10
basically supports only IPv4.
12
Perfect emulation is not provided, but it is passable..
14
Originally written by Jason Gunthorpe <jgg@debian.org> and placed into
15
the Public Domain, do with it what you will.
17
##################################################################### */
20
* $Id: rfc2553.h,v 2.2 2012/01/07 13:52:23 green Exp $
23
* Revision 2.2 2012/01/07 13:52:23 green
24
* Removed C++ comments (bad style, I know)
26
* Revision 2.1 2012/01/03 17:25:32 green
27
* Implemented IPv6 support
28
* - replace (almost) all getXbyY function calls with getaddrinfo/getnameinfo (RFC2553) calls
29
* - Add compatibility layer for target systems not supporting RFC2553 calls in rfc2553.[ch]
30
* - Add support for multiple listen sockets -- one for IPv4 and one for IPv6 (use V6ONLY)
31
* - For WIN32 platform add configuration parameter IPV6 (mutually exclusive with BINKD9X)
32
* - On WIN32 platform use Winsock2 API if IPV6 support is requested
33
* - config: node IP address literal + port supported: [<ipv6 address>]:<port>
42
/* Autosense getaddrinfo */
43
#if defined(AI_PASSIVE) && defined(EAI_NONAME)
44
#define HAVE_GETADDRINFO
47
/* Autosense getnameinfo */
48
#if defined(NI_NUMERICHOST)
49
#define HAVE_GETNAMEINFO
52
/* getaddrinfo support? */
53
#ifndef HAVE_GETADDRINFO
54
/* Renamed to advoid type clashing.. (for debugging) */
57
int ai_flags; /* AI_PASSIVE, AI_CANONNAME, AI_NUMERICHOST */
58
int ai_family; /* PF_xxx */
59
int ai_socktype; /* SOCK_xxx */
60
int ai_protocol; /* 0 or IPPROTO_xxx for IPv4 and IPv6 */
61
size_t ai_addrlen; /* length of ai_addr */
62
char *ai_canonname; /* canonical name for nodename */
63
struct sockaddr *ai_addr; /* binary address */
64
struct addrinfo_emu *ai_next; /* next structure in linked list */
66
#define addrinfo addrinfo_emu
68
int getaddrinfo(const char *nodename, const char *servname,
69
const struct addrinfo *hints,
70
struct addrinfo **res);
71
void freeaddrinfo(struct addrinfo *ai);
72
char * gai_strerror(int ecode);
75
#define AI_PASSIVE (1<<1)
84
#define EAI_SOCKTYPE -6
85
#define EAI_SERVICE -7
86
#define EAI_ADDRFAMILY -8
88
#define EAI_SYSTEM -10
89
#define EAI_UNKNOWN -11
92
/* If we don't have getaddrinfo then we probably don't have
93
sockaddr_storage either (same RFC) so we definately will not be
94
doing any IPv6 stuff. Do not use the members of this structure to
95
retain portability, cast to a sockaddr. */
96
#define sockaddr_storage sockaddr_in
99
/* getnameinfo support (glibc2.0 has getaddrinfo only) */
100
#ifndef HAVE_GETNAMEINFO
102
int getnameinfo(const struct sockaddr *sa, socklen_t salen,
103
char *host, size_t hostlen,
104
char *serv, size_t servlen,
108
#define NI_MAXHOST 1025
109
#define NI_MAXSERV 32
112
#ifndef NI_NUMERICHOST
113
#define NI_NUMERICHOST (1<<0)
114
#define NI_NUMERICSERV (1<<1)
115
/* #define NI_NOFQDN (1<<2) */
116
#define NI_NAMEREQD (1<<3)
117
#define NI_DATAGRAM (1<<4)
120
#define sockaddr_storage sockaddr_in
123
/* Glibc 2.0.7 misses this one */
124
#ifndef AI_NUMERICHOST
125
#define AI_NUMERICHOST 0
128
/* Win32 doesn't support these */
129
#ifndef AI_NUMERICSERV
130
#define AI_NUMERICSERV 0
133
/* Win32 doesn't support these */
134
#ifndef NI_NUMERICSERV
135
#define NI_NUMERICSERV 0