2
2
* cdpr - Cisco Discovery Protocol Reporter
3
* Copyright (c) 2002-2006 MonkeyMental.com
3
* Copyright (c) 2002-2010 MonkeyMental.com
5
5
* This program will show you which Cisco device your machine is
6
6
* connected to based on CDP packets received.
58
58
* 2.1.0 LO 03-11-08 Release - Got timeout code working on WIN32 port
59
59
* 2.2.0 LO 04-04-14 Added the ability specify the port to send the cdpr updates to.
60
60
* 2.2.1 LO 06-07-28 Fixed segfault when not providing port to a command line selected server (-s)
61
* 2.3.0 LO 09-??-?? Decode IPv6 addresses
62
* 2.4.0 LO 10-02-15 Add ioctl to OSX to disable buffers, add ability to read from file (-r)
63
65
/*#include "pcap.h" */
83
93
char switch_ip[100];
86
sprintf (switch_ip, "switch_ip=%d.%d.%d.%d",
96
sprintf (switch_ip, "switch_ip=%d.%d.%d.%d&",
87
97
(int) ip[0], (int) ip[1], (int) ip[2], (int) ip[3]);
88
98
cdprs_action(CDPRS_DATA, switch_ip, 0);
105
dump_ipv6 (const u_char *ip)
107
char ipv6_buf[INET6_ADDRSTRLEN];
108
struct in6_addr addr;
109
register const char *p_ipv6;
110
char switch_ip6[600];
112
memcpy(&addr, ip, sizeof(addr));
113
p_ipv6 = inet_ntop(AF_INET6, &addr, ipv6_buf, sizeof(ipv6_buf));
114
printf("%s", ipv6_buf);
117
sprintf(switch_ip6, "switch_ip6=%s&", ipv6_buf);
118
cdprs_action(CDPRS_DATA, switch_ip6, 0);
95
123
dump_hex (const u_char *p, int len)
185
213
if (protocol_len == 1 && *protocol_val == 0xCC && address_len == 4)
186
214
dump_ip (address_val);
215
// else if (protocol_len == 8 && *protocol_val == "0xAAAA0300000086DD" && address_len == 16)
216
else if (protocol_len == 8 && address_len == 16)
217
dump_ipv6 (address_val);
188
219
dump_hex (address_val, address_len);
275
portval = urlencode(v, strlen(v), &portlen);
276
sprintf(port, "&port=%.*s", portlen, portval);
306
portval = urlencode((char *)v, strlen((char *)v), &portlen);
307
sprintf(port, "port=%.*s", portlen, portval);
278
309
cdprs_action(CDPRS_DATA, port, verbose);
449
480
puts("h: Print this usage");
450
481
puts("t: time in seconds to abort waiting for a packet (should be > 60)");
451
482
puts("v[vv]: Set verbose mode");
483
puts("r: read from file instead of network device");
452
484
puts("\n** Options dealing with server updates: **");
453
485
puts(" u: Send cdpr information to a cdpr server\n requires config file as arg");
454
486
puts(" l: Location/description of this port for use with -u or -s and -p");
504
538
/* Print out header */
505
539
printf("cdpr - Cisco Discovery Protocol Reporter\nVersion %s\n", version);
506
printf("Copyright (c) 2002-2006 - MonkeyMental.com\n\n");
540
printf("Copyright (c) 2002-2010 - MonkeyMental.com\n\n");
508
542
/* Check command-line options */
509
while((c = getopt(argc, argv, "d:t:vhu:l:n:s:p:")) !=EOF)
543
while((c = getopt(argc, argv, "d:t:vhu:l:n:s:p:r:")) !=EOF)
602
640
/* Print the list */
603
641
for(d=alldevs; d; d=d->next)
605
printf("%d. %s", ++i, d->name);
607
printf(" (%s)\n", d->description);
609
printf(" (No description available)\n");
643
if (strcmp(d->name, "any") != 0)
645
printf("%d. %s", ++i, d->name);
647
printf(" (%s)\n", d->description);
649
printf(" (No description available)\n");
629
670
/* Jump to the selected adapter */
630
for(d=alldevs, i=0; i< inum-1 ;d=d->next, i++)
671
for(d=alldevs, i=0; d; d=d->next)
673
if (strcmp(d->name, "any") != 0)
676
if (i == inum) break;
638
printf("Using Device: %s\n", dev);
640
684
/* Get the network number and netmask */
641
685
pcap_lookupnet(dev, &net, &mask, errbuf);
643
687
/* Open the pcap device */
644
if((handle = pcap_open_live(dev, BUFSIZ, 1, 0, errbuf)) == NULL)
646
printf("Error opening device (%s)\n", errbuf);
649
else if (strlen(errbuf))
690
printf("Using Device: %s\n", dev);
691
if((handle = pcap_open_live(dev, BUFSIZ, 1, 1000, errbuf)) == NULL)
693
printf("Error opening device (%s)\n", errbuf);
696
#if defined(__APPLE_CC__) || defined(__APPLE__)
698
ioctl(pcap_fileno(handle), BIOCIMMEDIATE, &v);
704
printf("Using File %s\n", fname);
705
if((handle = pcap_open_offline(fname, errbuf)) == NULL)
707
printf("Error opening file (%s)\n", fname);
651
713
printf("Warning opening device (%s)\n", errbuf);