From: Kevin Day Date: Sun, 14 Apr 2024 13:57:28 +0000 (-0500) Subject: Update: Follow up changes for adding sockaddr_storage use in the socket type. X-Git-Url: https://git.kevux.org/?a=commitdiff_plain;h=622be586442261be4c98a0df78229163d763da6f;p=fll Update: Follow up changes for adding sockaddr_storage use in the socket type. The commit 6fa1ec1f961ba4bf134d6db4e6ee70f56756c5ab left out a few files. I also forgot to add the "_e" so that I have "f_socket_address_form_storage_e". Add use of this in the unit test. Remove seemingly duplicate unit tests. Maybe I was trying to do a case of "bind()" returning "false", but the code does not do that in the duplicate unit tests. Remove the duplicate unit tests as I can always add the "false" case in the future if I so choose to. --- diff --git a/level_0/f_socket/c/socket.c b/level_0/f_socket/c/socket.c index 476bc8f..c9a70fe 100644 --- a/level_0/f_socket/c/socket.c +++ b/level_0/f_socket/c/socket.c @@ -77,6 +77,10 @@ extern "C" { socket->address.local.sun_path[0] = 0; } } + else if (socket->form == f_socket_address_form_storage_e) { + address = (struct sockaddr *) &socket->address.storage; + socket->length = sizeof(struct sockaddr_storage); + } #ifdef _en_support_socket_address_arp_ else if (socket->form == f_socket_address_form_arp_e) { @@ -189,6 +193,10 @@ extern "C" { address = (struct sockaddr *) &socket->address.local; socket->length = sizeof(struct sockaddr_un); } + else if (socket->form == f_socket_address_form_storage_e) { + address = (struct sockaddr *) &socket->address.storage; + socket->length = sizeof(struct sockaddr_storage); + } #ifdef _en_support_socket_address_arp_ else if (socket->form == f_socket_address_form_arp_e) { diff --git a/level_0/f_socket/c/socket/address.h b/level_0/f_socket/c/socket/address.h index f8f57ea..19e7e9c 100644 --- a/level_0/f_socket/c/socket/address.h +++ b/level_0/f_socket/c/socket/address.h @@ -43,7 +43,7 @@ extern "C" { f_socket_address_form_inet4_e, f_socket_address_form_inet6_e, f_socket_address_form_local_e, - f_socket_address_form_storage, + f_socket_address_form_storage_e, #ifdef _en_support_socket_address_arp_ f_socket_address_form_arp_e, diff --git a/level_0/f_socket/tests/unit/c/test-socket-bind.c b/level_0/f_socket/tests/unit/c/test-socket-bind.c index 71de1fc..68fde1d 100644 --- a/level_0/f_socket/tests/unit/c/test-socket-bind.c +++ b/level_0/f_socket/tests/unit/c/test-socket-bind.c @@ -71,42 +71,6 @@ void test__f_socket_bind__fails(void **state) { { f_socket_t socket = f_socket_t_initialize; - socket.domain = f_socket_protocol_family_inet4_e; - socket.protocol = f_socket_protocol_tcp_e; - socket.type = f_socket_address_family_inet4_e; - socket.form = f_socket_address_form_inet4_e; - - for (uint8_t i = 0; i < 12; ++i) { - - will_return(__wrap_bind, true); - will_return(__wrap_bind, errnos[i]); - - const f_status_t status = f_socket_bind(&socket); - - assert_int_equal(status, F_status_set_error(statuss[i])); - } // for - } - - { - f_socket_t socket = f_socket_t_initialize; - socket.domain = f_socket_protocol_family_inet6_e; - socket.protocol = f_socket_protocol_tcp_e; - socket.type = f_socket_address_family_inet6_e; - socket.form = f_socket_address_form_inet6_e; - - for (uint8_t i = 0; i < 12; ++i) { - - will_return(__wrap_bind, true); - will_return(__wrap_bind, errnos[i]); - - const f_status_t status = f_socket_bind(&socket); - - assert_int_equal(status, F_status_set_error(statuss[i])); - } // for - } - - { - f_socket_t socket = f_socket_t_initialize; socket.domain = f_socket_protocol_family_inet6_e; socket.protocol = f_socket_protocol_tcp_e; socket.type = f_socket_address_family_inet6_e; @@ -141,12 +105,13 @@ void test__f_socket_bind__fails(void **state) { } // for } + // Storage is just that, so use ipv6 with storage as a test. { f_socket_t socket = f_socket_t_initialize; - socket.domain = f_socket_protocol_family_local_e; + socket.domain = f_socket_protocol_family_inet6_e; socket.protocol = f_socket_protocol_tcp_e; - socket.type = f_socket_address_family_local_e; - socket.form = f_socket_address_form_local_e; + socket.type = f_socket_address_family_inet6_e; + socket.form = f_socket_address_form_storage_e; for (uint8_t i = 0; i < 12; ++i) {