Commit 7d223639 authored by 's avatar

Added basic support for POS protocol.


git-svn-id: file:///home/svn/mapi/trunk@1394 8d5bb341-7cf1-0310-8cf6-ba355fef3186
parent bcf18b6c
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
#include <sys/shm.h> #include <sys/shm.h>
#include <string.h> #include <string.h>
#include <errno.h> #include <errno.h>
#include "mapidflib.h" #include "mapidflib.h"
#include "mapidlib.h" #include "mapidlib.h"
#include "mapidevices.h" #include "mapidevices.h"
...@@ -17,8 +18,7 @@ ...@@ -17,8 +18,7 @@
#include "acsmx2.h" #include "acsmx2.h"
#include "mapi_errors.h" #include "mapi_errors.h"
#include <stdio.h> #include <pcap.h>
#include <stdlib.h>
#include <netinet/in.h> #include <netinet/in.h>
#include <net/ethernet.h> #include <net/ethernet.h>
#include <netinet/ip.h> #include <netinet/ip.h>
...@@ -35,7 +35,6 @@ ...@@ -35,7 +35,6 @@
#include <fcntl.h> #include <fcntl.h>
#include <sys/wait.h> #include <sys/wait.h>
#include <sys/socket.h> #include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h> #include <arpa/inet.h>
#include <sys/time.h> #include <sys/time.h>
#include <time.h> #include <time.h>
...@@ -192,6 +191,10 @@ static int dc_process(mapidflib_function_instance_t *instance, ...@@ -192,6 +191,10 @@ static int dc_process(mapidflib_function_instance_t *instance,
struct list **dclist = ((struct mapid_dc*)instance->internal_data)->dclist; struct list **dclist = ((struct mapid_dc*)instance->internal_data)->dclist;
uint16_t ethertype; uint16_t ethertype;
struct ether_header *ep = NULL; struct ether_header *ep = NULL;
struct pos_header {
uint16_t af;
uint16_t cf;
} *pp = NULL;
struct iphdr *iph = NULL; struct iphdr *iph = NULL;
struct tcphdr *tcph = NULL; struct tcphdr *tcph = NULL;
struct udphdr *udph = NULL; struct udphdr *udph = NULL;
...@@ -211,28 +214,48 @@ static int dc_process(mapidflib_function_instance_t *instance, ...@@ -211,28 +214,48 @@ static int dc_process(mapidflib_function_instance_t *instance,
if(pkt_color != 0 && pkt_color != DC_COLOR) { if(pkt_color != 0 && pkt_color != DC_COLOR) {
return 0; return 0;
} }
p = pkt; p = pkt;
// lay the Ethernet header struct over the packet data switch(instance->hwinfo->link_type) {
ep = (struct ether_header *)p; case DLT_EN10MB:
// lay the Ethernet header struct over the packet data
ep = (struct ether_header *)p;
// skip ethernet header // skip ethernet header
p += sizeof(struct ether_header); p += sizeof(struct ether_header);
len -= sizeof(struct ether_header); len -= sizeof(struct ether_header);
ethertype = ntohs(ep->ether_type); ethertype = ntohs(ep->ether_type);
if(ethertype == ETHERTYPE_8021Q) { if(ethertype == ETHERTYPE_8021Q) {
vlan_header = (struct vlan_802q_header*)p; vlan_header = (struct vlan_802q_header*)p;
ethertype = ntohs(vlan_header->ether_type); ethertype = ntohs(vlan_header->ether_type);
p += sizeof(struct vlan_802q_header); 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 += sizeof(struct pos_header);
p += 4; len -= sizeof(struct pos_header);
}
else if(ethertype != ETHERTYPE_IP) { ethertype = ntohs(pp->cf);
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; // IP header struct over the packet data;
......
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
#include <string.h> #include <string.h>
#include <unistd.h> #include <unistd.h>
#include <errno.h> #include <errno.h>
#include "mapidflib.h" #include "mapidflib.h"
#include "mapidlib.h" #include "mapidlib.h"
#include "mapidevices.h" #include "mapidevices.h"
...@@ -15,6 +16,8 @@ ...@@ -15,6 +16,8 @@
#include "debug.h" #include "debug.h"
#include "mapiipc.h" #include "mapiipc.h"
#include "mstring.h" #include "mstring.h"
#include <pcap.h>
#include <netinet/in.h> #include <netinet/in.h>
#include <net/ethernet.h> #include <net/ethernet.h>
#include <netinet/ip.h> #include <netinet/ip.h>
...@@ -277,6 +280,10 @@ static int edonkey_process(mapidflib_function_instance_t *instance, ...@@ -277,6 +280,10 @@ static int edonkey_process(mapidflib_function_instance_t *instance,
struct list **edonkeylist = ((struct mapid_edonkey*)instance->internal_data)->edonkeylist; struct list **edonkeylist = ((struct mapid_edonkey*)instance->internal_data)->edonkeylist;
uint16_t ethertype; uint16_t ethertype;
struct ether_header *ep = NULL; struct ether_header *ep = NULL;
struct pos_header {
uint16_t af;
uint16_t cf;
} *pp = NULL;
struct iphdr *iph = NULL; struct iphdr *iph = NULL;
struct tcphdr *tcph = NULL; struct tcphdr *tcph = NULL;
struct udphdr *udph = NULL; struct udphdr *udph = NULL;
...@@ -303,27 +310,47 @@ static int edonkey_process(mapidflib_function_instance_t *instance, ...@@ -303,27 +310,47 @@ static int edonkey_process(mapidflib_function_instance_t *instance,
p = pkt; p = pkt;
// lay the Ethernet header struct over the packet data switch(instance->hwinfo->link_type) {
ep = (struct ether_header *)p; case DLT_EN10MB:
ether_len = sizeof(struct ether_header); // lay the Ethernet header struct over the packet data
ep = (struct ether_header *)p;
ether_len = sizeof(struct ether_header);
// skip ethernet header // skip ethernet header
p += sizeof(struct ether_header); p += sizeof(struct ether_header);
len -= sizeof(struct ether_header); len -= sizeof(struct ether_header);
ethertype = ntohs(ep->ether_type); ethertype = ntohs(ep->ether_type);
if(ethertype == ETHERTYPE_8021Q) { if(ethertype == ETHERTYPE_8021Q) {
vlan_header = (struct vlan_802q_header*)p; vlan_header = (struct vlan_802q_header*)p;
ethertype = ntohs(vlan_header->ether_type); ethertype = ntohs(vlan_header->ether_type);
p += sizeof(struct vlan_802q_header); 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 += sizeof(struct pos_header);
p += 4; len -= sizeof(struct pos_header);
}
else if(ethertype != ETHERTYPE_IP) { ethertype = ntohs(pp->cf);
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; // IP header struct over the packet data;
......
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
#include <sys/shm.h> #include <sys/shm.h>
#include <string.h> #include <string.h>
#include <errno.h> #include <errno.h>
#include "mapidflib.h" #include "mapidflib.h"
#include "mapidlib.h" #include "mapidlib.h"
#include "mapidevices.h" #include "mapidevices.h"
...@@ -17,8 +18,7 @@ ...@@ -17,8 +18,7 @@
#include "acsmx2.h" #include "acsmx2.h"
#include "mapi_errors.h" #include "mapi_errors.h"
#include <stdio.h> #include <pcap.h>
#include <stdlib.h>
#include <netinet/in.h> #include <netinet/in.h>
#include <net/ethernet.h> #include <net/ethernet.h>
#include <netinet/ip.h> #include <netinet/ip.h>
...@@ -35,7 +35,6 @@ ...@@ -35,7 +35,6 @@
#include <fcntl.h> #include <fcntl.h>
#include <sys/wait.h> #include <sys/wait.h>
#include <sys/socket.h> #include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h> #include <arpa/inet.h>
#include <sys/time.h> #include <sys/time.h>
#include <time.h> #include <time.h>
...@@ -177,6 +176,10 @@ static int gnutella_process(mapidflib_function_instance_t *instance, ...@@ -177,6 +176,10 @@ static int gnutella_process(mapidflib_function_instance_t *instance,
struct list **gnulist = ((struct mapid_gnutella*)instance->internal_data)->gnulist; struct list **gnulist = ((struct mapid_gnutella*)instance->internal_data)->gnulist;
uint16_t ethertype; uint16_t ethertype;
struct ether_header *ep = NULL; struct ether_header *ep = NULL;
struct pos_header {
uint16_t af;
uint16_t cf;
} *pp = NULL;
struct iphdr *iph = NULL; struct iphdr *iph = NULL;
struct tcphdr *tcph = NULL; struct tcphdr *tcph = NULL;
struct udphdr *udph = NULL; struct udphdr *udph = NULL;
...@@ -199,26 +202,45 @@ static int gnutella_process(mapidflib_function_instance_t *instance, ...@@ -199,26 +202,45 @@ static int gnutella_process(mapidflib_function_instance_t *instance,
p = pkt; p = pkt;
// lay the Ethernet header struct over the packet data switch(instance->hwinfo->link_type) {
ep = (struct ether_header *)p; case DLT_EN10MB:
// lay the Ethernet header struct over the packet data
ep = (struct ether_header *)p;
// skip ethernet header // skip ethernet header
p += sizeof(struct ether_header); p += sizeof(struct ether_header);
len -= sizeof(struct ether_header); len -= sizeof(struct ether_header);
ethertype = ntohs(ep->ether_type); ethertype = ntohs(ep->ether_type);
if(ethertype == ETHERTYPE_8021Q) { if(ethertype == ETHERTYPE_8021Q) {
vlan_header = (struct vlan_802q_header*)p; vlan_header = (struct vlan_802q_header*)p;
ethertype = ntohs(vlan_header->ether_type); ethertype = ntohs(vlan_header->ether_type);
p += sizeof(struct vlan_802q_header); p += sizeof(struct vlan_802q_header);
} }
if(ethertype == MPLS_MASK) { if(ethertype == MPLS_MASK) {
p += 4; p += 4;
} }
else if(ethertype != ETHERTYPE_IP) { else if(ethertype != ETHERTYPE_IP) {
return 0; 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; // IP header struct over the packet data;
......
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
#include <sys/shm.h> #include <sys/shm.h>
#include <string.h> #include <string.h>
#include <errno.h> #include <errno.h>
#include "mapidflib.h" #include "mapidflib.h"
#include "mapidlib.h" #include "mapidlib.h"
#include "mapidevices.h" #include "mapidevices.h"
...@@ -14,8 +15,8 @@ ...@@ -14,8 +15,8 @@
#include "debug.h" #include "debug.h"
#include "mapiipc.h" #include "mapiipc.h"
#include "mstring.h" #include "mstring.h"
#include <stdio.h>
#include <stdlib.h> #include <pcap.h>
#include <netinet/in.h> #include <netinet/in.h>
#include <net/ethernet.h> #include <net/ethernet.h>
#include <netinet/ip.h> #include <netinet/ip.h>
...@@ -32,7 +33,6 @@ ...@@ -32,7 +33,6 @@
#include <fcntl.h> #include <fcntl.h>
#include <sys/wait.h> #include <sys/wait.h>
#include <sys/socket.h> #include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h> #include <arpa/inet.h>
#include <sys/time.h> #include <sys/time.h>
#include <time.h> #include <time.h>
...@@ -101,6 +101,10 @@ static int gridftp_process(mapidflib_function_instance_t *instance, ...@@ -101,6 +101,10 @@ static int gridftp_process(mapidflib_function_instance_t *instance,
struct list **cntlist = ((struct mapid_ftp*)instance->internal_data)->cntlist; struct list **cntlist = ((struct mapid_ftp*)instance->internal_data)->cntlist;
uint16_t ethertype; uint16_t ethertype;
struct ether_header *ep = NULL; struct ether_header *ep = NULL;
struct pos_header {
uint16_t af;
uint16_t cf;
} *pp = NULL;
struct iphdr *iph = NULL; struct iphdr *iph = NULL;
struct tcphdr *tcph = NULL; struct tcphdr *tcph = NULL;
...@@ -119,26 +123,45 @@ static int gridftp_process(mapidflib_function_instance_t *instance, ...@@ -119,26 +123,45 @@ static int gridftp_process(mapidflib_function_instance_t *instance,
} }
p = pkt; p = pkt;
// lay the Ethernet header struct over the packet data switch(instance->hwinfo->link_type) {
ep = (struct ether_header *)p; case DLT_EN10MB:
// lay the Ethernet header struct over the packet data
ep = (struct ether_header *)p;
// skip ethernet header // skip ethernet header
p += sizeof(struct ether_header); p += sizeof(struct ether_header);
len -= 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) { if(ethertype == ETHERTYPE_8021Q) {
p += 4; vlan_header = (struct vlan_802q_header*)p;
} ethertype = ntohs(vlan_header->ether_type);
else if(ethertype != ETHERTYPE_IP) { p += sizeof(struct vlan_802q_header);
return 0; }
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; // IP header struct over the packet data;
......
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
#include <sys/shm.h> #include <sys/shm.h>
#include <string.h> #include <string.h>
#include <errno.h> #include <errno.h>
#include "mapidflib.h" #include "mapidflib.h"
#include "mapidlib.h" #include "mapidlib.h"
#include "mapidevices.h" #include "mapidevices.h"
...@@ -14,8 +15,8 @@ ...@@ -14,8 +15,8 @@
#include "debug.h" #include "debug.h"
#include "mapiipc.h" #include "mapiipc.h"
#include "mstring.h" #include "mstring.h"
#include <stdio.h>
#include <stdlib.h> #include <pcap.h>
#include <netinet/in.h> #include <netinet/in.h>
#include <net/ethernet.h> #include <net/ethernet.h>
#include <netinet/ip.h> #include <netinet/ip.h>
...@@ -32,7 +33,6 @@ ...@@ -32,7 +33,6 @@
#include <fcntl.h> #include <fcntl.h>
#include <sys/wait.h> #include <sys/wait.h>
#include <sys/socket.h> #include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h> #include <arpa/inet.h>
#include <sys/time.h> #include <sys/time.h>
#include <time.h> #include <time.h>
...@@ -132,6 +132,10 @@ static int irc_process(mapidflib_function_instance_t *instance, ...@@ -132,6 +132,10 @@ static int irc_process(mapidflib_function_instance_t *instance,
struct list **irclist = ((struct mapid_irc*)instance->internal_data)->irclist; struct list **irclist = ((struct mapid_irc*)instance->internal_data)->irclist;
uint16_t ethertype; uint16_t ethertype;
struct ether_header *ep = NULL; struct ether_header *ep = NULL;
struct pos_header {
uint16_t af;
uint16_t cf;
} *pp = NULL;
struct iphdr *iph = NULL; struct iphdr *iph = NULL;
struct tcphdr *tcph = NULL; struct tcphdr *tcph = NULL;
struct udphdr *udph = NULL; struct udphdr *udph = NULL;
...@@ -148,26 +152,45 @@ static int irc_process(mapidflib_function_instance_t *instance, ...@@ -148,26 +152,45 @@ static int irc_process(mapidflib_function_instance_t *instance,
p = pkt; p = pkt;
// lay the Ethernet header struct over the packet data switch(instance->hwinfo->link_type) {
ep = (struct ether_header *)p; case DLT_EN10MB:
// lay the Ethernet header struct over the packet data
ep = (struct ether_header *)p;
// skip ethernet header // skip ethernet header
p += sizeof(struct ether_header); p += sizeof(struct ether_header);
len -= sizeof(struct ether_header); len -= sizeof(struct ether_header);
ethertype = ntohs(ep->ether_type); ethertype = ntohs(ep->ether_type);
if(ethertype == ETHERTYPE_8021Q) { if(ethertype == ETHERTYPE_8021Q) {
vlan_header = (struct vlan_802q_header*)p; vlan_header = (struct vlan_802q_header*)p;
ethertype = ntohs(vlan_header->ether_type); ethertype = ntohs(vlan_header->ether_type);
p += sizeof(struct vlan_802q_header); 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 += sizeof(struct pos_header);
p += 4; len -= sizeof(struct pos_header);
}
else if(ethertype != ETHERTYPE_IP) { ethertype = ntohs(pp->cf);
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; // IP header struct over the packet data;
......
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
#include <sys/shm.h> #include <sys/shm.h>
#include <string.h> #include <string.h>
#include <errno.h> #include <errno.h>
#include "mapidflib.h" #include "mapidflib.h"
#include "mapidlib.h" #include "mapidlib.h"
#include "mapidevices.h" #include "mapidevices.h"
...@@ -14,8 +15,8 @@ ...@@ -14,8 +15,8 @@
#include "debug.h" #include "debug.h"
#include "mapiipc.h" #include "mapiipc.h"
#include "mstring.h" #include "mstring.h"
#include <stdio.h>
#include <stdlib.h> #include <pcap.h>
#include <netinet/in.h> #include <netinet/in.h>
#include <net/ethernet.h> #include <net/ethernet.h>
#include <netinet/ip.h> #include <netinet/ip.h>
...@@ -32,7 +33,6 @@ ...@@ -32,7 +33,6 @@
#include <fcntl.h> #include <fcntl.h>
#include <sys/wait.h> #include <sys/wait.h>
#include <sys/socket.h>