getservbyaddr.c 321 B

123456789101112131415161718
  1. #include <sys/types.h>
  2. #include <unistd.h>
  3. #include <stdio.h>
  4. /* bsd extensions */
  5. #include <sys/uio.h>
  6. #include <sys/socket.h>
  7. #include <netinet/in.h>
  8. #include <netdb.h>
  9. struct servent*
  10. getservbyport(int port, char *proto)
  11. {
  12. char buf[32];
  13. snprintf(buf, sizeof buf, "%d", port);
  14. return getservbyname(buf, proto);
  15. }