apt  2.2.4
About: Apt (Advanced Package Tool) is a management system for software packages (Debian/Ubuntu). Release series 2.2.
  Fossies Dox: apt-2.2.4.tar.gz  ("unofficial" and yet experimental doxygen-generated source code documentation)  

rfc2553emu.h
Go to the documentation of this file.
1 // -*- mode: cpp; mode: fold -*-
2 // Description /*{{{*/
3 /* ######################################################################
4 
5  RFC 2553 Emulation - Provides emulation for RFC 2553 getaddrinfo,
6  freeaddrinfo and getnameinfo
7 
8  These functions are necessary to write portable protocol independent
9  networking. They transparently support IPv4, IPv6 and probably many
10  other protocols too. This implementation is needed when the host does
11  not support these standards. It implements a simple wrapper that
12  basically supports only IPv4.
13 
14  Perfect emulation is not provided, but it is passable..
15 
16  Originally written by Jason Gunthorpe <jgg@debian.org> and placed into
17  the Public Domain, do with it what you will.
18 
19  ##################################################################### */
20  /*}}}*/
21 #ifndef RFC2553EMU_H
22 #define RFC2553EMU_H
23 
24 #include <netdb.h>
25 #include <sys/socket.h>
26 #include <sys/types.h>
27 
28 // Autosense getaddrinfo
29 #if defined(AI_PASSIVE) && defined(EAI_NONAME)
30 #define HAVE_GETADDRINFO
31 #endif
32 
33 // Autosense getnameinfo
34 #if defined(NI_NUMERICHOST)
35 #define HAVE_GETNAMEINFO
36 #endif
37 
38 // getaddrinfo support?
39 #ifndef HAVE_GETADDRINFO
40  // Renamed to advoid type clashing.. (for debugging)
41  struct addrinfo_emu
42  {
43  int ai_flags; /* AI_PASSIVE, AI_CANONNAME, AI_NUMERICHOST */
44  int ai_family; /* PF_xxx */
45  int ai_socktype; /* SOCK_xxx */
46  int ai_protocol; /* 0 or IPPROTO_xxx for IPv4 and IPv6 */
47  size_t ai_addrlen; /* length of ai_addr */
48  char *ai_canonname; /* canonical name for nodename */
49  struct sockaddr *ai_addr; /* binary address */
50  struct addrinfo_emu *ai_next; /* next structure in linked list */
51  };
52  #define addrinfo addrinfo_emu
53 
54  int getaddrinfo(const char *nodename, const char *servname,
55  const struct addrinfo *hints,
56  struct addrinfo **res);
57  void freeaddrinfo(struct addrinfo *ai);
58 
59  #ifndef AI_PASSIVE
60  #define AI_PASSIVE (1<<1)
61  #endif
62 
63  #ifndef EAI_NONAME
64  #define EAI_NONAME -1
65  #define EAI_AGAIN -2
66  #define EAI_FAIL -3
67  #define EAI_NODATA -4
68  #define EAI_FAMILY -5
69  #define EAI_SOCKTYPE -6
70  #define EAI_SERVICE -7
71  #define EAI_ADDRFAMILY -8
72  #define EAI_SYSTEM -10
73  #define EAI_MEMORY -11
74  #endif
75 
76  /* If we don't have getaddrinfo then we probably don't have
77  sockaddr_storage either (same RFC) so we definitely will not be
78  doing any IPv6 stuff. Do not use the members of this structure to
79  retain portability, cast to a sockaddr. */
80  #define sockaddr_storage sockaddr_in
81 #endif
82 
83 // getnameinfo support (glibc2.0 has getaddrinfo only)
84 #ifndef HAVE_GETNAMEINFO
85 
86  int getnameinfo(const struct sockaddr *sa, socklen_t salen,
87  char *host, size_t hostlen,
88  char *serv, size_t servlen,
89  int flags);
90 
91  #ifndef NI_MAXHOST
92  #define NI_MAXHOST 1025
93  #define NI_MAXSERV 32
94  #endif
95 
96  #ifndef NI_NUMERICHOST
97  #define NI_NUMERICHOST (1<<0)
98  #define NI_NUMERICSERV (1<<1)
99 // #define NI_NOFQDN (1<<2)
100  #define NI_NAMEREQD (1<<3)
101  #define NI_DATAGRAM (1<<4)
102  #endif
103 
104  #define sockaddr_storage sockaddr_in
105 #endif
106 
107 // Glibc 2.0.7 misses this one
108 #ifndef AI_NUMERICHOST
109 #define AI_NUMERICHOST 0
110 #endif
111 
112 #endif
int getaddrinfo(const char *nodename, const char *servname, const struct addrinfo_emu *hints, struct addrinfo_emu **res)
Definition: rfc2553emu.cc:29
int getnameinfo(const struct sockaddr *sa, socklen_t salen, char *host, size_t hostlen, char *serv, size_t servlen, int flags)
Definition: rfc2553emu.cc:170
void freeaddrinfo(struct addrinfo_emu *ai)
Definition: rfc2553emu.cc:154
#define addrinfo
Definition: rfc2553emu.h:52
struct sockaddr * ai_addr
Definition: rfc2553emu.h:49
int ai_socktype
Definition: rfc2553emu.h:45
int ai_protocol
Definition: rfc2553emu.h:46
size_t ai_addrlen
Definition: rfc2553emu.h:47
char * ai_canonname
Definition: rfc2553emu.h:48
struct addrinfo_emu * ai_next
Definition: rfc2553emu.h:50