]> git.saurik.com Git - apt.git/blob - methods/rfc2553emu.h
e24e7a3c18602ab1242d0a6c7a33ddedfe1175ff
[apt.git] / methods / rfc2553emu.h
1 // -*- mode: cpp; mode: fold -*-
2 // Description /*{{{*/
3 // $Id: rfc2553emu.h,v 1.1 1999/05/25 05:56:24 jgg Exp $
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
34 // getaddrinfo support?
35 #ifndef HAVE_GETADDRINFO
36 #error Boink
37
38 // Renamed to advoid type clashing.. (for debugging)
39 struct addrinfo_emu
40 {
41 int ai_flags; /* AI_PASSIVE, AI_CANONNAME, AI_NUMERICHOST */
42 int ai_family; /* PF_xxx */
43 int ai_socktype; /* SOCK_xxx */
44 int ai_protocol; /* 0 or IPPROTO_xxx for IPv4 and IPv6 */
45 size_t ai_addrlen; /* length of ai_addr */
46 char *ai_canonname; /* canonical name for nodename */
47 struct sockaddr *ai_addr; /* binary address */
48 struct addrinfo *ai_next; /* next structure in linked list */
49 };
50 #define addinfo addrinfo_emu
51
52 int getaddrinfo(const char *nodename, const char *servname,
53 const struct addrinfo *hints,
54 struct addrinfo **res);
55 void freeaddrinfo(struct addrinfo *ai);
56
57 #ifndef AI_PASSIVE
58 #define AI_PASSIVE (1<<1)
59 #endif
60
61 #ifndef EAI_NONAME
62 #define EAI_NONAME -1
63 #define EAI_AGAIN -2
64 #define EAI_FAIL -3
65 #define EAI_NODATA -4
66 #define EAI_FAMILY -5
67 #define EAI_SOCKTYPE -6
68 #define EAI_SERVICE -7
69 #define EAI_ADDRFAMILY -8
70 #define EAI_ADDRFAMILY -8
71 #define EAI_SYSTEM -10
72 #endif
73
74 #endif
75
76 // getnameinfo support (glibc2.0 has getaddrinfo only)
77 #ifndef HAVE_GETNAMEINFO
78
79 int getnameinfo(const struct sockaddr *sa, socklen_t salen,
80 char *host, size_t hostlen,
81 char *serv, size_t servlen,
82 int flags);
83 #endif
84
85 #endif