Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- [ainozama@notebook sandbox]$ cat ipv6util_storage.c
- #include <sys/types.h>
- #include <sys/socket.h>
- #include <netdb.h>
- #include <string.h>
- #include <stdlib.h>
- #include <stdio.h>
- #include <sys/types.h>
- #include <sys/socket.h>
- #include <arpa/inet.h>
- #include <bits/socket.h>
- #include <errno.h>
- #include <unistd.h>
- static int cached_getipbyname(char *host_name, struct sockaddr_storage *endereco) {
- struct addrinfo *res;
- getaddrinfo(host_name, "80", NULL, &res);
- memcpy(endereco, res->ai_addr, res->ai_addrlen);
- return(0);
- }
- int main(int argc, char *argv[]){
- struct sockaddr_storage endereco;
- char *t = NULL;
- cached_getipbyname(argv[1], &endereco);
- if (endereco.ss_family == AF_INET6) {
- int fd;
- struct sockaddr_in6 *addr;
- //memset(&addr,0,sizeof(addr));
- addr = (struct sockaddr_in6 *)&endereco;
- t = malloc (INET6_ADDRSTRLEN);
- inet_ntop(AF_INET6, &addr->sin6_addr, t, INET6_ADDRSTRLEN);
- printf("DEST IP: %s\n", t);
- printf("PORT: %d\n", addr->sin6_port);
- fd = socket(AF_INET6, SOCK_STREAM, 0);
- if (connect(fd, (struct sockaddr *)&addr, sizeof(addr->sin6_addr)) == -1) {
- printf("NOK\n");
- if(errno != EINPROGRESS) {
- printf("connect error: %s\n",strerror(errno));
- close(fd);
- }
- } else
- printf("OK\n");
- free(t);
- }
- return(0);
- }
- [ainozama@notebook sandbox]$ make storage
- gcc -g -Wall ipv6util_storage.c -o ipv6util_storage
- [ainozama@notebook sandbox]$ ./ipv6util_storage ipv6lab
- DEST IP: fef::6f:ec:b5
- PORT: 20480
- NOK
- connect error: Invalid argument
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement