Ticket #364: cygwin.diff

File cygwin.diff, 21.4 KB (added by didier@…, at 2008-02-20T12:44:06Z)
  • getaddrinfo.c

    === added file 'getaddrinfo.c'
     
     1/*
     2 * Copyright (c) 2001, 02  Motoyuki Kasahara
     3 *
     4 * Redistribution and use in source and binary forms, with or without
     5 * modification, are permitted provided that the following conditions
     6 * are met:
     7 * 1. Redistributions of source code must retain the above copyright
     8 *    notice, this list of conditions and the following disclaimer.
     9 * 2. Redistributions in binary form must reproduce the above copyright
     10 *    notice, this list of conditions and the following disclaimer in the
     11 *    documentation and/or other materials provided with the distribution.
     12 * 3. Neither the name of the project nor the names of its contributors
     13 *    may be used to endorse or promote products derived from this software
     14 *    without specific prior written permission.
     15 *
     16 * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
     17 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     19 * ARE DISCLAIMED.  IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
     20 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     22 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     26 * SUCH DAMAGE.
     27 */
     28
     29/*
     30 * This program provides getaddrinfo() and getnameinfo() described in
     31 * RFC2133, 2553 and 3493.  These functions are mainly used for IPv6
     32 * application to resolve hostname or address.
     33 *
     34 * This program is designed to be working on traditional IPv4 systems
     35 * which don't have those functions.  Therefore, this implementation
     36 * supports IPv4 only.
     37 *
     38 * This program is useful for application which should support both IPv6
     39 * and traditional IPv4 systems.  Use genuine getaddrinfo() and getnameinfo()
     40 * provided by system if the system supports IPv6.  Otherwise, use this
     41 * implementation.
     42 *
     43 * This program is intended to be used in combination with GNU Autoconf.
     44 *
     45 * This program also provides freeaddrinfo() and gai_strerror().
     46 *
     47 * To use this program in your application, insert the following lines to
     48 * C source files after including `sys/types.h', `sys/socket.h' and
     49 * `netdb.h'.  `getaddrinfo.h' defines `struct addrinfo' and AI_, NI_,
     50 * EAI_ macros.
     51 *
     52 *    #ifndef HAVE_GETADDRINFO
     53 *    #include "getaddrinfo.h"
     54 *    #endif
     55 *
     56 * Restriction:
     57 *   getaddrinfo() and getnameinfo() of this program are NOT thread
     58 *   safe, unless the cpp macro ENABLE_PTHREAD is defined.
     59 */
     60
     61/*
     62 * Add the following code to your configure.ac (or configure.in).
     63 *   AC_C_CONST
     64 *   AC_HEADER_STDC
     65 *   AC_CHECK_HEADERS(string.h memory.h stdlib.h)
     66 *   AC_CHECK_FUNCS(memcpy)
     67 *   AC_REPLACE_FUNCS(memset)
     68 *   AC_TYPE_SOCKLEN_T
     69 *   AC_TYPE_IN_PORT_T
     70 *   AC_DECL_H_ERRNO
     71 *
     72 *   AC_CHECK_FUNCS(getaddrinfo getnameinfo)
     73 *   if test "$ac_cv_func_getaddrinfo$ac_cv_func_getnameinfo" != yesyes ; then
     74 *       LIBOBJS="$LIBOBJS getaddrinfo.$ac_objext"
     75 *   fi
     76 */
     77
     78#ifdef HAVE_CONFIG_H
     79#include "config.h"
     80#endif
     81
     82#include <sys/types.h>
     83#include <stdio.h>
     84#include <sys/socket.h>
     85#include <netinet/in.h>
     86#include <arpa/inet.h>
     87#include <netdb.h>
     88
     89#if defined(STDC_HEADERS) || defined(HAVE_STRING_H)
     90#include <string.h>
     91#if !defined(STDC_HEADERS) && defined(HAVE_MEMORY_H)
     92#include <memory.h>
     93#endif /* not STDC_HEADERS and HAVE_MEMORY_H */
     94#else /* not STDC_HEADERS and not HAVE_STRING_H */
     95#include <strings.h>
     96#endif /* not STDC_HEADERS and not HAVE_STRING_H */
     97
     98#ifdef HAVE_STDLIB_H
     99#include <stdlib.h>
     100#endif
     101
     102#ifdef ENABLE_PTHREAD
     103#include <pthread.h>
     104#endif
     105
     106#ifdef ENABLE_NLS
     107#include <libintl.h>
     108#endif
     109
     110#ifndef HAVE_MEMCPY
     111#define memcpy(d, s, n) bcopy((s), (d), (n))
     112#ifdef __STDC__
     113void *memchr(const void *, int, size_t);
     114int memcmp(const void *, const void *, size_t);
     115void *memmove(void *, const void *, size_t);
     116void *memset(void *, int, size_t);
     117#else /* not __STDC__ */
     118char *memchr();
     119int memcmp();
     120char *memmove();
     121char *memset();
     122#endif /* not __STDC__ */
     123#endif /* not HAVE_MEMCPY */
     124
     125#ifndef H_ERRNO_DECLARED
     126extern int h_errno;
     127#endif
     128
     129#include "getaddrinfo.h"
     130
     131#ifdef ENABLE_NLS
     132#define _(string) gettext(string)
     133#ifdef gettext_noop
     134#define N_(string) gettext_noop(string)
     135#else
     136#define N_(string) (string)
     137#endif
     138#else
     139#define gettext(string) (string)
     140#define _(string) (string)
     141#define N_(string) (string)
     142#endif
     143
     144/*
     145 * Error messages for gai_strerror().
     146 */
     147static char *eai_errlist[] = {
     148    N_("Success"),
     149
     150    /* EAI_ADDRFAMILY */
     151    N_("Address family for hostname not supported"),
     152
     153    /* EAI_AGAIN */
     154    N_("Temporary failure in name resolution"),
     155
     156    /* EAI_BADFLAGS */
     157    N_("Invalid value for ai_flags"),
     158
     159    /* EAI_FAIL */
     160    N_("Non-recoverable failure in name resolution"),
     161
     162    /* EAI_FAMILY */
     163    N_("ai_family not supported"),                     
     164
     165    /* EAI_MEMORY */
     166    N_("Memory allocation failure"),
     167
     168    /* EAI_NONAME */
     169    N_("hostname nor servname provided, or not known"),
     170
     171    /* EAI_OVERFLOW */
     172    N_("An argument buffer overflowed"),
     173
     174    /* EAI_SERVICE */
     175    N_("servname not supported for ai_socktype"),
     176
     177    /* EAI_SOCKTYPE */
     178    N_("ai_socktype not supported"),
     179
     180    /* EAI_SYSTEM */
     181    N_("System error returned in errno")
     182};
     183
     184/*
     185 * Default hints for getaddrinfo().
     186 */
     187static struct addrinfo default_hints = {
     188    0, PF_UNSPEC, 0, 0, 0, NULL, NULL, NULL
     189};
     190
     191/*
     192 * Mutex.
     193 */
     194#ifdef ENABLE_PTHREAD
     195static pthread_mutex_t gai_mutex = PTHREAD_MUTEX_INITIALIZER;
     196#endif
     197
     198/*
     199 * Declaration of static functions.
     200 */
     201#ifdef __STDC__
     202static int is_integer(const char *);
     203static int is_address(const char *);
     204static int itoa_length(int);
     205#else
     206static int is_integer();
     207static int is_address();
     208static int itoa_length();
     209#endif
     210
     211/*
     212 * gai_strerror().
     213 */
     214const char *
     215gai_strerror(ecode)
     216    int ecode;
     217{
     218    if (ecode < 0 || ecode > EAI_SYSTEM)
     219        return _("Unknown error");
     220
     221    return gettext(eai_errlist[ecode]);
     222}
     223
     224/*
     225 * freeaddrinfo().
     226 */
     227void
     228freeaddrinfo(ai)
     229    struct addrinfo *ai;
     230{
     231    struct addrinfo *next_ai;
     232
     233    while (ai != NULL) {
     234        if (ai->ai_canonname != NULL)
     235            free(ai->ai_canonname);
     236        if (ai->ai_addr != NULL)
     237            free(ai->ai_addr);
     238        next_ai = ai->ai_next;
     239        free(ai);
     240        ai = next_ai;
     241    }
     242}
     243
     244/*
     245 * Return 1 if the string `s' represents an integer.
     246 */
     247static int
     248is_integer(s)
     249    const char *s;
     250{
     251    if (*s == '-' || *s == '+')
     252        s++;
     253    if (*s < '0' || '9' < *s)
     254        return 0;
     255
     256    s++;
     257    while ('0' <= *s && *s <= '9')
     258        s++;
     259
     260    return (*s == '\0');
     261}
     262
     263/*
     264 * Return 1 if the string `s' represents an IPv4 address.
     265 * Unlike inet_addr(), it doesn't permit malformed nortation such
     266 * as "192.168".
     267 */
     268static int
     269is_address(s)
     270    const char *s;
     271{
     272    const static char delimiters[] = {'.', '.', '.', '\0'};
     273    int i, j;
     274    int octet;
     275
     276    for (i = 0; i < 4; i++) {
     277        if (*s == '0' && *(s + 1) != delimiters[i])
     278            return 0;
     279        for (j = 0, octet = 0; '0' <= *s && *s <= '9' && j < 3; s++, j++)
     280            octet = octet * 10 + (*s - '0');
     281        if (j == 0 || octet > 255 || *s != delimiters[i])
     282            return 0;
     283        s++;
     284    }
     285
     286    return 1;
     287}
     288
     289/*
     290 * Calcurate length of the string `s', where `s' is set by
     291 * sprintf(s, "%d", n).
     292 */
     293static int
     294itoa_length(n)
     295    int n;
     296{
     297    int result = 1;
     298
     299    if (n < 0) {
     300        n = -n;
     301        result++;
     302    }
     303
     304    while (n >= 10) {
     305        result++;
     306        n /= 10;
     307    }
     308
     309    return result;
     310}
     311
     312/*
     313 * getaddrinfo().
     314 */
     315int
     316getaddrinfo(nodename, servname, hints, res)
     317    const char *nodename;
     318    const char *servname;
     319    const struct addrinfo *hints;
     320    struct addrinfo **res;
     321{
     322    struct addrinfo *head_res = NULL;
     323    struct addrinfo *tail_res = NULL;
     324    struct addrinfo *new_res;
     325    struct sockaddr_in *sa_in;
     326    struct in_addr **addr_list;
     327    struct in_addr *addr_list_buf[2];
     328    struct in_addr addr_buf;
     329    struct in_addr **ap;
     330    struct servent *servent;
     331    struct hostent *hostent;
     332    const char *canonname = NULL;
     333    in_port_t port;
     334    int saved_h_errno;
     335    int result = 0;
     336
     337#ifdef ENABLE_PTHREAD
     338    pthread_mutex_lock(&gai_mutex);
     339#endif
     340
     341    saved_h_errno = h_errno;
     342
     343    if (nodename == NULL && servname == NULL) {
     344        result = EAI_NONAME;
     345        goto end;
     346    }
     347
     348    if (hints != NULL) {
     349        if (hints->ai_family != PF_INET && hints->ai_family != PF_UNSPEC) {
     350            result = EAI_FAMILY;
     351            goto end;
     352        }
     353        if (hints->ai_socktype != SOCK_DGRAM
     354            && hints->ai_socktype != SOCK_STREAM
     355            && hints->ai_socktype != 0) {
     356            result = EAI_SOCKTYPE;
     357            goto end;
     358        }
     359    } else {
     360        hints = &default_hints;
     361    }
     362
     363    if (servname != NULL) {
     364        if (is_integer(servname))
     365            port = htons(atoi(servname));
     366        else  {
     367            if (hints->ai_flags & AI_NUMERICSERV) {
     368                result = EAI_NONAME;
     369                goto end;
     370            }
     371
     372            if (hints->ai_socktype == SOCK_DGRAM)
     373                servent = getservbyname(servname, "udp");
     374            else if (hints->ai_socktype == SOCK_STREAM)
     375                servent = getservbyname(servname, "tcp");
     376            else if (hints->ai_socktype == 0)
     377                servent = getservbyname(servname, "tcp");
     378            else {
     379                result = EAI_SOCKTYPE;
     380                goto end;
     381            }
     382
     383            if (servent == NULL) {
     384                result = EAI_SERVICE;
     385                goto end;
     386            }
     387            port = servent->s_port;
     388        }
     389    } else {
     390        port = htons(0);
     391    }
     392
     393    if (nodename != NULL) {
     394        if (is_address(nodename)) {
     395            addr_buf.s_addr = inet_addr(nodename);
     396            addr_list_buf[0] = &addr_buf;
     397            addr_list_buf[1] = NULL;
     398            addr_list = addr_list_buf;
     399
     400            if (hints->ai_flags & AI_CANONNAME
     401                && !(hints->ai_flags & AI_NUMERICHOST)) {
     402                hostent = gethostbyaddr((char *)&addr_buf,
     403                    sizeof(struct in_addr), AF_INET);
     404                if (hostent != NULL)
     405                    canonname = hostent->h_name;
     406                else
     407                    canonname = nodename;
     408            }
     409        } else {
     410            if (hints->ai_flags & AI_NUMERICHOST) {
     411                result = EAI_NONAME;
     412                goto end;
     413            }
     414
     415            hostent = gethostbyname(nodename);
     416            if (hostent == NULL) {
     417                switch (h_errno) {
     418                case HOST_NOT_FOUND:
     419                case NO_DATA:
     420                    result = EAI_NONAME;
     421                    goto end;
     422                case TRY_AGAIN:
     423                    result = EAI_AGAIN;
     424                    goto end;
     425                default:
     426                    result = EAI_FAIL;
     427                    goto end;
     428                }
     429            }
     430            addr_list = (struct in_addr **)hostent->h_addr_list;
     431
     432            if (hints->ai_flags & AI_CANONNAME)
     433                canonname = hostent->h_name;
     434        }
     435    } else {
     436        if (hints->ai_flags & AI_PASSIVE)
     437            addr_buf.s_addr = htonl(INADDR_ANY);
     438        else
     439            addr_buf.s_addr = htonl(0x7F000001);
     440        addr_list_buf[0] = &addr_buf;
     441        addr_list_buf[1] = NULL;
     442        addr_list = addr_list_buf;
     443    }
     444
     445    for (ap = addr_list; *ap != NULL; ap++) {
     446        new_res = (struct addrinfo *)malloc(sizeof(struct addrinfo));
     447        if (new_res == NULL) {
     448            if (head_res != NULL)
     449                freeaddrinfo(head_res);
     450            result = EAI_MEMORY;
     451            goto end;
     452        }
     453
     454        new_res->ai_family = PF_INET;
     455        new_res->ai_socktype = hints->ai_socktype;
     456        new_res->ai_protocol = hints->ai_protocol;
     457        new_res->ai_addr = NULL;
     458        new_res->ai_addrlen = sizeof(struct sockaddr_in);
     459        new_res->ai_canonname = NULL;
     460        new_res->ai_next = NULL;
     461
     462        new_res->ai_addr = (struct sockaddr *)
     463            malloc(sizeof(struct sockaddr_in));
     464        if (new_res->ai_addr == NULL) {
     465            free(new_res);
     466            if (head_res != NULL)
     467                freeaddrinfo(head_res);
     468            result = EAI_MEMORY;
     469            goto end;
     470        }
     471
     472        sa_in = (struct sockaddr_in *)new_res->ai_addr;
     473        memset(sa_in, 0, sizeof(struct sockaddr_in));
     474        sa_in->sin_family = PF_INET;
     475        sa_in->sin_port = port;
     476        memcpy(&sa_in->sin_addr, *ap, sizeof(struct in_addr));
     477
     478        if (head_res == NULL)
     479            head_res = new_res;
     480        else
     481            tail_res->ai_next = new_res;
     482        tail_res = new_res;
     483    }
     484
     485    if (canonname != NULL && head_res != NULL) {
     486        head_res->ai_canonname = (char *)malloc(strlen(canonname) + 1);
     487        if (head_res->ai_canonname != NULL)
     488            strcpy(head_res->ai_canonname, canonname);
     489    }
     490
     491    *res = head_res;
     492
     493  end:
     494    h_errno = saved_h_errno;
     495#ifdef ENABLE_PTHREAD
     496    pthread_mutex_unlock(&gai_mutex);
     497#endif
     498    return result;
     499}
     500
     501/*
     502 * getnameinfo().
     503 */
     504int
     505getnameinfo(sa, salen, node, nodelen, serv, servlen, flags)
     506    const struct sockaddr *sa;
     507    socklen_t salen;
     508    char *node;
     509    socklen_t nodelen;
     510    char *serv;
     511    socklen_t servlen;
     512    int flags;
     513{
     514    const struct sockaddr_in *sa_in = (const struct sockaddr_in *)sa;
     515    struct hostent *hostent;
     516    struct servent *servent;
     517    char *ntoa_address;
     518    int saved_h_errno;
     519    int result = 0;
     520
     521#ifdef ENABLE_PTHREAD
     522    pthread_mutex_lock(&gai_mutex);
     523#endif
     524
     525    saved_h_errno = h_errno;
     526
     527    if (sa_in->sin_family != PF_INET) {
     528        result = EAI_FAMILY;
     529        goto end;
     530    } else if (node == NULL && serv == NULL) {
     531        result = EAI_NONAME;
     532        goto end;
     533    }
     534
     535    if (serv != NULL && servlen > 0) {
     536        if (flags & NI_NUMERICSERV)
     537            servent = NULL;
     538        else if (flags & NI_DGRAM)
     539            servent = getservbyport(sa_in->sin_port, "udp");
     540        else
     541            servent = getservbyport(sa_in->sin_port, "tcp");
     542
     543        if (servent != NULL) {
     544            if (servlen <= strlen(servent->s_name)) {
     545                result = EAI_OVERFLOW;
     546                goto end;
     547            }
     548            strcpy(serv, servent->s_name);
     549        } else {
     550            if (servlen <= itoa_length(ntohs(sa_in->sin_port))) {
     551                result = EAI_OVERFLOW;
     552                goto end;
     553            }
     554            sprintf(serv, "%d", ntohs(sa_in->sin_port));
     555        }
     556    }
     557
     558    if (node != NULL && nodelen > 0) {
     559        if (flags & NI_NUMERICHOST)
     560            hostent = NULL;
     561        else {
     562            hostent = gethostbyaddr((char *)&sa_in->sin_addr,
     563                sizeof(struct in_addr), AF_INET);
     564        }
     565        if (hostent != NULL) {
     566            if (nodelen <= strlen(hostent->h_name)) {
     567                result = EAI_OVERFLOW;
     568                goto end;
     569            }
     570            strcpy(node, hostent->h_name);
     571        } else {
     572            if (flags & NI_NAMEREQD) {
     573                result = EAI_NONAME;
     574                goto end;
     575            }
     576            ntoa_address = inet_ntoa(sa_in->sin_addr);
     577            if (nodelen <= strlen(ntoa_address)) {
     578                result = EAI_OVERFLOW;
     579                goto end;
     580            }
     581            strcpy(node, ntoa_address);
     582        }
     583               
     584    }
     585
     586  end:
     587    h_errno = saved_h_errno;
     588#ifdef ENABLE_PTHREAD
     589    pthread_mutex_unlock(&gai_mutex);
     590#endif
     591    return result;
     592}
     593
  • getaddrinfo.h

    === added file 'getaddrinfo.h'
     
     1/*
     2 * Copyright (c) 2001, 02  Motoyuki Kasahara
     3 *
     4 * Redistribution and use in source and binary forms, with or without
     5 * modification, are permitted provided that the following conditions
     6 * are met:
     7 * 1. Redistributions of source code must retain the above copyright
     8 *    notice, this list of conditions and the following disclaimer.
     9 * 2. Redistributions in binary form must reproduce the above copyright
     10 *    notice, this list of conditions and the following disclaimer in the
     11 *    documentation and/or other materials provided with the distribution.
     12 * 3. Neither the name of the project nor the names of its contributors
     13 *    may be used to endorse or promote products derived from this software
     14 *    without specific prior written permission.
     15 *
     16 * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
     17 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     19 * ARE DISCLAIMED.  IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
     20 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     22 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     26 * SUCH DAMAGE.
     27 */
     28
     29#ifndef GETADDRINFO_H
     30#define GETADDRINFO_H
     31
     32#ifdef HAVE_CONFIG_H
     33#include "config.h"
     34#endif
     35
     36#include <sys/types.h>
     37#include <sys/socket.h>
     38#include <netdb.h>
     39
     40/********************************************************************/
     41/*
     42 * Undefine all the macros.
     43 * <netdb.h> might defines some of them.
     44 */
     45#ifdef EAI_ADDRFAMILY
     46#undef EAI_ADDRFAMILY
     47#endif
     48#ifdef EAI_AGAIN
     49#undef EAI_AGAIN
     50#endif
     51#ifdef EAI_BADFLAGS
     52#undef EAI_BADFLAGS
     53#endif
     54#ifdef EAI_FAIL
     55#undef EAI_FAIL
     56#endif
     57#ifdef EAI_FAMILY
     58#undef EAI_FAMILY
     59#endif
     60#ifdef EAI_MEMORY
     61#undef EAI_MEMORY
     62#endif
     63#ifdef EAI_NONAME
     64#undef EAI_NONAME
     65#endif
     66#ifdef EAI_OVERFLOW
     67#undef EAI_OVERFLOW
     68#endif
     69#ifdef EAI_SERVICE
     70#undef EAI_SERVICE
     71#endif
     72#ifdef EAI_SOCKTYPE
     73#undef EAI_SOCKTYPE
     74#endif
     75#ifdef EAI_SYSTEM
     76#undef EAI_SYSTEM
     77#endif
     78
     79#ifdef AI_PASSIVE
     80#undef AI_PASSIVE
     81#endif
     82#ifdef AI_CANONNAME
     83#undef AI_CANONNAME
     84#endif
     85#ifdef AI_NUMERICHOST
     86#undef AI_NUMERICHOST
     87#endif
     88#ifdef AI_NUMERICSERV
     89#undef AI_NUMERICSERV
     90#endif
     91#ifdef AI_V4MAPPED
     92#undef AI_V4MAPPED
     93#endif
     94#ifdef AI_ALL
     95#undef AI_ALL
     96#endif
     97#ifdef AI_ADDRCONFIG
     98#undef AI_ADDRCONFIG
     99#endif
     100#ifdef AI_DEFAULT
     101#undef AI_DEFAULT
     102#endif
     103
     104#ifdef NI_NOFQDN
     105#undef NI_NOFQDN
     106#endif
     107#ifdef NI_NUMERICHOST
     108#undef NI_NUMERICHOST
     109#endif
     110#ifdef NI_NAMEREQD
     111#undef NI_NAMEREQD
     112#endif
     113#ifdef NI_NUMERICSERV
     114#undef NI_NUMERICSERV
     115#endif
     116#ifdef NI_NUMERICSCOPE
     117#undef NI_NUMERICSCOPE
     118#endif
     119
     120#ifdef NI_DGRAM
     121#undef NI_DGRAM
     122#endif
     123#ifdef NI_MAXHOST
     124#undef NI_MAXHOST
     125#endif
     126#ifdef NI_MAXSERV
     127#undef NI_MAXSERV
     128#endif
     129
     130/*
     131 * Fake struct and function names.
     132 * <netdb.h> might declares all or some of them.
     133 */
     134#if defined(HAVE_GETADDRINFO) || defined(HAVE_GETNAMEINFO)
     135#define addrinfo my_addrinfo
     136#define gai_strerror my_gai_strerror
     137#define freeaddrinfo my_freeaddrinfo
     138#define getaddrinfo my_getaddrinfo
     139#define getnameinfo my_getnameinfo
     140#endif
     141
     142/********************************************************************/
     143/*
     144 * Error codes.
     145 */
     146#define EAI_ADDRFAMILY  1
     147#define EAI_AGAIN       2
     148#define EAI_BADFLAGS    3
     149#define EAI_FAIL        4
     150#define EAI_FAMILY      5
     151#define EAI_MEMORY      6
     152#define EAI_NONAME      7
     153#define EAI_OVERFLOW    8
     154#define EAI_SERVICE     9
     155#define EAI_SOCKTYPE    10
     156#define EAI_SYSTEM      11
     157
     158/*
     159 * Flags for getaddrinfo().
     160 */
     161#define AI_ADDRCONFIG   0x0001
     162#define AI_ALL          0x0002
     163#define AI_CANONNAME    0x0004
     164#define AI_NUMERICHOST  0x0008
     165#define AI_NUMERICSERV  0x0010
     166#define AI_PASSIVE      0x0020
     167#define AI_V4MAPPED     0x0040
     168#define AI_DEFAULT      (AI_V4MAPPED | AI_ADDRCONFIG)
     169
     170/*
     171 * Flags for getnameinfo().
     172 */
     173#define NI_DGRAM        0x0001
     174#define NI_NAMEREQD     0x0002
     175#define NI_NOFQDN       0x0004
     176#define NI_NUMERICHOST  0x0008
     177#define NI_NUMERICSCOPE 0x0010
     178#define NI_NUMERICSERV  0x0020
     179
     180/*
     181 * Maximum length of FQDN and servie name for getnameinfo().
     182 */
     183#define NI_MAXHOST      1025
     184#define NI_MAXSERV      32
     185
     186/*
     187 * Address families and Protocol families.
     188 */
     189#ifndef AF_UNSPEC
     190#define AF_UNSPEC AF_INET
     191#endif
     192#ifndef PF_UNSPEC
     193#define PF_UNSPEC PF_INET
     194#endif
     195
     196/*
     197 * struct addrinfo.
     198 */
     199struct addrinfo {
     200    int ai_flags;
     201    int ai_family;
     202    int ai_socktype;
     203    int ai_protocol;
     204    socklen_t ai_addrlen;
     205    char *ai_canonname;
     206    struct sockaddr *ai_addr;
     207    struct addrinfo *ai_next;
     208};
     209
     210/*
     211 * Functions.
     212 */
     213#ifdef __STDC__
     214const char *gai_strerror(int);
     215void freeaddrinfo(struct addrinfo *);
     216int getaddrinfo(const char *, const char *, const struct addrinfo *,
     217    struct addrinfo **);
     218int getnameinfo(const struct sockaddr *, socklen_t, char *,
     219    socklen_t, char *, socklen_t, int);
     220#else
     221const char *gai_strerror();
     222void freeaddrinfo();
     223int getaddrinfo();
     224int getnameinfo();
     225#endif
     226
     227#endif /* not GETADDRINFO_H */
  • Makefile

    === modified file 'Makefile'
     
    99-include Makefile.settings
    1010
    1111# Program variables
    12 objects = account.o bitlbee.o conf.o crypting.o help.o ipc.o irc.o irc_commands.o log.o nick.o query.o root_commands.o set.o storage.o $(STORAGE_OBJS) unix.o user.o
    13 headers = account.h bitlbee.h commands.h conf.h config.h crypting.h help.h ipc.h irc.h log.h nick.h query.h set.h sock.h storage.h user.h lib/events.h lib/http_client.h lib/ini.h lib/md5.h lib/misc.h lib/proxy.h lib/sha1.h lib/ssl_client.h lib/url.h protocols/nogaim.h
     12objects = account.o bitlbee.o conf.o crypting.o getaddrinfo.o help.o ipc.o irc.o irc_commands.o log.o nick.o query.o root_commands.o set.o storage.o $(STORAGE_OBJS) unix.o user.o
     13headers = account.h bitlbee.h commands.h conf.h config.h crypting.h getaddrinfo.h help.h ipc.h irc.h log.h nick.h query.h set.h sock.h storage.h user.h lib/events.h lib/http_client.h lib/ini.h lib/md5.h lib/misc.h lib/proxy.h lib/sha1.h lib/ssl_client.h lib/url.h protocols/nogaim.h
    1414subdirs = lib protocols
    1515
    1616# Expansion of variables
  • bitlbee.c

    === modified file 'bitlbee.c'
     
    2828#include "commands.h"
    2929#include "protocols/nogaim.h"
    3030#include "help.h"
     31#include "getaddrinfo.h
    3132#include "ipc.h"
    3233#include <signal.h>
    3334#include <stdio.h>
  • irc.c

    === modified file 'irc.c'
     
    2626#define BITLBEE_CORE
    2727#include "bitlbee.h"
    2828#include "crypting.h"
     29#include "getaddrinfo.h"
    2930#include "ipc.h"
    3031
    3132static gboolean irc_userping( gpointer _irc, int fd, b_input_condition cond );