-
Notifications
You must be signed in to change notification settings - Fork 2
/
debug.h
95 lines (75 loc) · 1.9 KB
/
debug.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
/* Copyright (C) Uppsala University
*
* This file is distributed under the terms of the GNU general Public
* License (GPL), see the file LICENSE
*
* Author: Erik Nordström, <[email protected]>
*/
#ifndef _DEBUG_H
#define _DEBUG_H
#ifdef __KERNEL__
#include <linux/kernel.h>
#include <linux/string.h>
#include <linux/ctype.h>
#include <linux/module.h>
#include <linux/if_ether.h>
#include <linux/in.h>
#include <linux/init.h>
extern atomic_t num_pkts;
#else
#include <stdarg.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <sys/types.h>
#include <netinet/in.h>
#endif /* __KERNEL__ */
#ifdef ENABLE_DEBUG
#define DEBUG_PROC
#define LOG_DBG(f, args...) do { if (get_confval(PrintDebug)) trace(__FUNCTION__, f, ## args); } while (0)
//#define LOG_DBG(f, args...) trace(__FUNCTION__, f, ## args)
#else
#define LOG_DBG(f, args...)
#endif
#ifndef NO_GLOBALS
#define DEBUG_BUFLEN 256
static inline char *print_ip(struct in_addr addr)
{
static char buf[16 * 4];
static int index = 0;
char *str;
sprintf(&buf[index], "%d.%d.%d.%d",
0x0ff & addr.s_addr,
0x0ff & (addr.s_addr >> 8),
0x0ff & (addr.s_addr >> 16), 0x0ff & (addr.s_addr >> 24));
str = &buf[index];
index += 16;
index %= 64;
return str;
}
static inline char *print_eth(char *addr)
{
static char buf[30];
sprintf(buf, "%02x:%02x:%02x:%02x:%02x:%02x",
(unsigned char)addr[0], (unsigned char)addr[1],
(unsigned char)addr[2], (unsigned char)addr[3],
(unsigned char)addr[4], (unsigned char)addr[5]);
return buf;
}
static inline char *print_pkt(char *p, int len)
{
static char buf[3000];
int i, l = 0;
for (i = 0; i < len; i++)
l += sprintf(buf + l, "%02X", (unsigned char)p[i]);
return buf;
}
#endif /* NO_GLOBALS */
#ifndef NO_DECLS
int trace(const char *func, const char *fmt, ...);
#endif /* NO_DECLS */
#ifdef __KERNEL__
int __init dbg_init(void);
void __exit dbg_cleanup(void);
#endif
#endif /* _DEBUG_H */