tcpdump.c
vfs/file.h
ubixos/kpanic.h
netif/tcpdump.h
net/ipv4/ip.h
net/tcp.h
net/udp.h
net/ipv4/inet.h
sys/thread.h
net/ipv4/ip.h
ubixos/kpanic.h
arch/lib.h
src/sys/net/netif/tcpdump.c
net/netif.h
net/udp.h
arch/cpu.h
arch/sys_arch.h
net/tcp.h
ubixos/types.h
sys/_types.h
net/arch.h
net/ipv4/icmp.h
vfs/file.h
net/lwipopts.h
net/def.h
net/mem.h
vfs/vfs.h
vfs/mount.h
net/ipv4/ip_addr.h
net/err.h
netif/tcpdump.h
ubixfs/dirCache.h
net/opt.h
sys/sysproto.h
sys/signal.h
net/sys.h
net/pbuf.h
net/debug.h
net/ipv4/inet.h
arch/cc.h
void void tcpdump (struct pbuf *p) tcpdump struct pbuf * p file NULL loopif_output
void void tcpdump_init (void) tcpdump_init void file fopen kpanic NULL
fileDescriptor * fileDescriptor* file file NULL tcpdump tcpdump_init

    /*
    *Copyright(c)2001,SwedishInstituteofComputerScience.
    *Allrightsreserved.
    *
    *Redistributionanduseinsourceandbinaryforms,withorwithout
    *modification,arepermittedprovidedthatthefollowingconditions
    *aremet:
    *1.Redistributionsofsourcecodemustretaintheabovecopyright
    *notice,thislistofconditionsandthefollowingdisclaimer.
    *2.Redistributionsinbinaryformmustreproducetheabovecopyright
    *notice,thislistofconditionsandthefollowingdisclaimerinthe
    *documentationand/orothermaterialsprovidedwiththedistribution.
    *3.NeitherthenameoftheInstitutenorthenamesofitscontributors
    *maybeusedtoendorseorpromoteproductsderivedfromthissoftware
    *withoutspecificpriorwrittenpermission.
    *
    *THISSOFTWAREISPROVIDEDBYTHEINSTITUTEANDCONTRIBUTORS``ASIS''AND
    *ANYEXPRESSORIMPLIEDWARRANTIES,INCLUDING,BUTNOTLIMITEDTO,THE
    *IMPLIEDWARRANTIESOFMERCHANTABILITYANDFITNESSFORAPARTICULARPURPOSE
    *AREDISCLAIMED.INNOEVENTSHALLTHEINSTITUTEORCONTRIBUTORSBELIABLE
    *FORANYDIRECT,INDIRECT,INCIDENTAL,SPECIAL,EXEMPLARY,ORCONSEQUENTIAL
    *DAMAGES(INCLUDING,BUTNOTLIMITEDTO,PROCUREMENTOFSUBSTITUTEGOODS
    *ORSERVICES;LOSSOFUSE,DATA,ORPROFITS;ORBUSINESSINTERRUPTION)
    *HOWEVERCAUSEDANDONANYTHEORYOFLIABILITY,WHETHERINCONTRACT,STRICT
    *LIABILITY,ORTORT(INCLUDINGNEGLIGENCEOROTHERWISE)ARISINGINANYWAY
    *OUTOFTHEUSEOFTHISSOFTWARE,EVENIFADVISEDOFTHEPOSSIBILITYOF
    *SUCHDAMAGE.
    *
    *ThisfileispartofthelwIPTCP/IPstack.
    *
    *Author:AdamDunkels<adam@sics.se>
    *
    *$Id: tcpdump_8c.xml 88 2016-01-12 00:11:29Z reddawg $
    */

    #include<vfs/file.h>
    #include<ubixos/kpanic.h>

    #include"netif/tcpdump.h"
    #include"net/ipv4/ip.h"
    #include"net/tcp.h"
    #include"net/udp.h"
    #include"net/ipv4/inet.h"

    fileDescriptor*file=NULL;

    voidtcpdump_init(void){
    char*fname;

    fname="tcpdump";
    file=fopen(fname,"wb");
    if(file==NULL){
    kpanic("tcpdump_init:fopen\n");
    }
    }

    voidtcpdump(structpbuf*p){
    /*
    structip_hdr*iphdr;
    structtcp_hdr*tcphdr;
    structudp_hdr*udphdr;
    charflags[5];
    inti;
    intlen;
    intoffset;
    */
    if(file==NULL){
    return;
    }

    /*
    iphdr=p->payload;
    switch(IPH_PROTO(iphdr)){
    caseIP_PROTO_TCP:
    tcphdr=(structtcp_hdr*)((char*)iphdr+IP_HLEN);

    pbuf_header(p,-IP_HLEN);
    if(inet_chksum_pseudo(p,(structip_addr*)&(iphdr->src),
    (structip_addr*)&(iphdr->dest),
    IP_PROTO_TCP,p->tot_len)!=0){
    DEBUGF(TCPDUMP_DEBUG,("tcpdump:IPchecksumfailed!\n"));
    fprintf(file,"!chksum");
    }

    i=0;
    if(TCPH_FLAGS(tcphdr)&TCP_SYN){
    flags[i++]='S';
    }
    if(TCPH_FLAGS(tcphdr)&TCP_PSH){
    flags[i++]='P';
    }
    if(TCPH_FLAGS(tcphdr)&TCP_FIN){
    flags[i++]='F';
    }
    if(TCPH_FLAGS(tcphdr)&TCP_RST){
    flags[i++]='R';
    }
    if(i==0){
    flags[i++]='.';
    }
    flags[i++]=0;

    fprintf(file,"%d.%d.%d.%d.%u>%d.%d.%d.%d.%u:",
    (int)(ntohl(iphdr->src.addr)>>24)&0xff,
    (int)(ntohl(iphdr->src.addr)>>16)&0xff,
    (int)(ntohl(iphdr->src.addr)>>8)&0xff,
    (int)(ntohl(iphdr->src.addr)>>0)&0xff,
    ntohs(tcphdr->src),
    (int)(ntohl(iphdr->dest.addr)>>24)&0xff,
    (int)(ntohl(iphdr->dest.addr)>>16)&0xff,
    (int)(ntohl(iphdr->dest.addr)>>8)&0xff,
    (int)(ntohl(iphdr->dest.addr)>>0)&0xff,
    ntohs(tcphdr->dest));
    offset=TCPH_OFFSET(tcphdr)>>4;

    len=ntohs(IPH_LEN(iphdr))-offset*4-IP_HLEN;
    if(len!=0||flags[0]!='.'){
    fprintf(file,"%s%lu:%lu(%u)",
    flags,
    ntohl(tcphdr->seqno),
    ntohl(tcphdr->seqno)+len,
    len);
    }
    if(TCPH_FLAGS(tcphdr)&TCP_ACK){
    fprintf(file,"ack%lu",
    ntohl(tcphdr->ackno));
    }
    fprintf(file,"wnd%u\n",
    ntohs(tcphdr->wnd));

    fflush(file);

    pbuf_header(p,IP_HLEN);
    break;

    caseIP_PROTO_UDP:
    udphdr=(structudp_hdr*)((char*)iphdr+IP_HLEN);

    pbuf_header(p,-IP_HLEN);
    if(inet_chksum_pseudo(p,(structip_addr*)&(iphdr->src),
    (structip_addr*)&(iphdr->dest),
    IP_PROTO_UDP,p->tot_len)!=0){
    kprintf("tcpdump:IPchecksumfailed!\n");
    fprintf(file,"!chksum");
    }

    fprintf(file,"%d.%d.%d.%d.%u>%d.%d.%d.%d.%u:",
    (int)(ntohl(iphdr->src.addr)>>24)&0xff,
    (int)(ntohl(iphdr->src.addr)>>16)&0xff,
    (int)(ntohl(iphdr->src.addr)>>8)&0xff,
    (int)(ntohl(iphdr->src.addr)>>0)&0xff,
    ntohs(udphdr->src),
    (int)(ntohl(iphdr->dest.addr)>>24)&0xff,
    (int)(ntohl(iphdr->dest.addr)>>16)&0xff,
    (int)(ntohl(iphdr->dest.addr)>>8)&0xff,
    (int)(ntohl(iphdr->dest.addr)>>0)&0xff,
    ntohs(udphdr->dest));
    fprintf(file,"U");
    len=ntohs(IPH_LEN(iphdr))-sizeof(structudp_hdr)-IP_HLEN;
    fprintf(file,"%d\n",len);

    fflush(file);

    pbuf_header(p,IP_HLEN);
    break;

    }
    */
    }

    /***
    END
    ***/