Skip to content

Commit

Permalink
net.c: pass sizeof sockaddr_in struct to bind()
Browse files Browse the repository at this point in the history
macOS (possibly others?) does not like `sizeof sockaddr_storage` being
passed to bind() and returns an `Invalid argument` error when attempting
to bind ports on startup.

This changes the call to instead use `sizeof(struct sockaddr_in)` (which assumes IPv4 but
so does the rest of the function).
  • Loading branch information
nrhtr authored and waywardmonkeys committed Jul 16, 2023
1 parent c9e272a commit f85ca99
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion src/net.c
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ static SOCKET grab_port(unsigned short port, const char * addr, int socktype) {
setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, &one, sizeof(int));

/* Bind the socket to port. */
if (bind(sock, (struct sockaddr *) &bind_addr, sizeof(bind_addr)) == -1) {
if (bind(sock, (struct sockaddr *) &bind_addr, sizeof(struct sockaddr_in)) == -1) {
server_failure_reason = bind_id;
return SOCKET_ERROR;
}
Expand Down

0 comments on commit f85ca99

Please sign in to comment.