diff -ur cdp-tools.orig/cdp-send.c cdp-tools/cdp-send.c --- cdp-tools.orig/cdp-send.c 2006-10-26 14:04:33.000000000 -0400 +++ cdp-tools/cdp-send.c 2007-02-28 17:13:35.000000000 -0500 @@ -2,6 +2,8 @@ * cdp-send is part of cdp-tools. * cdp-tools is (c) 2003-2006 Internet Connection, Inc. * + * Voice VLAN support by Kristian Kielhofner + * * cdp-send 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, or (at your option) @@ -37,6 +39,8 @@ static unsigned int use_vlanid = 0; +static unsigned int use_voiceid = 0; + static unsigned char *use_ip_prefix = 0; static unsigned int use_ip_prefix_len = 0; @@ -178,7 +182,7 @@ buffer+=sizeof(struct cdp_header); - buffer[0]=0x1; /* cdp version */ + buffer[0]=0x2; /* cdp version */ buffer[1]=0xb4; /* cdp holdtime, 180 sec by default */ buffer[2]=buffer[3]=0; /* checksum - will calculate later */ @@ -299,7 +303,7 @@ if (duplex == 0) return 0; if (len < 5) return 0; sx_write_short(buffer,htons(0x000b)); /* type=port duplex */ - sx_write_short(buffer+2,htons(1)); + sx_write_short(buffer+2,htons(5)); /* totallength*/ buffer[4] = (duplex == 1 ? 1 : 0); return 5; } @@ -309,11 +313,23 @@ { if (len < 6) return 0; sx_write_short(buffer,htons(0x000a)); /* type=vlan id */ - sx_write_short(buffer+2,htons(2)); + sx_write_short(buffer+2,htons(6)); /* totallength*/ sx_write_short(buffer+4,htons(use_vlanid)); return 6; } +int +cdp_add_voiceid(unsigned char* buffer, int len) +{ + if (len < 7) return 0; + sx_write_short(buffer,htons(0x000e)); /* type=voice vlan id */ + sx_write_short(buffer+2,htons(7)); /* totallength*/ + sx_write_short(buffer+4,htons(0x1)); /*PAD*/ + sx_write_short(buffer+5,htons(use_voiceid)); + return 7; +} + + unsigned short cdp_checksum(unsigned char *ptr, int length) { @@ -346,6 +362,7 @@ " -d enable debugging output\n" " -D dom specify VTP management domain (octal escapes ok)\n" " -L vlan specify native VLAN (vlanid)\n" +" -V vlan specify voice VLAN (voiceid)\n" " -m mach specify machine/platform to advertise (e.g. \"%s\")\n" " -n name specify a hostname\n" " -p name override port name (default: interface)\n" @@ -435,11 +452,12 @@ struct cdp_interface *ifaces=NULL; int specify_duplex = 0; int specified_vlan = 0; + int specified_vvlan = 0; int didcap = 0; char *q; uname(&myuname); - while((c=getopt(argc,argv,"a:c:dD:L:m:n:op:P:s:S:t:"))!=EOF) { + while((c=getopt(argc,argv,"a:c:dD:L:V:m:n:op:P:s:S:t:"))!=EOF) { switch(c) { case 'a': if (inet_aton(optarg, &iaddr)) { @@ -518,6 +536,15 @@ specified_vlan=1; use_vlanid = i; break; + case 'V': + i = strtod(optarg, &q); + if ((q && *q) || i < 0 || i > 65535) { + fprintf(stderr, "Voice VLAN ID is an unsigned 16-bit integer\n"); + exit(1); + } + specified_vvlan=1; + use_voiceid = i; + break; case 'm': use_machine = strdup(optarg); if (!use_machine) { @@ -673,7 +700,11 @@ if (specified_vlan) { offset+=cdp_add_vlanid(buffer+offset, sizeof(buffer)-offset); } - + + if (specified_vvlan) { + offset+=cdp_add_voiceid(buffer+offset, sizeof(buffer)-offset); + } + ((struct cdp_header*)buffer)->length=htons(offset-14); *(u_short*)(buffer+sizeof(struct cdp_header)+2)=cdp_checksum(