From bd337347f2cb59b381fe78fb3652b5994adbaa0b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Duval?= Date: Wed, 25 Nov 2020 16:17:21 +0100 Subject: [PATCH] ipv4: add getsockopt IP_MULTICAST_IF also fix setsockopt Change-Id: Idb8fafbe7aa9931af82ebccdc4d2e487f9c0eeb1 Reviewed-on: https://review.haiku-os.org/c/haiku/+/3419 Reviewed-by: Rene Gollent --- .../kernel/network/protocols/ipv4/ipv4.cpp | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/src/add-ons/kernel/network/protocols/ipv4/ipv4.cpp b/src/add-ons/kernel/network/protocols/ipv4/ipv4.cpp index a243c05675..3b3eb86d6f 100644 --- a/src/add-ons/kernel/network/protocols/ipv4/ipv4.cpp +++ b/src/add-ons/kernel/network/protocols/ipv4/ipv4.cpp @@ -1184,6 +1184,21 @@ ipv4_getsockopt(net_protocol* _protocol, int level, int option, void* value, return get_int_option(value, *_length, protocol->time_to_live); if (option == IP_TOS) return get_int_option(value, *_length, protocol->service_type); + if (option == IP_MULTICAST_IF) { + if (*_length != sizeof(struct in_addr)) + return B_BAD_VALUE; + struct sockaddr_in defaultAddress; + defaultAddress.sin_addr.s_addr = htonl(INADDR_ANY); + struct sockaddr_in* address = + (struct sockaddr_in*)protocol->multicast_address; + if (address == NULL) + address = &defaultAddress; + if (user_memcpy(value, &address->sin_addr, sizeof(struct in_addr)) + != B_OK) { + return B_BAD_ADDRESS; + } + return B_OK; + } if (option == IP_MULTICAST_TTL) { return get_char_int_option(value, *_length, protocol->multicast_time_to_live); @@ -1268,11 +1283,13 @@ ipv4_setsockopt(net_protocol* _protocol, int level, int option, if (address == NULL) return B_NO_MEMORY; - if (user_memcpy(&address->sin_addr, value, sizeof(struct in_addr)) + struct in_addr sin_addr; + if (user_memcpy(&sin_addr, value, sizeof(struct in_addr)) != B_OK) { delete address; return B_BAD_ADDRESS; } + fill_sockaddr_in(address, sin_addr.s_addr); // Using INADDR_ANY to remove the previous setting. if (address->sin_addr.s_addr == htonl(INADDR_ANY)) {