00001 /***************************************************************************** 00002 * Copyright 2005 Daniel Ferullo, Andrew Biggadike * 00003 * * 00004 * Licensed under the Apache License, Version 2.0 (the "License"); * 00005 * you may not use this file except in compliance with the License. * 00006 * You may obtain a copy of the License at * 00007 * * 00008 * http://www.apache.org/licenses/LICENSE-2.0 * 00009 * * 00010 * Unless required by applicable law or agreed to in writing, software * 00011 * distributed under the License is distributed on an "AS IS" BASIS, * 00012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * 00013 * See the License for the specific language governing permissions and * 00014 * limitations under the License. * 00015 * * 00016 *****************************************************************************/ 00017 00018 /** 00019 * @file debug.h 00020 * @author Andrew Biggadike (biggadike@cmu.edu) 00021 * @author Daniel Ferullo (ferullo@cmu.edu) 00022 * 00023 * @brief debug macros, stolen from andrew and tweaked 00024 */ 00025 00026 #include "berkeleyapi.h" 00027 #include <unistd.h> 00028 #include <sys/time.h> 00029 00030 #ifndef __DEBUG_H__ 00031 #define __DEBUG_H__ 00032 00033 /** @brief the ALL debug level: 00034 * if debuging is on at any level then it is forced on at this level 00035 */ 00036 #define DBG_ALL (0xffffffff) 00037 00038 /** @brief the VERBOSE debug level: 00039 * basic verbose information 00040 */ 00041 #define DBG_VERBOSE (0x00000001) 00042 00043 /** @brief the NETWORK debug level: 00044 * information about basic networking 00045 */ 00046 #define DBG_NETWORK (0x00000002) 00047 00048 /** @brief the LIST debug level: 00049 * information relating the the shared peer list structure 00050 */ 00051 #define DBG_LIST (0x00000004) 00052 00053 /** @brief the PROTOCOL debug level: 00054 * information about the natblaster communnication protocol 00055 */ 00056 00057 #define DBG_PROTOCOL (0x00000008) 00058 00059 /** @brief the THREAD debug level: 00060 * information about the list multi-threading 00061 */ 00062 #define DBG_THREAD (0x00000010) 00063 00064 /** @brief the PORT_PRED debug level: 00065 * information about port prediction 00066 */ 00067 #define DBG_PORT_PRED (0x00000020) 00068 00069 /** @brief the BUDDY debug level: 00070 * information about dealing with a peer's buddy 00071 */ 00072 #define DBG_BUDDY (0x00000040) 00073 00074 /** @brief the DIR_CONN debug level: 00075 * information relating directly to the direct connection attempt 00076 */ 00077 #define DBG_DIR_CONN (0x00000080) 00078 00079 /** @brief the SNIFF debug level: 00080 * information pertaining to the process of sniffing packets 00081 */ 00082 #define DBG_SNIFF (0x00000100) 00083 00084 /** @brief the SPOOF debug level: 00085 * information pertaining to spoofing packets 00086 */ 00087 #define DBG_SPOOF (0x00000200) 00088 00089 /** @brief the BDAY debug level: 00090 * information pertaining to the birthday paradox port determination 00091 */ 00092 #define DBG_BDAY (0x00000400) 00093 00094 /** @brief all the debug levels that are turned on */ 00095 #define DBG_LEVEL (DBG_PROTOCOL | DBG_VERBOSE | DBG_NETWORK | DBG_PORT_PRED \ 00096 | DBG_SNIFF | DBG_SPOOF | DBG_BDAY) 00097 00098 /** @brief a macro to allow easy debugging info to be turned on and off */ 00099 #define DEBUG(level,fmt,args...) \ 00100 if (level & DBG_LEVEL) fprintf(stderr,"%s:" fmt, __FUNCTION__, ##args) 00101 00102 /** @brief a macro to put ip_t in pretty-print format for debugging */ 00103 #define DBG_IP(x) ((char*)inet_ntoa(*(struct in_addr*)&x)) 00104 00105 /** @brief a macro to put port_t in pretty-print format for debugging */ 00106 #define DBG_PORT(x) ((unsigned short)(ntohs(x))) 00107 00108 /** @brief a macro to put seq_num_t in pretty-print format for debugging */ 00109 #define DBG_SEQ_NUM(x) ((unsigned int)ntohl(x)) 00110 00111 /** @brief a macro to print the current system time */ 00112 #define DBG_TIME(x) ({ \ 00113 struct timeval val; \ 00114 if (gettimeofday(&val,NULL)<0) \ 00115 {fprintf(stderr,"TIME:%s:%s <?>\n",__FUNCTION__,x);} \ 00116 else \ 00117 {fprintf(stderr,"TIME:%s:%s <%u.%u>\n",__FUNCTION__, x, (unsigned int) val.tv_sec, (unsigned int)val.tv_usec);} \ 00118 }) 00119 00120 #endif /* __DEBUG_H__ */