summaryrefslogtreecommitdiff
path: root/net/sdig/patches/patch-ab
blob: a2b738001768b3669e931baea722ac16578dfff2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
$NetBSD: patch-ab,v 1.2 2003/04/07 15:01:22 bouyer Exp $

--- sdig.c.orig	Tue Jul 23 05:03:20 2002
+++ sdig.c	Thu Apr  3 12:22:07 2003
@@ -25,16 +25,21 @@
 #include <stdlib.h> 
 #include <string.h> 
 #include <unistd.h> 
-#include <arpa/inet.h> 
-#include <netinet/in.h> 
+#include <sys/types.h>
 #include <sys/socket.h>
+#include <netinet/in.h>
+#include <arpa/inet.h>
+#include <netdb.h>
+#include <arpa/nameser.h>
+#include <resolv.h>
+
 
 #include "sdig.h"
 #include "common.h"
 #include "snmpget.h"
 #include "version.h"
 
-#define CONFIGFILE "/etc/sdig.conf"
+#define CONFIGFILE PREFIX "/etc/sdig.conf"
 
 	stype	*firstsw = NULL;
 	rtype	*firstrt = NULL;
@@ -114,7 +119,7 @@
 
 	/* build the OID for the mapping of MAC addresses to port numbers */
 
-	snprintf(query, sizeof(query), "17.4.3.1.2.%u.%u.%u.%u.%u.%u",
+	snprintf(query, sizeof(query), ".1.3.6.1.2.1.17.4.3.1.2.%u.%u.%u.%u.%u.%u",
 		mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
 
 	debug(5, "findport: query is [%s]\n", query);
@@ -355,6 +360,7 @@
 	snprintf(macfind, sizeof(macfind), "%02x %02x %02x", 
 		inmac[0], inmac[1], inmac[2]);
 
+	debug("looking for MAC prefix [%s] in %s\n", macfind, mactable);
 	while (fgets(buf, sizeof(buf), macdb)) {
 		buf[strlen(buf) - 1] = '\0';
 
@@ -494,14 +500,13 @@
 
 	/* first get the switch's ifnum for the port */
 	
-	snprintf(query, sizeof(query), "17.1.4.1.2.%ld", port);
+	snprintf(query, sizeof(query), ".1.3.6.1.2.1.17.1.4.1.2.%ld", port);
 	ifnum = snmpget_int(sw->ip, sw->pw, query);
 
 	if (ifnum == -1)
 		return;
 
-	snprintf(query, sizeof(query), "interfaces.ifTable.ifEntry.ifDescr.%ld",
-		ifnum);
+	snprintf(query, sizeof(query), ".1.3.6.1.2.1.2.2.1.2.%ld", ifnum);
 
 	ifdescr = snmpget_str(sw->ip, sw->pw, query);
 
@@ -728,6 +733,7 @@
 {
 	char	*prog, *query, *conf = NULL, *mac = NULL;
 	int	i;
+	char macaddr[6];
 
 	printf("Switch Digger %s - http://www.exploits.org/sdig/\n\n",
 		VERSION);
@@ -791,7 +797,10 @@
 			mac, query);
 
 		checkmac(mac);
-		switchscan(query, mac);
+		macaddr[0] = strtoul(strtok(mac, ":"), NULL, 16);
+		for (i = 1; i < 6; i++)
+			macaddr[i] = strtoul(strtok(NULL, ":"), NULL, 16);
+		switchscan(query, macaddr);
 
 		/* NOTREACHED */
 	}