aboutsummaryrefslogtreecommitdiff
path: root/src/util/network.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/util/network.c')
-rw-r--r--src/util/network.c28
1 files changed, 8 insertions, 20 deletions
diff --git a/src/util/network.c b/src/util/network.c
index c0b977368..793290b45 100644
--- a/src/util/network.c
+++ b/src/util/network.c
@@ -87,7 +87,9 @@ 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 fprintf (stderr, "Failed to create test socket: %s\n", STRERROR (errno)); 90 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
91 "Failed to create test socket: %s\n",
92 STRERROR (errno));
91 return GNUNET_SYSERR; 93 return GNUNET_SYSERR;
92 } 94 }
93#if WINDOWS 95#if WINDOWS
@@ -383,20 +385,18 @@ GNUNET_NETWORK_socket_accept (const struct GNUNET_NETWORK_Handle *desc,
383 * @param desc socket to bind 385 * @param desc socket to bind
384 * @param address address to be bound 386 * @param address address to be bound
385 * @param address_len length of @a address 387 * @param address_len length of @a address
386 * @param flags flags affecting bind behaviour
387 * @return #GNUNET_OK on success, #GNUNET_SYSERR otherwise 388 * @return #GNUNET_OK on success, #GNUNET_SYSERR otherwise
388 */ 389 */
389int 390int
390GNUNET_NETWORK_socket_bind (struct GNUNET_NETWORK_Handle *desc, 391GNUNET_NETWORK_socket_bind (struct GNUNET_NETWORK_Handle *desc,
391 const struct sockaddr *address, 392 const struct sockaddr *address,
392 socklen_t address_len, 393 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 (address->sa_family == AF_UNIX) 399 if (AF_UNIX == address->sa_family)
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,16 +431,6 @@ 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
444 ret = bind (desc->fd, address, bind_address_len); 434 ret = bind (desc->fd, address, bind_address_len);
445#ifdef MINGW 435#ifdef MINGW
446 if (SOCKET_ERROR == ret) 436 if (SOCKET_ERROR == ret)
@@ -449,12 +439,10 @@ GNUNET_NETWORK_socket_bind (struct GNUNET_NETWORK_Handle *desc,
449 if (ret != 0) 439 if (ret != 0)
450 return GNUNET_SYSERR; 440 return GNUNET_SYSERR;
451#ifndef MINGW 441#ifndef MINGW
452#ifndef LINUX
453 desc->addr = GNUNET_malloc (address_len); 442 desc->addr = GNUNET_malloc (address_len);
454 memcpy (desc->addr, address, address_len); 443 memcpy (desc->addr, address, address_len);
455 desc->addrlen = address_len; 444 desc->addrlen = address_len;
456#endif 445#endif
457#endif
458 return GNUNET_OK; 446 return GNUNET_OK;
459} 447}
460 448
@@ -483,17 +471,17 @@ GNUNET_NETWORK_socket_close (struct GNUNET_NETWORK_Handle *desc)
483#else 471#else
484 ret = close (desc->fd); 472 ret = close (desc->fd);
485#endif 473#endif
486#ifndef LINUX
487#ifndef MINGW 474#ifndef MINGW
488 if ((desc->af == AF_UNIX) && (NULL != desc->addr)) 475 if ((desc->af == AF_UNIX) && (NULL != desc->addr))
489 { 476 {
490 const struct sockaddr_un *un = (const struct sockaddr_un *) desc->addr; 477 const struct sockaddr_un *un = (const struct sockaddr_un *) desc->addr;
491 478
492 if (0 != unlink (un->sun_path)) 479 if (0 != unlink (un->sun_path))
493 LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "unlink", un->sun_path); 480 LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING,
481 "unlink",
482 un->sun_path);
494 } 483 }
495#endif 484#endif
496#endif
497 GNUNET_NETWORK_socket_free_memory_only_ (desc); 485 GNUNET_NETWORK_socket_free_memory_only_ (desc);
498 return (ret == 0) ? GNUNET_OK : GNUNET_SYSERR; 486 return (ret == 0) ? GNUNET_OK : GNUNET_SYSERR;
499} 487}