Source-Changes-HG archive

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

[src/trunk]: src/external/bsd/ipf/dist/tools copy structures for alignment pu...



details:   https://anonhg.NetBSD.org/src/rev/39403ebebc5a
branches:  trunk
changeset: 782301:39403ebebc5a
user:      christos <christos%NetBSD.org@localhost>
date:      Fri Oct 26 23:05:14 2012 +0000

description:
copy structures for alignment purposes

diffstat:

 external/bsd/ipf/dist/tools/ipmon.c |  374 ++++++++++++++++++------------------
 1 files changed, 187 insertions(+), 187 deletions(-)

diffs (truncated from 783 to 300 lines):

diff -r 9bbe809b8db9 -r 39403ebebc5a external/bsd/ipf/dist/tools/ipmon.c
--- a/external/bsd/ipf/dist/tools/ipmon.c       Fri Oct 26 21:03:26 2012 +0000
+++ b/external/bsd/ipf/dist/tools/ipmon.c       Fri Oct 26 23:05:14 2012 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: ipmon.c,v 1.5 2012/10/22 04:35:17 christos Exp $       */
+/*     $NetBSD: ipmon.c,v 1.6 2012/10/26 23:05:14 christos Exp $       */
 
 /*
  * Copyright (C) 2012 by Darren Reed.
@@ -130,9 +130,9 @@
 static void    handlehup(int);
 static void    flushlogs(const char *, FILE *);
 static void    print_log(config_t *, logsource_t *, const void *, size_t);
-static void    print_ipflog(config_t *, const void *, size_t);
-static void    print_natlog(config_t *, const void *, size_t);
-static void    print_statelog(config_t *, const void *, size_t);
+static void    print_ipflog(config_t *, const iplog_t *, const void *, size_t);
+static void    print_natlog(config_t *, const iplog_t *, const void *, size_t);
+static void    print_statelog(config_t *, const iplog_t *, const void *, size_t);
 static int     read_log(int, size_t *, void *, size_t);
 static void    write_pid(const char *);
 static char    *icmpname(u_int, u_int);
@@ -649,20 +649,18 @@
 }
 
 static void
-print_natlog(config_t *conf, const void *buf, size_t blen)
+print_natlog(config_t *conf, const iplog_t *ipl, const void *buf, size_t blen)
 {
        static u_32_t seqnum = 0;
        int res, i, len, family;
-       const struct natlog *nl;
+       struct natlog nl;
        struct tm *tm;
-       const iplog_t *ipl;
        char *proto;
        int simple;
        char *t;
 
        t = line;
        simple = 0;
-       ipl = (const iplog_t *)buf;
        if (ipl->ipl_seqnum != seqnum) {
                if ((ipmonopts & IPMON_SYSLOG) != 0) {
                        syslog(LOG_WARNING,
@@ -678,7 +676,7 @@
        }
        seqnum = ipl->ipl_seqnum + ipl->ipl_count;
 
-       nl = (const struct natlog *)((const char *)ipl + sizeof(*ipl));
+       memcpy(&nl, (const char *)buf + sizeof(*ipl), sizeof(nl));
        res = (ipmonopts & IPMON_RESOLVE) ? 1 : 0;
        tm = get_tm(ipl->ipl_sec);
        len = sizeof(line);
@@ -692,10 +690,10 @@
        (void) strftime(t, len, "%T", tm);
        t += strlen(t);
        (void) sprintf(t, ".%-.6ld @%hd ", (long)ipl->ipl_usec,
-           nl->nl_rule + 1);
+           nl.nl_rule + 1);
        t += strlen(t);
 
-       switch (nl->nl_action)
+       switch (nl.nl_action)
        {
        case NL_NEW :
                strcpy(t, "NAT:NEW");
@@ -722,13 +720,13 @@
                break;
 
        default :
-               sprintf(t, "NAT:Action(%d)", nl->nl_action);
+               sprintf(t, "NAT:Action(%d)", nl.nl_action);
                break;
        }
        t += strlen(t);
 
 
-       switch (nl->nl_type)
+       switch (nl.nl_type)
        {
        case NAT_MAP :
                strcpy(t, "-MAP ");
@@ -775,43 +773,43 @@
                break;
 
        default :
-               sprintf(t, "-Type(%d) ", nl->nl_type);
+               sprintf(t, "-Type(%d) ", nl.nl_type);
                break;
        }
        t += strlen(t);
 
-       proto = getlocalproto(nl->nl_p[0]);
+       proto = getlocalproto(nl.nl_p[0]);
 
-       family = vtof(nl->nl_v[0]);
+       family = vtof(nl.nl_v[0]);
 
        if (simple == 1) {
-               sprintf(t, "%s,%s <- -> ", hostname(family, nl->nl_osrcip.i6),
-                       portlocalname(res, proto, (u_int)nl->nl_osrcport));
+               sprintf(t, "%s,%s <- -> ", hostname(family, nl.nl_osrcip.i6),
+                       portlocalname(res, proto, (u_int)nl.nl_osrcport));
                t += strlen(t);
-               sprintf(t, "%s,%s ", hostname(family, nl->nl_nsrcip.i6),
-                       portlocalname(res, proto, (u_int)nl->nl_nsrcport));
+               sprintf(t, "%s,%s ", hostname(family, nl.nl_nsrcip.i6),
+                       portlocalname(res, proto, (u_int)nl.nl_nsrcport));
                t += strlen(t);
-               sprintf(t, "[%s,%s] ", hostname(family, nl->nl_odstip.i6),
-                       portlocalname(res, proto, (u_int)nl->nl_odstport));
+               sprintf(t, "[%s,%s] ", hostname(family, nl.nl_odstip.i6),
+                       portlocalname(res, proto, (u_int)nl.nl_odstport));
        } else {
-               sprintf(t, "%s,%s ", hostname(family, nl->nl_osrcip.i6),
-                       portlocalname(res, proto, (u_int)nl->nl_osrcport));
+               sprintf(t, "%s,%s ", hostname(family, nl.nl_osrcip.i6),
+                       portlocalname(res, proto, (u_int)nl.nl_osrcport));
                t += strlen(t);
-               sprintf(t, "%s,%s <- -> ", hostname(family, nl->nl_odstip.i6),
-                       portlocalname(res, proto, (u_int)nl->nl_odstport));
+               sprintf(t, "%s,%s <- -> ", hostname(family, nl.nl_odstip.i6),
+                       portlocalname(res, proto, (u_int)nl.nl_odstport));
                t += strlen(t);
-               sprintf(t, "%s,%s ", hostname(family, nl->nl_nsrcip.i6),
-                       portlocalname(res, proto, (u_int)nl->nl_nsrcport));
+               sprintf(t, "%s,%s ", hostname(family, nl.nl_nsrcip.i6),
+                       portlocalname(res, proto, (u_int)nl.nl_nsrcport));
                t += strlen(t);
-               sprintf(t, "%s,%s ", hostname(family, nl->nl_ndstip.i6),
-                       portlocalname(res, proto, (u_int)nl->nl_ndstport));
+               sprintf(t, "%s,%s ", hostname(family, nl.nl_ndstip.i6),
+                       portlocalname(res, proto, (u_int)nl.nl_ndstport));
        }
        t += strlen(t);
 
-       strcpy(t, getlocalproto(nl->nl_p[0]));
+       strcpy(t, getlocalproto(nl.nl_p[0]));
        t += strlen(t);
 
-       if (nl->nl_action == NL_EXPIRE || nl->nl_action == NL_FLUSH) {
+       if (nl.nl_action == NL_EXPIRE || nl.nl_action == NL_FLUSH) {
 #ifdef USE_QUAD_T
 # ifdef        PRId64
                sprintf(t, " Pkts %" PRId64 "/%" PRId64 " Bytes %" PRId64 "/%"
@@ -822,8 +820,8 @@
 #else
                sprintf(t, " Pkts %ld/%ld Bytes %ld/%ld",
 #endif
-                               nl->nl_pkts[0], nl->nl_pkts[1],
-                               nl->nl_bytes[0], nl->nl_bytes[1]);
+                               nl.nl_pkts[0], nl.nl_pkts[1],
+                               nl.nl_bytes[0], nl.nl_bytes[1]);
                t += strlen(t);
        }
 
@@ -837,14 +835,13 @@
 
 
 static void
-print_statelog(config_t *conf, const void *buf, size_t blen)
+print_statelog(config_t *conf, const iplog_t *ipl, const void *buf, size_t blen)
 {
        static u_32_t seqnum = 0;
        int res, i, len, family;
-       const struct ipslog *sl;
+       struct ipslog sl;
        char *t, *proto;
        struct tm *tm;
-       const iplog_t *ipl;
 
        t = line;
        ipl = (const iplog_t *)buf;
@@ -863,7 +860,7 @@
        }
        seqnum = ipl->ipl_seqnum + ipl->ipl_count;
 
-       sl = (const struct ipslog *)((const char *)ipl + sizeof(*ipl));
+       memcpy(&sl, (const char *)buf + sizeof(*ipl), sizeof(sl));
        res = (ipmonopts & IPMON_RESOLVE) ? 1 : 0;
        tm = get_tm(ipl->ipl_sec);
        len = sizeof(line);
@@ -878,9 +875,9 @@
        (void) sprintf(t, ".%-.6ld ", (long)ipl->ipl_usec);
        t += strlen(t);
 
-       family = vtof(sl->isl_v);
+       family = vtof(sl.isl_v);
 
-       switch (sl->isl_type)
+       switch (sl.isl_type)
        {
        case ISL_NEW :
                strcpy(t, "STATE:NEW ");
@@ -891,9 +888,9 @@
                break;
 
        case ISL_EXPIRE :
-               if ((sl->isl_p == IPPROTO_TCP) &&
-                   (sl->isl_state[0] > IPF_TCPS_ESTABLISHED ||
-                    sl->isl_state[1] > IPF_TCPS_ESTABLISHED))
+               if ((sl.isl_p == IPPROTO_TCP) &&
+                   (sl.isl_state[0] > IPF_TCPS_ESTABLISHED ||
+                    sl.isl_state[1] > IPF_TCPS_ESTABLISHED))
                        strcpy(t, "STATE:CLOSE ");
                else
                        strcpy(t, "STATE:EXPIRE ");
@@ -920,45 +917,45 @@
                break;
 
        default :
-               sprintf(t, "Type: %d ", sl->isl_type);
+               sprintf(t, "Type: %d ", sl.isl_type);
                break;
        }
        t += strlen(t);
 
-       proto = getlocalproto(sl->isl_p);
+       proto = getlocalproto(sl.isl_p);
 
-       if (sl->isl_p == IPPROTO_TCP || sl->isl_p == IPPROTO_UDP) {
+       if (sl.isl_p == IPPROTO_TCP || sl.isl_p == IPPROTO_UDP) {
                sprintf(t, "%s,%s -> ",
-                       hostname(family, (u_32_t *)&sl->isl_src),
-                       portlocalname(res, proto, (u_int)sl->isl_sport));
+                       hostname(family, (u_32_t *)&sl.isl_src),
+                       portlocalname(res, proto, (u_int)sl.isl_sport));
                t += strlen(t);
                sprintf(t, "%s,%s PR %s",
-                       hostname(family, (u_32_t *)&sl->isl_dst),
-                       portlocalname(res, proto, (u_int)sl->isl_dport), proto);
-       } else if (sl->isl_p == IPPROTO_ICMP) {
-               sprintf(t, "%s -> ", hostname(family, (u_32_t *)&sl->isl_src));
+                       hostname(family, (u_32_t *)&sl.isl_dst),
+                       portlocalname(res, proto, (u_int)sl.isl_dport), proto);
+       } else if (sl.isl_p == IPPROTO_ICMP) {
+               sprintf(t, "%s -> ", hostname(family, (u_32_t *)&sl.isl_src));
                t += strlen(t);
                sprintf(t, "%s PR icmp %d",
-                       hostname(family, (u_32_t *)&sl->isl_dst),
-                       sl->isl_itype);
-       } else if (sl->isl_p == IPPROTO_ICMPV6) {
-               sprintf(t, "%s -> ", hostname(family, (u_32_t *)&sl->isl_src));
+                       hostname(family, (u_32_t *)&sl.isl_dst),
+                       sl.isl_itype);
+       } else if (sl.isl_p == IPPROTO_ICMPV6) {
+               sprintf(t, "%s -> ", hostname(family, (u_32_t *)&sl.isl_src));
                t += strlen(t);
                sprintf(t, "%s PR icmpv6 %d",
-                       hostname(family, (u_32_t *)&sl->isl_dst),
-                       sl->isl_itype);
+                       hostname(family, (u_32_t *)&sl.isl_dst),
+                       sl.isl_itype);
        } else {
-               sprintf(t, "%s -> ", hostname(family, (u_32_t *)&sl->isl_src));
+               sprintf(t, "%s -> ", hostname(family, (u_32_t *)&sl.isl_src));
                t += strlen(t);
                sprintf(t, "%s PR %s",
-                       hostname(family, (u_32_t *)&sl->isl_dst), proto);
+                       hostname(family, (u_32_t *)&sl.isl_dst), proto);
        }
        t += strlen(t);
-       if (sl->isl_tag != FR_NOLOGTAG) {
-               sprintf(t, " tag %u", sl->isl_tag);
+       if (sl.isl_tag != FR_NOLOGTAG) {
+               sprintf(t, " tag %u", sl.isl_tag);
                t += strlen(t);
        }
-       if (sl->isl_type != ISL_NEW) {
+       if (sl.isl_type != ISL_NEW) {
                static const char fmt[] =
 #ifdef USE_QUAD_T
 #ifdef PRId64
@@ -973,10 +970,10 @@
                        " Forward: Pkts in %ld Bytes in %ld Pkts out %ld Bytes out %ld Backward: Pkts in %ld Bytes in %ld Pkts out %ld Bytes out %ld";
 #endif
                sprintf(t, fmt,
-                       sl->isl_pkts[0], sl->isl_bytes[0],
-                       sl->isl_pkts[1], sl->isl_bytes[1],
-                       sl->isl_pkts[2], sl->isl_bytes[2],
-                       sl->isl_pkts[3], sl->isl_bytes[3]);
+                       sl.isl_pkts[0], sl.isl_bytes[0],
+                       sl.isl_pkts[1], sl.isl_bytes[1],
+                       sl.isl_pkts[2], sl.isl_bytes[2],
+                       sl.isl_pkts[3], sl.isl_bytes[3]);
 
                t += strlen(t);
        }
@@ -1013,16 +1010,16 @@
                switch (log->logtype) {
                case IPL_LOGIPF:
                        if (ipl.ipl_magic == IPL_MAGIC)
-                               print_ipflog(conf, buf, psize);
+                               print_ipflog(conf, &ipl, buf, psize);
                        break;
                case IPL_LOGNAT:
                        if (ipl.ipl_magic == IPL_MAGIC_NAT)
-                               print_natlog(conf, buf, psize);
+                               print_natlog(conf, &ipl, buf, psize);



Home | Main Index | Thread Index | Old Index