Posted to tcl by rmax at Wed Sep 26 16:49:41 GMT 2012view raw

  1. #include <sys/types.h>
  2. #include <sys/socket.h>
  3. #include <netdb.h>
  4. #include <stdio.h>
  5. #include <string.h>
  6.  
  7. int main(int argc, char **argv)
  8. {
  9. struct addrinfo hints, *result;
  10. int err;
  11.  
  12. memset(&hints, 0, sizeof(struct addrinfo));
  13. hints.ai_family = AF_UNSPEC;
  14. hints.ai_socktype = SOCK_STREAM;
  15. hints.ai_flags = AI_PASSIVE;
  16.  
  17. err = getaddrinfo("localhost", "0", &hints, &result);
  18. printf("getaddrinfo returned: %d, %s\n", err,
  19. err ? gai_strerror(err) : "Success");
  20.  
  21. return 0;
  22. }
  23.