Changeset 232d6fec in rtems


Ignore:
Timestamp:
May 2, 2016, 12:49:32 PM (4 years ago)
Author:
Christian Mauderer <Christian.Mauderer@…>
Branches:
master
Children:
195d412
Parents:
7e6f235
git-author:
Christian Mauderer <Christian.Mauderer@…> (05/02/16 12:49:32)
git-committer:
Sebastian Huber <sebastian.huber@…> (06/28/16 11:01:38)
Message:

libnetworking: Import current <netdb.h>

Import the <netdb.h> from current FreeBSD. This allows to build some
current software (e.g. libressl).

Add h_errno().

Update gethostent_r() API. Linux and FreeBSD use a common API now.
Adapt the RTEMS one to provide the same one.

Match gethostbyname_r() with prototype.

Location:
cpukit/libnetworking
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • cpukit/libnetworking/libc/gethostbydns.c

    r7e6f235 r232d6fec  
    119119} align;
    120120
    121 extern int h_errno;
    122121int _dns_ttl_;
    123122
  • cpukit/libnetworking/libc/gethostbyht.c

    r7e6f235 r232d6fec  
    215215
    216216#ifdef _THREAD_SAFE
    217 struct hostent* gethostent_r(char* buf, int len)
     217int
     218gethostent_r(
     219        struct hostent *pe,
     220        char *buf,
     221        size_t len,
     222        struct hostent **result,
     223        int *h_errnop)
    218224{
    219225  char  *dest;
    220   struct hostent* pe=(struct hostent*)buf;
    221226  char*  last;
    222227  char*  max=buf+len;
    223228  int    aliasidx;
    224229  int    curlen;
    225  
    226    
    227   if (!hostf) return 0;
     230  int    rv;
     231
     232  if (pe == NULL || buf == NULL || result == NULL || h_errnop == NULL) {
     233    if (h_errnop != NULL) {
     234      *h_errnop = NETDB_INTERNAL;
     235    }
     236    return EINVAL;
     237  }
     238
     239  *result = NULL;
     240  *h_errnop = NETDB_INTERNAL;
     241  rv = -1;
     242
     243  if (!hostf) {
     244    rv = ENOENT;
     245    return rv;
     246  }
    228247  fseek(hostf,0,SEEK_END);
    229248  curlen=ftell(hostf);
     
    249268again:
    250269  if ((size_t)len<sizeof(struct hostent)+11*sizeof(char*)) goto nospace;
    251   dest=buf+sizeof(struct hostent);
     270  dest=buf;
    252271  pe->h_name=0;
    253272  pe->h_aliases=(char**)dest; pe->h_aliases[0]=0; dest+=10*sizeof(char*);
    254273  pe->h_addr_list=(char**)dest; dest+=2*sizeof(char**);
    255   if (cur>=last) return 0;
     274  if (cur>=last) {
     275    rv = ERANGE;
     276    return rv;
     277  }
    256278  if (*cur=='#' || *cur=='\n') goto parseerror;
    257279  /* first, the ip number */
    258280  pe->h_name=cur;
    259281  while (cur<last && !isspace((unsigned char)*cur)) cur++;
    260   if (cur>=last) return 0;
     282  if (cur>=last) {
     283    rv = ERANGE;
     284    return rv;
     285  }
    261286  if (*cur=='\n') goto parseerror;
    262287  {
     
    302327  pe->h_name=pe->h_aliases[0];
    303328  pe->h_aliases++;
    304   return pe;
     329  *result = pe;
     330  *h_errnop = 0;
     331  rv = 0;
     332  return rv;
    305333parseerror:
    306334  while (cur<last && *cur!='\n') cur++;
     
    308336  goto again;
    309337nospace:
    310   errno=ERANGE;
     338  rv=ERANGE;
    311339  goto __error;
    312340error:
    313   errno=ENOMEM;
     341  rv=ENOMEM;
    314342__error:
    315343  if (hostmap!=NULL) free(hostmap);
    316344  hostmap=NULL;
    317   return 0;
     345  return rv;
    318346}
    319347#endif
  • cpukit/libnetworking/libc/gethostnamadr.c

    r7e6f235 r232d6fec  
    372372        struct hostent*  result,
    373373        char            *buf,
    374         int              buflen,
     374        size_t           buflen,
    375375        struct hostent **RESULT,
    376376        int             *h_errnop)
     
    415415  {
    416416    struct hostent* r;
     417    struct hostent* he_buf = (struct hostent *)buf;
     418    char *work_buf = buf + sizeof(struct hostent);
     419    size_t remain_len = buflen - sizeof(struct hostent);
     420    int he_errno;
     421
    417422    sethostent(0);
    418     while ((r=gethostent_r(buf,buflen))) {
     423    while (gethostent_r(he_buf, work_buf, remain_len, &r, &he_errno) == 0) {
    419424      int i;
    420425      if (r->h_addrtype==AF_INET && !strcasecmp(r->h_name,name)) {  /* found it! */
  • cpukit/libnetworking/libc/getnetbydns.c

    r7e6f235 r232d6fec  
    8080
    8181#include "res_config.h"
    82 
    83 extern int h_errno;
    8482
    8583#define BYADDR 0
  • cpukit/libnetworking/libc/herror.c

    r7e6f235 r232d6fec  
    6868int     h_nerr = { sizeof h_errlist / sizeof h_errlist[0] };
    6969
    70 int     h_errno;
     70int *
     71__h_errno(void)
     72{
     73        static int the_h_errno;
     74
     75        return &the_h_errno;
     76}
    7177
    7278#define HERROR_USE_WRITEV
  • cpukit/libnetworking/netdb.h

    r7e6f235 r232d6fec  
    1111 *    notice, this list of conditions and the following disclaimer in the
    1212 *    documentation and/or other materials provided with the distribution.
    13  * 3. All advertising materials mentioning features or use of this software
    14  *    must display the following acknowledgement:
    15  *      This product includes software developed by the University of
    16  *      California, Berkeley and its contributors.
    17  * 4. Neither the name of the University nor the names of its contributors
     13 * 3. Neither the name of the University nor the names of its contributors
    1814 *    may be used to endorse or promote products derived from this software
    1915 *    without specific prior written permission.
     
    5652 *      @(#)netdb.h     8.1 (Berkeley) 6/2/93
    5753 *      From: Id: netdb.h,v 8.9 1996/11/19 08:39:29 vixie Exp $
    58  * $FreeBSD: src/include/netdb.h,v 1.34 2005/02/14 11:33:11 phantom Exp $
    59  */
    60  
     54 * $FreeBSD: head/include/netdb.h 301711 2016-06-09 01:28:44Z markj $
     55 */
    6156
    6257#ifndef _NETDB_H_
     
    6459
    6560#include <sys/cdefs.h>
    66 #include <rtems/bsdnet/_types.h>
     61#include <sys/_types.h>
     62
     63#ifndef _IN_ADDR_T_DECLARED
     64typedef __uint32_t      in_addr_t;
     65#define _IN_ADDR_T_DECLARED
     66#endif
     67
     68#ifndef _IN_PORT_T_DECLARED
     69typedef __uint16_t      in_port_t;
     70#define _IN_PORT_T_DECLARED
     71#endif
     72
     73#ifndef _SIZE_T_DECLARED
     74typedef __size_t        size_t;
     75#define _SIZE_T_DECLARED
     76#endif
    6777
    6878#ifndef _SOCKLEN_T_DECLARED
    6979typedef __socklen_t     socklen_t;
    7080#define _SOCKLEN_T_DECLARED
     81#endif
     82
     83#ifndef _UINT32_T_DECLARED
     84typedef __uint32_t      uint32_t;
     85#define _UINT32_T_DECLARED
    7186#endif
    7287
     
    7893#define _PATH_PROTOCOLS "/etc/protocols"
    7994#define _PATH_SERVICES  "/etc/services"
    80 
    81 extern int h_errno;
     95#define _PATH_SERVICES_DB "/var/db/services.db"
     96
     97#define h_errno (*__h_errno())
    8298
    8399/*
     
    86102 * use in system calls).
    87103 */
    88 struct  hostent {
     104struct hostent {
    89105        char    *h_name;        /* official name of host */
    90106        char    **h_aliases;    /* alias list */
     
    95111};
    96112
    97 struct  netent {
     113struct netent {
    98114        char            *n_name;        /* official name of net */
    99115        char            **n_aliases;    /* alias list */
     
    102118};
    103119
    104 struct  servent {
     120struct servent {
    105121        char    *s_name;        /* official service name */
    106122        char    **s_aliases;    /* alias list */
     
    109125};
    110126
    111 struct  protoent {
     127struct protoent {
    112128        char    *p_name;        /* official protocol name */
    113129        char    **p_aliases;    /* alias list */
    114130        int     p_proto;        /* protocol # */
    115131};
     132
     133struct addrinfo {
     134        int     ai_flags;       /* AI_PASSIVE, AI_CANONNAME, AI_NUMERICHOST */
     135        int     ai_family;      /* AF_xxx */
     136        int     ai_socktype;    /* SOCK_xxx */
     137        int     ai_protocol;    /* 0 or IPPROTO_xxx for IPv4 and IPv6 */
     138        socklen_t ai_addrlen;   /* length of ai_addr */
     139        char    *ai_canonname;  /* canonical name for hostname */
     140        struct  sockaddr *ai_addr;      /* binary address */
     141        struct  addrinfo *ai_next;      /* next structure in linked list */
     142};
     143
     144#define IPPORT_RESERVED 1024
    116145
    117146/*
     
    128157#define NO_ADDRESS      NO_DATA         /* no address, look for MX record */
    129158
     159/*
     160 * Error return codes from getaddrinfo()
     161 */
     162#if 0
     163/* obsoleted */
     164#define EAI_ADDRFAMILY   1      /* address family for hostname not supported */
     165#endif
     166#define EAI_AGAIN        2      /* temporary failure in name resolution */
     167#define EAI_BADFLAGS     3      /* invalid value for ai_flags */
     168#define EAI_FAIL         4      /* non-recoverable failure in name resolution */
     169#define EAI_FAMILY       5      /* ai_family not supported */
     170#define EAI_MEMORY       6      /* memory allocation failure */
     171#if 0
     172/* obsoleted */
     173#define EAI_NODATA       7      /* no address associated with hostname */
     174#endif
     175#define EAI_NONAME       8      /* hostname nor servname provided, or not known */
     176#define EAI_SERVICE      9      /* servname not supported for ai_socktype */
     177#define EAI_SOCKTYPE    10      /* ai_socktype not supported */
     178#define EAI_SYSTEM      11      /* system error returned in errno */
     179#define EAI_BADHINTS    12      /* invalid value for hints */
     180#define EAI_PROTOCOL    13      /* resolved protocol is unknown */
     181#define EAI_OVERFLOW    14      /* argument buffer overflow */
     182#define EAI_MAX         15
     183
     184/*
     185 * Flag values for getaddrinfo()
     186 */
     187#define AI_PASSIVE      0x00000001 /* get address to use bind() */
     188#define AI_CANONNAME    0x00000002 /* fill ai_canonname */
     189#define AI_NUMERICHOST  0x00000004 /* prevent host name resolution */
     190#define AI_NUMERICSERV  0x00000008 /* prevent service name resolution */
     191/* valid flags for addrinfo (not a standard def, apps should not use it) */
     192#define AI_MASK \
     193    (AI_PASSIVE | AI_CANONNAME | AI_NUMERICHOST | AI_NUMERICSERV | \
     194    AI_ADDRCONFIG | AI_ALL | AI_V4MAPPED)
     195
     196#define AI_ALL          0x00000100 /* IPv6 and IPv4-mapped (with AI_V4MAPPED) */
     197#define AI_V4MAPPED_CFG 0x00000200 /* accept IPv4-mapped if kernel supports */
     198#define AI_ADDRCONFIG   0x00000400 /* only if any address is assigned */
     199#define AI_V4MAPPED     0x00000800 /* accept IPv4-mapped IPv6 address */
     200/* special recommended flags for getipnodebyname */
     201#define AI_DEFAULT      (AI_V4MAPPED_CFG | AI_ADDRCONFIG)
     202
     203/*
     204 * Constants for getnameinfo()
     205 */
     206#define NI_MAXHOST      1025
     207#define NI_MAXSERV      32
     208
     209/*
     210 * Flag values for getnameinfo()
     211 */
     212#define NI_NOFQDN       0x00000001
     213#define NI_NUMERICHOST  0x00000002
     214#define NI_NAMEREQD     0x00000004
     215#define NI_NUMERICSERV  0x00000008
     216#define NI_DGRAM        0x00000010
     217#if 0 /* obsolete */
     218#define NI_WITHSCOPEID  0x00000020
     219#endif
     220
     221/*
     222 * Scope delimit character
     223 */
     224#define SCOPE_DELIMITER '%'
     225
    130226__BEGIN_DECLS
    131227void            endhostent(void);
     
    133229void            endprotoent(void);
    134230void            endservent(void);
     231#if __BSD_VISIBLE || (__POSIX_VISIBLE && __POSIX_VISIBLE <= 200112)
    135232struct hostent  *gethostbyaddr(const void *, socklen_t, int);
    136233struct hostent  *gethostbyname(const char *);
    137 struct hostent  *gethostbyname2(const char *, int);
     234#endif
    138235struct hostent  *gethostent(void);
    139236struct netent   *getnetbyaddr(uint32_t, int);
     
    146243struct servent  *getservbyport(int, const char *);
    147244struct servent  *getservent(void);
    148 void            herror(const char *);
    149 __const char    *hstrerror(int);
    150245void            sethostent(int);
    151246/* void         sethostfile(const char *); */
    152247void            setnetent(int);
    153248void            setprotoent(int);
     249int             getaddrinfo(const char *, const char *,
     250                            const struct addrinfo *, struct addrinfo **);
     251int             getnameinfo(const struct sockaddr *, socklen_t, char *,
     252                            size_t, char *, size_t, int);
     253void            freeaddrinfo(struct addrinfo *);
     254const char      *gai_strerror(int);
    154255void            setservent(int);
    155256
    156 #ifdef _THREAD_SAFE
    157 struct hostent* gethostent_r(char* buf, int len);
    158 int gethostbyname_r(const char*      name,
    159                     struct hostent*  result,
    160                     char            *buf,
    161                     int              buflen,
    162                     struct hostent **RESULT,
    163                     int             *h_errnop) ;
    164 #endif             
     257#if __BSD_VISIBLE
     258void            endnetgrent(void);
     259void            freehostent(struct hostent *);
     260int             gethostbyaddr_r(const void *, socklen_t, int, struct hostent *,
     261    char *, size_t, struct hostent **, int *);
     262int             gethostbyname_r(const char *, struct hostent *, char *, size_t,
     263    struct hostent **, int *);
     264struct hostent  *gethostbyname2(const char *, int);
     265int             gethostbyname2_r(const char *, int, struct hostent *, char *,
     266    size_t, struct hostent **, int *);
     267int             gethostent_r(struct hostent *, char *, size_t,
     268    struct hostent **, int *);
     269struct hostent  *getipnodebyaddr(const void *, size_t, int, int *);
     270struct hostent  *getipnodebyname(const char *, int, int, int *);
     271int             getnetbyaddr_r(uint32_t, int, struct netent *, char *, size_t,
     272    struct netent**, int *);
     273int             getnetbyname_r(const char *, struct netent *, char *, size_t,
     274    struct netent **, int *);
     275int             getnetent_r(struct netent *, char *, size_t, struct netent **,
     276    int *);
     277int             getnetgrent(char **, char **, char **);
     278int             getnetgrent_r(char **, char **, char **, char *, size_t);
     279int             getprotobyname_r(const char *, struct protoent *, char *,
     280    size_t, struct protoent **);
     281int             getprotobynumber_r(int, struct protoent *, char *, size_t,
     282    struct protoent **);
     283int             getprotoent_r(struct protoent *, char *, size_t,
     284    struct protoent **);
     285int             getservbyname_r(const char *, const char *, struct servent *,
     286    char *, size_t, struct servent **);
     287int             getservbyport_r(int, const char *, struct servent *, char *,
     288    size_t, struct servent **);
     289int             getservent_r(struct servent *, char *, size_t,
     290    struct servent **);
     291void            herror(const char *);
     292const char      *hstrerror(int);
     293int             innetgr(const char *, const char *, const char *, const char *);
     294void            setnetgrent(const char *);
     295#endif
     296
    165297
    166298/*
     
    169301
    170302/* DO NOT USE THESE, THEY ARE SUBJECT TO CHANGE AND ARE NOT PORTABLE!!! */
     303int     * __h_errno(void);
    171304__END_DECLS
    172305
  • cpukit/libnetworking/resolv.h

    r7e6f235 r232d6fec  
    6868
    6969#define __RES   19960801
    70 
    71 /*%
    72  * This used to be defined in res_query.c, now it's in herror.c.  It was
    73  * never extern'd by any *.h file before it was placed here.  herror.c is
    74  * part of libresolv.a even though it might make more sense in libnetdb.a
    75  * or even libnet.a.
    76  */
    77 
    78 extern int h_errno;
    7970
    8071/*%
Note: See TracChangeset for help on using the changeset viewer.