/contrib/ntp/libntp/socktoa.c

https://bitbucket.org/freebsd/freebsd-head/ · C · 56 lines · 41 code · 12 blank · 3 comment · 3 complexity · 74c0c7445f0f90f3e7db6c80b1f476a2 MD5 · raw file

  1. /*
  2. * socktoa - return a numeric host name from a sockaddr_storage structure
  3. */
  4. #include <config.h>
  5. #include <sys/types.h>
  6. #include <sys/socket.h>
  7. #include <netinet/in.h>
  8. #include <arpa/inet.h>
  9. #ifdef ISC_PLATFORM_NEEDNTOP
  10. #include <isc/net.h>
  11. #endif
  12. #include <stdio.h>
  13. #include "ntp_fp.h"
  14. #include "lib_strbuf.h"
  15. #include "ntp_stdlib.h"
  16. #include "ntp.h"
  17. char *
  18. socktoa(
  19. struct sockaddr_storage* sock
  20. )
  21. {
  22. register char *buffer;
  23. LIB_GETBUF(buffer);
  24. if (sock == NULL)
  25. strcpy(buffer, "null");
  26. else
  27. {
  28. switch(sock->ss_family) {
  29. default:
  30. case AF_INET :
  31. inet_ntop(AF_INET, &GET_INADDR(*sock), buffer,
  32. LIB_BUFLENGTH);
  33. break;
  34. case AF_INET6 :
  35. inet_ntop(AF_INET6, &GET_INADDR6(*sock), buffer,
  36. LIB_BUFLENGTH);
  37. #if 0
  38. default:
  39. strcpy(buffer, "unknown");
  40. #endif
  41. }
  42. }
  43. return buffer;
  44. }