root/src/router/openlldp/src/lldp_debug.c

Revision 8348, 2.2 kB (checked in by BrainSlayer, 2 years ago)

no debug crap

Line 
1 /** @file lldp_debug.c
2  *
3  * OpenLLDP Debug Core
4  *
5  * Licensed under a dual GPL/Proprietary license. 
6  * See LICENSE file for more info.
7  *
8  * File: lldp_debug.c
9  *
10  * Authors: Terry Simons (terry.simons@gmail.com)
11  *
12  * Some code below was borrowed from the Open1X project.
13  *
14  *******************************************************************/
15
16 #include <stdio.h>
17 #include <stdarg.h>
18 #include <strings.h>
19 #include <string.h>
20 #include <stdlib.h>
21 #include <unistd.h>
22 #include <ctype.h>
23 #include <syslog.h>
24 #include <stdint.h>
25
26 #include "lldp_debug.h"
27
28 /* Borrowed from Open1X */
29 unsigned char debug_level = 0;
30 int isdaemon = 0;
31 int syslogging = 0;
32 FILE *logfile = NULL;
33
34 /* Borrowed from Open1X */
35 static inline char to_hex_char(int val)
36 {
37   return("0123456789abcdef"[val & 0xf]);
38 }
39
40
41
42 /**
43  *
44  * Display some information.  But only if we are at a debug level that
45  * should display it.
46  *
47  */
48
49
50 /**
51  *
52  * Set flags based on the numeric value that was passed in.
53  *
54  */
55 void debug_set_flags(int new_flags)
56 {
57   if (new_flags >= 1) debug_level |= DEBUG_CONFIG;
58   if (new_flags >= 2) debug_level |= DEBUG_STATE;
59   if (new_flags >= 3) debug_level |= DEBUG_TLV;
60   if (new_flags >= 4) debug_level |= DEBUG_INT;
61   if (new_flags >= 5) debug_level |= DEBUG_SNMP;
62   if (new_flags >= 6) debug_level |= DEBUG_EVERYTHING;
63   if (new_flags >= 7) debug_level |= DEBUG_EXCESSIVE;
64 }
65
66 /**
67  *
68  * Set flags based on an ASCII string that was passed in.
69  *
70  */
71 void debug_alpha_set_flags(char *new_flags)
72 {
73   int i;
74
75   debug_level = 0;
76
77   for (i=0;i<strlen(new_flags);i++)
78     {
79       switch (new_flags[i])
80         {
81         case 'c':
82           debug_level |= DEBUG_CONFIG;
83           break;
84
85         case 's':
86           debug_level |= DEBUG_STATE;
87           break;
88
89         case 't':
90           debug_level |= DEBUG_TLV;
91           break;
92
93         case 'i':
94           debug_level |= DEBUG_INT;
95           break;
96
97         case 'n':
98           debug_level |= DEBUG_SNMP;
99           break;
100
101         case 'e':
102           debug_level |= DEBUG_EVERYTHING;
103           break;
104
105         case 'x':
106           debug_level |= DEBUG_EXCESSIVE;
107           break;
108
109         case 'A':
110           debug_level |= 0xff;   // Set all flags.
111           break;
112         }
113     }
114 }
Note: See TracBrowser for help on using the browser.