Skip to content

Commit

Permalink
extra socket bind checks and logging
Browse files Browse the repository at this point in the history
  • Loading branch information
sbSteveK committed Jan 9, 2025
1 parent 4ea2651 commit ca0ab21
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions source/darwin/nw_socket.c
Original file line number Diff line number Diff line change
Expand Up @@ -1483,14 +1483,24 @@ static int s_socket_bind_fn(
return aws_raise_error(AWS_IO_SOCKET_ILLEGAL_OPERATION_FOR_STATE);
}

socket->local_endpoint = *local_endpoint;
size_t address_strlen;
if (aws_secure_strlen(local_endpoint->address, AWS_ADDRESS_MAX_LEN, &address_strlen)) {
return AWS_OP_ERR;
}

if (aws_socket_validate_port_for_bind(local_endpoint->port, socket->options.domain)) {
return AWS_OP_ERR;
}

AWS_LOGF_INFO(
AWS_LS_IO_SOCKET,
"id=%p: binding to %s:%d.",
(void *)socket,
local_endpoint->address,
(int)local_endpoint->port);

socket->local_endpoint = *local_endpoint;

if (nw_socket->nw_parameters == NULL) {
if (retrieve_tls_options) {
struct tls_connection_context tls_connection_context;
Expand Down Expand Up @@ -1559,7 +1569,13 @@ static int s_socket_bind_fn(
// Apple network framework requires connection besides bind.
socket->state = BOUND;

AWS_LOGF_DEBUG(AWS_LS_IO_SOCKET, "id=%p: successfully bound", (void *)socket);
AWS_LOGF_DEBUG(
AWS_LS_IO_SOCKET,
"id=%p fd=%d: successfully bound to %s:%u",
(void *)socket,
socket->io_handle.data.fd,
socket->local_endpoint.address,
socket->local_endpoint.port);

return AWS_OP_SUCCESS;
}
Expand Down

0 comments on commit ca0ab21

Please sign in to comment.