[Oisf-devel] [PATCH 2/8] ethernet: use switch instead of 'else if'
Eric Leblond
eleblond at edenwall.com
Mon Jan 11 10:11:32 UTC 2010
This patch uses a switch instead of a 'else if' series. It also
adds a debug message for unsupported ethernet type.
---
src/decode-ethernet.c | 36 ++++++++++++++++++++++++------------
1 files changed, 24 insertions(+), 12 deletions(-)
diff --git a/src/decode-ethernet.c b/src/decode-ethernet.c
index 48ecbdb..5ba9475 100644
--- a/src/decode-ethernet.c
+++ b/src/decode-ethernet.c
@@ -23,18 +23,30 @@ void DecodeEthernet(ThreadVars *tv, DecodeThreadVars *dtv, Packet *p, uint8_t *p
SCLogDebug("p %p pkt %p ether type %04x", p, pkt, ntohs(ethh->eth_type));
- if (ntohs(ethh->eth_type) == ETHERNET_TYPE_IP) {
- //printf("DecodeEthernet ip4\n");
- DecodeIPV4(tv, dtv, p, pkt + ETHERNET_HEADER_LEN, len - ETHERNET_HEADER_LEN, pq);
- } else if(ntohs(ethh->eth_type) == ETHERNET_TYPE_IPV6) {
- //printf("DecodeEthernet ip6\n");
- DecodeIPV6(tv, dtv, p, pkt + ETHERNET_HEADER_LEN, len - ETHERNET_HEADER_LEN, pq);
- } else if(ntohs(ethh->eth_type) == ETHERNET_TYPE_PPPOE_SESS) {
- //printf("DecodeEthernet PPPOE Session\n");
- DecodePPPOESession(tv, dtv, p, pkt + ETHERNET_HEADER_LEN, len - ETHERNET_HEADER_LEN, pq);
- } else if(ntohs(ethh->eth_type) == ETHERNET_TYPE_PPPOE_DISC) {
- //printf("DecodeEthernet PPPOE Discovery\n");
- DecodePPPOEDiscovery(tv, dtv, p, pkt + ETHERNET_HEADER_LEN, len - ETHERNET_HEADER_LEN, pq);
+ switch (ntohs(ethh->eth_type)) {
+ case ETHERNET_TYPE_IP:
+ //printf("DecodeEthernet ip4\n");
+ DecodeIPV4(tv, dtv, p, pkt + ETHERNET_HEADER_LEN,
+ len - ETHERNET_HEADER_LEN, pq);
+ break;
+ case ETHERNET_TYPE_IPV6:
+ //printf("DecodeEthernet ip6\n");
+ DecodeIPV6(tv, dtv, p, pkt + ETHERNET_HEADER_LEN,
+ len - ETHERNET_HEADER_LEN, pq);
+ break;
+ case ETHERNET_TYPE_PPPOE_SESS:
+ //printf("DecodeEthernet PPPOE Session\n");
+ DecodePPPOESession(tv, dtv, p, pkt + ETHERNET_HEADER_LEN,
+ len - ETHERNET_HEADER_LEN, pq);
+ break;
+ case ETHERNET_TYPE_PPPOE_DISC:
+ //printf("DecodeEthernet PPPOE Discovery\n");
+ DecodePPPOEDiscovery(tv, dtv, p, pkt + ETHERNET_HEADER_LEN,
+ len - ETHERNET_HEADER_LEN, pq);
+ break;
+ default:
+ SCLogDebug("p %p pkt %p ether type %04x not supported", p,
+ pkt, ntohs(ethh->eth_type));
}
return;
--
1.6.6
More information about the Oisf-devel
mailing list