Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void client(char *botname, int port, char *host)
- {
- int sockfd;
- printf("Botname: %s\nPort: %d\nServer: %s\n", botname, port, host);
- sockfd = socket(AF_INET, SOCK_STREAM, 0);
- lookuphost(host, port);
- }
- void lookuphost(const char *host, const int port)
- {
- int s;
- char portstring[6];
- struct addrinfo hints, *result;
- void *ptr;
- char addrstr[100];
- (void)snprintf(portstring, 6, "%d", port);
- memset(&hints, 0, sizeof(hints));
- hints.ai_family = AF_INET;
- hints.ai_socktype = SOCK_STREAM;
- hints.ai_protocol = 0;
- s = getaddrinfo(host, portstring, &hints, &result);
- if(s != 0)
- {
- fprintf(stderr, "getaddrinfo: %s\n", gai_strerror(s));
- exit(EXIT_FAILURE);
- }
- while (result)
- {
- inet_ntop (result->ai_family, result->ai_addr->sa_data, addrstr, 100);
- ptr = &((struct sockaddr_in *) result->ai_addr)->sin_addr;
- inet_ntop (result->ai_family, ptr, addrstr, 100);
- printf ("IPv addresults: %s\n", addrstr);
- result = result->ai_next;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement