diff options
author | Christian Grothoff <christian@grothoff.org> | 2010-07-18 20:17:50 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2010-07-18 20:17:50 +0000 |
commit | 39652d5d03a832f2bf45c58f237f91672cfeb4db (patch) | |
tree | cdd5858451e04aa1d42f9111484220cd318cecbd /src/util/network.c | |
parent | ed5ede797347e5decdfc56085815dcdf2843609d (diff) | |
download | gnunet-39652d5d03a832f2bf45c58f237f91672cfeb4db.tar.gz gnunet-39652d5d03a832f2bf45c58f237f91672cfeb4db.zip |
bind to v6 only
Diffstat (limited to 'src/util/network.c')
-rw-r--r-- | src/util/network.c | 22 |
1 files changed, 21 insertions, 1 deletions
diff --git a/src/util/network.c b/src/util/network.c index 2d59b46dd..886813426 100644 --- a/src/util/network.c +++ b/src/util/network.c | |||
@@ -45,6 +45,10 @@ struct GNUNET_NETWORK_Handle | |||
45 | SOCKET fd; | 45 | SOCKET fd; |
46 | #endif | 46 | #endif |
47 | 47 | ||
48 | /** | ||
49 | * Address family / domain. | ||
50 | */ | ||
51 | int af; | ||
48 | }; | 52 | }; |
49 | 53 | ||
50 | 54 | ||
@@ -203,6 +207,9 @@ GNUNET_NETWORK_socket_accept (const struct GNUNET_NETWORK_Handle *desc, | |||
203 | struct GNUNET_NETWORK_Handle *ret; | 207 | struct GNUNET_NETWORK_Handle *ret; |
204 | 208 | ||
205 | ret = GNUNET_malloc (sizeof (struct GNUNET_NETWORK_Handle)); | 209 | ret = GNUNET_malloc (sizeof (struct GNUNET_NETWORK_Handle)); |
210 | ret->af = address->sa_family; | ||
211 | /* NOTE: if sa_family does not exist on some platform, | ||
212 | using AF_UNSPEC should be safe */ | ||
206 | ret->fd = accept (desc->fd, address, address_len); | 213 | ret->fd = accept (desc->fd, address, address_len); |
207 | if (ret->fd == INVALID_SOCKET) | 214 | if (ret->fd == INVALID_SOCKET) |
208 | { | 215 | { |
@@ -260,7 +267,18 @@ GNUNET_NETWORK_socket_bind (struct GNUNET_NETWORK_Handle *desc, | |||
260 | socklen_t address_len) | 267 | socklen_t address_len) |
261 | { | 268 | { |
262 | int ret; | 269 | int ret; |
263 | 270 | ||
271 | #ifdef IPV6_V6ONLY | ||
272 | #ifdef IPPROTO_IPV6 | ||
273 | const int on = 1; | ||
274 | if (desc->af == AF_INET6) | ||
275 | setsockopt (desc->fd, IPPROTO_IPV6, IPV6_V6ONLY, &on, sizeof (on)); | ||
276 | #if 0 | ||
277 | /* is this needed or desired? or done elsewhere? */ | ||
278 | setsockopt (desc->fd, SOL_SOCKET, SO_REUSEADDR, &on, sizeof (on)); | ||
279 | #endif | ||
280 | #endif | ||
281 | #endif | ||
264 | ret = bind (desc->fd, address, address_len); | 282 | ret = bind (desc->fd, address, address_len); |
265 | #ifdef MINGW | 283 | #ifdef MINGW |
266 | if (SOCKET_ERROR == ret) | 284 | if (SOCKET_ERROR == ret) |
@@ -320,6 +338,7 @@ GNUNET_NETWORK_socket_box_native (int fd) | |||
320 | return NULL; /* invalid FD */ | 338 | return NULL; /* invalid FD */ |
321 | ret = GNUNET_malloc (sizeof (struct GNUNET_NETWORK_Handle)); | 339 | ret = GNUNET_malloc (sizeof (struct GNUNET_NETWORK_Handle)); |
322 | ret->fd = fd; | 340 | ret->fd = fd; |
341 | ret->af = AF_UNSPEC; | ||
323 | return ret; | 342 | return ret; |
324 | #endif | 343 | #endif |
325 | } | 344 | } |
@@ -602,6 +621,7 @@ GNUNET_NETWORK_socket_create (int domain, int type, int protocol) | |||
602 | { | 621 | { |
603 | struct GNUNET_NETWORK_Handle *ret; | 622 | struct GNUNET_NETWORK_Handle *ret; |
604 | ret = GNUNET_malloc (sizeof (struct GNUNET_NETWORK_Handle)); | 623 | ret = GNUNET_malloc (sizeof (struct GNUNET_NETWORK_Handle)); |
624 | ret->af = domain; | ||
605 | ret->fd = socket (domain, type, protocol); | 625 | ret->fd = socket (domain, type, protocol); |
606 | if (INVALID_SOCKET == ret->fd) | 626 | if (INVALID_SOCKET == ret->fd) |
607 | { | 627 | { |