gethostbyaddr.c 490 B

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