Added code for testing

master
Aadhavan Srinivasan 2 years ago
parent 66150609c3
commit 1ab6ffe44f

@ -89,7 +89,6 @@ int create_remote (int network,char transport,char* address,int port,struct sock
memset(&hints,'\0',sizeof(hints)); memset(&hints,'\0',sizeof(hints));
// hints.ai_family = int_to_inet(network); /* AF_INET if network is 4, AF_INET6 if it is 6 */
hints.ai_socktype = char_to_socktype(transport); hints.ai_socktype = char_to_socktype(transport);
err_code = getaddrinfo(address,port_str,&hints,&results); err_code = getaddrinfo(address,port_str,&hints,&results);
@ -106,10 +105,11 @@ int create_remote (int network,char transport,char* address,int port,struct sock
if (socket < 0) { if (socket < 0) {
exit(errno); exit(errno);
} }
unsigned char ip[100]= ""; unsigned char ip[INET_ADDRSTRLEN];
struct sockaddr_in6 *in6 = (struct sockaddr_in6 *)remote_addr_struct;
inet_ntop(int_to_inet(network), &results->ai_addr->sa_data[2], ip, sizeof(ip)); memcpy(ip, in6->sin6_addr.s6_addr, 16);
printf ("IP address: %s\n\n", ip); char ip_str[254];
printf("%s\n",inet_ntop(AF_INET6,ip,ip_str,254));
int addrlen; int addrlen;

Loading…
Cancel
Save