|
|
|
@ -26,7 +26,7 @@ int create_socket(int network, char transport) {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void create_addr(int network, char* address, int port,struct sockaddr* dest) {
|
|
|
|
|
int create_addr(int network, char* address, int port,struct sockaddr* dest) {
|
|
|
|
|
if (network == 4) {
|
|
|
|
|
struct sockaddr_in listen_address;
|
|
|
|
|
|
|
|
|
@ -45,7 +45,7 @@ void create_addr(int network, char* address, int port,struct sockaddr* dest) {
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
exit(202);
|
|
|
|
|
return -202;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
@ -53,7 +53,7 @@ void create_addr(int network, char* address, int port,struct sockaddr* dest) {
|
|
|
|
|
int create_local (int network, char transport, char* address, int port,struct sockaddr* addr_struct) {
|
|
|
|
|
int socket = create_socket(network,transport);
|
|
|
|
|
if (socket < 0) {
|
|
|
|
|
exit(errno);
|
|
|
|
|
return (-1 * errno);
|
|
|
|
|
}
|
|
|
|
|
create_addr(network,address,port,addr_struct);
|
|
|
|
|
int addrlen;
|
|
|
|
@ -62,7 +62,7 @@ int create_local (int network, char transport, char* address, int port,struct so
|
|
|
|
|
} else if (network == 6) {
|
|
|
|
|
addrlen = sizeof(struct sockaddr_in6);
|
|
|
|
|
} else {
|
|
|
|
|
exit(207);
|
|
|
|
|
return -207;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* The value of addrlen should be the size of the 'sockaddr'.
|
|
|
|
@ -71,7 +71,7 @@ int create_local (int network, char transport, char* address, int port,struct so
|
|
|
|
|
|
|
|
|
|
int i = bind (socket,addr_struct,(socklen_t)addrlen);
|
|
|
|
|
if (i < 0) {
|
|
|
|
|
exit(errno);
|
|
|
|
|
return (-1 * errno);
|
|
|
|
|
}
|
|
|
|
|
return socket;
|
|
|
|
|
}
|
|
|
|
@ -104,7 +104,7 @@ int create_remote (int network,char transport,char* address,int port,struct sock
|
|
|
|
|
|
|
|
|
|
int socket = create_socket(network,transport);
|
|
|
|
|
if (socket < 0) {
|
|
|
|
|
exit(errno);
|
|
|
|
|
return (-1 * errno);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int addrlen;
|
|
|
|
@ -113,7 +113,7 @@ int create_remote (int network,char transport,char* address,int port,struct sock
|
|
|
|
|
} else if (network == 6) {
|
|
|
|
|
addrlen = sizeof(struct sockaddr_in6);
|
|
|
|
|
} else {
|
|
|
|
|
exit(207);
|
|
|
|
|
return (-1 * errno);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* The value of addrlen should be the size of the 'sockaddr'.
|
|
|
|
@ -122,7 +122,7 @@ int create_remote (int network,char transport,char* address,int port,struct sock
|
|
|
|
|
|
|
|
|
|
int i = connect(socket,remote_addr_struct,(socklen_t)addrlen);
|
|
|
|
|
if (i < 0) {
|
|
|
|
|
exit(errno);
|
|
|
|
|
return (-1 * errno);
|
|
|
|
|
}
|
|
|
|
|
return socket;
|
|
|
|
|
}
|
|
|
|
@ -145,7 +145,7 @@ int int_to_inet(int network) {
|
|
|
|
|
} else if (network == 6) {
|
|
|
|
|
return AF_INET6;
|
|
|
|
|
} else {
|
|
|
|
|
exit(207);
|
|
|
|
|
return -207;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -155,7 +155,7 @@ int inet_to_int(int af_type) {
|
|
|
|
|
} else if (af_type == AF_INET6) {
|
|
|
|
|
return 6;
|
|
|
|
|
} else {
|
|
|
|
|
exit(207);
|
|
|
|
|
return -207;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -165,6 +165,6 @@ int char_to_socktype(char transport) {
|
|
|
|
|
} else if (transport == 'U') {
|
|
|
|
|
return SOCK_DGRAM;
|
|
|
|
|
} else {
|
|
|
|
|
exit(250);
|
|
|
|
|
return -250;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|