sdig-devel Mailing List for Switch Digger
Status: Beta
Brought to you by:
raj2
You can subscribe to this list here.
2005 |
Jan
|
Feb
(3) |
Mar
(1) |
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
---|---|---|---|---|---|---|---|---|---|---|---|---|
2006 |
Jan
|
Feb
|
Mar
(1) |
Apr
(2) |
May
(14) |
Jun
|
Jul
|
Aug
|
Sep
(1) |
Oct
|
Nov
|
Dec
|
2007 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
(2) |
Nov
|
Dec
|
2010 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
(2) |
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
From: SourceForge.net <no...@so...> - 2010-07-13 06:47:46
|
Patches item #3028812, was opened at 2010-07-13 10:47 Message generated for change (Tracker Item Submitted) made by jimklimov You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=699935&aid=3028812&group_id=124610 Please note that this message will contain a full copy of the comment thread, including the initial issue submission, for this request, not just the latest update. Category: General Group: None Status: Open Resolution: None Priority: 5 Private: No Submitted By: Jim Klimov (jimklimov) Assigned to: Russell Jackson (raj2) Summary: Separate "SNMP IP" & "routing iface IP", MAC-only search... Initial Comment: * Added feature: search only by MAC address, without an IP (and check each switch only once) * Added feature: accept MAC addresses in various formats - Standard XX:XX:XX:XX:XX:XX Windows XX-XX-XX-XX-XX-XX Hewlett XXXXXX-XXXXXX Cisco XXXX.XXXX.XXXX Unseparated XXXXXXXXXXXX Standard and Windows formats may have 0 to 2 hex digits in each component. Less than 2 digits are zero-padded, more are processed as an error. MAC adresses are "tolower()ed" as to easily copy them to switch telnet sessions (i.e. for Cisco IOS "sh mac- | in maca.ddre.ss01") * Added feature: for ROUTER config entries we can have a separate "SNMP IP" (old position of IP address) and "Routing interface IP" (optional sixth position). For future format expansions, an empty string ("") can be specified (if a seventh parameter is added, but then it is mandatory). This feature allows to run SNMP queries against an IP address accessible from the management station, but request info about an interface in the specific subnet (used for ARP lookups to find the target host's MAC). * Added feature: ROUTER configurations can also (like SWITCHes) use textual host names for "SNMP IP" and/or "Routing interface IP". Previously the "SNMP IP == Routing interface IP" could only be a numeric IP address. Now resolvable names can be used and forged i.e. via /etc/hosts, so that the same sdig.conf can be used from mgmt stations in different subnets accessing different "SNMP IP" hosts. Useful against inter-subnet firewalls ;) The resolved IP value is reported at debug_level >= 1. * Added feature: print user-defined interface descriptions (ifAlias) from SNMP lookups, if available, in curly braces. The ifDesc value is almost useless, since many switches (HP, Cisco) fill it with port's long name. NOTES Code has been aligned with the SourceForge trunk version (unreleased sdig-044) used as the base. File layout differs from sdig-0.43, so the patch is not directly applicable to the released tar.gz source. It can be backported (reverse of my forward-porting last night ;) ) - but not worth the effort if you can do "svn checkout". Parallelized SNMP search in SVN trunk sdig-0.44 seems cool ;) "Config" version is bumped to "0.45cvs". ---------------------------------------------------------------------- You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=699935&aid=3028812&group_id=124610 |
From: SourceForge.net <no...@so...> - 2010-07-13 06:40:37
|
Patches item #3028806, was opened at 2010-07-13 10:40 Message generated for change (Tracker Item Submitted) made by jimklimov You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=699935&aid=3028806&group_id=124610 Please note that this message will contain a full copy of the comment thread, including the initial issue submission, for this request, not just the latest update. Category: General Group: None Status: Open Resolution: None Priority: 5 Private: No Submitted By: Jim Klimov (jimklimov) Assigned to: Russell Jackson (raj2) Summary: CGI wrapper for sdig Initial Comment: This is a couple of scripts to enable a simple web interface to sdig. The perl script "sdig.cgi" takes care of rendering an HTML form to receive IP/MAC/HOST parameters, calling sdig and producing results for the end-user (admin). It can also call on "sdig-preamble" shell script to ping/arping/tracert the path to the target host. Both scripts can take configuration parameters from a common per-user or global config file (/etc/sdig-cgi.conf). (C) 2005-2010 by Jim Klimov ---------------------------------------------------------------------- You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=699935&aid=3028806&group_id=124610 |
From: Russell J. <ra...@cs...> - 2007-10-11 18:33:18
|
David Hartburn wrote: > Hi, > > The current release of Sdig does not support Cisco Catalyst switches, as > they use a per-vlan MAC table, unlike many other switches that use a > single MAC table. > > I have updated Sdig to resolve this issue and have the code ready to be > joined to the official project. I have tried contacting the current > maintainer of this project via the list owner mail address, and not had a > response. > > If anyone has contact with the project maintainer, can you ask them to get > in touch with me, so I can get the updated code submitted. > I'm not sure why I didn't get anything on the owner address. It may go through the sf.net forwarding address which might be suffering from bit rot. I haven't worked on sdig in a long while due to a number of factors. The most pressing reason is that we've started using netdisco here which already does most of the things I had set out to implement in sdig (auto-uplink-discovery and CAM table history). I'm not sure what sdig's future is at this point, but I'll incorporate your patch for the time being. I hope your patch isn't against trunk ;-). -- Russell A. Jackson <ra...@cs...> Network Analyst California State University, Bakersfield Food for thought is no substitute for the real thing. -- Walt Kelly, "Putluck Pogo" |
From: David H. <da...@sa...> - 2007-10-11 13:39:02
|
Hi, The current release of Sdig does not support Cisco Catalyst switches, as they use a per-vlan MAC table, unlike many other switches that use a single MAC table. I have updated Sdig to resolve this issue and have the code ready to be joined to the official project. I have tried contacting the current maintainer of this project via the list owner mail address, and not had a response. If anyone has contact with the project maintainer, can you ask them to get in touch with me, so I can get the updated code submitted. Thanks Dave -- |
From: Russell J. <ra...@us...> - 2006-09-08 18:20:20
|
Update of /cvsroot/sdig/sdig In directory sc8-pr-cvs8.sourceforge.net:/tmp/cvs-serv15651 Modified Files: Tag: STABLE sdig.c Log Message: Print out the interface index along with the internal port number Index: sdig.c =================================================================== RCS file: /cvsroot/sdig/sdig/Attic/sdig.c,v retrieving revision 1.3 retrieving revision 1.3.4.1 diff -C2 -d -r1.3 -r1.3.4.1 *** sdig.c 11 Apr 2005 08:57:08 -0000 1.3 --- sdig.c 8 Sep 2006 18:20:16 -0000 1.3.4.1 *************** *** 428,453 **** { char query[256], *ifdescr, *ifname; ! long ifnum; ! /* first get the switch's ifnum for the port */ snprintf(query, sizeof(query), "SNMPv2-SMI::mib-2.17.1.4.1.2.%ld", port); ! ifnum = snmpget_int(sw->ip, sw->pw, query); ! if (ifnum == -1) return; snprintf(query, sizeof(query), "IF-MIB::ifName.%ld", ! ifnum); ifname = snmpget_str(sw->ip, sw->pw, query); if (!ifname) { ! snprintf(query, sizeof(query), "IF-MIB::ifAlias.%ld", ifnum); snmpget_str(sw->ip, sw->pw, query); } snprintf(query, sizeof(query), "IF-MIB::ifDescr.%ld", ! ifnum); ifdescr = snmpget_str(sw->ip, sw->pw, query); --- 428,455 ---- { char query[256], *ifdescr, *ifname; ! long ifidx; ! /* first get the switch's ifidx for the port */ snprintf(query, sizeof(query), "SNMPv2-SMI::mib-2.17.1.4.1.2.%ld", port); ! ifidx = snmpget_int(sw->ip, sw->pw, query); ! if (ifidx == -1) return; + else + printf("/%d", ifidx); snprintf(query, sizeof(query), "IF-MIB::ifName.%ld", ! ifidx); ifname = snmpget_str(sw->ip, sw->pw, query); if (!ifname) { ! snprintf(query, sizeof(query), "IF-MIB::ifAlias.%ld", ifidx); snmpget_str(sw->ip, sw->pw, query); } snprintf(query, sizeof(query), "IF-MIB::ifDescr.%ld", ! ifidx); ifdescr = snmpget_str(sw->ip, sw->pw, query); |
From: Russell J. <ra...@us...> - 2006-05-23 00:03:28
|
Update of /cvsroot/sdig/sdig/src In directory sc8-pr-cvs8.sourceforge.net:/tmp/cvs-serv1787 Modified Files: sdig.c Log Message: Add RCS tag Add myself to copyright Index: sdig.c =================================================================== RCS file: /cvsroot/sdig/sdig/src/sdig.c,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** sdig.c 18 May 2006 18:31:57 -0000 1.4 --- sdig.c 23 May 2006 00:03:24 -0000 1.5 *************** *** 1,5 **** ! /* sdig.c - the Switch Digger main file ! * * Copyright (C) 2000 Russell Kroll <rk...@ex...> * * This program is free software; you can redistribute it and/or modify --- 1,5 ---- ! /* * Copyright (C) 2000 Russell Kroll <rk...@ex...> + * Copyright (C) 2006 Russell Jackson <ra...@cs...> * * This program is free software; you can redistribute it and/or modify *************** *** 16,19 **** --- 16,21 ---- * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * $Id$ */ |
From: Russell J. <ra...@us...> - 2006-05-22 01:42:55
|
Update of /cvsroot/sdig/sdig/src In directory sc8-pr-cvs8.sourceforge.net:/tmp/cvs-serv26765 Modified Files: output.c Log Message: Add semaphore clean up function Index: output.c =================================================================== RCS file: /cvsroot/sdig/sdig/src/output.c,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** output.c 18 May 2006 18:31:09 -0000 1.1 --- output.c 22 May 2006 01:42:51 -0000 1.2 *************** *** 16,23 **** enum ops { UNLOCK = 1, LOCK = -1 }; - int lock = 0; ! void output_sem_init() { int ret; --- 16,26 ---- enum ops { UNLOCK = 1, LOCK = -1 }; int lock = 0; ! /* ! * initialize output locking semaphore ! */ ! void ! output_sem_init() { int ret; *************** *** 52,56 **** } ! void output_sem_cleanup() { int ret; --- 55,63 ---- } ! /* ! * deallocate lock semaphore ! */ ! void ! output_sem_cleanup() { int ret; *************** *** 64,68 **** } ! void output_lock(enum ops op) { struct sembuf buf = { 0, 0, SEM_UNDO }; --- 71,79 ---- } ! /* ! * toggle output lock ! */ ! void ! output_lock(enum ops op) { struct sembuf buf = { 0, 0, SEM_UNDO }; *************** *** 78,82 **** } ! /* make the octet string into something nicer for humans */ void printmac(unsigned const char *mac) --- 89,95 ---- } ! /* ! * make the octet string into something nicer for humans ! */ void printmac(unsigned const char *mac) *************** *** 129,132 **** output_lock(UNLOCK); } - - --- 142,143 ---- |
From: Russell J. <ra...@us...> - 2006-05-22 01:41:41
|
Update of /cvsroot/sdig/sdig/src In directory sc8-pr-cvs8.sourceforge.net:/tmp/cvs-serv26282 Modified Files: query.c Log Message: Use config.h properly Clean up after semaphore allocation Index: query.c =================================================================== RCS file: /cvsroot/sdig/sdig/src/query.c,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** query.c 18 May 2006 18:31:57 -0000 1.4 --- query.c 22 May 2006 01:41:32 -0000 1.5 *************** *** 3,6 **** --- 3,10 ---- */ + #ifdef HAVE_CONFIG_H + #include <config.h> + #endif + #include <ctype.h> #include <errno.h> *************** *** 20,25 **** #include "snmpget.h" - #include "../include/config.h" - char *findmac(const char *ip, rtype *rtr) --- 24,27 ---- *************** *** 325,329 **** switch (ret) { ! case 0: fork_wrapper(macaddr, sw); _exit(EX_OK); --- 327,331 ---- switch (ret) { ! case 0: /* child process */ fork_wrapper(macaddr, sw); _exit(EX_OK); *************** *** 332,338 **** case -1: perror("fork"); break; ! default: debug(3, "child %d started\n", ret); break; --- 334,341 ---- case -1: perror("fork"); + exit(EX_SOFTWARE); break; ! default: /* parent process */ debug(3, "child %d started\n", ret); break; *************** *** 345,349 **** debug(3, "child %d exited\n", ret); ! exit(0); } --- 348,354 ---- debug(3, "child %d exited\n", ret); ! output_sem_cleanup(); ! ! exit(EX_OK); } *************** *** 518,521 **** return mac; } - - --- 523,524 ---- |
From: Russell J. <ra...@us...> - 2006-05-18 19:29:03
|
Update of /cvsroot/sdig/sdig/src In directory sc8-pr-cvs8.sourceforge.net:/tmp/cvs-serv11735/src Modified Files: Makefile.am Log Message: Add headers Index: Makefile.am =================================================================== RCS file: /cvsroot/sdig/sdig/src/Makefile.am,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** Makefile.am 18 May 2006 18:17:42 -0000 1.3 --- Makefile.am 18 May 2006 19:28:56 -0000 1.4 *************** *** 7,14 **** sdig_SOURCES = \ ! common.c \ ! sdig.c \ ! query.c \ ! config.c \ ! snmpget.c \ ! output.c --- 7,19 ---- sdig_SOURCES = \ ! common.c \ ! sdig.c \ ! query.c \ ! config.c \ ! snmpget.c \ ! output.c ! ! noinst_HEADERS = \ ! sdig.h \ ! common.h \ ! snmpget.h |
From: Russell J. <ra...@us...> - 2006-05-18 19:28:21
|
Update of /cvsroot/sdig/sdig In directory sc8-pr-cvs8.sourceforge.net:/tmp/cvs-serv11010 Modified Files: autogen.sh Log Message: run aclocal use autoreconf run automake with flags to add missing files Index: autogen.sh =================================================================== RCS file: /cvsroot/sdig/sdig/autogen.sh,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** autogen.sh 2 May 2006 21:24:25 -0000 1.1 --- autogen.sh 18 May 2006 19:28:18 -0000 1.2 *************** *** 1,6 **** #!/bin/sh ! autoconf || exit 1 ! automake || exit 1 ./configure --- 1,7 ---- #!/bin/sh ! aclocal || exit 1 ! autoreconf || exit 1 ! automake --add-missing || exit 1 ./configure |
From: Russell J. <ra...@us...> - 2006-05-18 19:26:39
|
Update of /cvsroot/sdig/sdig In directory sc8-pr-cvs8.sourceforge.net:/tmp/cvs-serv10984 Modified Files: configure.in Log Message: Update version string Index: configure.in =================================================================== RCS file: /cvsroot/sdig/sdig/configure.in,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** configure.in 24 Apr 2006 20:48:43 -0000 1.3 --- configure.in 18 May 2006 19:26:34 -0000 1.4 *************** *** 1,4 **** AC_INIT(src/sdig.c) ! AM_INIT_AUTOMAKE(sdig, 0.42) AC_CONFIG_HEADER(include/config.h) AC_REVISION([$Id$]) --- 1,4 ---- AC_INIT(src/sdig.c) ! AM_INIT_AUTOMAKE(sdig, 0.44cvs) AC_CONFIG_HEADER(include/config.h) AC_REVISION([$Id$]) *************** *** 26,33 **** AC_SUBST(NET_SNMP_LIBS) ! AC_SUBST(HAVE_INET_PTON) ! AC_SUBST(HAVE_INET_ATON) ! ! CFLAGS="$CFLAGS -DCONFPATH=$sysconfdir" AC_OUTPUT(Makefile src/Makefile) --- 26,31 ---- AC_SUBST(NET_SNMP_LIBS) ! #AC_SUBST(HAVE_INET_PTON) ! #AC_SUBST(HAVE_INET_ATON) AC_OUTPUT(Makefile src/Makefile) |
From: Russell J. <ra...@us...> - 2006-05-18 18:32:06
|
Update of /cvsroot/sdig/sdig/src In directory sc8-pr-cvs8.sourceforge.net:/tmp/cvs-serv23916 Modified Files: query.c sdig.c Log Message: Use the version string in config.h rather than version.h Index: query.c =================================================================== RCS file: /cvsroot/sdig/sdig/src/query.c,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** query.c 18 May 2006 18:17:42 -0000 1.3 --- query.c 18 May 2006 18:31:57 -0000 1.4 *************** *** 19,23 **** #include "common.h" #include "snmpget.h" - #include "version.h" #include "../include/config.h" --- 19,22 ---- Index: sdig.c =================================================================== RCS file: /cvsroot/sdig/sdig/src/sdig.c,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** sdig.c 18 May 2006 18:17:42 -0000 1.3 --- sdig.c 18 May 2006 18:31:57 -0000 1.4 *************** *** 38,42 **** #include "common.h" #include "snmpget.h" - #include "version.h" /* --- 38,41 ---- |
From: Russell J. <ra...@us...> - 2006-05-18 18:31:15
|
Update of /cvsroot/sdig/sdig/src In directory sc8-pr-cvs8.sourceforge.net:/tmp/cvs-serv23554 Added Files: output.c Log Message: Forgot to add this when commiting for the modularization and forking stuff --- NEW FILE: output.c --- /* * $Id: output.c,v 1.1 2006/05/18 18:31:09 raj2 Exp $ */ #ifdef HAVE_CONFIG_H #include <config.h> #endif #include <stdio.h> #include <sys/types.h> #include <sys/ipc.h> #include <sys/sem.h> #include <sysexits.h> #include "sdig.h" enum ops { UNLOCK = 1, LOCK = -1 }; int lock = 0; void output_sem_init() { int ret; /* * Create semaphore set with permissions for us to * read and alter it */ lock = semget(IPC_PRIVATE, 1, IPC_EXCL | IPC_CREAT | 0600); if (lock == -1) { perror("semget"); goto error; } debug(3, "output_sem_init: got semid %d\n", lock); /* * the lock needs to be initialized to un unlocked state */ ret = semctl(lock, 0, SETVAL, UNLOCK); if (ret == -1) { perror("semctl"); goto error; } return; error: exit(EX_SOFTWARE); } void output_sem_cleanup() { int ret; ret = semctl(lock, 0, IPC_RMID); if (ret == -1) { perror("semctl"); exit(EX_SOFTWARE); } } void output_lock(enum ops op) { struct sembuf buf = { 0, 0, SEM_UNDO }; int ret; buf.sem_op = op; ret = semop(lock, &buf, 1); if (ret == -1) { perror("semop"); exit(EX_SOFTWARE); } } /* make the octet string into something nicer for humans */ void printmac(unsigned const char *mac) { int i; for (i = 0; i < 5; i++) printf("%02x:", mac[i]); printf("%02x", mac[5]); } void printport(stype *sw, long port) { char *ds, *li, *swdesc; char query[256]; output_lock(LOCK); /* 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"); output_lock(UNLOCK); } |
From: Russell J. <ra...@us...> - 2006-05-18 18:29:05
|
Update of /cvsroot/sdig/sdig/include In directory sc8-pr-cvs8.sourceforge.net:/tmp/cvs-serv22789 Removed Files: version.h Log Message: Don't need this because autoconf already provides this macro --- version.h DELETED --- |
From: Russell J. <ra...@us...> - 2006-05-18 18:27:17
|
Update of /cvsroot/sdig/sdig In directory sc8-pr-cvs8.sourceforge.net:/tmp/cvs-serv22082 Modified Files: ChangeLog Log Message: Update changelog Index: ChangeLog =================================================================== RCS file: /cvsroot/sdig/sdig/ChangeLog,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** ChangeLog 26 Apr 2006 01:36:08 -0000 1.4 --- ChangeLog 18 May 2006 18:27:05 -0000 1.5 *************** *** 1,2 **** --- 1,9 ---- + 0.44: + + Thu May 18 11:24:23 PDT 2006 / Russell Jackson <ra...@cs... + + * Split up source into modules + * Parallelize MAC switch queries by fork()ing child worker processes + 0.43: |
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); |
From: Russell J. <ra...@us...> - 2006-05-02 22:05:13
|
Update of /cvsroot/sdig/sdig/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv23640 Modified Files: config.c query.c Log Message: Get rid of some of the copy paste stuff Index: query.c =================================================================== RCS file: /cvsroot/sdig/sdig/src/query.c,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** query.c 2 May 2006 21:21:37 -0000 1.1 --- query.c 2 May 2006 22:05:10 -0000 1.2 *************** *** 1,19 **** ! /* sdig.c - the Switch Digger main file ! * ! * Copyright (C) 2000 Russell Kroll <rk...@ex...> ! * ! * This program is free software; you can redistribute it and/or modify ! * it under the terms of the GNU General Public License as published by ! * the Free Software Foundation; either version 2 of the License, or ! * (at your option) any later version. ! * ! * This program is distributed in the hope that it will be useful, ! * but WITHOUT ANY WARRANTY; without even the implied warranty of ! * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ! * GNU General Public License for more details. ! * ! * You should have received a copy of the GNU General Public License ! * along with this program; if not, write to the Free Software ! * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ --- 1,4 ---- ! /* ! * $Id$ */ Index: config.c =================================================================== RCS file: /cvsroot/sdig/sdig/src/config.c,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** config.c 2 May 2006 21:21:37 -0000 1.1 --- config.c 2 May 2006 22:05:10 -0000 1.2 *************** *** 1,20 **** ! /* sdig.c - the Switch Digger main file ! * ! * Copyright (C) 2000 Russell Kroll <rk...@ex...> ! * ! * This program is free software; you can redistribute it and/or modify ! * it under the terms of the GNU General Public License as published by ! * the Free Software Foundation; either version 2 of the License, or ! * (at your option) any later version. ! * ! * This program is distributed in the hope that it will be useful, ! * but WITHOUT ANY WARRANTY; without even the implied warranty of ! * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ! * GNU General Public License for more details. ! * ! * You should have received a copy of the GNU General Public License ! * along with this program; if not, write to the Free Software ! * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA ! * * $Id$ */ --- 1,3 ---- ! /* * $Id$ */ |
From: Russell J. <ra...@us...> - 2006-05-02 21:24:29
|
Update of /cvsroot/sdig/sdig In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv23783 Added Files: autogen.sh Log Message: autogen will run the various autotools to get a configure --- NEW FILE: autogen.sh --- #!/bin/sh autoconf || exit 1 automake || exit 1 ./configure |
From: Russell J. <ra...@us...> - 2006-05-02 21:21:44
|
Update of /cvsroot/sdig/sdig/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv21796 Modified Files: Makefile.am common.c sdig.c sdig.h snmpget.c snmpget.h Added Files: config.c query.c Log Message: Firsts steps at modularization. Index: snmpget.c =================================================================== RCS file: /cvsroot/sdig/sdig/src/snmpget.c,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** snmpget.c 24 Apr 2006 20:47:30 -0000 1.1 --- snmpget.c 2 May 2006 21:21:37 -0000 1.2 *************** *** 1,26 **** /* snmpget.c - SNMP OID retrieval functions for sdig ! ! Copyright (C) 2002 Russell Kroll <rk...@ex...> ! ! based on snmp-ups.c from Network UPS Tools: ! ! * Copyright (C) 2002 Arnaud Quette <arn...@fr...> ! * some parts are Copyright (C) : * Hans Ekkehard Plesser <han...@it...> ! ! This program is free software; you can redistribute it and/or modify ! it under the terms of the GNU General Public License as published by ! the Free Software Foundation; either version 2 of the License, or ! (at your option) any later version. ! ! This program is distributed in the hope that it will be useful, ! but WITHOUT ANY WARRANTY; without even the implied warranty of ! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ! GNU General Public License for more details. ! ! You should have received a copy of the GNU General Public License ! along with this program; if not, write to the Free Software ! Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA ! */ #include <stdio.h> --- 1,28 ---- /* snmpget.c - SNMP OID retrieval functions for sdig ! * ! * Copyright (C) 2002 Russell Kroll <rk...@ex...> ! * ! * based on snmp-ups.c from Network UPS Tools: ! * ! * Copyright (C) 2002 Arnaud Quette <arn...@fr...> ! * some parts are Copyright (C) : * Hans Ekkehard Plesser <han...@it...> ! * ! * This program is free software; you can redistribute it and/or modify ! * it under the terms of the GNU General Public License as published by ! * the Free Software Foundation; either version 2 of the License, or ! * (at your option) any later version. ! * ! * This program is distributed in the hope that it will be useful, ! * but WITHOUT ANY WARRANTY; without even the implied warranty of ! * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ! * GNU General Public License for more details. ! * ! * You should have received a copy of the GNU General Public License ! * along with this program; if not, write to the Free Software ! * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA ! * ! * $Id$ ! */ #include <stdio.h> *************** *** 33,39 **** #include "common.h" ! netsnmp_pdu *response; ! static int snmpget(char *host, char *community, char *reqoid) { int status; --- 35,42 ---- #include "common.h" ! netsnmp_pdu *response; ! int ! snmpget(char *host, char *community, char *reqoid) { int status; *************** *** 87,91 **** } ! int snmpget_int(char *host, char *community, char *reqoid) { int ret; --- 90,95 ---- } ! int ! snmpget_int(char *host, char *community, char *reqoid) { int ret; *************** *** 109,113 **** } ! char *snmpget_mac(char *host, char *community, char *reqoid) { int ret, i; --- 113,118 ---- } ! char ! *snmpget_mac(char *host, char *community, char *reqoid) { int ret, i; *************** *** 138,142 **** } ! char *snmpget_str(char *host, char *community, char *reqoid) { int ret; --- 143,148 ---- } ! char ! *snmpget_str(char *host, char *community, char *reqoid) { int ret; Index: sdig.h =================================================================== RCS file: /cvsroot/sdig/sdig/src/sdig.h,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** sdig.h 24 Apr 2006 20:47:30 -0000 1.1 --- sdig.h 2 May 2006 21:21:37 -0000 1.2 *************** *** 41,42 **** --- 41,49 ---- void *next; } pdtype; + + struct response { + char sysName; + char ifIdx; + char ifAlias; + char ifName; + } --- NEW FILE: query.c --- /* sdig.c - the Switch Digger main file * * Copyright (C) 2000 Russell Kroll <rk...@ex...> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include <ctype.h> #include <errno.h> #include <netdb.h> #include <stdio.h> #include <stdarg.h> #include <stdlib.h> #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 "snmpget.h" #include "version.h" #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; int ifnum; debug(2, "\n\nfindmac: [%s] [%s] [%s]\n", ip, rtr->ip, rtr->pw); /* find the router's internal interface number */ snprintf(query, sizeof(query), "IP-MIB::ipAdEntIfIndex.%s", rtr->ip); ifnum = snmpget_int(rtr->ip, rtr->pw, query); if (ifnum == -1) return NULL; debug(6, "router interface number for %s is %d\n", rtr->ip, ifnum); /* now look it up in the net to media table relative to the ifnum */ /* if digging the router itself, use a different OID */ if (!strcmp(ip, rtr->ip)) snprintf(query, sizeof(query), "interfaces.ifTable.ifEntry.ifPhysAddress.%d", ifnum); else snprintf(query, sizeof(query), "ip.ipNetToMediaTable.ipNetToMediaEntry.ipNetToMediaPhysAddress.%d.%s", ifnum, ip); ret = snmpget_mac(rtr->ip, rtr->pw, query); return ret; } static int findport(unsigned const char *mac, stype *sw) { char query[64]; if (sw->ip == NULL) { printf("No switch defined for that network\n"); exit(1); } /* build the OID for the mapping of MAC addresses to port numbers */ snprintf(query, sizeof(query), "SNMPv2-SMI::mib-2.17.4.3.1.2.%u.%u.%u.%u.%u.%u", mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]); debug(4, "findport: snmpget_int(%s, %s, %s)\n", sw->ip, sw->pw, query); return snmpget_int(sw->ip, sw->pw, query); } static char *getlink(const char *ip, long port) { litype *tmp; tmp = firstli; while (tmp) { if ((!strcmp(tmp->ip, ip)) && (tmp->port == port)) return tmp->desc; tmp = tmp->next; } return NULL; } static char *getdesc(const char *ip, long port) { pdtype *tmp; tmp = firstpd; while (tmp) { if ((!strcmp(tmp->ip, ip)) && (tmp->port == port)) return tmp->desc; tmp = tmp->next; } return NULL; } static const char *macmfr(unsigned char *inmac) { FILE *macdb; char buf[256], *tmp, macfind[16]; int i; macdb = fopen(mactable, "r"); if (!macdb) return "MAC table file not available"; /* rewrite the MAC address into something that'll match the table */ snprintf(macfind, sizeof(macfind), "%02x %02x %02x", inmac[0], inmac[1], inmac[2]); while (fgets(buf, sizeof(buf), macdb)) { buf[strlen(buf) - 1] = '\0'; if (!strncasecmp(buf, macfind, 8)) { tmp = xstrdup(&buf[9]); for (i = strlen(tmp) - 1; i >= 0; i--) { if (!isspace(tmp[i])) { tmp[i+1] = '\0'; return tmp; } } return tmp; } } fclose(macdb); return "Not available"; } static char *wins_resolve(const char *host) { char exec[256], buf[256]; FILE *wq; if (!wins) { fprintf(stderr, "WINS not defined in config file!\n"); return NULL; } if (!nmblookup) { fprintf(stderr, "NMBLOOKUP not defined in config file!\n"); return NULL; } snprintf(exec, sizeof(exec), "%s -U %s -R %s | tail -1 | cut -f 1 -d \" \"", nmblookup, wins, host); debug(5, "popen: %s\n", exec); wq = popen(exec, "r"); fgets(buf, sizeof(buf), wq); pclose(wq); buf[strlen(buf) - 1] = '\0'; debug(7, "read [%s]\n", buf); if (!strcmp(buf, "name_query")) { fprintf(stderr, "WINS lookup failed\n"); exit(1); } printf(" Address: %s (WINS)\n", buf); return(xstrdup(buf)); } static char *dns_resolve(const char *host) { struct hostent *dns; struct in_addr addr; if ((dns = gethostbyname(host)) == (struct hostent *) NULL) return NULL; memcpy(&addr, dns->h_addr, dns->h_length); printf(" Address: %s (DNS)\n", inet_ntoa(addr)); return(xstrdup(inet_ntoa(addr))); } static void do_ifdescr(stype *sw, long port) { char query[256], *ifdescr, *ifname; long ifnum; /* first get the switch's ifnum for the port */ snprintf(query, sizeof(query), "SNMPv2-SMI::mib-2.17.1.4.1.2.%ld", port); ifnum = snmpget_int(sw->ip, sw->pw, query); if (ifnum == -1) return; snprintf(query, sizeof(query), "IF-MIB::ifName.%ld", ifnum); ifname = snmpget_str(sw->ip, sw->pw, query); if (!ifname) { snprintf(query, sizeof(query), "IF-MIB::ifAlias.%ld", ifnum); snmpget_str(sw->ip, sw->pw, query); } snprintf(query, sizeof(query), "IF-MIB::ifDescr.%ld", ifnum); ifdescr = snmpget_str(sw->ip, sw->pw, query); if (ifname) { printf(" (%s)", ifname); free(ifname); } if (ifdescr) { printf(" [%s]", ifdescr); free(ifdescr); } } 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; for (i = 0; i < strlen(buf); i++) if ((!isdigit(buf[i])) && (buf[i] != '.')) return 0; return 1; } static void dnsreverse(const char *ip) { struct hostent *dns; struct in_addr addr; #if HAVE_INET_ATON inet_aton(ip, &addr); #elif HAVE_INET_PTON inet_pton(AF_INET, ip, &addr); #else #error Cannot convert address #endif dns = gethostbyaddr((char *)&addr, sizeof(struct in_addr), AF_INET); if (dns) printf(" Hostname: %s (DNS)\n", dns->h_name); } static stype *find_switch(const char *ipaddr, stype *last) { stype *tmp; int addrchk, swchk; if (last) tmp = last->next; else tmp = firstsw; while (tmp) { addrchk = ntohl(inet_addr(ipaddr)) & tmp->mask; swchk = tmp->addr & tmp->mask; if (swchk == addrchk) return tmp; tmp = tmp->next; } return NULL; } /* 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"); } sw = find_switch(ipaddr, NULL); 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; int addrchk, rtchk; if (last) tmp = last->next; else tmp = firstrt; while (tmp) { addrchk = ntohl(inet_addr(ipaddr)) & tmp->mask; rtchk = tmp->addr & tmp->mask; if (rtchk == addrchk) return tmp; tmp = tmp->next; } return NULL; } /* run the user's script for extra details about a host */ static void do_hostinfo(const char *ipaddr) { char exec[256]; fflush(stdout); snprintf(exec, sizeof(exec), "%s %s", hostinfo, ipaddr); system(exec); } /* walk the list of routers checking for the IP address */ static void routerscan(const char *ipaddr) { unsigned char *macaddr; rtype *rtr; /* spew out some additional info about the IP address */ if (fastmode == 0) { dnsreverse(ipaddr); if (hostinfo) do_hostinfo(ipaddr); } printf("\n"); debug(2, "routerscan: looking for a router for host %s\n", ipaddr); /* XXX: ping code for waking up sleeping/inactive hosts */ /* find the first one that covers this network */ rtr = find_router(ipaddr, NULL); while (rtr) { debug(3, "routerscan: matched %s\n", rtr->ip); /* try to find the target IP address on this router */ macaddr = findmac(ipaddr, rtr); if (macaddr) { printf(" Router: %s - %s\n", rtr->desc, rtr->ip); printf(" MAC: "); printmac(macaddr); printf(" (%s)\n", macmfr(macaddr)); switchscan(ipaddr, macaddr); } rtr = find_router(ipaddr, rtr); } fprintf(stderr, "Error: no routers found for %s\n", ipaddr); exit(1); } /* turn <name> into an IP address and pass it to the router scanner */ static void resolvename(const char *name) { char *ipaddr; /* first try DNS */ ipaddr = dns_resolve(name); if (ipaddr) routerscan(ipaddr); /* now try WINS */ ipaddr = wins_resolve(name); if (ipaddr) routerscan(ipaddr); fprintf(stderr, "Can't resolve %s with DNS or WINS!\n", name); exit(1); } /* 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; char *ptr, *cp; static char mac[16]; cc = 0; for (i = 0; i < strlen(buf); i++) { if (buf[i] == ':') cc++; if ((!isxdigit(buf[i])) && (buf[i] != ':')) { fprintf(stderr, "Invalid MAC address specified: %s\n", buf); fprintf(stderr, "Valid characters are hex digits and :\n"); exit(1); } } if (cc != 5) { fprintf(stderr, "Invalid MAC address specified: %s\n", buf); fprintf(stderr, "It must contain exactly 5 : separators.\n"); exit(1); } strcpy(mac, ""); ptr = buf; sl = strlen(buf); mp = 0; for (i = 0; i < sl; i++) { cp = strchr(ptr, ':'); if (!cp) { v = strtol(ptr, (char **) NULL, 16); mac[mp++] = v; break; } *cp++ = '\0'; v = strtol(ptr, (char **) NULL, 16); mac[mp++] = v; ptr = cp; } return mac; } --- NEW FILE: config.c --- /* sdig.c - the Switch Digger main file * * Copyright (C) 2000 Russell Kroll <rk...@ex...> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * * $Id: config.c,v 1.1 2006/05/02 21:21:37 raj2 Exp $ */ #include <ctype.h> #include <errno.h> #include <netdb.h> #include <stdio.h> #include <stdarg.h> #include <stdlib.h> #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 loadconfig(const char *fn) { FILE *conf; char cfn[256], buf[256], *arg[5]; int ln, i; if (!fn) { snprintf(cfn, sizeof(cfn), "%s/sdig.conf", "CONFPATH"); conf = fopen(cfn, "r"); } else { conf = fopen(fn, "r"); } if (!conf) { fprintf(stderr, "fopen %s: %s\n", cfn, strerror(errno)); exit(1); } ln = 0; while (fgets(buf, sizeof(buf), conf)) { buf[strlen(buf) - 1] = '\0'; ln++; i = parseconf("sdig.conf", ln, buf, arg, 5); if (i == 0) continue; if (!strcmp(arg[0], "ROUTER")) addrouter(arg[1], arg[2], arg[3], arg[4]); if (!strcmp(arg[0], "SWITCH")) addswitch(arg[1], arg[2], arg[3], arg[4]); if (!strcmp(arg[0], "LINKINFO")) addli(arg[1], arg[2], arg[3]); if (!strcmp(arg[0], "PORTDESC")) addpd(arg[1], arg[2], arg[3]); if (!strcmp(arg[0], "WINS")) wins = xstrdup(arg[1]); if (!strcmp(arg[0], "NMBLOOKUP")) nmblookup = xstrdup(arg[1]); if (!strcmp(arg[0], "MACTABLE")) mactable = xstrdup(arg[1]); if (!strcmp(arg[0], "HOSTINFO")) hostinfo = xstrdup(arg[1]); } fclose(conf); } /* split up buf into a number of substrings, returning pointers in arg */ int parseconf(const char *fn, int ln, char *buf, char **arg, int numargs) { char *ptr, *ws; int i, buflen, an, state; an = state = 0; ws = NULL; buflen = strlen (buf); ptr = buf; /* yes, it's a state machine! be afraid! */ for (i = 0; i < buflen; i++) { switch (state) { case 0: /* scan */ if (*ptr == '"') { ws = ptr + 1; /* start after quote */ state = 1; /* goto quotecollect */ break; } if (isspace(*ptr)) break; /* loop */ if (*ptr == '\\') { /* literal as start */ if (i == (buflen - 1)) { fprintf(stderr, "%s:%d:" "\\ at end of line!", fn, ln); return 0; /* failure */ } ws = ptr; /* shift string to the left */ memmove(ptr, ptr+1, buflen-i); /* fix length */ buflen--; state = 2; /* goto collect */ } if (!isspace(*ptr)) { ws = ptr; state = 2; /* goto collect */ break; } break; case 1: /* quotecollect */ if (*ptr == '"') state = 3; /* goto save */ if (*ptr == '\\') { /* literal handling */ if (i == (buflen - 1)) { fprintf(stderr, "%s:%d:" "\\ at end of line!", fn, ln); return 0; /* failure */ } /* shift string to the left */ memmove(ptr, ptr+1, buflen-i); /* fix length */ buflen--; } break; /* loop */ case 2: /* collect */ if (*ptr == '\\') { /* literal handling */ if (i == (buflen - 1)) { fprintf(stderr, "%s:%d:" "\\ at end of line!", fn, ln); return 0; /* failure */ } /* shift string to the left */ memmove(ptr, ptr+1, buflen-i); /* fix length */ buflen--; break; /* loop */ } if (!isspace(*ptr)) break; /* loop */ state = 3; /* goto save */ } if (state == 3) { /* save */ if (an < numargs) arg[an++] = ws; *ptr = '\0'; ws = NULL; state = 0; } ptr++; } if (state == 1) { /* end-of-string in state 1 == missing quote */ fprintf(stderr, "%s:%d: Unbalanced \" in line", fn, ln); return 0; /* FAILED */ } if (state == 2) { /* catch last word when exiting from collect */ *ptr = '\0'; if (an < numargs) arg[an++] = ws; } /* zap any leftover pointers */ for (i = an; i < numargs; i++) arg[i] = NULL; /* safety catch: don't allow all nulls back as 'success' */ if (arg[0] == NULL) return 0; /* FAILED (don't parse this) */ return 1; /* success */ } /* ROUTER <netblock> <ip> <pw> <"desc"> */ void addrouter(char *net, const char *ip, const char *pw, const char *desc) { rtype *tmp, *last; char *addr, *mask; mask = strchr(net, '/'); if (!mask) return; *mask++ = '\0'; addr = net; tmp = last = firstrt; while (tmp != NULL) { last = tmp; tmp = tmp->next; } tmp = xmalloc(sizeof(rtype)); tmp->addr = ntohl(inet_addr(addr)); tmp->pw = xstrdup(pw); tmp->ip = xstrdup(ip); tmp->desc = xstrdup(desc); tmp->next = NULL; if (strstr(mask, ".") == NULL) { /* must be a /nn CIDR type block */ if (atoi(mask) != 32) tmp->mask = ((unsigned int) ((1 << atoi(mask)) - 1) << (32 - atoi(mask))); else tmp->mask = 0xffffffff; /* avoid overflow from 2^32 */ } else tmp->mask = ntohl(inet_addr(mask)); if (last != NULL) last->next = tmp; else firstrt = tmp; } /* SWITCH <netblock> <ip> <community> ["<desc>"] */ void addswitch(char *net, const char *ip, const char *pw, const char *desc) { stype *tmp, *last; char *addr, *mask; mask = strchr(net, '/'); if (!mask) return; *mask++ = '\0'; addr = net; tmp = last = firstsw; while (tmp != NULL) { last = tmp; tmp = tmp->next; } tmp = xmalloc(sizeof(stype)); tmp->addr = ntohl(inet_addr(addr)); tmp->pw = xstrdup(pw); tmp->ip = xstrdup(ip); tmp->desc = xstrdup(desc); tmp->firstlink = NULL; tmp->next = NULL; if (strstr(mask, ".") == NULL) { /* must be a /nn CIDR type block */ if (atoi(mask) != 32) tmp->mask = ((unsigned int) ((1 << atoi(mask)) - 1) << (32 - atoi(mask))); else tmp->mask = 0xffffffff; /* avoid overflow from 2^32 */ } else tmp->mask = ntohl(inet_addr(mask)); if (last != NULL) last->next = tmp; else firstsw = tmp; } /* LINKINFO <ip> <port> "<desc>" */ void addli(const char *ip, const char *port, const char *desc) { litype *tmp, *last; tmp = last = firstli; while (tmp) { last = tmp; tmp = tmp->next; } tmp = xmalloc(sizeof(litype)); tmp->ip = xstrdup(ip); tmp->port = strtol(port, (char **) NULL, 10); tmp->desc = xstrdup(desc); if (last) last->next = tmp; else firstli = tmp; } /* PORTDESC <ip> <port> "<desc>" */ void addpd(const char *ip, const char *port, const char *desc) { pdtype *last, *tmp; tmp = last = firstpd; while (tmp) { last = tmp; tmp = tmp->next; } tmp = xmalloc(sizeof(pdtype)); tmp->ip = xstrdup(ip); tmp->port = strtol(port, (char **) NULL, 10); tmp->desc = xstrdup(desc); if (last) last->next = tmp; else firstpd = tmp; } Index: sdig.c =================================================================== RCS file: /cvsroot/sdig/sdig/src/sdig.c,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** sdig.c 24 Apr 2006 20:47:30 -0000 1.1 --- sdig.c 2 May 2006 21:21:37 -0000 1.2 *************** *** 1,20 **** /* sdig.c - the Switch Digger main file ! ! Copyright (C) 2000 Russell Kroll <rk...@ex...> ! ! This program is free software; you can redistribute it and/or modify ! it under the terms of the GNU General Public License as published by ! the Free Software Foundation; either version 2 of the License, or ! (at your option) any later version. ! ! This program is distributed in the hope that it will be useful, ! but WITHOUT ANY WARRANTY; without even the implied warranty of ! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ! GNU General Public License for more details. ! ! You should have received a copy of the GNU General Public License ! along with this program; if not, write to the Free Software ! Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA ! */ #include <ctype.h> --- 1,20 ---- /* sdig.c - the Switch Digger main file ! * ! * Copyright (C) 2000 Russell Kroll <rk...@ex...> ! * ! * This program is free software; you can redistribute it and/or modify ! * it under the terms of the GNU General Public License as published by ! * the Free Software Foundation; either version 2 of the License, or ! * (at your option) any later version. ! * ! * This program is distributed in the hope that it will be useful, ! * but WITHOUT ANY WARRANTY; without even the implied warranty of ! * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ! * GNU General Public License for more details. ! * ! * You should have received a copy of the GNU General Public License ! * along with this program; if not, write to the Free Software ! * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA ! */ #include <ctype.h> *************** *** 37,361 **** #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; ! int ifnum; ! ! debug(2, "\n\nfindmac: [%s] [%s] [%s]\n", ip, rtr->ip, rtr->pw); ! ! /* find the router's internal interface number */ ! ! snprintf(query, sizeof(query), ! "IP-MIB::ipAdEntIfIndex.%s", rtr->ip); ! ! ifnum = snmpget_int(rtr->ip, rtr->pw, query); ! ! if (ifnum == -1) ! return NULL; ! ! debug(6, "router interface number for %s is %d\n", ! rtr->ip, ifnum); ! ! /* now look it up in the net to media table relative to the ifnum */ ! ! /* if digging the router itself, use a different OID */ ! ! if (!strcmp(ip, rtr->ip)) ! snprintf(query, sizeof(query), ! "interfaces.ifTable.ifEntry.ifPhysAddress.%d", ! ifnum); ! else ! snprintf(query, sizeof(query), ! "ip.ipNetToMediaTable.ipNetToMediaEntry.ipNetToMediaPhysAddress.%d.%s", ! ifnum, ip); ! ! ret = snmpget_mac(rtr->ip, rtr->pw, query); ! ! return ret; ! } ! ! static int findport(unsigned const char *mac, stype *sw) ! { ! char query[64]; ! ! if (sw->ip == NULL) { ! printf("No switch defined for that network\n"); ! exit(1); ! } ! ! /* build the OID for the mapping of MAC addresses to port numbers */ ! ! snprintf(query, sizeof(query), "SNMPv2-SMI::mib-2.17.4.3.1.2.%u.%u.%u.%u.%u.%u", ! mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]); ! ! debug(4, "findport: snmpget_int(%s, %s, %s)\n", ! sw->ip, sw->pw, query); ! ! return snmpget_int(sw->ip, sw->pw, query); ! } ! ! /* ROUTER <netblock> <ip> <pw> <"desc"> */ ! static void addrouter(char *net, const char *ip, const char *pw, ! const char *desc) ! { ! rtype *tmp, *last; ! char *addr, *mask; ! ! mask = strchr(net, '/'); ! ! if (!mask) ! return; ! ! *mask++ = '\0'; ! addr = net; ! ! tmp = last = firstrt; ! ! while (tmp != NULL) { ! last = tmp; ! tmp = tmp->next; ! } ! ! tmp = xmalloc(sizeof(rtype)); ! tmp->addr = ntohl(inet_addr(addr)); ! tmp->pw = xstrdup(pw); ! tmp->ip = xstrdup(ip); ! tmp->desc = xstrdup(desc); ! tmp->next = NULL; ! ! if (strstr(mask, ".") == NULL) { /* must be a /nn CIDR type block */ ! if (atoi(mask) != 32) ! tmp->mask = ((unsigned int) ((1 << atoi(mask)) - 1) << ! (32 - atoi(mask))); ! else ! tmp->mask = 0xffffffff; /* avoid overflow from 2^32 */ ! } ! else ! tmp->mask = ntohl(inet_addr(mask)); ! ! if (last != NULL) ! last->next = tmp; ! else ! firstrt = tmp; ! } ! ! /* SWITCH <netblock> <ip> <community> ["<desc>"] */ ! static void addswitch(char *net, const char *ip, const char *pw, ! const char *desc) ! { ! stype *tmp, *last; ! char *addr, *mask; ! ! mask = strchr(net, '/'); ! ! if (!mask) ! return; ! ! *mask++ = '\0'; ! addr = net; ! ! tmp = last = firstsw; ! ! while (tmp != NULL) { ! last = tmp; ! tmp = tmp->next; ! } ! ! tmp = xmalloc(sizeof(stype)); ! tmp->addr = ntohl(inet_addr(addr)); ! tmp->pw = xstrdup(pw); ! tmp->ip = xstrdup(ip); ! tmp->desc = xstrdup(desc); ! tmp->firstlink = NULL; ! tmp->next = NULL; ! ! if (strstr(mask, ".") == NULL) { /* must be a /nn CIDR type block */ ! if (atoi(mask) != 32) ! tmp->mask = ((unsigned int) ((1 << atoi(mask)) - 1) << ! (32 - atoi(mask))); ! else ! tmp->mask = 0xffffffff; /* avoid overflow from 2^32 */ ! } ! else ! tmp->mask = ntohl(inet_addr(mask)); ! ! if (last != NULL) ! last->next = tmp; ! else ! firstsw = tmp; ! } ! ! /* LINKINFO <ip> <port> "<desc>" */ ! static void addli(const char *ip, const char *port, const char *desc) ! { ! litype *tmp, *last; ! ! tmp = last = firstli; ! ! while (tmp) { ! last = tmp; ! tmp = tmp->next; ! } ! ! tmp = xmalloc(sizeof(litype)); ! tmp->ip = xstrdup(ip); ! tmp->port = strtol(port, (char **) NULL, 10); ! tmp->desc = xstrdup(desc); ! ! if (last) ! last->next = tmp; ! else ! firstli = tmp; ! } ! ! /* PORTDESC <ip> <port> "<desc>" */ ! static void addpd(const char *ip, const char *port, const char *desc) ! { ! pdtype *last, *tmp; ! ! tmp = last = firstpd; ! ! while (tmp) { ! last = tmp; ! tmp = tmp->next; ! } ! ! tmp = xmalloc(sizeof(pdtype)); ! tmp->ip = xstrdup(ip); ! tmp->port = strtol(port, (char **) NULL, 10); ! tmp->desc = xstrdup(desc); ! ! if (last) ! last->next = tmp; ! else ! firstpd = tmp; ! } ! ! static void loadconfig(const char *fn) ! { ! FILE *conf; ! char cfn[256], buf[256], *arg[5]; ! int ln, i; ! ! if (!fn) { ! snprintf(cfn, sizeof(cfn), "%s/sdig.conf", "CONFPATH"); ! conf = fopen(cfn, "r"); ! } else { ! conf = fopen(fn, "r"); ! } ! ! if (!conf) { ! fprintf(stderr, "fopen %s: %s\n", cfn, strerror(errno)); ! exit(1); ! } ! ! ln = 0; ! while (fgets(buf, sizeof(buf), conf)) { ! buf[strlen(buf) - 1] = '\0'; ! ln++; ! ! i = parseconf("sdig.conf", ln, buf, arg, 5); ! ! if (i == 0) ! continue; ! ! if (!strcmp(arg[0], "ROUTER")) ! addrouter(arg[1], arg[2], arg[3], arg[4]); ! if (!strcmp(arg[0], "SWITCH")) ! addswitch(arg[1], arg[2], arg[3], arg[4]); ! if (!strcmp(arg[0], "LINKINFO")) ! addli(arg[1], arg[2], arg[3]); ! if (!strcmp(arg[0], "PORTDESC")) ! addpd(arg[1], arg[2], arg[3]); ! if (!strcmp(arg[0], "WINS")) ! wins = xstrdup(arg[1]); ! if (!strcmp(arg[0], "NMBLOOKUP")) ! nmblookup = xstrdup(arg[1]); ! if (!strcmp(arg[0], "MACTABLE")) ! mactable = xstrdup(arg[1]); ! if (!strcmp(arg[0], "HOSTINFO")) ! hostinfo = xstrdup(arg[1]); ! } ! ! fclose(conf); ! } ! ! static char *getlink(const char *ip, long port) ! { ! litype *tmp; ! ! tmp = firstli; ! ! while (tmp) { ! if ((!strcmp(tmp->ip, ip)) && (tmp->port == port)) ! return tmp->desc; ! ! tmp = tmp->next; ! } ! ! return NULL; ! } ! ! static char *getdesc(const char *ip, long port) ! { ! pdtype *tmp; ! ! tmp = firstpd; ! ! while (tmp) { ! if ((!strcmp(tmp->ip, ip)) && (tmp->port == port)) ! return tmp->desc; ! ! tmp = tmp->next; ! } ! ! return NULL; ! } ! ! static const char *macmfr(unsigned char *inmac) ! { ! FILE *macdb; ! char buf[256], *tmp, macfind[16]; ! int i; ! ! macdb = fopen(mactable, "r"); ! if (!macdb) ! return "MAC table file not available"; ! ! /* rewrite the MAC address into something that'll match the table */ ! ! snprintf(macfind, sizeof(macfind), "%02x %02x %02x", ! inmac[0], inmac[1], inmac[2]); ! ! while (fgets(buf, sizeof(buf), macdb)) { ! buf[strlen(buf) - 1] = '\0'; ! ! if (!strncasecmp(buf, macfind, 8)) { ! tmp = xstrdup(&buf[9]); ! for (i = strlen(tmp) - 1; i >= 0; i--) { ! if (!isspace(tmp[i])) { ! tmp[i+1] = '\0'; ! return tmp; ! } ! } ! return tmp; ! } ! } ! ! fclose(macdb); ! return "Not available"; ! } ! static void help(const char *prog) { printf("SNMP-based router and switch probe for locating client systems.\n\n"); --- 37,52 ---- #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) { printf("SNMP-based router and switch probe for locating client systems.\n\n"); *************** *** 374,758 **** } ! static char *wins_resolve(const char *host) ! { ! char exec[256], buf[256]; ! FILE *wq; ! ! if (!wins) { ! fprintf(stderr, "WINS not defined in config file!\n"); ! return NULL; ! } ! ! if (!nmblookup) { ! fprintf(stderr, "NMBLOOKUP not defined in config file!\n"); ! return NULL; ! } ! ! snprintf(exec, sizeof(exec), "%s -U %s -R %s | tail -1 | cut -f 1 -d \" \"", ! nmblookup, wins, host); ! ! debug(5, "popen: %s\n", exec); ! wq = popen(exec, "r"); ! ! fgets(buf, sizeof(buf), wq); ! pclose(wq); ! ! buf[strlen(buf) - 1] = '\0'; ! debug(7, "read [%s]\n", buf); ! if (!strcmp(buf, "name_query")) { ! fprintf(stderr, "WINS lookup failed\n"); ! exit(1); ! } ! ! printf(" Address: %s (WINS)\n", buf); ! ! return(xstrdup(buf)); ! } ! ! static char *dns_resolve(const char *host) ! { ! struct hostent *dns; ! struct in_addr addr; ! ! if ((dns = gethostbyname(host)) == (struct hostent *) NULL) ! return NULL; ! ! memcpy(&addr, dns->h_addr, dns->h_length); ! ! printf(" Address: %s (DNS)\n", inet_ntoa(addr)); ! ! return(xstrdup(inet_ntoa(addr))); ! } ! ! static void do_ifdescr(stype *sw, long port) ! { ! char query[256], *ifdescr, *ifname; ! long ifnum; ! ! /* first get the switch's ifnum for the port */ ! ! snprintf(query, sizeof(query), "SNMPv2-SMI::mib-2.17.1.4.1.2.%ld", port); ! ifnum = snmpget_int(sw->ip, sw->pw, query); ! ! if (ifnum == -1) ! return; ! ! snprintf(query, sizeof(query), "IF-MIB::ifName.%ld", ! ifnum); ! ! ifname = snmpget_str(sw->ip, sw->pw, query); ! ! if (!ifname) { ! snprintf(query, sizeof(query), "IF-MIB::ifAlias.%ld", ifnum); ! snmpget_str(sw->ip, sw->pw, query); ! } ! ! snprintf(query, sizeof(query), "IF-MIB::ifDescr.%ld", ! ifnum); ! ! ifdescr = snmpget_str(sw->ip, sw->pw, query); ! ! if (ifname) { ! printf(" (%s)", ifname); ! free(ifname); ! } ! ! if (ifdescr) { ! printf(" [%s]", ifdescr); ! free(ifdescr); ! } ! } ! ! 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; ! ! for (i = 0; i < strlen(buf); i++) ! if ((!isdigit(buf[i])) && (buf[i] != '.')) ! return 0; ! ! return 1; ! } ! ! static void dnsreverse(const char *ip) ! { ! struct hostent *dns; ! struct in_addr addr; ! ! #if HAVE_INET_ATON ! inet_aton(ip, &addr); ! #elif HAVE_INET_PTON ! inet_pton(AF_INET, ip, &addr); ! #else ! #error Cannot convert address ! #endif ! ! dns = gethostbyaddr((char *)&addr, sizeof(struct in_addr), AF_INET); ! ! if (dns) ! printf(" Hostname: %s (DNS)\n", dns->h_name); ! } ! ! static stype *find_switch(const char *ipaddr, stype *last) ! { ! stype *tmp; ! int addrchk, swchk; ! ! if (last) ! tmp = last->next; ! else ! tmp = firstsw; ! ! while (tmp) { ! addrchk = ntohl(inet_addr(ipaddr)) & tmp->mask; ! swchk = tmp->addr & tmp->mask; ! ! if (swchk == addrchk) ! return tmp; ! ! tmp = tmp->next; ! } ! ! return NULL; ! } ! ! /* 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"); ! } ! ! sw = find_switch(ipaddr, NULL); ! ! 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; ! int addrchk, rtchk; ! ! if (last) ! tmp = last->next; ! else ! tmp = firstrt; ! ! while (tmp) { ! addrchk = ntohl(inet_addr(ipaddr)) & tmp->mask; ! rtchk = tmp->addr & tmp->mask; ! ! if (rtchk == addrchk) ! return tmp; ! ! tmp = tmp->next; ! } ! ! return NULL; ! } ! ! /* run the user's script for extra details about a host */ ! static void do_hostinfo(const char *ipaddr) ! { ! char exec[256]; ! ! fflush(stdout); ! ! snprintf(exec, sizeof(exec), "%s %s", hostinfo, ipaddr); ! system(exec); ! } ! ! /* walk the list of routers checking for the IP address */ ! static void routerscan(const char *ipaddr) ! { ! unsigned char *macaddr; ! rtype *rtr; ! ! /* spew out some additional info about the IP address */ ! if (fastmode == 0) { ! dnsreverse(ipaddr); ! ! if (hostinfo) ! do_hostinfo(ipaddr); ! } ! ! printf("\n"); ! ! debug(2, "routerscan: looking for a router for host %s\n", ipaddr); ! ! /* XXX: ping code for waking up sleeping/inactive hosts */ ! ! /* find the first one that covers this network */ ! rtr = find_router(ipaddr, NULL); ! ! while (rtr) { ! debug(3, "routerscan: matched %s\n", rtr->ip); ! ! /* try to find the target IP address on this router */ ! macaddr = findmac(ipaddr, rtr); ! ! if (macaddr) { ! printf(" Router: %s - %s\n", rtr->desc, rtr->ip); ! ! printf(" MAC: "); ! printmac(macaddr); ! printf(" (%s)\n", macmfr(macaddr)); ! ! switchscan(ipaddr, macaddr); ! } ! ! rtr = find_router(ipaddr, rtr); ! } ! ! fprintf(stderr, "Error: no routers found for %s\n", ipaddr); ! exit(1); ! } ! ! /* turn <name> into an IP address and pass it to the router scanner */ ! static void resolvename(const char *name) ! { ! char *ipaddr; ! ! /* first try DNS */ ! ipaddr = dns_resolve(name); ! ! if (ipaddr) ! routerscan(ipaddr); ! ! /* now try WINS */ ! ipaddr = wins_resolve(name); ! ! if (ipaddr) ! routerscan(ipaddr); ! ! fprintf(stderr, "Can't resolve %s with DNS or WINS!\n", name); ! exit(1); ! } ! ! /* 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; ! char *ptr, *cp; ! static char mac[16]; ! ! cc = 0; ! for (i = 0; i < strlen(buf); i++) { ! ! if (buf[i] == ':') ! cc++; ! ! if ((!isxdigit(buf[i])) && (buf[i] != ':')) { ! fprintf(stderr, "Invalid MAC address specified: %s\n", buf); ! fprintf(stderr, "Valid characters are hex digits and :\n"); ! exit(1); ! } ! } ! ! if (cc != 5) { ! fprintf(stderr, "Invalid MAC address specified: %s\n", buf); ! fprintf(stderr, "It must contain exactly 5 : separators.\n"); ! exit(1); ! } ! ! strcpy(mac, ""); ! ptr = buf; ! sl = strlen(buf); ! mp = 0; ! ! for (i = 0; i < sl; i++) { ! cp = strchr(ptr, ':'); ! ! if (!cp) { ! v = strtol(ptr, (char **) NULL, 16); ! ! mac[mp++] = v; ! break; ! } ! ! *cp++ = '\0'; ! ! v = strtol(ptr, (char **) NULL, 16); ! mac[mp++] = v; ! ! ptr = cp; ! } ! ! return mac; ! } ! ! int main(int argc, char **argv) { char *prog, *query, *conf = NULL, *mac = NULL; int i; ! printf("Switch Digger %s - http://www.exploits.org/sdig/\n\n", ! VERSION); prog = argv[0]; --- 65,75 ---- } ! int ! main(int argc, char *argv[]) { char *prog, *query, *conf = NULL, *mac = NULL; int i; ! printf("Switch Digger %s\n\n", VERSION); prog = argv[0]; Index: snmpget.h =================================================================== RCS file: /cvsroot/sdig/sdig/src/snmpget.h,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** snmpget.h 24 Apr 2006 20:47:30 -0000 1.1 --- snmpget.h 2 May 2006 21:21:37 -0000 1.2 *************** *** 1,4 **** int snmpget_int(char *host, char *community, char *reqoid); char *snmpget_mac(char *host, char *community, char *reqoid); char *snmpget_str(char *host, char *community, char *reqoid); - --- 1,7 ---- + /* + * $Id$ + */ + int snmpget_int(char *host, char *community, char *reqoid); char *snmpget_mac(char *host, char *community, char *reqoid); char *snmpget_str(char *host, char *community, char *reqoid); Index: Makefile.am =================================================================== RCS file: /cvsroot/sdig/sdig/src/Makefile.am,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** Makefile.am 24 Apr 2006 20:47:30 -0000 1.1 --- Makefile.am 2 May 2006 21:21:36 -0000 1.2 *************** *** 9,11 **** --- 9,13 ---- common.c \ sdig.c \ + query.c \ + config.c \ snmpget.c Index: common.c =================================================================== RCS file: /cvsroot/sdig/sdig/src/common.c,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** common.c 24 Apr 2006 20:47:30 -0000 1.1 --- common.c 2 May 2006 21:21:37 -0000 1.2 *************** *** 34,38 **** #include "common.h" ! int debuglevel = 0; /* debug levels: --- 34,39 ---- #include "common.h" ! static int debuglevel = 0; ! static const char *oom_msg = "Out of memory"; /* debug levels: *************** *** 46,50 **** */ ! void debug(int level, const char *format, ...) { va_list args; --- 47,52 ---- */ ! void ! debug(int level, const char *format, ...) { va_list args; *************** *** 58,62 **** } ! void fatal(const char *fmt, ...) { va_list va; --- 60,65 ---- } ! void ! fatal(const char *fmt, ...) { va_list va; *************** *** 71,206 **** } ! ! /* split up buf into a number of substrings, returning pointers in arg */ ! int parseconf(const char *fn, int ln, char *buf, char **arg, int numargs) ! { ! char *ptr, *ws; ! int i, buflen, an, state; ! ! an = state = 0; ! ws = NULL; ! ! buflen = strlen (buf); ! ptr = buf; ! ! /* yes, it's a state machine! be afraid! */ ! ! for (i = 0; i < buflen; i++) { ! switch (state) { ! case 0: /* scan */ ! if (*ptr == '"') { ! ws = ptr + 1; /* start after quote */ ! state = 1; /* goto quotecollect */ ! break; ! } ! ! if (isspace(*ptr)) ! break; /* loop */ ! ! if (*ptr == '\\') { /* literal as start */ ! if (i == (buflen - 1)) { ! fprintf(stderr, "%s:%d:" ! "\\ at end of line!", ! fn, ln); ! return 0; /* failure */ ! } ! ! ws = ptr; ! ! /* shift string to the left */ ! memmove(ptr, ptr+1, buflen-i); ! ! /* fix length */ ! buflen--; ! ! state = 2; /* goto collect */ ! } ! ! if (!isspace(*ptr)) { ! ws = ptr; ! state = 2; /* goto collect */ ! break; ! } ! ! break; ! ! case 1: /* quotecollect */ ! if (*ptr == '"') ! state = 3; /* goto save */ ! ! if (*ptr == '\\') { /* literal handling */ ! if (i == (buflen - 1)) { ! fprintf(stderr, "%s:%d:" ! "\\ at end of line!", ! fn, ln); ! return 0; /* failure */ ! } ! ! /* shift string to the left */ ! memmove(ptr, ptr+1, buflen-i); ! ! /* fix length */ ! buflen--; ! } ! ! break; /* loop */ ! ! case 2: /* collect */ ! if (*ptr == '\\') { /* literal handling */ ! if (i == (buflen - 1)) { ! fprintf(stderr, "%s:%d:" ! "\\ at end of line!", ! fn, ln); ! return 0; /* failure */ ! } ! ! /* shift string to the left */ ! memmove(ptr, ptr+1, buflen-i); ! ! /* fix length */ ! buflen--; ! break; /* loop */ ! } ! ! if (!isspace(*ptr)) ! break; /* loop */ ! ! state = 3; /* goto save */ ! } ! ! if (state == 3) { /* save */ ! if (an < numargs) ! arg[an++] = ws; ! *ptr = '\0'; ! ws = NULL; ! state = 0; ! } ! ! ptr++; ! } ! ! if (state == 1) { /* end-of-string in state 1 == missing quote */ ! fprintf(stderr, "%s:%d: Unbalanced \" in line", fn, ln); ! return 0; /* FAILED */ ! } ! ! if (state == 2) { /* catch last word when exiting from collect */ ! *ptr = '\0'; ! if (an < numargs) ! arg[an++] = ws; ! } ! ! /* zap any leftover pointers */ ! for (i = an; i < numargs; i++) ! arg[i] = NULL; ! ! /* safety catch: don't allow all nulls back as 'success' */ ! if (arg[0] == NULL) ! return 0; /* FAILED (don't parse this) */ ! ! return 1; /* success */ ! } ! ! int snprintfcat(char *dst, size_t size, const char *fmt, ...) { va_list ap; --- 74,79 ---- } ! int ! snprintfcat(char *dst, size_t size, const char *fmt, ...) { va_list ap; *************** *** 218,224 **** } ! static const char *oom_msg = "Out of memory"; ! ! void *xmalloc(size_t size) { void *p = malloc(size); --- 91,96 ---- } ! void ! *xmalloc(size_t size) { void *p = malloc(size); *************** *** 229,233 **** } ! char *xstrdup(const char *string) { char *p = strdup(string); --- 101,106 ---- } ! char ! *xstrdup(const char *string) { char *p = strdup(string); *************** *** 237,239 **** return p; } - --- 110,111 ---- |
From: Russell J. <ra...@us...> - 2006-04-26 01:36:13
|
Update of /cvsroot/sdig/sdig In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv18286 Modified Files: ChangeLog Log Message: Test yet again. |
From: Russell J. <ra...@pa...> - 2006-04-26 01:07:27
|
is this thing working? |
From: Niels B. <ni...@ba...> - 2006-03-20 21:39:25
|
On Wed, Mar 02, 2005 at 11:35:25PM -0800, Russell Jackson wrote: > Right now I'm refactoring the code to seperate the back end into a=20 > library so that I can make several different front ends (cli, graphical= ,=20 > web, etc...). I also plan on either threading or forking to parallelize= =20 > the search queries. On the campus network, we have about 40 or so=20 > switches, and a query takes some time with the current model. Long time, no see! Anything happening, or have you abandoned the projects? I have a few new patches that I could donate :-) /Niels --=20 Niels Baggesen -- @home -- =C5rhus -- Denmark -- ni...@ba... The purpose of computing is insight, not numbers -- R W Hamming |
From: Russell J. <ra...@cs...> - 2005-03-03 07:36:02
|
Niels Baggesen wrote: > On Sun, Feb 13, 2005 at 10:49:28PM -0800, Russell Jackson wrote: > >>It doesn't look like the patch survived the list archiver. Could you >>submit it again using the patch tracker? > > > Could also be that I forgot to attach it :-( > > It is in the patch db now. > > /Niels > Sorry for the delay. Thanks for the patch. I'll merge it in and make a small point release (if it doesn't break anything). I'm a university student, and I have very little time at the moment. I try to work on sdig whenever I have the chance. Right now I'm refactoring the code to seperate the back end into a library so that I can make several different front ends (cli, graphical, web, etc...). I also plan on either threading or forking to parallelize the search queries. On the campus network, we have about 40 or so switches, and a query takes some time with the current model. I hacked up a crude php interface for the current incarnation of sdig. If you're insterested, I can post the script. Sorry for the delay again, but I have finals and upteen million papers due. -- Russell A. Jackson First Corollary of Taber's Second Law: Machines that piss people off get murdered. -- Pat Taber |
From: Niels B. <nb...@us...> - 2005-02-14 17:37:24
|
On Sun, Feb 13, 2005 at 10:49:28PM -0800, Russell Jackson wrote: > It doesn't look like the patch survived the list archiver. Could you > submit it again using the patch tracker? Could also be that I forgot to attach it :-( It is in the patch db now. /Niels --=20 Niels Baggesen -- @home -- =C5rhus -- Denmark -- ni...@ba... The purpose of computing is insight, not numbers -- R W Hamming |
From: Russell J. <ra...@cs...> - 2005-02-14 06:49:35
|
It might help if I subscribe to the mailing list. It doesn't look like the patch survived the list archiver. Could you submit it again using the patch tracker? http://sourceforge.net/tracker/?group_id=124610&atid=699935 Thanks, -- Russell A. Jackson First Corollary of Taber's Second Law: Machines that piss people off get murdered. -- Pat Taber |