From 45b5203b786a318040f09aafd9b7d86877d30fe9 Mon Sep 17 00:00:00 2001 From: Hugo Santos Date: Wed, 9 May 2007 12:57:00 +0000 Subject: [PATCH] network stack: getsockopt/setsockopt are no longer optional for protocols, as suggested by Axel. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@21085 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- .../kernel/network/protocols/icmp/icmp.cpp | 22 +++++++++++++++++-- .../kernel/network/protocols/udp/udp.cpp | 22 +++++++++++++++++-- src/add-ons/kernel/network/stack/link.cpp | 22 +++++++++++++++++-- .../kernel/network/stack/net_socket.cpp | 20 ++++------------- 4 files changed, 64 insertions(+), 22 deletions(-) diff --git a/src/add-ons/kernel/network/protocols/icmp/icmp.cpp b/src/add-ons/kernel/network/protocols/icmp/icmp.cpp index 6638dcceca..8d52e3d319 100644 --- a/src/add-ons/kernel/network/protocols/icmp/icmp.cpp +++ b/src/add-ons/kernel/network/protocols/icmp/icmp.cpp @@ -129,6 +129,24 @@ icmp_control(net_protocol *protocol, int level, int option, void *value, } +status_t +icmp_getsockopt(net_protocol *protocol, int level, int option, + void *value, int *length) +{ + return protocol->next->module->getsockopt(protocol->next, level, option, + value, length); +} + + +status_t +icmp_setsockopt(net_protocol *protocol, int level, int option, + const void *value, int length) +{ + return protocol->next->module->setsockopt(protocol->next, level, option, + value, length); +} + + status_t icmp_bind(net_protocol *protocol, const struct sockaddr *address) { @@ -330,8 +348,8 @@ net_protocol_module_info sICMPModule = { icmp_connect, icmp_accept, icmp_control, - NULL, // getsockopt - NULL, // setsockopt + icmp_getsockopt, + icmp_setsockopt, icmp_bind, icmp_unbind, icmp_listen, diff --git a/src/add-ons/kernel/network/protocols/udp/udp.cpp b/src/add-ons/kernel/network/protocols/udp/udp.cpp index bd1e835481..f43054b0fe 100644 --- a/src/add-ons/kernel/network/protocols/udp/udp.cpp +++ b/src/add-ons/kernel/network/protocols/udp/udp.cpp @@ -1021,6 +1021,24 @@ udp_control(net_protocol *protocol, int level, int option, void *value, } +status_t +udp_getsockopt(net_protocol *protocol, int level, int option, void *value, + int *length) +{ + return protocol->next->module->getsockopt(protocol->next, level, option, + value, length); +} + + +status_t +udp_setsockopt(net_protocol *protocol, int level, int option, + const void *value, int length) +{ + return protocol->next->module->setsockopt(protocol->next, level, option, + value, length); +} + + status_t udp_bind(net_protocol *protocol, const struct sockaddr *address) { @@ -1218,8 +1236,8 @@ net_protocol_module_info sUDPModule = { udp_connect, udp_accept, udp_control, - NULL, // getsockopt - NULL, // setsockopt + udp_getsockopt, + udp_setsockopt, udp_bind, udp_unbind, udp_listen, diff --git a/src/add-ons/kernel/network/stack/link.cpp b/src/add-ons/kernel/network/stack/link.cpp index 3e5d408f4e..288e10c93d 100644 --- a/src/add-ons/kernel/network/stack/link.cpp +++ b/src/add-ons/kernel/network/stack/link.cpp @@ -319,6 +319,24 @@ link_control(net_protocol *_protocol, int level, int option, void *value, } +status_t +link_getsockopt(net_protocol *protocol, int level, int option, void *value, + int *length) +{ + return protocol->next->module->getsockopt(protocol, level, option, + value, length); +} + + +status_t +link_setsockopt(net_protocol *protocol, int level, int option, + const void *value, int length) +{ + return protocol->next->module->setsockopt(protocol, level, option, + value, length); +} + + status_t link_bind(net_protocol *protocol, const struct sockaddr *address) { @@ -467,8 +485,8 @@ net_protocol_module_info gLinkModule = { link_connect, link_accept, link_control, - NULL, // getsockopt - NULL, // setsockopt + link_getsockopt, + link_setsockopt, link_bind, link_unbind, link_listen, diff --git a/src/add-ons/kernel/network/stack/net_socket.cpp b/src/add-ons/kernel/network/stack/net_socket.cpp index ab085cb8a4..a4ad02d90e 100644 --- a/src/add-ons/kernel/network/stack/net_socket.cpp +++ b/src/add-ons/kernel/network/stack/net_socket.cpp @@ -751,14 +751,8 @@ int socket_getsockopt(net_socket *socket, int level, int option, void *value, int *_length) { - for (net_protocol *protocol = socket->first_protocol; - protocol; protocol = protocol->next) { - if (protocol->module->getsockopt) - return protocol->module->getsockopt(protocol, level, option, - value, _length); - } - - return socket_get_option(socket, level, option, value, _length); + return socket->first_protocol->module->getsockopt(socket->first_protocol, + level, option, value, _length); } @@ -1069,14 +1063,8 @@ int socket_setsockopt(net_socket *socket, int level, int option, const void *value, int length) { - for (net_protocol *protocol = socket->first_protocol; - protocol; protocol = protocol->next) { - if (protocol->module->setsockopt) - return protocol->module->setsockopt(protocol, level, option, - value, length); - } - - return socket_set_option(socket, level, option, value, length); + return socket->first_protocol->module->setsockopt(socket->first_protocol, + level, option, value, length); }