Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/crypto/dist/ipsec-tools/src/racoon From Roman Hoog Antink <r...



details:   https://anonhg.NetBSD.org/src/rev/f759704c230c
branches:  trunk
changeset: 761455:f759704c230c
user:      tteras <tteras%NetBSD.org@localhost>
date:      Fri Jan 28 12:51:40 2011 +0000

description:
>From Roman Hoog Antink <rha%open.ch@localhost>: Log remote IP address if available
(slightly modified by tteras)

diffstat:

 crypto/dist/ipsec-tools/src/racoon/plog.c |  49 ++++++++++++++++++++++++------
 1 files changed, 38 insertions(+), 11 deletions(-)

diffs (101 lines):

diff -r e69f48d9f73a -r f759704c230c crypto/dist/ipsec-tools/src/racoon/plog.c
--- a/crypto/dist/ipsec-tools/src/racoon/plog.c Fri Jan 28 11:58:38 2011 +0000
+++ b/crypto/dist/ipsec-tools/src/racoon/plog.c Fri Jan 28 12:51:40 2011 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: plog.c,v 1.6 2009/04/20 13:23:55 tteras Exp $  */
+/*     $NetBSD: plog.c,v 1.7 2011/01/28 12:51:40 tteras Exp $  */
 
 /* Id: plog.c,v 1.11 2006/06/20 09:57:31 vanhu Exp */
 
@@ -36,6 +36,7 @@
 #include <sys/types.h>
 #include <sys/param.h>
 
+#include <arpa/inet.h>
 #include <stdlib.h>
 #include <stdio.h>
 #include <string.h>
@@ -78,7 +79,7 @@
 static struct log *logp = NULL;
 static char *logfile = NULL;
 
-static char *plog_common __P((int, const char *, const char *));
+static char *plog_common __P((int, const char *, const char *, struct sockaddr *));
 
 static struct plogtags {
        char *name;
@@ -94,11 +95,13 @@
 };
 
 static char *
-plog_common(pri, fmt, func)
+plog_common(pri, fmt, func, sa)
        int pri;
        const char *fmt, *func;
+       struct sockaddr *sa;
 {
        static char buf[800];   /* XXX shoule be allocated every time ? */
+       void *addr;
        char *p;
        int reslen, len;
 
@@ -116,19 +119,43 @@
                reslen -= len;
        }
 
+       if (sa && reslen > 3) {
+               addr = NULL;
+               switch (sa->sa_family) {
+               case AF_INET:
+                       addr = &((struct sockaddr_in*)sa)->sin_addr;
+                       break;
+               case AF_INET6:
+                       addr = &((struct sockaddr_in6*)sa)->sin6_addr;
+                       break;
+               }
+               if (inet_ntop(sa->sa_family, addr, p + 1, reslen - 3) != NULL) {
+                       *p++ = '[';
+                       len = strlen(p);
+                       p += len;
+                       *p++ = ']';
+                       *p++ = ' ';
+                       reslen -= len + 3;
+               }
+       }
+
        if (pri < ARRAYLEN(ptab)) {
                len = snprintf(p, reslen, "%s: ", ptab[pri].name);
-               if (len >= 0 && len < reslen) {
-                       p += len;
-                       reslen -= len;
-               } else
-                       *p = '\0';
+               p += len;
+               reslen -= len;
        }
 
        if (print_location)
-               snprintf(p, reslen, "%s: %s", func, fmt);
+               len = snprintf(p, reslen, "%s: %s", func, fmt);
        else
-               snprintf(p, reslen, "%s", fmt);
+               len = snprintf(p, reslen, "%s", fmt);
+       p += len;
+       reslen -= len;
+
+       /* Force nul termination */
+       if (reslen == 0)
+               p[-1] = 0;
+
 #ifdef BROKEN_PRINTF
        while ((p = strstr(buf,"%z")) != NULL)
                p[1] = 'l';
@@ -157,7 +184,7 @@
        if (pri > loglevel)
                return;
 
-       newfmt = plog_common(pri, fmt, func);
+       newfmt = plog_common(pri, fmt, func, sa);
 
        VA_COPY(ap_bak, ap);
        



Home | Main Index | Thread Index | Old Index