Thu, Feb 26, 2015 at 02:30:24PM CET, jtluka@redhat.com wrote:
Test for setting socket option IP_MULTICAST_IF using struct ip_mreqn is buggy.
System call setsockopt() can use both in_addr and ip_mreqn structs but getsockopt() returns struct in_addr only. Therefore the test failed because the size of the passed and returned structure did not match.
I added second function test_sockopt_value2() that takes additional two parameters that are expected when getsockopt() is called.
Signed-off-by: Jan Tluka jtluka@redhat.com
test_tools/multicast/offline/sockopt_if.c | 10 ++++++---- test_tools/multicast/sockopt_utils.h | 13 +++++++++++++ 2 files changed, 19 insertions(+), 4 deletions(-)
diff --git a/test_tools/multicast/offline/sockopt_if.c b/test_tools/multicast/offline/sockopt_if.c index 2396629..70e2df7 100644 --- a/test_tools/multicast/offline/sockopt_if.c +++ b/test_tools/multicast/offline/sockopt_if.c @@ -39,14 +39,16 @@ void test_if() struct ip_mreqn mreqn; mreqn.imr_multiaddr.s_addr = inet_addr("239.1.2.3"); mreqn.imr_address.s_addr = INADDR_ANY;
- address.s_addr = INADDR_ANY; mreqn.imr_ifindex = 0;
- test_sockopt_value("IP_MULTICAST_IF set to INADDR_ANY",
IP_MULTICAST_IF, &mreqn, sizeof(mreqn));
test_sockopt_value2("IP_MULTICAST_IF set to INADDR_ANY mreqn",
IP_MULTICAST_IF, &mreqn, sizeof(mreqn), &address, size);
mreqn.imr_address.s_addr = inet_addr("127.0.0.1");
- test_sockopt_value("IP_MULTICAST_IF set to 127.0.0.1",
IP_MULTICAST_IF, &mreqn, sizeof(mreqn));
address.s_addr = inet_addr("127.0.0.1");
test_sockopt_value2("IP_MULTICAST_IF set to 127.0.0.1 mreqn",
IP_MULTICAST_IF, &mreqn, sizeof(mreqn), &address, size);
/* Errors */
diff --git a/test_tools/multicast/sockopt_utils.h b/test_tools/multicast/sockopt_utils.h index 6486f71..d722cef 100644 --- a/test_tools/multicast/sockopt_utils.h +++ b/test_tools/multicast/sockopt_utils.h @@ -129,6 +129,19 @@ void test_sockopt_value(char* test_name, int optname, test_getsockopt(test_name, optname, optval, optlen); }
+/* In some cases setsockopt and getsockopt can work with different data
- structures, e.g. setsockopt() can use 'struct ip_mreqn' for setting
- the source ip address and getsockopt() always returns 'struct in_addr'.
- This function is provided to deal with such situation.
- */
+void test_sockopt_value2(char* test_name, int optname,
void *optval, socklen_t optlen,
void *expval, socklen_t explen)
+{
- test_setsockopt(test_name, optname, optval, optlen);
- test_getsockopt(test_name, optname, expval, explen);
+}
I believe that this should be called something like "test_sockopt_value_ext" or something like that and test_sockopt_value should be wrapper which calls test_sockopt_value_ext.
void test_setsockopt_error(char* test_name, int optname, void *optval, socklen_t optlen, int expected_errorcode) { -- 1.9.3
LNST-developers mailing list LNST-developers@lists.fedorahosted.org https://lists.fedorahosted.org/mailman/listinfo/lnst-developers