diff options
-rw-r--r-- | astraceroute/Makefile | 1 | ||||
-rw-r--r-- | bpf.c | 1 | ||||
-rw-r--r-- | bpf_parser.y | 1 | ||||
-rw-r--r-- | bpfc/Makefile | 1 | ||||
-rw-r--r-- | ct_client.c | 1 | ||||
-rw-r--r-- | ct_servmgmt.c | 1 | ||||
-rw-r--r-- | ct_usermgmt.c | 1 | ||||
-rw-r--r-- | curve.c | 1 | ||||
-rw-r--r-- | curvetun.c | 1 | ||||
-rw-r--r-- | curvetun/Makefile | 1 | ||||
-rw-r--r-- | dissector_eth.c | 1 | ||||
-rw-r--r-- | flowtop.c | 1 | ||||
-rw-r--r-- | flowtop/Makefile | 1 | ||||
-rw-r--r-- | geoip.c | 1 | ||||
-rw-r--r-- | ifpps/Makefile | 1 | ||||
-rw-r--r-- | irq.c | 1 | ||||
-rw-r--r-- | lockme.h | 19 | ||||
-rw-r--r-- | mac80211.c | 1 | ||||
-rw-r--r-- | mausezahn/Makefile | 1 | ||||
-rw-r--r-- | netsniff-ng.c | 2 | ||||
-rw-r--r-- | netsniff-ng/Makefile | 1 | ||||
-rw-r--r-- | oui.c | 1 | ||||
-rw-r--r-- | str.c | 88 | ||||
-rw-r--r-- | str.h | 12 | ||||
-rw-r--r-- | trafgen.c | 2 | ||||
-rw-r--r-- | trafgen/Makefile | 1 | ||||
-rw-r--r-- | trafgen_parser.y | 1 | ||||
-rw-r--r-- | tstamping.c | 1 | ||||
-rw-r--r-- | xio.c | 1 | ||||
-rw-r--r-- | xmalloc.c | 1 | ||||
-rw-r--r-- | xutils.c | 89 | ||||
-rw-r--r-- | xutils.h | 7 |
32 files changed, 149 insertions, 95 deletions
diff --git a/astraceroute/Makefile b/astraceroute/Makefile index 36e37f0..4cf9a3e 100644 --- a/astraceroute/Makefile +++ b/astraceroute/Makefile @@ -8,6 +8,7 @@ astraceroute-objs = xmalloc.o \ proto_none.o \ tprintf.o \ bpf.o \ + str.o \ geoip.o \ ring_rx.o \ ring.o \ @@ -18,6 +18,7 @@ #include "xmalloc.h" #include "xutils.h" #include "die.h" +#include "str.h" #define EXTRACT_SHORT(packet) \ ((unsigned short) ntohs(*(unsigned short *) packet)) diff --git a/bpf_parser.y b/bpf_parser.y index 7734fb3..307066e 100644 --- a/bpf_parser.y +++ b/bpf_parser.y @@ -19,6 +19,7 @@ #include <libgen.h> #include "bpf.h" +#include "str.h" #include "xmalloc.h" #include "bpf_parser.tab.h" #include "built_in.h" diff --git a/bpfc/Makefile b/bpfc/Makefile index 4451f64..efebcc9 100644 --- a/bpfc/Makefile +++ b/bpfc/Makefile @@ -2,6 +2,7 @@ bpfc-libs = bpfc-objs = xmalloc.o \ xutils.o \ + str.o \ bpf.o \ bpf_lexer.yy.o \ bpf_parser.tab.o \ diff --git a/ct_client.c b/ct_client.c index dbf07c5..d99e7bb 100644 --- a/ct_client.c +++ b/ct_client.c @@ -27,6 +27,7 @@ #include "built_in.h" #include "die.h" +#include "str.h" #include "xio.h" #include "xutils.h" #include "curve.h" diff --git a/ct_servmgmt.c b/ct_servmgmt.c index a63eb57..0d7da78 100644 --- a/ct_servmgmt.c +++ b/ct_servmgmt.c @@ -12,6 +12,7 @@ #include <syslog.h> #include "die.h" +#include "str.h" #include "built_in.h" #include "locking.h" #include "xmalloc.h" diff --git a/ct_usermgmt.c b/ct_usermgmt.c index c728801..6dc7f35 100644 --- a/ct_usermgmt.c +++ b/ct_usermgmt.c @@ -19,6 +19,7 @@ #include "locking.h" #include "xmalloc.h" #include "xio.h" +#include "str.h" #include "curvetun.h" #include "xutils.h" #include "curve.h" @@ -22,6 +22,7 @@ #include "xutils.h" #include "xio.h" #include "die.h" +#include "str.h" #include "curvetun.h" #include "locking.h" #include "crypto_verify_32.h" @@ -27,6 +27,7 @@ #include "xutils.h" #include "die.h" +#include "str.h" #include "xmalloc.h" #include "curvetun.h" #include "curve.h" diff --git a/curvetun/Makefile b/curvetun/Makefile index 954a865..c54f8e2 100644 --- a/curvetun/Makefile +++ b/curvetun/Makefile @@ -4,6 +4,7 @@ curvetun-libs = -lnacl \ curvetun-objs = xmalloc.o \ xio.o \ xutils.o \ + str.o \ stun.o \ patricia.o \ trie.o \ diff --git a/dissector_eth.c b/dissector_eth.c index 0ac88af..b8166e4 100644 --- a/dissector_eth.c +++ b/dissector_eth.c @@ -8,6 +8,7 @@ #include "hash.h" #include "oui.h" +#include "str.h" #include "protos.h" #include "pkt_buff.h" #include "dissector.h" @@ -30,6 +30,7 @@ #include "die.h" #include "xmalloc.h" #include "xio.h" +#include "str.h" #include "geoip.h" #include "xutils.h" #include "built_in.h" diff --git a/flowtop/Makefile b/flowtop/Makefile index 29a58ce..2446832 100644 --- a/flowtop/Makefile +++ b/flowtop/Makefile @@ -9,6 +9,7 @@ flowtop-objs = xmalloc.o \ xio.o \ xutils.o \ oui.o \ + str.o \ hash.o \ dissector_eth.o \ dissector_80211.o \ @@ -20,6 +20,7 @@ #include "die.h" #include "xutils.h" #include "xio.h" +#include "str.h" #include "xmalloc.h" #include "zlib.h" #include "geoip.h" diff --git a/ifpps/Makefile b/ifpps/Makefile index a86e88c..ef26a71 100644 --- a/ifpps/Makefile +++ b/ifpps/Makefile @@ -3,4 +3,5 @@ ifpps-libs = $(shell pkg-config --libs ncurses) ifpps-objs = xmalloc.o \ xio.o \ xutils.o \ + str.o \ ifpps.o @@ -14,6 +14,7 @@ #include <fcntl.h> #include "irq.h" +#include "str.h" #include "die.h" #include "xutils.h" diff --git a/lockme.h b/lockme.h new file mode 100644 index 0000000..7cce97b --- /dev/null +++ b/lockme.h @@ -0,0 +1,19 @@ +#ifndef LOCKME_H +#define LOCKME_H + +#include <sys/mman.h> + +#include "die.h" + +static inline void xlockme(void) +{ + if (mlockall(MCL_CURRENT | MCL_FUTURE) != 0) + panic("Cannot lock pages!\n"); +} + +static inline void xunlockme(void) +{ + munlockall(); +} + +#endif /* LOCKME_H */ @@ -23,6 +23,7 @@ #include <libnl3/netlink/attr.h> #include "die.h" +#include "str.h" #include "xutils.h" #include "mac80211.h" #include "xmalloc.h" diff --git a/mausezahn/Makefile b/mausezahn/Makefile index ea5d195..cecd139 100644 --- a/mausezahn/Makefile +++ b/mausezahn/Makefile @@ -6,6 +6,7 @@ mausezahn-libs = -lcli \ -lm mausezahn-objs = xutils.o \ + str.o \ staging/layer1.o \ staging/layer2.o \ staging/layer3.o \ diff --git a/netsniff-ng.c b/netsniff-ng.c index b61dec9..ed3d659 100644 --- a/netsniff-ng.c +++ b/netsniff-ng.c @@ -33,7 +33,9 @@ #include "xio.h" #include "die.h" #include "irq.h" +#include "str.h" #include "geoip.h" +#include "lockme.h" #include "tprintf.h" #include "dissector.h" #include "xmalloc.h" diff --git a/netsniff-ng/Makefile b/netsniff-ng/Makefile index 53f1fea..f397b92 100644 --- a/netsniff-ng/Makefile +++ b/netsniff-ng/Makefile @@ -32,6 +32,7 @@ netsniff-ng-objs = dissector.o \ proto_vlan_q_in_q.o \ proto_mpls_unicast.o \ proto_80211_mac_hdr.o \ + str.o \ irq.o \ iosched.o \ xio.o \ @@ -11,6 +11,7 @@ #include "xmalloc.h" #include "xutils.h" #include "oui.h" +#include "str.h" static struct hash_table oui; @@ -0,0 +1,88 @@ +/* + * netsniff-ng - the packet sniffing beast + * Copyright 2009, 2010 Daniel Borkmann. + * Subject to the GPL, version 2. + */ + +#include <stdio.h> +#include <string.h> +#include <stdarg.h> + +#include "str.h" + +size_t strlcpy(char *dest, const char *src, size_t size) +{ + size_t ret = strlen(src); + + if (size) { + size_t len = (ret >= size) ? size - 1 : ret; + + memcpy(dest, src, len); + dest[len] = '\0'; + } + + return ret; +} + +static inline int vslprintf(char *dst, size_t size, const char *fmt, va_list ap) +{ + int ret; + + ret = vsnprintf(dst, size, fmt, ap); + dst[size - 1] = '\0'; + + return ret; +} + +int slprintf(char *dst, size_t size, const char *fmt, ...) +{ + int ret; + va_list ap; + + va_start(ap, fmt); + ret = vslprintf(dst, size, fmt, ap); + va_end(ap); + + return ret; +} + +int slprintf_nocheck(char *dst, size_t size, const char *fmt, ...) +{ + int ret; + va_list ap; + + va_start(ap, fmt); + ret = vslprintf(dst, size, fmt, ap); + va_end(ap); + + return ret; +} + +noinline void *xmemset(void *s, int c, size_t n) +{ + size_t i; + uint8_t *ptr = s; + + for (i = 0; i < n; ++i) + ptr[i] = (uint8_t) c; + + return ptr; +} + +char *strtrim_right(char *p, char c) +{ + char *end; + size_t len; + + len = strlen(p); + while (*p && len) { + end = p + len - 1; + if (c == *end) + *end = 0; + else + break; + len = strlen(p); + } + + return p; +} @@ -0,0 +1,12 @@ +#ifndef STR_H +#define STR_H + +#include "built_in.h" + +extern size_t strlcpy(char *dest, const char *src, size_t size); +extern int slprintf(char *dst, size_t size, const char *fmt, ...) __check_format_printf(3, 4); +extern int slprintf_nocheck(char *dst, size_t size, const char *fmt, ...); +extern char *strtrim_right(char *p, char c); +extern noinline void *xmemset(void *s, int c, size_t n); + +#endif /* STR_H */ @@ -34,6 +34,8 @@ #include "xmalloc.h" #include "die.h" +#include "str.h" +#include "lockme.h" #include "mac80211.h" #include "xutils.h" #include "xio.h" diff --git a/trafgen/Makefile b/trafgen/Makefile index 914b61c..75a9c09 100644 --- a/trafgen/Makefile +++ b/trafgen/Makefile @@ -6,6 +6,7 @@ trafgen-objs = xmalloc.o \ xio.o \ xutils.o \ irq.o \ + str.o \ mac80211.o \ ring_tx.o \ ring.o \ diff --git a/trafgen_parser.y b/trafgen_parser.y index 1112f8a..85d7b01 100644 --- a/trafgen_parser.y +++ b/trafgen_parser.y @@ -23,6 +23,7 @@ #include "trafgen_conf.h" #include "built_in.h" #include "die.h" +#include "str.h" #include "csum.h" #include "xutils.h" diff --git a/tstamping.c b/tstamping.c index 4de455d..9ef1a4a 100644 --- a/tstamping.c +++ b/tstamping.c @@ -18,6 +18,7 @@ extern int set_sockopt_hwtimestamp(int sock, const char *dev); #include <linux/if.h> #include "xutils.h" +#include "str.h" int set_sockopt_hwtimestamp(int sock, const char *dev) { @@ -23,6 +23,7 @@ #include "die.h" #include "xio.h" +#include "str.h" #include "xutils.h" int open_or_die(const char *file, int flags) @@ -18,6 +18,7 @@ #include "xutils.h" #include "built_in.h" #include "die.h" +#include "str.h" void *xmalloc(size_t size) { @@ -41,6 +41,7 @@ #include <netinet/udp.h> #include "die.h" +#include "str.h" #include "xutils.h" #include "ring.h" #include "built_in.h" @@ -707,94 +708,6 @@ int set_sched_status(int policy, int priority) return 0; } -void xlockme(void) -{ - if (mlockall(MCL_CURRENT | MCL_FUTURE) != 0) - panic("Cannot lock pages!\n"); -} - -void xunlockme(void) -{ - munlockall(); -} - -size_t strlcpy(char *dest, const char *src, size_t size) -{ - size_t ret = strlen(src); - - if (size) { - size_t len = (ret >= size) ? size - 1 : ret; - - memcpy(dest, src, len); - dest[len] = '\0'; - } - - return ret; -} - -static inline int vslprintf(char *dst, size_t size, const char *fmt, va_list ap) -{ - int ret; - - ret = vsnprintf(dst, size, fmt, ap); - dst[size - 1] = '\0'; - - return ret; -} - -int slprintf(char *dst, size_t size, const char *fmt, ...) -{ - int ret; - va_list ap; - - va_start(ap, fmt); - ret = vslprintf(dst, size, fmt, ap); - va_end(ap); - - return ret; -} - -int slprintf_nocheck(char *dst, size_t size, const char *fmt, ...) -{ - int ret; - va_list ap; - - va_start(ap, fmt); - ret = vslprintf(dst, size, fmt, ap); - va_end(ap); - - return ret; -} - -noinline void *xmemset(void *s, int c, size_t n) -{ - size_t i; - uint8_t *ptr = s; - - for (i = 0; i < n; ++i) - ptr[i] = (uint8_t) c; - - return ptr; -} - -char *strtrim_right(char *p, char c) -{ - char *end; - size_t len; - - len = strlen(p); - while (*p && len) { - end = p + len - 1; - if (c == *end) - *end = 0; - else - break; - len = strlen(p); - } - - return p; -} - int get_default_sched_policy(void) { return SCHED_FIFO; @@ -40,8 +40,6 @@ extern int device_ifindex(const char *ifname); extern short device_get_flags(const char *ifname); extern void device_set_flags(const char *ifname, const short flags); extern void drop_privileges(bool enforce, uid_t uid, gid_t gid); -extern void xlockme(void); -extern void xunlockme(void); extern void set_nonblocking(int fd); extern int set_nonblocking_sloppy(int fd); extern int set_reuseaddr(int fd); @@ -69,11 +67,6 @@ extern void cpu_affinity(int cpu); extern int set_cpu_affinity(char *str, int inverted); extern int set_proc_prio(int prio); extern int set_sched_status(int policy, int priority); -extern size_t strlcpy(char *dest, const char *src, size_t size); -extern int slprintf(char *dst, size_t size, const char *fmt, ...) __check_format_printf(3, 4); -extern int slprintf_nocheck(char *dst, size_t size, const char *fmt, ...); -extern noinline void *xmemset(void *s, int c, size_t n); -extern char *strtrim_right(char *p, char c); extern int get_default_sched_policy(void); extern int get_default_sched_prio(void); extern int get_number_cpus(void); |