1 #ifndef IPTRAF_NG_COMPAT_H
2 #define IPTRAF_NG_COMPAT_H
23 #include <sys/types.h>
25 #include <sys/socket.h>
27 #include <sys/ioctl.h>
32 #include <netinet/in.h>
33 #include <netinet/udp.h>
34 #include <netinet/ip.h>
35 #include <netinet/tcp.h>
36 #include <netinet/ip6.h>
37 #include <netinet/icmp6.h>
38 #include <netinet/ip_icmp.h>
40 #include <arpa/inet.h>
42 #include <linux/if_ether.h>
43 #include <linux/if_packet.h>
44 #include <linux/if_fddi.h>
45 #include <linux/types.h>
48 #include <linux/if_arp.h>
51 #define ETH_P_8021AD 0x88A8 /* 802.1ad Service VLAN */
55 #define ETH_P_QINQ1 0x9100 /* deprecated QinQ VLAN [ NOT AN OFFICIALLY REGISTERED ID ] */
59 #define ETH_P_QINQ2 0x9200 /* deprecated QinQ VLAN [ NOT AN OFFICIALLY REGISTERED ID ] */
63 #define ETH_P_QINQ3 0x9300 /* deprecated QinQ VLAN [ NOT AN OFFICIALLY REGISTERED ID ] */
68 fprintf(stderr, "%s:%s():%d:", \
69 __FILE__, __func__, __LINE__); \
70 fprintf(stderr, __VA_ARGS__); \
71 fprintf(stderr, "\n"); \
76 #define dispmode(mode) \
77 (((mode) == KBITS) ? "kbps": "kBps")
79 #define __noreturn __attribute__((noreturn))
80 #define __unused __attribute__((unused))
81 #define __printf(x, y) __attribute__((format(printf, (x), (y))))
83 /* screen delay (in msecs) if update rate == 0 */
84 #define DEFAULT_UPDATE_DELAY 50
86 #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
88 #define alloc_nr(x) (((x)+16)*3/2)
91 * Realloc the buffer pointed at by variable 'x' so that it can hold
92 * at least 'nr' entries; the number of entries currently allocated
93 * is 'alloc', using the standard growing factor alloc_nr() macro.
95 * DO NOT USE any expression with side-effect for 'x', 'nr', or 'alloc'.
97 #define ALLOC_GROW(x, nr, alloc) \
100 if (alloc_nr(alloc) < (nr)) \
103 alloc = alloc_nr(alloc); \
104 x = xrealloc((x), alloc * sizeof(*(x))); \
108 extern int daemonized
;
111 extern void *xmalloc(size_t size
);
112 extern void *xcalloc(size_t nmemb
, size_t size
);
113 extern void *xrealloc(void *ptr
, size_t size
);
114 extern void *xmallocz(size_t size
);
115 extern char *xstrdup(const char *s
);
116 extern int strtoul_ui(char const *s
, int base
, unsigned int *result
);
117 extern int strtol_i(char const *s
, int base
, int *result
);
119 extern void die(const char *err
, ...) __noreturn
__printf(1,2);
120 extern void die_errno(const char *fmt
, ...) __noreturn
__printf(1,2);
121 extern void error(const char *err
, ...) __printf(1,2);
123 static inline char *skip_whitespace(char *str
)
125 while (isspace(*str
))
131 static inline unsigned long timeval_diff_msec(const struct timeval
*end
,
132 const struct timeval
*start
)
137 signed long secs
= end
->tv_sec
- start
->tv_sec
;
138 signed long usecs
= end
->tv_usec
- start
->tv_usec
;
141 usecs
= 1000000 - usecs
;
145 return secs
* 1000UL + usecs
/ 1000UL;
150 #endif /* IPTRAF_NG_COMPAT_H */