Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <sys/types.h>
- #include <sys/socket.h>
- #include <netdb.h>
- #include <stdio.h>
- #include <stdlib.h>
- #include <unistd.h>
- #include <string.h>
- int main() {
- struct addrinfo hints;
- struct addrinfo *result, *rp;
- int s;
- //const char * host="www.aliyun.com";
- const char * host="www.baidu.com";
- const char * port="80";
- memset(&hints, 0, sizeof(struct addrinfo));
- hints.ai_family = AF_UNSPEC; /* Allow IPv4 or IPv6 */
- hints.ai_socktype = SOCK_DGRAM; /* Datagram socket */
- hints.ai_flags = 0;
- hints.ai_protocol = 0; /* Any protocol */
- s = getaddrinfo(host, port, &hints, &result);
- // ERRRRRROR: getaddrinfo: Name or service not known
- if (s != 0) {
- fprintf(stderr, "getaddrinfo: %s\n", gai_strerror(s));
- exit(EXIT_FAILURE);
- }
- }
Add Comment
Please, Sign In to add comment