akaros/tools/compilers/gcc-glibc/glibc-2.19-akaros/sysdeps/akaros/gethstbyad.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 <arpa/inet.h>
  19
  20#include <sys/plan9_helpers.h>
  21
  22struct hostent *gethostbyaddr(const void *addr, socklen_t len, int type)
  23{
  24        unsigned long a, y;
  25        struct in_addr x;
  26        __const unsigned char *p = addr;
  27
  28        if (type != AF_INET || len != 4) {
  29                h_errno = NO_RECOVERY;
  30                return 0;
  31        }
  32
  33        y = (p[0] << 24) | (p[1] << 16) | (p[2] << 8) | p[3];
  34        x.s_addr = htonl(y);
  35
  36        return gethostbyname(inet_ntoa(x));
  37}
  38