X-Git-Url: http://git.tuebingen.mpg.de/?p=paraslash.git;a=blobdiff_plain;f=net.c;h=91200fc040bcfebafccf9e737fb65514af9ff8f2;hp=ba19408e11337a82aaa380d2e8fe96ceca0c5673;hb=3685a9093ae12ff9ce02fc58e607eb9b63894443;hpb=53af5c6efb309565990203fd8504a812ec9166c9 diff --git a/net.c b/net.c index ba19408e..91200fc0 100644 --- a/net.c +++ b/net.c @@ -10,18 +10,6 @@ #include #include #include - -/* At least NetBSD needs these. */ -#ifndef AI_V4MAPPED -#define AI_V4MAPPED 0 -#endif -#ifndef AI_ALL -#define AI_ALL 0 -#endif -#ifndef AI_ADDRCONFIG -#define AI_ADDRCONFIG 0 -#endif - #include #include "error.h" @@ -886,14 +874,13 @@ int dccp_available_ccids(uint8_t **ccid_array) * The first call to this function tries to bind a socket to the abstract name * space. The result of this test is stored in a static variable. Subsequent * calls read this variable and create abstract sockets on systems that support - * them. + * them. If a NULL pointer is passed as the name, the function only + * initializes the static variable. */ static int init_unix_addr(struct sockaddr_un *u, const char *name) { static int use_abstract; - if (strlen(name) + 1 >= UNIX_PATH_MAX) - return -E_NAME_TOO_LONG; memset(u->sun_path, 0, UNIX_PATH_MAX); u->sun_family = PF_UNIX; if (use_abstract == 0) { /* executed only once */ @@ -907,6 +894,10 @@ static int init_unix_addr(struct sockaddr_un *u, const char *name) PARA_NOTICE_LOG("%susing abstract socket namespace\n", use_abstract == 1? "" : "not "); } + if (!name) + return 0; + if (strlen(name) + 1 >= UNIX_PATH_MAX) + return -E_NAME_TOO_LONG; strcpy(u->sun_path + (use_abstract == 1? 1 : 0), name); return 1; } @@ -931,7 +922,7 @@ int create_local_socket(const char *name) int fd, ret; ret = init_unix_addr(&unix_addr, name); - if (ret < 0) + if (ret <= 0) /* error, or name was NULL */ return ret; ret = socket(PF_UNIX, SOCK_STREAM, 0); if (ret < 0)