libibverbs/examples: fix IPv6 support
authorshefty <shefty@ad392aa1-c5ef-ae45-8dd8-e69d62a5ef86>
Wed, 11 Mar 2009 21:37:05 +0000 (21:37 +0000)
committershefty <shefty@ad392aa1-c5ef-ae45-8dd8-e69d62a5ef86>
Wed, 11 Mar 2009 21:37:05 +0000 (21:37 +0000)
Allow servers to accept connections from IPv4 and IPv6 clients.  Fix based on patch provided by Leonid.

Signed-off-by: Sean Hefty <sean.hefty@intel.com>
git-svn-id: svn://openib.tc.cornell.edu/gen1/trunk@2023 ad392aa1-c5ef-ae45-8dd8-e69d62a5ef86

ulp/libibverbs/examples/rc_pingpong/rc_pingpong.c
ulp/libibverbs/examples/srq_pingpong/srq_pingpong.c
ulp/libibverbs/examples/uc_pingpong/uc_pingpong.c
ulp/libibverbs/examples/ud_pingpong/ud_pingpong.c

index 7281e8a..5f9511a 100644 (file)
@@ -207,8 +207,9 @@ static struct pingpong_dest *pp_server_exch_dest(struct pingpong_context *ctx,
        for (t = res; t; t = t->ai_next) {\r
                sockfd = socket(t->ai_family, t->ai_socktype, t->ai_protocol);\r
                if (sockfd != INVALID_SOCKET) {\r
+                       n = 0;\r
+                       setsockopt(sockfd, IPPROTO_IPV6, IPV6_V6ONLY, (char *) &n, sizeof n);\r
                        n = 1;\r
-\r
                        setsockopt(sockfd, SOL_SOCKET, SO_REUSEADDR, (char *) &n, sizeof n);\r
 \r
                        if (!bind(sockfd, t->ai_addr, t->ai_addrlen))\r
index a789275..36446aa 100644 (file)
@@ -248,9 +248,10 @@ static struct pingpong_dest *pp_server_exch_dest(struct pingpong_context *ctx,
        for (t = res; t; t = t->ai_next) {\r
                sockfd = socket(t->ai_family, t->ai_socktype, t->ai_protocol);\r
                if (sockfd >= 0) {\r
+                       n = 0;\r
+                       setsockopt(sockfd, IPPROTO_IPV6, IPV6_V6ONLY, (char *) &n, sizeof n);\r
                        n = 1;\r
-\r
-                       setsockopt(sockfd, SOL_SOCKET, SO_REUSEADDR, &n, sizeof n);\r
+                       setsockopt(sockfd, SOL_SOCKET, SO_REUSEADDR, (char *) &n, sizeof n);\r
 \r
                        if (!bind(sockfd, t->ai_addr, t->ai_addrlen))\r
                                break;\r
index b292c5f..d17559c 100644 (file)
@@ -194,8 +194,9 @@ static struct pingpong_dest *pp_server_exch_dest(struct pingpong_context *ctx,
        for (t = res; t; t = t->ai_next) {\r
                sockfd = socket(t->ai_family, t->ai_socktype, t->ai_protocol);\r
                if (sockfd != INVALID_SOCKET) {\r
+                       n = 0;\r
+                       setsockopt(sockfd, IPPROTO_IPV6, IPV6_V6ONLY, (char *) &n, sizeof n);\r
                        n = 1;\r
-\r
                        setsockopt(sockfd, SOL_SOCKET, SO_REUSEADDR, (char *) &n, sizeof n);\r
 \r
                        if (!bind(sockfd, t->ai_addr, t->ai_addrlen))\r
index 831f7d0..f3e73f7 100644 (file)
@@ -195,8 +195,9 @@ static struct pingpong_dest *pp_server_exch_dest(struct pingpong_context *ctx,
        for (t = res; t; t = t->ai_next) {\r
                sockfd = socket(t->ai_family, t->ai_socktype, t->ai_protocol);\r
                if (sockfd != INVALID_SOCKET) {\r
+                       n = 0;\r
+                       setsockopt(sockfd, IPPROTO_IPV6, IPV6_V6ONLY, (char *) &n, sizeof n);\r
                        n = 1;\r
-\r
                        setsockopt(sockfd, SOL_SOCKET, SO_REUSEADDR, (char *) &n, sizeof n);\r
 \r
                        if (!bind(sockfd, t->ai_addr, t->ai_addrlen))\r