Moved 'check_ip_ver' function to easysock.c

master
Aadhavan Srinivasan 2 years ago
parent d8ef471618
commit 5261398d69

@ -102,3 +102,15 @@ int create_remote (int network,char transport,char* address,int port,struct sock
} }
return socket; return socket;
} }
int check_ip_ver(char* address) {
char buffer[16]; /* 16 chars - 128 bits - is enough to hold an ipv6 address */
if (inet_pton(AF_INET,address,buffer) == 1) {
return 4;
} else if (inet_pton(AF_INET6,address,buffer) == 1) {
return 6;
} else {
return -1;
}
}

@ -50,5 +50,9 @@ It prints the error returned by 'connect' if something went wrong, and exits wit
int create_remote (int network,char transport,char* address,int port,struct sockaddr* remote_addr_struct); int create_remote (int network,char transport,char* address,int port,struct sockaddr* remote_addr_struct);
/* check_ip_ver - This function checks if the given string is an IPv4 address (returns 4),
IPv6 address (returns 6) or neither (returns -1).
int check_ip_ver(char* address);
#endif #endif

@ -13,18 +13,6 @@ void forward_data(int from_fd, int to_fd) {
} }
} }
int check_ip_ver(char* address) {
char buffer[16]; /* 16 chars - 128 bits - is enough to hold an ipv6 address */
if (inet_pton(AF_INET,address,buffer) == 1) {
return 4;
} else if (inet_pton(AF_INET6,address,buffer) == 1) {
return 6;
} else {
return -1;
}
}
void print_prog_info() { void print_prog_info() {
printf("%s [Local IP address] [local port] [remote IP address] [remote port]\n",PROG_NAME); printf("%s [Local IP address] [local port] [remote IP address] [remote port]\n",PROG_NAME);
} }

Loading…
Cancel
Save