diff options
author | Matthias Wachs <wachs@net.in.tum.de> | 2011-05-24 16:35:59 +0000 |
---|---|---|
committer | Matthias Wachs <wachs@net.in.tum.de> | 2011-05-24 16:35:59 +0000 |
commit | c8474ed9fabff3506d86c915e08fd9f5827ee3ec (patch) | |
tree | 600a272819393d01d584098dbca5c517b646d1b9 /src/util | |
parent | fef362e060524f45452a6f4f2c31f52474f9cf7e (diff) | |
download | gnunet-c8474ed9fabff3506d86c915e08fd9f5827ee3ec.tar.gz gnunet-c8474ed9fabff3506d86c915e08fd9f5827ee3ec.zip |
bug on bsd
Diffstat (limited to 'src/util')
-rw-r--r-- | src/util/network.c | 53 |
1 files changed, 42 insertions, 11 deletions
diff --git a/src/util/network.c b/src/util/network.c index d23f1a23d..5ff49b1ca 100644 --- a/src/util/network.c +++ b/src/util/network.c | |||
@@ -29,7 +29,7 @@ | |||
29 | #include "disk.h" | 29 | #include "disk.h" |
30 | #include "gnunet_container_lib.h" | 30 | #include "gnunet_container_lib.h" |
31 | 31 | ||
32 | #define DEBUG_NETWORK GNUNET_NO | 32 | #define DEBUG_NETWORK GNUNET_YES |
33 | 33 | ||
34 | #ifndef INVALID_SOCKET | 34 | #ifndef INVALID_SOCKET |
35 | #define INVALID_SOCKET -1 | 35 | #define INVALID_SOCKET -1 |
@@ -49,6 +49,17 @@ struct GNUNET_NETWORK_Handle | |||
49 | * Address family / domain. | 49 | * Address family / domain. |
50 | */ | 50 | */ |
51 | int af; | 51 | int af; |
52 | |||
53 | /** | ||
54 | * Number of bytes in addr. | ||
55 | */ | ||
56 | socklen_t addrlen; | ||
57 | |||
58 | /** | ||
59 | * Address we were bound to, or NULL. | ||
60 | */ | ||
61 | struct sockaddr *addr; | ||
62 | |||
52 | }; | 63 | }; |
53 | 64 | ||
54 | 65 | ||
@@ -279,23 +290,30 @@ GNUNET_NETWORK_socket_bind (struct GNUNET_NETWORK_Handle *desc, | |||
279 | #endif | 290 | #endif |
280 | #endif | 291 | #endif |
281 | #endif | 292 | #endif |
293 | #ifndef LINUX | ||
294 | #ifndef MINGW | ||
295 | if (address->sa_family == AF_UNIX) | ||
296 | { | ||
297 | const struct sockaddr_un *un = (const struct sockaddr_un*) address; | ||
298 | (void) unlink (un->sun_path); | ||
299 | } | ||
300 | #endif | ||
301 | #endif | ||
282 | ret = bind (desc->fd, address, address_len); | 302 | ret = bind (desc->fd, address, address_len); |
283 | #ifdef MINGW | 303 | #ifdef MINGW |
284 | if (SOCKET_ERROR == ret) | 304 | if (SOCKET_ERROR == ret) |
285 | SetErrnoFromWinsockError (WSAGetLastError ()); | 305 | SetErrnoFromWinsockError (WSAGetLastError ()); |
286 | #else | 306 | #endif |
307 | if (ret != 0) | ||
308 | return GNUNET_SYSERR; | ||
309 | #ifndef MINGW | ||
287 | #ifndef LINUX | 310 | #ifndef LINUX |
288 | if ( (ret == 0) && (address->sa_family == AF_UNIX)) | 311 | desc->addr = GNUNET_malloc (address_len); |
289 | { | 312 | memcpy (desc->addr, address, address_len); |
290 | const struct sockaddr_un *un = (const struct sockaddr_un*) address; | 313 | desc->addrlen = address_len; |
291 | if (0 != unlink (un->sun_path)) | ||
292 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, | ||
293 | "unlink", | ||
294 | un->sun_path); | ||
295 | } | ||
296 | #endif | 314 | #endif |
297 | #endif | 315 | #endif |
298 | return ret == 0 ? GNUNET_OK : GNUNET_SYSERR; | 316 | return GNUNET_OK; |
299 | } | 317 | } |
300 | 318 | ||
301 | 319 | ||
@@ -315,6 +333,19 @@ GNUNET_NETWORK_socket_close (struct GNUNET_NETWORK_Handle *desc) | |||
315 | #else | 333 | #else |
316 | ret = close (desc->fd); | 334 | ret = close (desc->fd); |
317 | #endif | 335 | #endif |
336 | #ifndef LINUX | ||
337 | #ifndef MINGW | ||
338 | if ( (desc->af == AF_UNIX) && (NULL != desc->addr) ) | ||
339 | { | ||
340 | const struct sockaddr_un *un = (const struct sockaddr_un*) desc->addr; | ||
341 | if (0 != unlink (un->sun_path)) | ||
342 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, | ||
343 | "unlink", | ||
344 | un->sun_path); | ||
345 | } | ||
346 | #endif | ||
347 | #endif | ||
348 | GNUNET_free_non_null (desc->addr); | ||
318 | GNUNET_free (desc); | 349 | GNUNET_free (desc); |
319 | return (ret == 0) ? GNUNET_OK : GNUNET_SYSERR; | 350 | return (ret == 0) ? GNUNET_OK : GNUNET_SYSERR; |
320 | } | 351 | } |