]>
git.saurik.com Git - apt.git/blob - methods/rfc2553emu.h
1 // -*- mode: cpp; mode: fold -*-
3 // $Id: rfc2553emu.h,v 1.2 1999/05/26 04:08:39 jgg Exp $
4 /* ######################################################################
6 RFC 2553 Emulation - Provides emulation for RFC 2553 getaddrinfo,
7 freeaddrinfo and getnameinfo
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.
15 Perfect emulation is not provided, but it is passable..
17 Originally written by Jason Gunthorpe <jgg@debian.org> and placed into
18 the Public Domain, do with it what you will.
20 ##################################################################### */
26 #include <sys/types.h>
27 #include <sys/socket.h>
29 // Autosense getaddrinfo
30 #if defined(AI_PASSIVE) && defined(EAI_NONAME)
31 #define HAVE_GETADDRINFO
34 // Autosense getnameinfo
35 #if defined(NI_NUMERICHOST)
36 #define HAVE_GETNAMEINFO
39 // getaddrinfo support?
40 #ifndef HAVE_GETADDRINFO
43 // Renamed to advoid type clashing.. (for debugging)
46 int ai_flags
; /* AI_PASSIVE, AI_CANONNAME, AI_NUMERICHOST */
47 int ai_family
; /* PF_xxx */
48 int ai_socktype
; /* SOCK_xxx */
49 int ai_protocol
; /* 0 or IPPROTO_xxx for IPv4 and IPv6 */
50 size_t ai_addrlen
; /* length of ai_addr */
51 char *ai_canonname
; /* canonical name for nodename */
52 struct sockaddr
*ai_addr
; /* binary address */
53 struct addrinfo
*ai_next
; /* next structure in linked list */
55 #define addinfo addrinfo_emu
57 int getaddrinfo(const char *nodename
, const char *servname
,
58 const struct addrinfo
*hints
,
59 struct addrinfo
**res
);
60 void freeaddrinfo(struct addrinfo
*ai
);
63 #define AI_PASSIVE (1<<1)
72 #define EAI_SOCKTYPE -6
73 #define EAI_SERVICE -7
74 #define EAI_ADDRFAMILY -8
75 #define EAI_SYSTEM -10
80 // getnameinfo support (glibc2.0 has getaddrinfo only)
81 #ifndef HAVE_GETNAMEINFO
83 int getnameinfo(const struct sockaddr
*sa
, socklen_t salen
,
84 char *host
, size_t hostlen
,
85 char *serv
, size_t servlen
,
89 #define NI_MAXHOST 1025
93 #ifndef NI_NUMERICHOST
94 #define NI_NUMERICHOST (1<<0)
95 #define NI_NUMERICSERV (1<<1)
96 // #define NI_NOFQDN (1<<2)
97 #define NI_NAMEREQD (1<<3)
98 #define NI_DATAGRAM (1<<4)