From c96586446bae9a0ec1574317f22ef055fba89ec3 Mon Sep 17 00:00:00 2001 From: Eric Leblond Date: Mon, 11 Jan 2010 11:11:32 +0100 Subject: [PATCH] ethernet: use switch instead of 'else if' 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 file changed, 24 insertions(+), 12 deletions(-) diff --git a/src/decode-ethernet.c b/src/decode-ethernet.c index 48ecbdb87d..5ba9475054 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;