akaros/tools/compilers/gcc-glibc/glibc-2.19-akaros/sysdeps/akaros/gethstbyad_r.c
<<
>>
Prefs
   1/* 
   2 * This file is part of the UCB release of Plan 9. It is subject to the license
   3 * terms in the LICENSE file found in the top-level directory of this
   4 * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No
   5 * part of the UCB release of Plan 9, including this file, may be copied,
   6 * modified, propagated, or distributed except according to the terms contained
   7 * in the LICENSE file.
   8 */
   9/* posix */
  10#include <sys/types.h>
  11#include <unistd.h>
  12
  13/* bsd extensions */
  14#include <sys/uio.h>
  15#include <sys/socket.h>
  16#include <netinet/in.h>
  17#include <netdb.h>
  18#include <errno.h>
  19#include <arpa/inet.h>
  20
  21#include <sys/plan9_helpers.h>
  22
  23/* similar to gethostbyaddr, just calling the reentrant _r method, and using
  24 * inet_ntop instead of the non-reentrant inet_ntoa. */
  25int __gethostbyaddr_r(const void *addr, socklen_t len, int type,
  26                      struct hostent *ret, char *buf, size_t buflen,
  27                      struct hostent **result, int *h_errnop)
  28{
  29        unsigned long y;
  30        struct in_addr x;
  31        __const unsigned char *p = addr;
  32        char name[INET6_ADDRSTRLEN];
  33
  34        if (type != AF_INET || len != 4) {
  35                h_errno = NO_RECOVERY;
  36                return -EAFNOSUPPORT;
  37        }
  38
  39        y = (p[0] << 24) | (p[1] << 16) | (p[2] << 8) | p[3];
  40        x.s_addr = htonl(y);
  41
  42        if (!inet_ntop(AF_INET, (void*)&x, name, INET6_ADDRSTRLEN))
  43                return -errno;
  44
  45        return gethostbyname_r(name, ret, buf, buflen, result, h_errnop);
  46}
  47weak_alias(__gethostbyaddr_r, gethostbyaddr_r);
  48