|
|
|
@ -60,14 +60,14 @@ SOCKET create_socket(int network, char transport) {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int create_addr(int network, const char* address, int port,struct sockaddr* dest) {
|
|
|
|
|
int create_addr(int network, const char* address, int port,struct sockaddr_storage* dest) {
|
|
|
|
|
if (network == 4) {
|
|
|
|
|
struct sockaddr_in listen_address;
|
|
|
|
|
|
|
|
|
|
listen_address.sin_family = AF_INET;
|
|
|
|
|
listen_address.sin_port = htons(port);
|
|
|
|
|
inet_pton(AF_INET,address,&listen_address.sin_addr);
|
|
|
|
|
memcpy(dest,&listen_address,sizeof(listen_address));
|
|
|
|
|
memcpy((struct sockaddr *)dest,&listen_address,sizeof(listen_address));
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
|
|
} else if (network == 6) {
|
|
|
|
@ -75,7 +75,7 @@ int create_addr(int network, const char* address, int port,struct sockaddr* dest
|
|
|
|
|
listen_ipv6.sin6_family = AF_INET6;
|
|
|
|
|
listen_ipv6.sin6_port = htons(port);
|
|
|
|
|
inet_pton(AF_INET6,address,&listen_ipv6.sin6_addr);
|
|
|
|
|
memcpy(dest,&listen_ipv6,sizeof(listen_ipv6));
|
|
|
|
|
memcpy((struct sockaddr_in6 *)dest,&listen_ipv6,sizeof(listen_ipv6));
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
|
|
} else {
|
|
|
|
@ -84,7 +84,7 @@ int create_addr(int network, const char* address, int port,struct sockaddr* dest
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
SOCKET create_local (int network, char transport, const char* address, int port,struct sockaddr* addr_struct) {
|
|
|
|
|
SOCKET create_local (int network, char transport, const char* address, int port,struct sockaddr_storage* addr_struct) {
|
|
|
|
|
int socket = create_socket(network,transport);
|
|
|
|
|
if (socket < 0) {
|
|
|
|
|
return (-1 * errno);
|
|
|
|
@ -103,14 +103,14 @@ SOCKET create_local (int network, char transport, const char* address, int port,
|
|
|
|
|
This should be set to the size of 'sockaddr_in' for IPv4, and 'sockaddr_in6' for IPv6.
|
|
|
|
|
See https://stackoverflow.com/questions/73707162/socket-bind-failed-with-invalid-argument-error-for-program-running-on-macos */
|
|
|
|
|
|
|
|
|
|
int i = bind (socket,addr_struct,(socklen_t)addrlen);
|
|
|
|
|
int i = bind (socket,(struct sockaddr *)addr_struct,(socklen_t)addrlen);
|
|
|
|
|
if (i < 0) {
|
|
|
|
|
return (-1 * errno);
|
|
|
|
|
}
|
|
|
|
|
return socket;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
SOCKET create_remote (int network,char transport, const char* address,int port,struct sockaddr* remote_addr_struct) {
|
|
|
|
|
SOCKET create_remote (int network,char transport, const char* address,int port,struct sockaddr_storage* remote_addr_struct) {
|
|
|
|
|
|
|
|
|
|
struct addrinfo hints; /* Used to tell getaddrinfo what kind of address we want */
|
|
|
|
|
struct addrinfo* results; /* Used by getaddrinfo to store the addresses */
|
|
|
|
|