Skip to content

Commit

Permalink
Add VLAN and Duplex parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
qistoph committed Feb 19, 2012
1 parent f1915db commit 1f4fdf3
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions CdpSniffino.ino
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,12 @@ void loop() {
case 0x0006:
handleCdpAsciiField(F("Platform: "), rbuf, rbufIndex, cdpFieldLength);
break;
case 0x000a:
handleCdpNumField(F("Native VLAN: "), rbuf, rbufIndex, cdpFieldLength);
break;
case 0x000b:
handleCdpDuplex(rbuf, rbufIndex, cdpFieldLength);
break;
default:
Serial.print(F("Field "));
printhex(cdpFieldType >> 8); printhex(cdpFieldType & 0xFF);
Expand All @@ -139,12 +145,25 @@ void loop() {
}
}


void handleCdpAsciiField(const __FlashStringHelper * title, const byte a[], unsigned int offset, unsigned int length) {
Serial.print(title);
print_str(a, offset, length);
Serial.println();
}

void handleCdpNumField(const __FlashStringHelper * title, const byte a[], unsigned int offset, unsigned int length) {
unsigned long num = 0;
for(int i=0; i<length; ++i) {
num <<= 8;
num += a[offset + i];
}

Serial.print(title);
Serial.print(num, DEC);
Serial.println();
}

void handleCdpAddresses(const byte a[], unsigned int offset, unsigned int length) {
Serial.println(F("Addresses: "));
unsigned long numOfAddrs = (a[offset] << 24) | (a[offset+1] << 16) | (a[offset+2] << 8) | a[offset+3];
Expand All @@ -170,6 +189,15 @@ void handleCdpAddresses(const byte a[], unsigned int offset, unsigned int length
Serial.println();
}

void handleCdpDuplex(const byte a[], unsigned int offset, unsigned int length) {
Serial.print(F("Duplex: "));
if(a[offset]) {
Serial.println(F("Full"));
} else {
Serial.println(F("Half"));
}
}

void print_str(const byte a[], unsigned int offset, unsigned int length) {
for(int i=offset; i<offset+length; ++i) {
Serial.write(a[i]);
Expand Down

0 comments on commit 1f4fdf3

Please sign in to comment.