Compare commits
2 Commits
54374082f4
...
755acd067a
Author | SHA1 | Date | |
---|---|---|---|
755acd067a | |||
a1d17770ba |
4
TODO.txt
4
TODO.txt
@@ -8,4 +8,6 @@
|
||||
|
||||
3. Add support for configuration files, which can be specified via a command-line arg
|
||||
|
||||
4. Fix Makefile - Doesn't recompile if source files have changed, only if .o files have.
|
||||
---SHOULD BE DONE---- 4. Fix Makefile - Doesn't recompile if source files have changed, only if .o files have.
|
||||
|
||||
5. Check IPv6 support for remote socket
|
||||
|
32
easysock.c
32
easysock.c
@@ -51,11 +51,23 @@ 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 == -1) {
|
||||
exit(-1);
|
||||
if (socket < 0) {
|
||||
printf("Something went wrong creating the socket: %s\n",strerror(errno));
|
||||
}
|
||||
create_addr(network,address,port,addr_struct);
|
||||
int addrlen = sizeof(*addr_struct);
|
||||
int addrlen;
|
||||
if (network == 4) {
|
||||
addrlen = sizeof(struct sockaddr_in);
|
||||
} else if (network == 6) {
|
||||
addrlen = sizeof(struct sockaddr_in6);
|
||||
} else {
|
||||
exit(-7);
|
||||
}
|
||||
|
||||
/* The value of addrlen should be the size of the 'sockaddr'.
|
||||
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);
|
||||
if (i < 0) {
|
||||
printf("Something went wrong: %s\n",strerror(errno));
|
||||
@@ -73,7 +85,19 @@ int create_remote (int network,char transport,char* address,int port) {
|
||||
}
|
||||
struct sockaddr remote_addr_struct;
|
||||
create_addr(network,address,port,&remote_addr_struct);
|
||||
int addrlen = sizeof(remote_addr_struct);
|
||||
int addrlen;
|
||||
if (network == 4) {
|
||||
addrlen = sizeof(struct sockaddr_in);
|
||||
} else if (network == 6) {
|
||||
addrlen = sizeof(struct sockaddr_in6);
|
||||
} else {
|
||||
exit(-7);
|
||||
}
|
||||
|
||||
/* The value of addrlen should be the size of the 'sockaddr'.
|
||||
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 = connect(socket,&remote_addr_struct,(socklen_t)addrlen);
|
||||
if (i < 0) {
|
||||
printf("Something went wrong: %s\n",strerror(errno));
|
||||
|
2
main.c
2
main.c
@@ -40,7 +40,7 @@ int main(int argc,char* argv[]) {
|
||||
int preferred_remote_network = check_ip_ver(remote_addr);
|
||||
printf("Using %d for local\nUsing %d for remote\n",preferred_local_network,preferred_remote_network);
|
||||
|
||||
if ((preferred_local_network == -1) && (preferred_remote_network == -1)) {
|
||||
if ((preferred_local_network == -1) || (preferred_remote_network == -1)) {
|
||||
exit(-7);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user