| 1 | /*
|
|---|
| 2 | * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
|
|---|
| 3 | * All rights reserved.
|
|---|
| 4 | *
|
|---|
| 5 | * Redistribution and use in source and binary forms, with or without
|
|---|
| 6 | * modification, are permitted provided that the following conditions
|
|---|
| 7 | * are met:
|
|---|
| 8 | * 1. Redistributions of source code must retain the above copyright
|
|---|
| 9 | * notice, this list of conditions and the following disclaimer.
|
|---|
| 10 | * 2. Redistributions in binary form must reproduce the above copyright
|
|---|
| 11 | * notice, this list of conditions and the following disclaimer in the
|
|---|
| 12 | * documentation and/or other materials provided with the distribution.
|
|---|
| 13 | * 3. Neither the name of the project nor the names of its contributors
|
|---|
| 14 | * may be used to endorse or promote products derived from this software
|
|---|
| 15 | * without specific prior written permission.
|
|---|
| 16 | *
|
|---|
| 17 | * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
|
|---|
| 18 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|---|
| 19 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|---|
| 20 | * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
|
|---|
| 21 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|---|
| 22 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|---|
| 23 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|---|
| 24 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|---|
| 25 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|---|
| 26 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|---|
| 27 | * SUCH DAMAGE.
|
|---|
| 28 | */
|
|---|
| 29 |
|
|---|
| 30 | /*
|
|---|
| 31 | * Issues to be discussed:
|
|---|
| 32 | * - Thread safe-ness must be checked
|
|---|
| 33 | * - Return values. There seems to be no standard for return value (RFC2133)
|
|---|
| 34 | * but INRIA implementation returns EAI_xxx defined for getaddrinfo().
|
|---|
| 35 | */
|
|---|
| 36 |
|
|---|
| 37 | #if 0
|
|---|
| 38 | #include <sys/types.h>
|
|---|
| 39 | #include <sys/socket.h>
|
|---|
| 40 | #include <netinet/in.h>
|
|---|
| 41 | #include <arpa/inet.h>
|
|---|
| 42 | #include <arpa/nameser.h>
|
|---|
| 43 | #include <netdb.h>
|
|---|
| 44 | #include <resolv.h>
|
|---|
| 45 | #include <string.h>
|
|---|
| 46 | #include <stddef.h>
|
|---|
| 47 |
|
|---|
| 48 | #include "addrinfo.h"
|
|---|
| 49 | #endif
|
|---|
| 50 |
|
|---|
| 51 | #define SUCCESS 0
|
|---|
| 52 | #define YES 1
|
|---|
| 53 | #define NO 0
|
|---|
| 54 |
|
|---|
| 55 | static struct gni_afd {
|
|---|
| 56 | int a_af;
|
|---|
| 57 | int a_addrlen;
|
|---|
| 58 | int a_socklen;
|
|---|
| 59 | int a_off;
|
|---|
| 60 | } gni_afdl [] = {
|
|---|
| 61 | #ifdef ENABLE_IPV6
|
|---|
| 62 | {PF_INET6, sizeof(struct in6_addr), sizeof(struct sockaddr_in6),
|
|---|
| 63 | offsetof(struct sockaddr_in6, sin6_addr)},
|
|---|
| 64 | #endif
|
|---|
| 65 | {PF_INET, sizeof(struct in_addr), sizeof(struct sockaddr_in),
|
|---|
| 66 | offsetof(struct sockaddr_in, sin_addr)},
|
|---|
| 67 | {0, 0, 0},
|
|---|
| 68 | };
|
|---|
| 69 |
|
|---|
| 70 | struct gni_sockinet {
|
|---|
| 71 | u_char si_len;
|
|---|
| 72 | u_char si_family;
|
|---|
| 73 | u_short si_port;
|
|---|
| 74 | };
|
|---|
| 75 |
|
|---|
| 76 | #define ENI_NOSOCKET 0
|
|---|
| 77 | #define ENI_NOSERVNAME 1
|
|---|
| 78 | #define ENI_NOHOSTNAME 2
|
|---|
| 79 | #define ENI_MEMORY 3
|
|---|
| 80 | #define ENI_SYSTEM 4
|
|---|
| 81 | #define ENI_FAMILY 5
|
|---|
| 82 | #define ENI_SALEN 6
|
|---|
| 83 |
|
|---|
| 84 | /* forward declaration to make gcc happy */
|
|---|
| 85 | int getnameinfo Py_PROTO((const struct sockaddr *, size_t, char *, size_t,
|
|---|
| 86 | char *, size_t, int));
|
|---|
| 87 |
|
|---|
| 88 | int
|
|---|
| 89 | getnameinfo(sa, salen, host, hostlen, serv, servlen, flags)
|
|---|
| 90 | const struct sockaddr *sa;
|
|---|
| 91 | size_t salen;
|
|---|
| 92 | char *host;
|
|---|
| 93 | size_t hostlen;
|
|---|
| 94 | char *serv;
|
|---|
|
|---|