Guest User

Untitled

a guest
Aug 18th, 2018
299
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.83 KB | None | 0 0
  1. #include <sys/types.h>
  2. #include <sys/socket.h>
  3. #include <netdb.h>
  4. #include <stdio.h>
  5. #include <stdlib.h>
  6. #include <unistd.h>
  7. #include <string.h>
  8.  
  9. int main() {
  10.     struct addrinfo hints;
  11.     struct addrinfo *result, *rp;
  12.     int s;
  13.  
  14.     //const char * host="www.aliyun.com";
  15.     const char * host="www.baidu.com";
  16.     const char * port="80";
  17.  
  18.     memset(&hints, 0, sizeof(struct addrinfo));
  19.     hints.ai_family = AF_UNSPEC;    /* Allow IPv4 or IPv6 */
  20.     hints.ai_socktype = SOCK_DGRAM; /* Datagram socket */
  21.     hints.ai_flags = 0;
  22.     hints.ai_protocol = 0;          /* Any protocol */
  23.  
  24.     s = getaddrinfo(host, port, &hints, &result);
  25.     // ERRRRRROR: getaddrinfo: Name or service not known
  26.     if (s != 0) {
  27.         fprintf(stderr, "getaddrinfo: %s\n", gai_strerror(s));
  28.         exit(EXIT_FAILURE);
  29.     }
  30. }
Add Comment
Please, Sign In to add comment