Thread: [sdig-devel] sdig/src Makefile.am,1.2,1.3 common.c,1.2,1.3 common.h,1.1,1.2 config.c,1.2,1.3 query.c
Status: Beta
Brought to you by:
raj2
From: Russell J. <ra...@us...> - 2006-05-18 18:17:48
|
Update of /cvsroot/sdig/sdig/src In directory sc8-pr-cvs8.sourceforge.net:/tmp/cvs-serv18596 Modified Files: Makefile.am common.c common.h config.c query.c sdig.c sdig.h Log Message: Fix build after splitting source modules. Impliement fork()ing parallization of queries. Protect output routine with sysv sem lock. Index: sdig.h =================================================================== RCS file: /cvsroot/sdig/sdig/src/sdig.h,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** sdig.h 2 May 2006 21:21:37 -0000 1.2 --- sdig.h 18 May 2006 18:17:42 -0000 1.3 *************** *** 42,49 **** } pdtype; ! struct response { ! char sysName; ! char ifIdx; ! char ifAlias; ! char ifName; ! } --- 42,70 ---- } pdtype; ! /* holds the results of a matched port */ ! struct result { ! stype s; ! char *ifIdx; ! char *ifAlias; ! char *ifName; ! } result; ! ! /* ! * global data ! */ ! ! extern stype *firstsw; ! extern rtype *firstrt; ! extern pdtype *firstpd; ! extern litype *firstli; ! ! extern char *wins, *nmblookup, *mactable, *hostinfo; ! ! extern int fastmode, verbose; ! ! /* ! * Function prototypes ! */ ! ! void printport(stype *sw, long port); ! void printmac(unsigned const char *mac); Index: query.c =================================================================== RCS file: /cvsroot/sdig/sdig/src/query.c,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** query.c 2 May 2006 22:05:10 -0000 1.2 --- query.c 18 May 2006 18:17:42 -0000 1.3 *************** *** 14,17 **** --- 14,18 ---- #include <netinet/in.h> #include <sys/socket.h> + #include <sysexits.h> #include "sdig.h" *************** *** 22,36 **** #include "../include/config.h" ! stype *firstsw = NULL; ! rtype *firstrt = NULL; ! pdtype *firstpd = NULL; ! litype *firstli = NULL; ! ! char *wins = NULL, *nmblookup = NULL, *mactable = NULL, ! *hostinfo = NULL; ! ! int verbose = 0, fastmode = 0; ! ! static char *findmac(const char *ip, rtype *rtr) { char query[256], *ret; --- 23,28 ---- #include "../include/config.h" ! char ! *findmac(const char *ip, rtype *rtr) { char query[256], *ret; *************** *** 70,74 **** } ! static int findport(unsigned const char *mac, stype *sw) { char query[64]; --- 62,67 ---- } ! int ! findport(unsigned const char *mac, stype *sw) { char query[64]; *************** *** 90,94 **** } ! static char *getlink(const char *ip, long port) { litype *tmp; --- 83,88 ---- } ! char ! *getlink(const char *ip, long port) { litype *tmp; *************** *** 106,110 **** } ! static char *getdesc(const char *ip, long port) { pdtype *tmp; --- 100,105 ---- } ! char ! *getdesc(const char *ip, long port) { pdtype *tmp; *************** *** 122,126 **** } ! static const char *macmfr(unsigned char *inmac) { FILE *macdb; --- 117,122 ---- } ! const char ! *macmfr(unsigned char *inmac) { FILE *macdb; *************** *** 156,160 **** } ! static char *wins_resolve(const char *host) { char exec[256], buf[256]; --- 152,157 ---- } ! char ! *wins_resolve(const char *host) { char exec[256], buf[256]; *************** *** 192,196 **** } ! static char *dns_resolve(const char *host) { struct hostent *dns; --- 189,194 ---- } ! char ! *dns_resolve(const char *host) { struct hostent *dns; *************** *** 207,211 **** } ! static void do_ifdescr(stype *sw, long port) { char query[256], *ifdescr, *ifname; --- 205,210 ---- } ! void ! do_ifdescr(stype *sw, long port) { char query[256], *ifdescr, *ifname; *************** *** 246,285 **** } ! static void printport(stype *sw, long port) ! { ! char *ds, *li, *swdesc; ! char query[256]; ! ! /* don't print if it's a switch-switch link unless in verbose mode */ ! ! li = getlink(sw->ip, port); ! ! if ((li) && (!verbose)) ! return; ! ! snprintf(query, sizeof(query), "SNMPv2-MIB::sysName.0"); ! swdesc = snmpget_str(sw->ip, sw->pw, query); ! ! if (swdesc) ! printf(" Switch: %s (%s) - %s\n", ! sw->desc, swdesc, sw->ip); ! else ! printf(" Switch: %s - %s\n", sw->desc, sw->ip); ! ! printf(" Port: %ld", port); ! do_ifdescr(sw, port); ! printf("\n"); ! ! if (li) ! printf(" Link: %s\n", li); ! ! ds = getdesc(sw->ip, port); ! if (ds) ! printf(" Info: %s\n", ds); ! ! printf("\n"); ! } ! ! static int isip(const char *buf) { int i; --- 245,250 ---- } ! int ! isip(const char *buf) { int i; *************** *** 292,296 **** } ! static void dnsreverse(const char *ip) { struct hostent *dns; --- 257,262 ---- } ! void ! dnsreverse(const char *ip) { struct hostent *dns; *************** *** 311,315 **** } ! static stype *find_switch(const char *ipaddr, stype *last) { stype *tmp; --- 277,282 ---- } ! stype ! *find_switch(const char *ipaddr, stype *last) { stype *tmp; *************** *** 334,358 **** } ! /* make the octet string into something nicer for humans */ ! static void printmac(unsigned const char *mac) ! { ! int i; ! ! for (i = 0; i < 5; i++) ! printf("%02x:", mac[i]); ! ! printf("%02x", mac[5]); ! } /* ask the switch about where the MAC address is */ ! static void switchscan(const char *ipaddr, unsigned const char *macaddr) { stype *sw; ! long port; printf("\n"); ! ! if (debuglevel >= 2) { ! printf("switchscan: seeking (%s, ", ipaddr); printmac(macaddr); printf(")\n"); --- 301,317 ---- } ! void fork_wrapper(unsigned const char *macaddr, stype *sw); /* ask the switch about where the MAC address is */ ! void ! switchscan(const char *ipaddr, unsigned const char *macaddr) { stype *sw; ! int ret, status; printf("\n"); ! ! if (get_debuglevel() >= 2) { ! debug(2, "switchscan: seeking (%s, ", ipaddr); printmac(macaddr); printf(")\n"); *************** *** 363,381 **** while (sw) { debug(3, "switchscan: matched %s\n", sw->ip); ! port = findport(macaddr, sw); ! debug(3, "findport got port %d\n", port); ! if (port != -1) ! printport(sw, port); sw = find_switch(ipaddr, sw); } exit(0); } ! static rtype *find_router(const char *ipaddr, rtype *last) { rtype *tmp; --- 322,367 ---- while (sw) { debug(3, "switchscan: matched %s\n", sw->ip); + + ret = fork(); ! switch (ret) { ! case 0: ! fork_wrapper(macaddr, sw); ! _exit(EX_OK); ! break; ! case -1: ! perror("fork"); ! break; ! default: ! debug(3, "child %d started\n", ret); ! break; ! } sw = find_switch(ipaddr, sw); } + + while ((ret = wait(&status)) != -1) + debug(3, "child %d exited\n", ret); exit(0); } ! void ! fork_wrapper(unsigned const char *macaddr, stype *sw) ! { ! long port; ! ! port = findport(macaddr, sw); ! ! if (port != -1) ! printport(sw, port); ! ! debug(3, "findport got port %d\n", port); ! } ! ! rtype ! *find_router(const char *ipaddr, rtype *last) { rtype *tmp; *************** *** 401,405 **** /* run the user's script for extra details about a host */ ! static void do_hostinfo(const char *ipaddr) { char exec[256]; --- 387,392 ---- /* run the user's script for extra details about a host */ ! void ! do_hostinfo(const char *ipaddr) { char exec[256]; *************** *** 412,416 **** /* walk the list of routers checking for the IP address */ ! static void routerscan(const char *ipaddr) { unsigned char *macaddr; --- 399,404 ---- /* walk the list of routers checking for the IP address */ ! void ! routerscan(const char *ipaddr) { unsigned char *macaddr; *************** *** 446,450 **** printmac(macaddr); printf(" (%s)\n", macmfr(macaddr)); ! switchscan(ipaddr, macaddr); } --- 434,438 ---- printmac(macaddr); printf(" (%s)\n", macmfr(macaddr)); ! switchscan(ipaddr, macaddr); } *************** *** 458,462 **** /* turn <name> into an IP address and pass it to the router scanner */ ! static void resolvename(const char *name) { char *ipaddr; --- 446,451 ---- /* turn <name> into an IP address and pass it to the router scanner */ ! void ! resolvename(const char *name) { char *ipaddr; *************** *** 479,483 **** /* see if the specified mac address is sane, and make it machine-readable */ ! static char *pack_mac(char *buf) { int i, cc, sl, v, mp; --- 468,473 ---- /* see if the specified mac address is sane, and make it machine-readable */ ! char ! *pack_mac(char *buf) { int i, cc, sl, v, mp; *************** *** 529,530 **** --- 519,522 ---- return mac; } + + Index: config.c =================================================================== RCS file: /cvsroot/sdig/sdig/src/config.c,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** config.c 2 May 2006 22:05:10 -0000 1.2 --- config.c 18 May 2006 18:17:42 -0000 1.3 *************** *** 3,9 **** */ #include <ctype.h> #include <errno.h> - #include <netdb.h> #include <stdio.h> #include <stdarg.h> --- 3,12 ---- */ + #ifdef HAVE_CONFIG_H + #include <config.h> + #endif + #include <ctype.h> #include <errno.h> #include <stdio.h> #include <stdarg.h> *************** *** 11,22 **** #include <string.h> #include <unistd.h> - #include <arpa/inet.h> - #include <netinet/in.h> - #include <sys/socket.h> #include "sdig.h" #include "common.h" ! #include "../include/config.h" void --- 14,39 ---- #include <string.h> #include <unistd.h> #include "sdig.h" #include "common.h" ! /* ! * Head pointers to object lists ! */ ! stype *firstsw = NULL; ! rtype *firstrt = NULL; ! pdtype *firstpd = NULL; ! litype *firstli = NULL; ! ! char *wins = NULL, *nmblookup = NULL, *mactable = NULL, ! *hostinfo = NULL; ! ! /* ! * Function prototypes ! */ ! void addrouter(char *net, const char *ip, const char *pw, const char *desc); ! void addswitch(char *net, const char *ip, const char *pw, const char *desc); ! void addli(const char *ip, const char *port, const char *desc); ! void addpd(const char *ip, const char *port, const char *desc); void *************** *** 28,32 **** if (!fn) { ! snprintf(cfn, sizeof(cfn), "%s/sdig.conf", "CONFPATH"); conf = fopen(cfn, "r"); } else { --- 45,49 ---- if (!fn) { ! snprintf(cfn, sizeof(cfn), "%s/sdig.conf", CONFPATH); conf = fopen(cfn, "r"); } else { Index: common.c =================================================================== RCS file: /cvsroot/sdig/sdig/src/common.c,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** common.c 2 May 2006 21:21:37 -0000 1.2 --- common.c 18 May 2006 18:17:42 -0000 1.3 *************** *** 34,39 **** #include "common.h" ! static int debuglevel = 0; ! static const char *oom_msg = "Out of memory"; /* debug levels: --- 34,39 ---- #include "common.h" ! int debuglevel = 0; ! const char *oom_msg = "Out of memory"; /* debug levels: *************** *** 61,64 **** --- 61,76 ---- void + inc_debuglevel(void) + { + debuglevel++; + } + + int + get_debuglevel(void) + { + return debuglevel; + } + + void fatal(const char *fmt, ...) { Index: Makefile.am =================================================================== RCS file: /cvsroot/sdig/sdig/src/Makefile.am,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** Makefile.am 2 May 2006 21:21:36 -0000 1.2 --- Makefile.am 18 May 2006 18:17:42 -0000 1.3 *************** *** 3,7 **** bin_PROGRAMS = sdig ! AM_CFLAGS = @NET_SNMP_CFLAGS@ LDADD = @NET_SNMP_LIBS@ --- 3,7 ---- bin_PROGRAMS = sdig ! AM_CFLAGS = @NET_SNMP_CFLAGS@ -DCONFPATH=\"${sysconfdir}\" LDADD = @NET_SNMP_LIBS@ *************** *** 11,13 **** query.c \ config.c \ ! snmpget.c --- 11,14 ---- query.c \ config.c \ ! snmpget.c \ ! output.c Index: sdig.c =================================================================== RCS file: /cvsroot/sdig/sdig/src/sdig.c,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** sdig.c 2 May 2006 21:21:37 -0000 1.2 --- sdig.c 18 May 2006 18:17:42 -0000 1.3 *************** *** 18,21 **** --- 18,25 ---- */ + #ifdef HAVE_CONFIG_H + #include <config.h> + #endif + #include <ctype.h> #include <errno.h> *************** *** 29,32 **** --- 33,37 ---- #include <netinet/in.h> #include <sys/socket.h> + #include <sysexits.h> #include "sdig.h" *************** *** 35,51 **** #include "version.h" ! #include "../include/config.h" ! ! extern stype *firstsw = NULL; ! extern rtype *firstrt = NULL; ! extern pdtype *firstpd = NULL; ! extern litype *firstli = NULL; ! ! extern char *wins = NULL, *nmblookup = NULL, *mactable = NULL, ! *hostinfo = NULL; ! extern int verbose = 0, fastmode = 0; ! static void help(const char *prog) { --- 40,50 ---- #include "version.h" ! /* ! * Flags ! */ ! int verbose = 0, fastmode = 0; ! void help(const char *prog) { *************** *** 62,66 **** printf(" <hostname> - DNS/WINS hostname to find\n"); ! exit(0); } --- 61,65 ---- printf(" <hostname> - DNS/WINS hostname to find\n"); ! exit(EX_OK); } *************** *** 78,82 **** switch (i) { case 'd': ! debuglevel++; break; --- 77,81 ---- switch (i) { case 'd': ! inc_debuglevel(); break; *************** *** 115,118 **** --- 114,118 ---- loadconfig(conf); + output_sem_init(); /* split off to resolve things based on what kind of input we got */ Index: common.h =================================================================== RCS file: /cvsroot/sdig/sdig/src/common.h,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** common.h 24 Apr 2006 20:47:30 -0000 1.1 --- common.h 18 May 2006 18:17:42 -0000 1.2 *************** *** 1,9 **** - extern int debuglevel; - #define LARGEBUF 1024 void debug(int level, const char *format, ...); void fatal(const char *fmt, ...); int parseconf(const char *fn, int ln, char *buf, char **arg, int numargs); int snprintfcat(char *dst, size_t size, const char *fmt, ...); void *xmalloc(size_t size); --- 1,12 ---- #define LARGEBUF 1024 void debug(int level, const char *format, ...); + void inc_debuglevel(void); + int get_debuglevel(void); + void fatal(const char *fmt, ...); + int parseconf(const char *fn, int ln, char *buf, char **arg, int numargs); + int snprintfcat(char *dst, size_t size, const char *fmt, ...); void *xmalloc(size_t size); |