struct IPTU_PROTO {
const unsigned short port;
const char* name;
char act;
unsigned long count;
void* pointer;
};
IPTU_PROTO tcp[]={
{ 21, "FTP", 1, 0, 0},
{ 25, "SMTP", 1, 0, 0},
{ 53, "DNS", 0, 0, 0},
{ 37, "TIME", 1, 0, 0},
{ 80, "HTTP", 1, 0, 0},
{ 110, "POP3", 1, 0, 0},
{ 143, "IMAP", 1, 0, 0},
{ 443, "SHTTP", 1, 0, 0},
};
const int tcp_size=sizeof(tcp)/sizeof(IPTU_PROTO);
IPTU_PROTO udp[]={
{ 37, "TIME", 1, 0, 0},
{ 53, "DNS", 1, 0, 0},
{ 67, "BOOTPS", 1, 0, 0},
{ 68, "BOOTPC", 1, 0, 0},
};
const int udp_size=sizeof(tcp)/sizeof(IPTU_PROTO);
void print(const char[]);
void process_packet(const unsigned char data[]) {
if ( data[12]==0x08 && data[13]==0x00 ) {
if ( data[23]==0x06 ) {
unsigned short pr = data[36] + 256*data[37];
for (int i=0; i<tcp_size; i++) {
if ( pr==tcp[i].port && tcp[i].act ) {
tcp[i].count++;
print( tcp[i].name );
break;
}
}
} else if ( data[23]==0x11 ) {
unsigned short pr = data[36] + 256*data[37];
for (int i=0; i<udp_size; i++) {
if ( pr==udp[i].port && udp[i].act ) {
udp[i].count++;
print( tcp[i].name );
break;
}
}
} else ;
} else if ( data[12]==0x08 && data[13]==0x06 ) {
if( data[16]==0x08 && data[17]==0x00 )
print( "ARP" );
else
print( "ARP for non IP" );
} else ;
}