From: R.E. Wolff Date: Thu, 18 Aug 2016 07:25:44 +0000 (+0200) Subject: more cleanup X-Git-Tag: v0.88~35 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=eb4c9448258e1849ae0fab048953b96d9169acd8;p=thirdparty%2Fmtr.git more cleanup --- diff --git a/asn.c b/asn.c index bdc46c2..fb0a961 100644 --- a/asn.c +++ b/asn.c @@ -40,12 +40,15 @@ #include "mtr.h" #include "asn.h" -/* -#ifndef IIDEBUG -#define IIDEBUG +//#define IIDEBUG + +#ifdef IIDEBUG #include +#define DEB_syslog syslog +#else +#define DEB_syslog(...) do {} while (0) #endif -*/ + #define IIHASH_HI 128 #define ITEMSMAX 15 @@ -83,10 +86,8 @@ char *ipinfo_lookup(const char *domain) { memset(answer, 0, PACKETSZ); if((len = res_query(domain, C_IN, T_TXT, answer, PACKETSZ)) < 0) { -#ifdef IIDEBUG if (iihash) - syslog(LOG_INFO, "Malloc-txt: %s", UNKN); -#endif + DEB_syslog(LOG_INFO, "Malloc-txt: %s", UNKN); return (iihash)?strdup(UNKN):UNKN; } @@ -138,10 +139,8 @@ char *ipinfo_lookup(const char *domain) { strncpy(txt, (char*) pt, txtlen); txt[txtlen] = 0; -#ifdef IIDEBUG if (iihash) - syslog(LOG_INFO, "Malloc-txt(%p): %s", txt, txt); -#endif + DEB_syslog(LOG_INFO, "Malloc-txt(%p): %s", txt, txt); return txt; } @@ -161,13 +160,9 @@ char* split_txtrec(char *txt_rec) { if (!txt_rec) return NULL; if (iihash) { -#ifdef IIDEBUG - syslog(LOG_INFO, "Malloc-tbl: %s", txt_rec); -#endif + DEB_syslog(LOG_INFO, "Malloc-tbl: %s", txt_rec); if (!(items = malloc(sizeof(*items)))) { -#ifdef IIDEBUG - syslog(LOG_INFO, "Free-txt(%p)", txt_rec); -#endif + DEB_syslog(LOG_INFO, "Free-txt(%p)", txt_rec); free(txt_rec); return NULL; } @@ -240,35 +235,25 @@ char *get_ipinfo(ip_t *addr) { ENTRY item; if (iihash) { -#ifdef IIDEBUG - syslog(LOG_INFO, ">> Search: %s", key); -#endif + DEB_syslog(LOG_INFO, ">> Search: %s", key); item.key = key;; ENTRY *found_item; if ((found_item = hsearch(item, FIND))) { if (!(val = (*((items_t*)found_item->data))[ipinfo_no])) val = (*((items_t*)found_item->data))[0]; -#ifdef IIDEBUG - syslog(LOG_INFO, "Found (hashed): %s", val); -#endif + DEB_syslog(LOG_INFO, "Found (hashed): %s", val); } } if (!val) { -#ifdef IIDEBUG - syslog(LOG_INFO, "Lookup: %s", key); -#endif + DEB_syslog(LOG_INFO, "Lookup: %s", key); if ((val = split_txtrec(ipinfo_lookup(lookup_key)))) { -#ifdef IIDEBUG - syslog(LOG_INFO, "Looked up: %s", key); -#endif + DEB_syslog(LOG_INFO, "Looked up: %s", key); if (iihash) if ((item.key = strdup(key))) { item.data = items; hsearch(item, ENTER); -#ifdef IIDEBUG - syslog(LOG_INFO, "Insert into hash: %s", key); -#endif + DEB_syslog(LOG_INFO, "Insert into hash: %s", key); } } } @@ -294,19 +279,15 @@ int is_printii(void) { void asn_open(void) { if (ipinfo_no >= 0) { -#ifdef IIDEBUG - syslog(LOG_INFO, "hcreate(%d)", IIHASH_HI); -#endif + DEB_syslog(LOG_INFO, "hcreate(%d)", IIHASH_HI); if (!(iihash = hcreate(IIHASH_HI))) perror("ipinfo hash"); } } void asn_close(void) { - if (iihash) { -#ifdef IIDEBUG - syslog(LOG_INFO, "hdestroy()"); -#endif + if ((ipinfo_no >= 0) && iihash) { + DEB_syslog(LOG_INFO, "hdestroy()"); hdestroy(); iihash = 0; } diff --git a/display.c b/display.c index 8e272a6..ed05035 100644 --- a/display.c +++ b/display.c @@ -35,6 +35,7 @@ extern int DisplayMode; #ifdef NO_CURSES +// No support for curses mode, allow the calls to remain in the code. #define mtr_curses_open() #define mtr_curses_close() #define mtr_curses_redraw() @@ -45,6 +46,7 @@ extern int DisplayMode; #endif #ifdef NO_GTK +// No support for gtk mode, allow the calls to remain in the code. #define gtk_open() #define gtk_close() #define gtk_redraw() @@ -55,6 +57,7 @@ extern int DisplayMode; #endif #ifdef NO_SPLIT +// No support for split mode, allow the calls to remain in the code. #define split_open() #define split_close() #define split_redraw() @@ -63,22 +66,28 @@ extern int DisplayMode; #include "split.h" #endif -void display_detect(int *argc -#ifdef NO_GTK -UNUSED +#ifndef IPINFO +// No support for IPINFO allow the calls to remain in the main code. +#define asn_open() +#define asn_close() #endif - , char ***argv -#ifdef NO_GTK -UNUSED + +#ifdef NO_CURSES +#define DEFAULT_DISPLAY DisplayReport +#else +#define DEFAULT_DISPLAY DisplayCurses #endif -) { -#ifndef NO_CURSES - DisplayMode = DisplayCurses; +#ifdef NO_GTK +#define UNUSED_IF_NO_GTK UNUSED #else - DisplayMode = DisplayReport; +#define UNUSED_IF_NO_GTK #endif +void display_detect(int *argc UNUSED_IF_NO_GTK, char ***argv UNUSED_IF_NO_GTK) +{ + DisplayMode = DEFAULT_DISPLAY; + #ifndef NO_GTK if(gtk_detect(argc, argv)) { DisplayMode = DisplayGTK; @@ -108,20 +117,14 @@ void display_open(void) break; case DisplayCurses: mtr_curses_open(); -#ifdef IPINFO - if (ipinfo_no >= 0) - asn_open(); -#endif + asn_open(); break; case DisplaySplit: split_open(); break; case DisplayGTK: gtk_open(); -#ifdef IPINFO - if (ipinfo_no >= 0) - asn_open(); -#endif + asn_open(); break; } } @@ -146,10 +149,7 @@ void display_close(time_t now) csv_close(now); break; case DisplayCurses: -#ifdef IPINFO - if (ipinfo_no >= 0) - asn_close(); -#endif + asn_close(); mtr_curses_close(); break; case DisplaySplit: diff --git a/dns.c b/dns.c index 69df14c..d10e702 100644 --- a/dns.c +++ b/dns.c @@ -86,11 +86,13 @@ char *strlongip(ip_t * ip) } -int longipstr( char *s, ip_t *dst, int family -#ifndef ENABLE_IPV6 -UNUSED +#ifdef ENABLE_IPV6 +#define UNUSED_IF_NO_IPV6 +#else +#define UNUSED_IF_NO_IPV6 UNUSED #endif -) + +int longipstr( char *s, ip_t *dst, int family UNUSED_IF_NO_IPV6) { #ifdef ENABLE_IPV6 return inet_pton( family, s, dst );