X-Git-Url: http://www.privoxy.org/gitweb/?p=privoxy.git;a=blobdiff_plain;f=jbsockets.c;h=7b20fa38c4ae7e704cb255449346b98798fa62cf;hp=7bdb504687c59a14637a7c8f75726e0574231ef3;hb=b2f6c04a498e1ad875a35664c46bf33680171164;hpb=861f2331b86d82c770f38b7a60f8328862fe6da3 diff --git a/jbsockets.c b/jbsockets.c index 7bdb5046..7b20fa38 100644 --- a/jbsockets.c +++ b/jbsockets.c @@ -1,4 +1,4 @@ -const char jbsockets_rcs[] = "$Id: jbsockets.c,v 1.132 2015/11/06 13:34:56 fabiankeil Exp $"; +const char jbsockets_rcs[] = "$Id: jbsockets.c,v 1.136 2016/05/25 10:50:55 fabiankeil Exp $"; /********************************************************************* * * File : $Source: /cvsroot/ijbswa/current/jbsockets.c,v $ @@ -8,7 +8,7 @@ const char jbsockets_rcs[] = "$Id: jbsockets.c,v 1.132 2015/11/06 13:34:56 fabia * OS-independent. Contains #ifdefs to make this work * on many platforms. * - * Copyright : Written by and Copyright (C) 2001-2014 the + * Copyright : Written by and Copyright (C) 2001-2016 the * Privoxy team. http://www.privoxy.org/ * * Based on the Internet Junkbuster originally written @@ -1221,6 +1221,8 @@ int accept_connection(struct client_state * csp, jb_socket fds[]) int max_selected_socket; fd_set selected_fds; jb_socket fd; + const char *host_addr; + size_t listen_addr_size; c_length = sizeof(client); @@ -1307,7 +1309,7 @@ int accept_connection(struct client_state * csp, jb_socket fds[]) struct linger linger_options; linger_options.l_onoff = 1; linger_options.l_linger = 5; - if (0 != setsockopt(fd, SOL_SOCKET, SO_LINGER, &linger_options, sizeof(linger_options))) + if (0 != setsockopt(afd, SOL_SOCKET, SO_LINGER, &linger_options, sizeof(linger_options))) { log_error(LOG_LEVEL_ERROR, "Setting SO_LINGER on socket %d failed.", afd); } @@ -1348,6 +1350,26 @@ int accept_connection(struct client_state * csp, jb_socket fds[]) csp->ip_addr_long = ntohl(client.sin_addr.s_addr); #endif /* def HAVE_RFC2553 */ + /* + * Save the name and port of the accepting socket for later lookup. + * + * The string needs space for strlen(...) + 7 characters: + * strlen(haddr[i]) + 1 (':') + 5 (port digits) + 1 ('\0') + */ + host_addr = (csp->config->haddr[i] != NULL) ? csp->config->haddr[i] : ""; + listen_addr_size = strlen(host_addr) + 7; + csp->listen_addr_str = malloc_or_die(listen_addr_size); + retval = snprintf(csp->listen_addr_str, listen_addr_size, + "%s:%d", host_addr, csp->config->hport[i]); + if ((-1 == retval) || listen_addr_size <= retval) + { + log_error(LOG_LEVEL_ERROR, + "Server name (%s) and port number (%d) ASCII decimal representation" + "don't fit into %d bytes", + host_addr, csp->config->hport[i], listen_addr_size); + return 0; + } + return 1; }