Check-in [2a36924161]
Overview
Comment:Updated to correctly display IPv4 address if bound to IPv4 addresses
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1:2a36924161d93af0871843b0d506dd6c0ff7d066
User & Date: rkeene on 2014-02-08 06:55:33
Other Links: manifest | tags
Context
2014-02-08
06:57
Filed 1.0 check-in: 235573fe1c user: rkeene tags: trunk, 1.0
06:55
Updated to correctly display IPv4 address if bound to IPv4 addresses check-in: 2a36924161 user: rkeene tags: trunk
06:43
Moved more file size variables to correct type and started reporting on completion of files check-in: 521131f382 user: rkeene tags: trunk
Changes

Modified filed.c from [99eaeee2ab] to [1f0badde9e].

   205    205   }
   206    206   
   207    207   /* Log a message */
   208    208   #ifdef FILED_DONT_LOG
   209    209   #  define filed_logging_thread_init(x) 0
   210    210   #  define filed_log_msg_debug(x, ...) /**/
   211    211   #  define filed_log_msg(x, ...) /**/
          212  +#  define filed_log_ip(x, ...) "<unknown>"
   212    213   #else
   213    214   #ifdef FILED_DEBUG
   214    215   #  define filed_log_msg_debug(x, ...) { fprintf(stderr, x, __VA_ARGS__); fprintf(stderr, "\n"); fflush(stderr); }
   215    216   #else
   216    217   #  define filed_log_msg_debug(x, ...) /**/
   217    218   #endif
   218    219   
................................................................................
   295    296   
   296    297   	pthread_mutex_unlock(&filed_log_msg_list_mutex);
   297    298   
   298    299   	pthread_cond_signal(&filed_log_msg_list_ready);
   299    300   
   300    301   	return;
   301    302   }
          303  +
          304  +
          305  +static const char *filed_log_ip(struct sockaddr *addr, char *buffer, size_t bufferlen) {
          306  +	struct sockaddr_in *addr_v4;
          307  +	struct sockaddr_in6 *addr_v6;
          308  +	const char *retval = NULL;
          309  +
          310  +	addr_v6 = (struct sockaddr_in6 *) addr;
          311  +
          312  +	switch (addr_v6->sin6_family) {
          313  +		case AF_INET:
          314  +			addr_v4 = (struct sockaddr_in *) addr;
          315  +			retval = inet_ntop(AF_INET, &addr_v4->sin_addr, buffer, bufferlen);
          316  +			break;
          317  +		case AF_INET6:
          318  +			retval = inet_ntop(AF_INET6, &addr_v6->sin6_addr, buffer, bufferlen);
          319  +			break;
          320  +	}
          321  +
          322  +	if (retval == NULL) {
          323  +		retval = "<unknown>";
          324  +	}
          325  +
          326  +	return(retval);
          327  +}
   302    328   #endif
   303    329   
   304    330   /* Format time per RFC2616 */
   305    331   static char *filed_format_time(char *buffer, size_t buffer_len, const time_t timeinfo) {
   306    332   	struct tm timeinfo_tm, *timeinfo_tm_p;
   307    333   
   308    334   	timeinfo_tm_p = gmtime_r(&timeinfo, &timeinfo_tm);
................................................................................
   815    841   			failure_count++;
   816    842   
   817    843   			continue;
   818    844   		}
   819    845   
   820    846   		/* Log the new connection */
   821    847   		filed_log_msg("NEW_CONNECTION SRC_ADDR=%s SRC_PORT=%lu FD=%i",
   822         -			inet_ntop(AF_INET6, &addr.sin6_addr, logbuf_ip, sizeof(logbuf_ip)) ? logbuf_ip : "<unknown>",
          848  +			filed_log_ip((struct sockaddr *) &addr, logbuf_ip, sizeof(logbuf_ip)),
   823    849   			(unsigned long) addr.sin6_port,
   824    850   			fd
   825    851   		);
   826    852   
   827    853   		/* Reset failure count*/
   828    854   		failure_count = 0;
   829    855