#include<iostream>
#include<queue>
#include<string>
#include<fstream>

std::string getProtocolOf(const char * frame){

    enum Transport {
        TCP = 6,
        UDP = 17
    };

    enum FrameType {
        IP   = 0x0800,
        IP6  = 0x86dd
    };

    typedef unsigned char uchar;

    const char* ipVerString;
    const char* tpProtoString;

    const char* p;
    const char* pIP = frame + 14;

    p = frame + (6 + 6); // dst + src

    // AF in Mac
    switch( (unsigned short)( (*p) << 8 | *(p+1) ) ){
        default: return "not IP";
        case IP:  break;
        case IP6: break;
    }

    p = pIP;

    // Ver in IP
    switch( (uchar)( ( *p >> 4 ) & 0x0f ) ){
        default: return "IP? Unknown";
        case 0x4: p = pIP + 9; ipVerString = "IPv4"; break;
        case 0x6: p = pIP + 6; ipVerString = "IPv6"; break;
    }
    
    // Proto in IP
    switch( (uchar)*p ){
        default:  tpProtoString = "not TCP/UDP"; break;
        case TCP: tpProtoString = "TCP"; break;
        case UDP: tpProtoString = "UDP "; break;
    }
    
    return std::string(ipVerString) + " " + tpProtoString;
}

const int kSizeRead = 32;

int main ( int argc, char** argv ){

    std::queue<std::string> queue;
    
    // push to queue
    for( int i = 1; i < argc; i++ ){
        char frame[kSizeRead];
        std::ifstream(argv[i]).read(frame,sizeof(frame));
        queue.push( getProtocolOf(frame) );
    }
    
    // extract
    for( ; !queue.empty(); queue.pop() )
        std::cout << queue.front() << std::endl;

    return 0; 
}
