/contrib/ntp/libntp/socktohost.c

https://bitbucket.org/freebsd/freebsd-head/ · C · 31 lines · 21 code · 7 blank · 3 comment · 1 complexity · fbab8167551fb67d8770b565e8c3e9f2 MD5 · raw file

  1. /*
  2. * socktoa - return a numeric host name from a sockaddr_storage structure
  3. */
  4. #include <sys/types.h>
  5. #include <sys/socket.h>
  6. #include <netinet/in.h>
  7. #include <arpa/inet.h>
  8. #include <stdio.h>
  9. #include "ntp_fp.h"
  10. #include "lib_strbuf.h"
  11. #include "ntp_stdlib.h"
  12. #include "ntp.h"
  13. char *
  14. socktohost(
  15. struct sockaddr_storage* sock
  16. )
  17. {
  18. register char *buffer;
  19. LIB_GETBUF(buffer);
  20. if (getnameinfo((struct sockaddr *)sock, SOCKLEN(sock), buffer,
  21. LIB_BUFLENGTH /* NI_MAXHOST*/, NULL, 0, 0))
  22. return stoa(sock);
  23. return buffer;
  24. }