//* use of array of structures for data processing - networked embedded system*

struct IPTU_PROTO {                     // Internet Protocol processing description for TCP or UDP
    const unsigned short    port;       // TCP/IP port number
    const char*             name;       // protocol name follwoed by \0
        char                act;        // process data: 0-no 1-yes
        unsigned long       count;      // count how many encountered
        void*               pointer;    // pointer to a function to display
};

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 ) {
        // IP protocol detected
        if ( data[23]==0x06 ) {
            // TCP detected
            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 ) {
            // UDP detected
            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 ;// not a TCP or UDP
    } else if ( data[12]==0x08 && data[13]==0x06 ) {
        // ARP protcol detected
        if( data[16]==0x08 && data[17]==0x00 ) 
            print(  "ARP" );
        else 
            print(  "ARP for non IP" );
    } else ;// not an IP nor ARP
}