diff --git a/src/add-ons/kernel/network/protocols/ipv4/multicast.cpp b/src/add-ons/kernel/network/protocols/ipv4/multicast.cpp index 21b78e08e0..5e24757b37 100644 --- a/src/add-ons/kernel/network/protocols/ipv4/multicast.cpp +++ b/src/add-ons/kernel/network/protocols/ipv4/multicast.cpp @@ -257,12 +257,14 @@ MulticastFilter::MulticastFilter(ProtocolType *socket) template MulticastFilter::~MulticastFilter() { - typename States::Iterator iterator = fStates.GetIterator(); - while (iterator.HasNext()) { + while (true) { + typename States::Iterator iterator = fStates.GetIterator(); + if (!iterator.HasNext()) + return; + GroupState *state = iterator.Next(); state->Clear(); - ReturnGroup(state); - iterator.Rewind(); + _ReturnGroup(state); } } @@ -296,11 +298,17 @@ MulticastFilter::GetGroup(const AddressType &groupAddress, template void MulticastFilter::ReturnGroup(GroupState *group) { - if (group->IsEmpty()) { - Addressing::LeaveGroup(group); - fStates.Remove(group); - delete group; - } + if (group->IsEmpty()) + _ReturnGroup(group); +} + + +template void +MulticastFilter::_ReturnGroup(GroupState *group) +{ + Addressing::LeaveGroup(group); + fStates.Remove(group); + delete group; } // IPv4 explicit template instantiation diff --git a/src/add-ons/kernel/network/protocols/ipv4/multicast.h b/src/add-ons/kernel/network/protocols/ipv4/multicast.h index a533def67f..3119257f79 100644 --- a/src/add-ons/kernel/network/protocols/ipv4/multicast.h +++ b/src/add-ons/kernel/network/protocols/ipv4/multicast.h @@ -160,6 +160,8 @@ private: typedef typename GroupState::HashDefinition GroupHashDefinition; typedef OpenHashTable States; + void _ReturnGroup(GroupState *group); + ProtocolType *fParent; States fStates; }; diff --git a/src/add-ons/kernel/network/stack/net_socket.cpp b/src/add-ons/kernel/network/stack/net_socket.cpp index bcad5ec1f1..8e3f53bf17 100644 --- a/src/add-ons/kernel/network/stack/net_socket.cpp +++ b/src/add-ons/kernel/network/stack/net_socket.cpp @@ -749,8 +749,12 @@ socket_getsockopt(net_socket *socket, int level, int option, void *value, { status_t status = (level == SOL_SOCKET) ? B_OK : B_BAD_VALUE; - if (socket->first_info->getsockopt) - status = socket->first_info->getsockopt(socket->first_protocol, level, + net_protocol *protocol = socket->first_protocol; + while (protocol && protocol->module->getsockopt == NULL) + protocol = protocol->next; + + if (protocol) + status = protocol->module->getsockopt(protocol, level, option, value, _length); if (status < B_OK) @@ -1066,9 +1070,13 @@ socket_setsockopt(net_socket *socket, int level, int option, const void *value, { status_t status = (level == SOL_SOCKET) ? B_OK : B_BAD_VALUE; - if (socket->first_info->setsockopt) - status = socket->first_info->setsockopt(socket->first_protocol, level, - option, value, length); + net_protocol *protocol = socket->first_protocol; + while (protocol && protocol->module->setsockopt == NULL) + protocol = protocol->next; + + if (protocol) + status = protocol->module->setsockopt(protocol, level, option, + value, length); if (status < B_OK) return status; diff --git a/src/tests/kits/net/multicast/multicast.cpp b/src/tests/kits/net/multicast/multicast.cpp index 829a9e53c5..dee285fc28 100644 --- a/src/tests/kits/net/multicast/multicast.cpp +++ b/src/tests/kits/net/multicast/multicast.cpp @@ -30,7 +30,7 @@ int main(int argc, char *argv[]) inet_pton(AF_INET, argv[1], &mreq.imr_multiaddr); - setsockopt(sock, AF_INET, IP_ADD_MEMBERSHIP, &mreq, sizeof(mreq)); + setsockopt(sock, IPPROTO_IP, IP_ADD_MEMBERSHIP, &mreq, sizeof(mreq)); while (1) { int len = recv(sock, buf, sizeof(buf), 0);