1 /* posix */ 2 #include <sys/types.h> 3 #include <unistd.h> 4 5 /* bsd extensions */ 6 #include <sys/uio.h> 7 #include <sys/socket.h> 8 #include <netinet/in.h> 9 #include <netdb.h> 10 11 int h_errno; 12 13 struct hostent* gethostbyaddr(void * addr,int len,int type)14gethostbyaddr(void *addr, int len, int type) 15 { 16 unsigned long y; 17 struct in_addr x; 18 unsigned char *p = addr; 19 20 if(type != AF_INET || len != 4){ 21 h_errno = NO_RECOVERY; 22 return 0; 23 } 24 25 y = (p[0]<<24)|(p[1]<<16)|(p[2]<<8)|p[3]; 26 x.s_addr = htonl(y); 27 28 return gethostbyname(inet_ntoa(x)); 29 } 30