remove the responsibility for setting listensocklen to the function that made the sockaddr

svn:r17799
This commit is contained in:
Nick Mathewson 2008-12-27 15:46:13 +00:00
parent 365c72246c
commit ae71b52945

View File

@ -759,7 +759,7 @@ connection_expire_held_open(void)
*/ */
static struct sockaddr_in * static struct sockaddr_in *
create_inet_sockaddr(const char *listenaddress, uint16_t listenport, create_inet_sockaddr(const char *listenaddress, uint16_t listenport,
char **readable_address) { char **readable_address, socklen_t *socklen_out) {
struct sockaddr_in *listenaddr = NULL; struct sockaddr_in *listenaddr = NULL;
uint32_t addr; uint32_t addr;
uint16_t usePort = 0; uint16_t usePort = 0;
@ -778,6 +778,8 @@ create_inet_sockaddr(const char *listenaddress, uint16_t listenport,
listenaddr->sin_family = AF_INET; listenaddr->sin_family = AF_INET;
listenaddr->sin_port = htons((uint16_t) usePort); listenaddr->sin_port = htons((uint16_t) usePort);
*socklen_out = sizeof(struct sockaddr_in);
return listenaddr; return listenaddr;
err: err:
@ -800,7 +802,8 @@ create_inet_sockaddr(const char *listenaddress, uint16_t listenport,
* The listenaddr struct has to be freed by the caller. * The listenaddr struct has to be freed by the caller.
*/ */
static struct sockaddr_un * static struct sockaddr_un *
create_unix_sockaddr(const char *listenaddress, char **readable_address) create_unix_sockaddr(const char *listenaddress, char **readable_address,
socklen_t *len_out)
{ {
struct sockaddr_un *sockaddr = NULL; struct sockaddr_un *sockaddr = NULL;
@ -811,16 +814,19 @@ create_unix_sockaddr(const char *listenaddress, char **readable_address)
if (readable_address) if (readable_address)
*readable_address = tor_strdup(listenaddress); *readable_address = tor_strdup(listenaddress);
*len_out = sizeof(struct sockaddr_un);
return sockaddr; return sockaddr;
} }
#else #else
static struct sockaddr * static struct sockaddr *
create_unix_sockaddr(const char *listenaddress, char **readable_address) create_unix_sockaddr(const char *listenaddress, char **readable_address,
socklen_t *len_out)
{ {
(void)listenaddress; (void)listenaddress;
(void)readable_address; (void)readable_address;
log_fn(LOG_ERR, LD_BUG, log_fn(LOG_ERR, LD_BUG,
"Unix domain sockets not supported, yet we tried to create one."); "Unix domain sockets not supported, yet we tried to create one.");
*len_out = 0;
tor_assert(0); tor_assert(0);
}; };
#endif /* HAVE_SYS_UN_H */ #endif /* HAVE_SYS_UN_H */
@ -1420,25 +1426,22 @@ retry_listeners(int type, config_line_t *cfg,
/* Now open all the listeners that are configured but not opened. */ /* Now open all the listeners that are configured but not opened. */
r = 0; r = 0;
if (!disable_all_conns) { if (!disable_all_conns) {
SMARTLIST_FOREACH(launch, config_line_t *, cfg_line, SMARTLIST_FOREACH_BEGIN(launch, config_line_t *, cfg_line) {
{
char *address = NULL; char *address = NULL;
struct sockaddr *listensockaddr; struct sockaddr *listensockaddr;
socklen_t listensocklen; socklen_t listensocklen = 0;
switch (socket_family) { switch (socket_family) {
case AF_INET: case AF_INET:
listensockaddr = (struct sockaddr *) listensockaddr = (struct sockaddr *)
create_inet_sockaddr(cfg_line->value, create_inet_sockaddr(cfg_line->value,
(uint16_t) port_option, (uint16_t) port_option,
&address); &address, &listensocklen);
listensocklen = sizeof(struct sockaddr_in);
break; break;
case AF_UNIX: case AF_UNIX:
listensockaddr = (struct sockaddr *) listensockaddr = (struct sockaddr *)
create_unix_sockaddr(cfg_line->value, create_unix_sockaddr(cfg_line->value,
&address); &address, &listensocklen);
listensocklen = sizeof(struct sockaddr_un);
break; break;
default: default:
tor_assert(0); tor_assert(0);
@ -1458,7 +1461,7 @@ retry_listeners(int type, config_line_t *cfg,
if (new_conns) if (new_conns)
smartlist_add(new_conns, conn); smartlist_add(new_conns, conn);
} }
}); } SMARTLIST_FOREACH_END(cfg_line);
} }
if (free_launch_elts) { if (free_launch_elts) {