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