From 7d223639ca89b47b543160c88c096ef49703ac2d Mon Sep 17 00:00:00 2001 From: Date: Thu, 20 Mar 2008 13:00:06 +0000 Subject: [PATCH] Added basic support for POS protocol. git-svn-id: file:///home/svn/mapi/trunk@1394 8d5bb341-7cf1-0310-8cf6-ba355fef3186 --- src/trackflib/dc.c | 61 +++++++++++++------- src/trackflib/edonkey.c | 61 ++++++++++++++------ src/trackflib/gnutella.c | 62 +++++++++++++------- src/trackflib/gridftp.c | 63 +++++++++++++------- src/trackflib/irc.c | 61 +++++++++++++------- src/trackflib/skype.c | 64 ++++++++++++++------- src/trackflib/torrent.c | 120 +++++++++++++++++++++++++++++++-------- src/trackflib/trackftp.c | 63 +++++++++++++------- src/trackflib/web.c | 67 +++++++++++++++------- 9 files changed, 441 insertions(+), 181 deletions(-) diff --git a/src/trackflib/dc.c b/src/trackflib/dc.c index 92cf937..9c99829 100644 --- a/src/trackflib/dc.c +++ b/src/trackflib/dc.c @@ -6,6 +6,7 @@ #include #include #include + #include "mapidflib.h" #include "mapidlib.h" #include "mapidevices.h" @@ -17,8 +18,7 @@ #include "acsmx2.h" #include "mapi_errors.h" -#include -#include +#include #include #include #include @@ -35,7 +35,6 @@ #include #include #include -#include #include #include #include @@ -192,6 +191,10 @@ static int dc_process(mapidflib_function_instance_t *instance, struct list **dclist = ((struct mapid_dc*)instance->internal_data)->dclist; uint16_t ethertype; struct ether_header *ep = NULL; + struct pos_header { + uint16_t af; + uint16_t cf; + } *pp = NULL; struct iphdr *iph = NULL; struct tcphdr *tcph = NULL; struct udphdr *udph = NULL; @@ -211,28 +214,48 @@ static int dc_process(mapidflib_function_instance_t *instance, if(pkt_color != 0 && pkt_color != DC_COLOR) { return 0; } + p = pkt; - // lay the Ethernet header struct over the packet data - ep = (struct ether_header *)p; + switch(instance->hwinfo->link_type) { + case DLT_EN10MB: + // lay the Ethernet header struct over the packet data + ep = (struct ether_header *)p; - // skip ethernet header - p += sizeof(struct ether_header); - len -= sizeof(struct ether_header); + // skip ethernet header + p += sizeof(struct ether_header); + len -= sizeof(struct ether_header); - ethertype = ntohs(ep->ether_type); + ethertype = ntohs(ep->ether_type); - if(ethertype == ETHERTYPE_8021Q) { - vlan_header = (struct vlan_802q_header*)p; - ethertype = ntohs(vlan_header->ether_type); - p += sizeof(struct vlan_802q_header); - } + if(ethertype == ETHERTYPE_8021Q) { + vlan_header = (struct vlan_802q_header*)p; + ethertype = ntohs(vlan_header->ether_type); + p += sizeof(struct vlan_802q_header); + } + + if(ethertype == MPLS_MASK) { + p += 4; + } + else if(ethertype != ETHERTYPE_IP) { + return 0; + } + break; + case DLT_CHDLC: + pp = (struct pos_header *)p; - if(ethertype == MPLS_MASK) { - p += 4; - } - else if(ethertype != ETHERTYPE_IP) { - return 0; + p += sizeof(struct pos_header); + len -= sizeof(struct pos_header); + + ethertype = ntohs(pp->cf); + + if (ethertype != ETHERTYPE_IP) { + return 0; + } + break; + default: + //DEBUG_CMD(Debug_Message("Link layer not supported")); + return 0; } // IP header struct over the packet data; diff --git a/src/trackflib/edonkey.c b/src/trackflib/edonkey.c index 5e165fd..4469c32 100644 --- a/src/trackflib/edonkey.c +++ b/src/trackflib/edonkey.c @@ -7,6 +7,7 @@ #include #include #include + #include "mapidflib.h" #include "mapidlib.h" #include "mapidevices.h" @@ -15,6 +16,8 @@ #include "debug.h" #include "mapiipc.h" #include "mstring.h" + +#include #include #include #include @@ -277,6 +280,10 @@ static int edonkey_process(mapidflib_function_instance_t *instance, struct list **edonkeylist = ((struct mapid_edonkey*)instance->internal_data)->edonkeylist; uint16_t ethertype; struct ether_header *ep = NULL; + struct pos_header { + uint16_t af; + uint16_t cf; + } *pp = NULL; struct iphdr *iph = NULL; struct tcphdr *tcph = NULL; struct udphdr *udph = NULL; @@ -303,27 +310,47 @@ static int edonkey_process(mapidflib_function_instance_t *instance, p = pkt; - // lay the Ethernet header struct over the packet data - ep = (struct ether_header *)p; - ether_len = sizeof(struct ether_header); + switch(instance->hwinfo->link_type) { + case DLT_EN10MB: + // lay the Ethernet header struct over the packet data + ep = (struct ether_header *)p; + ether_len = sizeof(struct ether_header); - // skip ethernet header - p += sizeof(struct ether_header); - len -= sizeof(struct ether_header); + // skip ethernet header + p += sizeof(struct ether_header); + len -= sizeof(struct ether_header); - ethertype = ntohs(ep->ether_type); + ethertype = ntohs(ep->ether_type); - if(ethertype == ETHERTYPE_8021Q) { - vlan_header = (struct vlan_802q_header*)p; - ethertype = ntohs(vlan_header->ether_type); - p += sizeof(struct vlan_802q_header); - } + if(ethertype == ETHERTYPE_8021Q) { + vlan_header = (struct vlan_802q_header*)p; + ethertype = ntohs(vlan_header->ether_type); + p += sizeof(struct vlan_802q_header); + } + + if(ethertype == MPLS_MASK) { + p += 4; + } + else if(ethertype != ETHERTYPE_IP) { + return 0; + } + break; + case DLT_CHDLC: + pp = (struct pos_header *)p; + ether_len = sizeof(struct pos_header); - if(ethertype == MPLS_MASK) { - p += 4; - } - else if(ethertype != ETHERTYPE_IP) { - return 0; + p += sizeof(struct pos_header); + len -= sizeof(struct pos_header); + + ethertype = ntohs(pp->cf); + + if (ethertype != ETHERTYPE_IP) { + return 0; + } + break; + default: + //DEBUG_CMD(Debug_Message("Link layer not supported")); + return 0; } // IP header struct over the packet data; diff --git a/src/trackflib/gnutella.c b/src/trackflib/gnutella.c index 5430527..645f160 100644 --- a/src/trackflib/gnutella.c +++ b/src/trackflib/gnutella.c @@ -6,6 +6,7 @@ #include #include #include + #include "mapidflib.h" #include "mapidlib.h" #include "mapidevices.h" @@ -17,8 +18,7 @@ #include "acsmx2.h" #include "mapi_errors.h" -#include -#include +#include #include #include #include @@ -35,7 +35,6 @@ #include #include #include -#include #include #include #include @@ -177,6 +176,10 @@ static int gnutella_process(mapidflib_function_instance_t *instance, struct list **gnulist = ((struct mapid_gnutella*)instance->internal_data)->gnulist; uint16_t ethertype; struct ether_header *ep = NULL; + struct pos_header { + uint16_t af; + uint16_t cf; + } *pp = NULL; struct iphdr *iph = NULL; struct tcphdr *tcph = NULL; struct udphdr *udph = NULL; @@ -199,26 +202,45 @@ static int gnutella_process(mapidflib_function_instance_t *instance, p = pkt; - // lay the Ethernet header struct over the packet data - ep = (struct ether_header *)p; + switch(instance->hwinfo->link_type) { + case DLT_EN10MB: + // lay the Ethernet header struct over the packet data + ep = (struct ether_header *)p; - // skip ethernet header - p += sizeof(struct ether_header); - len -= sizeof(struct ether_header); + // skip ethernet header + p += sizeof(struct ether_header); + len -= sizeof(struct ether_header); - ethertype = ntohs(ep->ether_type); + ethertype = ntohs(ep->ether_type); - if(ethertype == ETHERTYPE_8021Q) { - vlan_header = (struct vlan_802q_header*)p; - ethertype = ntohs(vlan_header->ether_type); - p += sizeof(struct vlan_802q_header); - } - - if(ethertype == MPLS_MASK) { - p += 4; - } - else if(ethertype != ETHERTYPE_IP) { - return 0; + if(ethertype == ETHERTYPE_8021Q) { + vlan_header = (struct vlan_802q_header*)p; + ethertype = ntohs(vlan_header->ether_type); + p += sizeof(struct vlan_802q_header); + } + + if(ethertype == MPLS_MASK) { + p += 4; + } + else if(ethertype != ETHERTYPE_IP) { + return 0; + } + break; + case DLT_CHDLC: + pp = (struct pos_header *)p; + + p += sizeof(struct pos_header); + len -= sizeof(struct pos_header); + + ethertype = ntohs(pp->cf); + + if (ethertype != ETHERTYPE_IP) { + return 0; + } + break; + default: + //DEBUG_CMD(Debug_Message("Link layer not supported")); + return 0; } // IP header struct over the packet data; diff --git a/src/trackflib/gridftp.c b/src/trackflib/gridftp.c index cbba004..87a34c9 100644 --- a/src/trackflib/gridftp.c +++ b/src/trackflib/gridftp.c @@ -6,6 +6,7 @@ #include #include #include + #include "mapidflib.h" #include "mapidlib.h" #include "mapidevices.h" @@ -14,8 +15,8 @@ #include "debug.h" #include "mapiipc.h" #include "mstring.h" -#include -#include + +#include #include #include #include @@ -32,7 +33,6 @@ #include #include #include -#include #include #include #include @@ -101,6 +101,10 @@ static int gridftp_process(mapidflib_function_instance_t *instance, struct list **cntlist = ((struct mapid_ftp*)instance->internal_data)->cntlist; uint16_t ethertype; struct ether_header *ep = NULL; + struct pos_header { + uint16_t af; + uint16_t cf; + } *pp = NULL; struct iphdr *iph = NULL; struct tcphdr *tcph = NULL; @@ -119,26 +123,45 @@ static int gridftp_process(mapidflib_function_instance_t *instance, } p = pkt; - // lay the Ethernet header struct over the packet data - ep = (struct ether_header *)p; + switch(instance->hwinfo->link_type) { + case DLT_EN10MB: + // lay the Ethernet header struct over the packet data + ep = (struct ether_header *)p; - // skip ethernet header - p += sizeof(struct ether_header); - len -= sizeof(struct ether_header); + // skip ethernet header + p += sizeof(struct ether_header); + len -= sizeof(struct ether_header); - ethertype = ntohs(ep->ether_type); - - if(ethertype == ETHERTYPE_8021Q) { - vlan_header = (struct vlan_802q_header*)p; - ethertype = ntohs(vlan_header->ether_type); - p += sizeof(struct vlan_802q_header); - } + ethertype = ntohs(ep->ether_type); - if(ethertype == MPLS_MASK) { - p += 4; - } - else if(ethertype != ETHERTYPE_IP) { - return 0; + if(ethertype == ETHERTYPE_8021Q) { + vlan_header = (struct vlan_802q_header*)p; + ethertype = ntohs(vlan_header->ether_type); + p += sizeof(struct vlan_802q_header); + } + + if(ethertype == MPLS_MASK) { + p += 4; + } + else if(ethertype != ETHERTYPE_IP) { + return 0; + } + break; + case DLT_CHDLC: + pp = (struct pos_header *)p; + + p += sizeof(struct pos_header); + len -= sizeof(struct pos_header); + + ethertype = ntohs(pp->cf); + + if (ethertype != ETHERTYPE_IP) { + return 0; + } + break; + default: + //DEBUG_CMD(Debug_Message("Link layer not supported")); + return 0; } // IP header struct over the packet data; diff --git a/src/trackflib/irc.c b/src/trackflib/irc.c index 585ae20..13355a4 100644 --- a/src/trackflib/irc.c +++ b/src/trackflib/irc.c @@ -6,6 +6,7 @@ #include #include #include + #include "mapidflib.h" #include "mapidlib.h" #include "mapidevices.h" @@ -14,8 +15,8 @@ #include "debug.h" #include "mapiipc.h" #include "mstring.h" -#include -#include + +#include #include #include #include @@ -32,7 +33,6 @@ #include #include #include -#include #include #include #include @@ -132,6 +132,10 @@ static int irc_process(mapidflib_function_instance_t *instance, struct list **irclist = ((struct mapid_irc*)instance->internal_data)->irclist; uint16_t ethertype; struct ether_header *ep = NULL; + struct pos_header { + uint16_t af; + uint16_t cf; + } *pp = NULL; struct iphdr *iph = NULL; struct tcphdr *tcph = NULL; struct udphdr *udph = NULL; @@ -148,26 +152,45 @@ static int irc_process(mapidflib_function_instance_t *instance, p = pkt; - // lay the Ethernet header struct over the packet data - ep = (struct ether_header *)p; + switch(instance->hwinfo->link_type) { + case DLT_EN10MB: + // lay the Ethernet header struct over the packet data + ep = (struct ether_header *)p; - // skip ethernet header - p += sizeof(struct ether_header); - len -= sizeof(struct ether_header); + // skip ethernet header + p += sizeof(struct ether_header); + len -= sizeof(struct ether_header); - ethertype = ntohs(ep->ether_type); + ethertype = ntohs(ep->ether_type); - if(ethertype == ETHERTYPE_8021Q) { - vlan_header = (struct vlan_802q_header*)p; - ethertype = ntohs(vlan_header->ether_type); - p += sizeof(struct vlan_802q_header); - } + if(ethertype == ETHERTYPE_8021Q) { + vlan_header = (struct vlan_802q_header*)p; + ethertype = ntohs(vlan_header->ether_type); + p += sizeof(struct vlan_802q_header); + } + + if(ethertype == MPLS_MASK) { + p += 4; + } + else if(ethertype != ETHERTYPE_IP) { + return 0; + } + break; + case DLT_CHDLC: + pp = (struct pos_header *)p; - if(ethertype == MPLS_MASK) { - p += 4; - } - else if(ethertype != ETHERTYPE_IP) { - return 0; + p += sizeof(struct pos_header); + len -= sizeof(struct pos_header); + + ethertype = ntohs(pp->cf); + + if (ethertype != ETHERTYPE_IP) { + return 0; + } + break; + default: + //DEBUG_CMD(Debug_Message("Link layer not supported")); + return 0; } // IP header struct over the packet data; diff --git a/src/trackflib/skype.c b/src/trackflib/skype.c index 98d479c..92f013c 100644 --- a/src/trackflib/skype.c +++ b/src/trackflib/skype.c @@ -6,6 +6,7 @@ #include #include #include + #include "mapidflib.h" #include "mapidlib.h" #include "mapidevices.h" @@ -14,8 +15,8 @@ #include "debug.h" #include "mapiipc.h" #include "mstring.h" -#include -#include + +#include #include #include #include @@ -32,7 +33,6 @@ #include #include #include -#include #include #include #include @@ -272,6 +272,10 @@ static int trackskype_process(mapidflib_function_instance_t *instance, struct list **cntlist = ((struct mapid_skype*)instance->internal_data)->cntlist; uint16_t ethertype; struct ether_header *ep = NULL; + struct pos_header { + uint16_t af; + uint16_t cf; + } *pp = NULL; struct iphdr *iph = NULL; struct tcphdr *tcph = NULL; struct udphdr *udph = NULL; @@ -293,28 +297,48 @@ static int trackskype_process(mapidflib_function_instance_t *instance, if(pkt_color != 0 && pkt_color != SKYPE_COLOR) { return 0; } + p = pkt; - // lay the Ethernet header struct over the packet data - ep = (struct ether_header *)p; + switch(instance->hwinfo->link_type) { + case DLT_EN10MB: + // lay the Ethernet header struct over the packet data + ep = (struct ether_header *)p; - // skip ethernet header - p += sizeof(struct ether_header); - len -= sizeof(struct ether_header); + // skip ethernet header + p += sizeof(struct ether_header); + len -= sizeof(struct ether_header); - ethertype = ntohs(ep->ether_type); - - if(ethertype == ETHERTYPE_8021Q) { - vlan_header = (struct vlan_802q_header*)p; - ethertype = ntohs(vlan_header->ether_type); - p += sizeof(struct vlan_802q_header); - } + ethertype = ntohs(ep->ether_type); - if(ethertype == MPLS_MASK) { - p += 4; - } - else if(ethertype != ETHERTYPE_IP) { - return 0; + if(ethertype == ETHERTYPE_8021Q) { + vlan_header = (struct vlan_802q_header*)p; + ethertype = ntohs(vlan_header->ether_type); + p += sizeof(struct vlan_802q_header); + } + + if(ethertype == MPLS_MASK) { + p += 4; + } + else if(ethertype != ETHERTYPE_IP) { + return 0; + } + break; + case DLT_CHDLC: + pp = (struct pos_header *)p; + + p += sizeof(struct pos_header); + len -= sizeof(struct pos_header); + + ethertype = ntohs(pp->cf); + + if (ethertype != ETHERTYPE_IP) { + return 0; + } + break; + default: + //DEBUG_CMD(Debug_Message("Link layer not supported")); + return 0; } // IP header struct over the packet data; diff --git a/src/trackflib/torrent.c b/src/trackflib/torrent.c index c3d7fa9..0b10aa1 100644 --- a/src/trackflib/torrent.c +++ b/src/trackflib/torrent.c @@ -18,8 +18,7 @@ #include "acsmx2.h" #include "mapi_errors.h" -#include -#include +#include #include #include #include @@ -36,7 +35,6 @@ #include #include #include -#include #include #include #include @@ -220,6 +218,10 @@ static int torrent_process(mapidflib_function_instance_t *instance, struct list **torlist = ((struct mapid_torrent*)instance->internal_data)->torlist; uint16_t ethertype; struct ether_header *ep = NULL; + struct pos_header { + uint16_t af; + uint16_t cf; + } *pp = NULL; struct iphdr *iph = NULL; struct tcphdr *tcph = NULL; struct udphdr *udph = NULL; @@ -235,7 +237,7 @@ static int torrent_process(mapidflib_function_instance_t *instance, int i = 0; - int ether_len =0 , ip_len = 0, tcp_len = 0, udp_len = 0; + int ip_len = 0, tcp_len = 0, udp_len = 0; int pkt_color = pkt_head->color; @@ -244,29 +246,99 @@ static int torrent_process(mapidflib_function_instance_t *instance, } p = pkt; +/* +typedef struct flags { + uint8_t iface:2; + uint8_t vlen:1; + uint8_t trunc:1; + uint8_t rxerror:1; + uint8_t dserror:1; + uint8_t reserved:1; + uint8_t direction:1; +} flags_t; +typedef struct dag_record { + uint64_t ts; + uint8_t type; + flags_t flags; + uint16_t rlen; + uint16_t lctr; + uint16_t wlen; + union { + pos_rec_t pos; + eth_rec_t eth; + atm_rec_t atm; + aal5_rec_t aal5; + aal2_rec_t aal2; + mc_hdlc_rec_t mc_hdlc; + mc_raw_rec_t mc_raw; + mc_atm_rec_t mc_atm; + mc_aal_rec_t mc_aal5; + mc_aal_rec_t mc_aal2; + mc_raw_channel_rec_t mc_raw_channel; + } rec; +} dag_record_t; + +typedef struct pos_rec { + uint32_t hdlc; + uint8_t pload[1]; +} pos_rec_t; + +typedef struct eth_rec { + uint8_t offset; + uint8_t pad; + + uint8_t dst[6]; + uint8_t src[6]; + uint16_t etype; + + uint8_t pload[1]; +} eth_rec_t; + +typedef struct mc_hdlc_rec { + uint32_t mc_header; + + uint8_t pload[1]; +} mc_hdlc_rec_t; +*/ + switch(instance->hwinfo->link_type) { + case DLT_EN10MB: + // lay the Ethernet header struct over the packet data + ep = (struct ether_header *)p; + + // skip ethernet header + p += sizeof(struct ether_header); + len -= sizeof(struct ether_header); + + ethertype = ntohs(ep->ether_type); + + if(ethertype == ETHERTYPE_8021Q) { + vlan_header = (struct vlan_802q_header*)p; + ethertype = ntohs(vlan_header->ether_type); + p += sizeof(struct vlan_802q_header); + } + + if(ethertype == MPLS_MASK) { + p += 4; + } + else if(ethertype != ETHERTYPE_IP) { + return 0; + } + break; + case DLT_CHDLC: + pp = (struct pos_header *)p; - // lay the Ethernet header struct over the packet data - ep = (struct ether_header *)p; - ether_len = sizeof(struct ether_header); - - - // skip ethernet header - p += sizeof(struct ether_header); - len -= sizeof(struct ether_header); + p += sizeof(struct pos_header); + len -= sizeof(struct pos_header); - ethertype = ntohs(ep->ether_type); + ethertype = ntohs(pp->cf); - if(ethertype == ETHERTYPE_8021Q) { - vlan_header = (struct vlan_802q_header*)p; - ethertype = ntohs(vlan_header->ether_type); - p += sizeof(struct vlan_802q_header); - } - - if(ethertype == MPLS_MASK) { - p += 4; - } - else if(ethertype != ETHERTYPE_IP) { - return 0; + if (ethertype != ETHERTYPE_IP) { + return 0; + } + break; + default: + //DEBUG_CMD(Debug_Message("Link layer not supported")); + return 0; } // IP header struct over the packet data; diff --git a/src/trackflib/trackftp.c b/src/trackflib/trackftp.c index d6809f8..1194092 100644 --- a/src/trackflib/trackftp.c +++ b/src/trackflib/trackftp.c @@ -6,6 +6,7 @@ #include #include #include + #include "mapidflib.h" #include "mapidlib.h" #include "mapidevices.h" @@ -14,8 +15,8 @@ #include "debug.h" #include "mapiipc.h" #include "mstring.h" -#include -#include + +#include #include #include #include @@ -32,7 +33,6 @@ #include #include #include -#include #include #include #include @@ -101,6 +101,10 @@ static int trackftp_process(mapidflib_function_instance_t *instance, struct list **cntlist = ((struct mapid_ftp*)instance->internal_data)->cntlist; uint16_t ethertype; struct ether_header *ep = NULL; + struct pos_header { + uint16_t af; + uint16_t cf; + } *pp = NULL; struct iphdr *iph = NULL; struct tcphdr *tcph = NULL; @@ -119,26 +123,45 @@ static int trackftp_process(mapidflib_function_instance_t *instance, } p = pkt; - // lay the Ethernet header struct over the packet data - ep = (struct ether_header *)p; + switch(instance->hwinfo->link_type) { + case DLT_EN10MB: + // lay the Ethernet header struct over the packet data + ep = (struct ether_header *)p; - // skip ethernet header - p += sizeof(struct ether_header); - len -= sizeof(struct ether_header); + // skip ethernet header + p += sizeof(struct ether_header); + len -= sizeof(struct ether_header); - ethertype = ntohs(ep->ether_type); - - if(ethertype == ETHERTYPE_8021Q) { - vlan_header = (struct vlan_802q_header*)p; - ethertype = ntohs(vlan_header->ether_type); - p += sizeof(struct vlan_802q_header); - } + ethertype = ntohs(ep->ether_type); - if(ethertype == MPLS_MASK) { - p += 4; - } - else if(ethertype != ETHERTYPE_IP) { - return 0; + if(ethertype == ETHERTYPE_8021Q) { + vlan_header = (struct vlan_802q_header*)p; + ethertype = ntohs(vlan_header->ether_type); + p += sizeof(struct vlan_802q_header); + } + + if(ethertype == MPLS_MASK) { + p += 4; + } + else if(ethertype != ETHERTYPE_IP) { + return 0; + } + break; + case DLT_CHDLC: + pp = (struct pos_header *)p; + + p += sizeof(struct pos_header); + len -= sizeof(struct pos_header); + + ethertype = ntohs(pp->cf); + + if (ethertype != ETHERTYPE_IP) { + return 0; + } + break; + default: + //DEBUG_CMD(Debug_Message("Link layer not supported")); + return 0; } // IP header struct over the packet data; diff --git a/src/trackflib/web.c b/src/trackflib/web.c index df2b27d..fbe4c24 100644 --- a/src/trackflib/web.c +++ b/src/trackflib/web.c @@ -6,6 +6,7 @@ #include #include #include + #include "mapidflib.h" #include "mapidlib.h" #include "mapidevices.h" @@ -17,8 +18,7 @@ #include "acsmx2.h" #include "mapi_errors.h" -#include -#include +#include #include #include #include @@ -53,6 +53,10 @@ static int web_process(MAPI_UNUSED mapidflib_function_instance_t *instance, uint16_t ethertype; struct ether_header *ep = NULL; + struct pos_header { + uint16_t af; + uint16_t cf; + } *pp = NULL; struct iphdr *iph = NULL; struct tcphdr *tcph = NULL; @@ -71,26 +75,45 @@ static int web_process(MAPI_UNUSED mapidflib_function_instance_t *instance, p = pkt; - // lay the Ethernet header struct over the packet data - ep = (struct ether_header *)p; - - // skip ethernet header - p += sizeof(struct ether_header); - len -= sizeof(struct ether_header); - - ethertype = ntohs(ep->ether_type); - - if(ethertype == ETHERTYPE_8021Q) { - vlan_header = (struct vlan_802q_header*)p; - ethertype = ntohs(vlan_header->ether_type); - p += sizeof(struct vlan_802q_header); - } - - if(ethertype == MPLS_MASK) { - p += 4; - } - else if(ethertype != ETHERTYPE_IP) { - return 0; + switch(instance->hwinfo->link_type) { + case DLT_EN10MB: + // lay the Ethernet header struct over the packet data + ep = (struct ether_header *)p; + + // skip ethernet header + p += sizeof(struct ether_header); + len -= sizeof(struct ether_header); + + ethertype = ntohs(ep->ether_type); + + if(ethertype == ETHERTYPE_8021Q) { + vlan_header = (struct vlan_802q_header*)p; + ethertype = ntohs(vlan_header->ether_type); + p += sizeof(struct vlan_802q_header); + } + + if(ethertype == MPLS_MASK) { + p += 4; + } + else if(ethertype != ETHERTYPE_IP) { + return 0; + } + break; + case DLT_CHDLC: + pp = (struct pos_header *)p; + + p += sizeof(struct pos_header); + len -= sizeof(struct pos_header); + + ethertype = ntohs(pp->cf); + + if (ethertype != ETHERTYPE_IP) { + return 0; + } + break; + default: + //DEBUG_CMD(Debug_Message("Link layer not supported")); + return 0; } // IP header struct over the packet data; -- GitLab