diff options
author | Christian Grothoff <christian@grothoff.org> | 2013-09-27 09:49:39 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2013-09-27 09:49:39 +0000 |
commit | bcdae74167d2e1f9d8dd9b01fb368bf8bcc2287d (patch) | |
tree | b1f47d243e677d53de0c3503a1d5caf43dba073e /src/util/network.c | |
parent | dd22c2132e58ba4ac960337efc0f843c12f58780 (diff) | |
download | gnunet-bcdae74167d2e1f9d8dd9b01fb368bf8bcc2287d.tar.gz gnunet-bcdae74167d2e1f9d8dd9b01fb368bf8bcc2287d.zip |
-undo #29640, somehow causes problems
Diffstat (limited to 'src/util/network.c')
-rw-r--r-- | src/util/network.c | 28 |
1 files changed, 20 insertions, 8 deletions
diff --git a/src/util/network.c b/src/util/network.c index 793290b45..c0b977368 100644 --- a/src/util/network.c +++ b/src/util/network.c | |||
@@ -87,9 +87,7 @@ GNUNET_NETWORK_test_pf (int pf) | |||
87 | { | 87 | { |
88 | if (EAFNOSUPPORT == errno) | 88 | if (EAFNOSUPPORT == errno) |
89 | return GNUNET_NO; | 89 | return GNUNET_NO; |
90 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 90 | fprintf (stderr, "Failed to create test socket: %s\n", STRERROR (errno)); |
91 | "Failed to create test socket: %s\n", | ||
92 | STRERROR (errno)); | ||
93 | return GNUNET_SYSERR; | 91 | return GNUNET_SYSERR; |
94 | } | 92 | } |
95 | #if WINDOWS | 93 | #if WINDOWS |
@@ -385,18 +383,20 @@ GNUNET_NETWORK_socket_accept (const struct GNUNET_NETWORK_Handle *desc, | |||
385 | * @param desc socket to bind | 383 | * @param desc socket to bind |
386 | * @param address address to be bound | 384 | * @param address address to be bound |
387 | * @param address_len length of @a address | 385 | * @param address_len length of @a address |
386 | * @param flags flags affecting bind behaviour | ||
388 | * @return #GNUNET_OK on success, #GNUNET_SYSERR otherwise | 387 | * @return #GNUNET_OK on success, #GNUNET_SYSERR otherwise |
389 | */ | 388 | */ |
390 | int | 389 | int |
391 | GNUNET_NETWORK_socket_bind (struct GNUNET_NETWORK_Handle *desc, | 390 | GNUNET_NETWORK_socket_bind (struct GNUNET_NETWORK_Handle *desc, |
392 | const struct sockaddr *address, | 391 | const struct sockaddr *address, |
393 | socklen_t address_len) | 392 | socklen_t address_len, |
393 | int flags) | ||
394 | { | 394 | { |
395 | int ret; | 395 | int ret; |
396 | socklen_t bind_address_len = address_len; | 396 | socklen_t bind_address_len = address_len; |
397 | 397 | ||
398 | #ifdef LINUX | 398 | #ifdef LINUX |
399 | if (AF_UNIX == address->sa_family) | 399 | if (address->sa_family == AF_UNIX) |
400 | { | 400 | { |
401 | const struct sockaddr_un *address_un = (const struct sockaddr_un *)address; | 401 | const struct sockaddr_un *address_un = (const struct sockaddr_un *)address; |
402 | if (address_un->sun_path[0] == '\0') | 402 | if (address_un->sun_path[0] == '\0') |
@@ -431,6 +431,16 @@ GNUNET_NETWORK_socket_bind (struct GNUNET_NETWORK_Handle *desc, | |||
431 | LOG_STRERROR (GNUNET_ERROR_TYPE_DEBUG, "setsockopt"); | 431 | LOG_STRERROR (GNUNET_ERROR_TYPE_DEBUG, "setsockopt"); |
432 | } | 432 | } |
433 | #endif | 433 | #endif |
434 | #ifndef LINUX | ||
435 | #ifndef MINGW | ||
436 | if (address->sa_family == AF_UNIX && (flags & GNUNET_BIND_EXCLUSIVE) == 0) | ||
437 | { | ||
438 | const struct sockaddr_un *un = (const struct sockaddr_un *) address; | ||
439 | |||
440 | (void) unlink (un->sun_path); | ||
441 | } | ||
442 | #endif | ||
443 | #endif | ||
434 | ret = bind (desc->fd, address, bind_address_len); | 444 | ret = bind (desc->fd, address, bind_address_len); |
435 | #ifdef MINGW | 445 | #ifdef MINGW |
436 | if (SOCKET_ERROR == ret) | 446 | if (SOCKET_ERROR == ret) |
@@ -439,10 +449,12 @@ GNUNET_NETWORK_socket_bind (struct GNUNET_NETWORK_Handle *desc, | |||
439 | if (ret != 0) | 449 | if (ret != 0) |
440 | return GNUNET_SYSERR; | 450 | return GNUNET_SYSERR; |
441 | #ifndef MINGW | 451 | #ifndef MINGW |
452 | #ifndef LINUX | ||
442 | desc->addr = GNUNET_malloc (address_len); | 453 | desc->addr = GNUNET_malloc (address_len); |
443 | memcpy (desc->addr, address, address_len); | 454 | memcpy (desc->addr, address, address_len); |
444 | desc->addrlen = address_len; | 455 | desc->addrlen = address_len; |
445 | #endif | 456 | #endif |
457 | #endif | ||
446 | return GNUNET_OK; | 458 | return GNUNET_OK; |
447 | } | 459 | } |
448 | 460 | ||
@@ -471,17 +483,17 @@ GNUNET_NETWORK_socket_close (struct GNUNET_NETWORK_Handle *desc) | |||
471 | #else | 483 | #else |
472 | ret = close (desc->fd); | 484 | ret = close (desc->fd); |
473 | #endif | 485 | #endif |
486 | #ifndef LINUX | ||
474 | #ifndef MINGW | 487 | #ifndef MINGW |
475 | if ((desc->af == AF_UNIX) && (NULL != desc->addr)) | 488 | if ((desc->af == AF_UNIX) && (NULL != desc->addr)) |
476 | { | 489 | { |
477 | const struct sockaddr_un *un = (const struct sockaddr_un *) desc->addr; | 490 | const struct sockaddr_un *un = (const struct sockaddr_un *) desc->addr; |
478 | 491 | ||
479 | if (0 != unlink (un->sun_path)) | 492 | if (0 != unlink (un->sun_path)) |
480 | LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, | 493 | LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "unlink", un->sun_path); |
481 | "unlink", | ||
482 | un->sun_path); | ||
483 | } | 494 | } |
484 | #endif | 495 | #endif |
496 | #endif | ||
485 | GNUNET_NETWORK_socket_free_memory_only_ (desc); | 497 | GNUNET_NETWORK_socket_free_memory_only_ (desc); |
486 | return (ret == 0) ? GNUNET_OK : GNUNET_SYSERR; | 498 | return (ret == 0) ? GNUNET_OK : GNUNET_SYSERR; |
487 | } | 499 | } |