Sponsored Content
Top Forums Programming Why am i getting these strange packets while running my packet capture module written in c.? Post 302769036 by arunpushkar on Monday 11th of February 2013 05:31:53 AM
Old 02-11-2013
Why am i getting these strange packets while running my packet capture module written in c.?

I have made an packet capture application running on intel machine, it is capturing packets with src address- 17.0.0.0 destination ip- 66.0.0.0, source port- 0, destination port- 0, and protocol- 0 what does these packets mean ?
The code written to interpreter captured bytes is given below. Which basically locate source address, destination address, source port, destination port, and protocol from various headers from packet captured. After it is done then only TCP and UDP packets are stored into a file. so it means only those packets having protocol number 6,17 should be saved but when i go through the file the packets with protocol 0,20,255,100,8,66 are also saved more over strange IP address are also seen like.2.8.2.8, 17.0.0.0, 66.0.0.0, 0.0.0.0 etc what are these packets, am i correct in my approach.
Code:
 inline u_int32_t hash_function(const u_char *packet, int pkt_len) 
{
  u_int32_t hash=0;
  u_int8_t next_protocol;
  u_int32_t src_ip,dst_ip;  
  u_short  src_p,dst_p;       
  
  
  unsigned short ip_hdr_len;
  
      // Checking if it is a IPv4 or IPv6 packet
    struct ether_header *eptr;  /* net/ethernet.h */
    eptr = (struct ether_header *) packet;

    if (ntohs (eptr->ether_type) == ETHERTYPE_IP) // means it is IPv4 pkt
        {
            struct iphdr *ip4h = (struct iphdr *)(packet  + sizeof(struct ethhdr) );
        ip_hdr_len =ip4h->ihl*4;
        next_protocol=ip4h->protocol;
        pktFeatures.src_ip=ntohl(ip4h->saddr);
        pktFeatures.dst_ip=ntohl(ip4h->daddr);
        pktFeatures.pkt_len=pkt_len;
        switch (next_protocol) //Check the Protocol and do accordingly...
        {
        case 6:  //TCP Protocol
               {
                struct tcphdr *tcph=(struct tcphdr*)(packet + ip_hdr_len + sizeof(struct ethhdr));
                pktFeatures.src_p=ntohs(tcph->th_sport);
                pktFeatures.dst_p=ntohs(tcph->th_dport);
                pktFeatures.protocol=next_protocol;
                writeBytes((char *)&pktFeatures,sizeof(struct packet_features),WRITE_TO_FILE);
            }
            break;
        case 17: //UDP Protocol
            {
                struct udphdr *udph = (struct udphdr*)(packet + ip_hdr_len  + sizeof(struct ethhdr));
                pktFeatures.src_p=ntohs(udph->uh_sport);
                pktFeatures.dst_p=ntohs(udph->uh_sport);
                pktFeatures.protocol=next_protocol;
                writeBytes((char *)&pktFeatures,sizeof(struct packet_features),WRITE_TO_FILE);                 
            }
            break;
        default: //Some Other Protocol like ARP FTP etc.
            {
                printf(" * Some Other Protocol \n");
                            
            }
        }
        int rm=0;
        }/*else  if (ntohs (eptr->ether_type) == ETHERTYPE_IPV6) // means it is IPv6 pkt
            {
                
            u_int32_t *s, *d;
            struct ip6_hdr *ip6h = (struct ip6_hdr *)(packet  + sizeof(struct ethhdr) );
            ip_hdr_len=320;
            next_protocol=ip6h->ip6_un1_nxt; // is the next protocol type
            s = (u_int32_t *) &ip6h->ip6_src, d = (u_int32_t *) &ip6h->ip6_dst;
            hash=(s[0] + s[1] + s[2] + s[3] + d[0] + d[1] + d[2] + d[3]+ip6h->ip6_un1_nxt); // ip6_un1_nxt is the next protocol                                         type TCP/UDP can be extention header ? need to be catered for
             
            }else hash=0;
         */
         
 return hash;

}

 

8 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

how to capture multicast packets using snoop

How do I use snoop command to capture multicast packets in the network? (1 Reply)
Discussion started by: caden312
1 Replies

2. AIX

Capture Network Packets from AIX

Hi, I am using smitty to create and configure a print queue. I am giving a print of a text file to the print queue created. I am using this in network. How to capture network packets of the print from AIX to the printer and printer to AIX. I tried Wireshark to capture network packets. I am... (16 Replies)
Discussion started by: meeraramanathan
16 Replies

3. Infrastructure Monitoring

capture snmp packets in AIX

Hi, I want to capture snmp packets in AIX. When i give print from AIX6.1, Printer will give its response thru' snmp. I used iptrace command like below, but it is not capturing snmp packets other packets are captured like udp, tcp.. 1. iptrace command: /usr/sbin/iptrace -a -i en0... (1 Reply)
Discussion started by: meeraramanathan
1 Replies

4. IP Networking

Capture packets (TcpDump) and forwarding them

Hi, I want to capture a certain type of packets (selected according to the protocol) coming to my PC and then transmit them to another PC. I had the idea to use tcpdump to filter input packets and extract those chosen. Well my questions are: 1- after filtering input packets, those that have not... (1 Reply)
Discussion started by: ziedf
1 Replies

5. Programming

Receiving broadcast packets using packet socket

Hello I try to send DHCP RENEW packets to the network and receive the responses. I broadcast the packet and I can see that it's successfully sent using Wireshark. But I have difficulties receiving the responses.I use packet sockets to catch the packets. I can see that there are responses to my... (0 Replies)
Discussion started by: xyzt
0 Replies

6. Programming

packet capture

can anyone tell me how can i capture the packets. i have tried ethernet software to capture them but its not doing what i want it to do it (1 Reply)
Discussion started by: dazdseg
1 Replies

7. Programming

Linking Linux Driver written in C with ASM module

Hi, I have got sample linux driver written in C. I got also some assembly code, compiled into .o file (using as compiler). In my Makefile I got: obj-m += someDriver.o someDriver-objs := CFile1.o CFile2.o ASMFile.o default: $(MAKE) -C $(KDIR) SUBDIRS=$(PWD) modulesUnfortunatelly I cannot... (0 Replies)
Discussion started by: Chrisdot
0 Replies

8. UNIX for Advanced & Expert Users

How many packets can be written into Kernel sockets per second?

Hi, Its been a long time since i programmed a multithreaded application that can do Tx and Rx of datagrams over unix sockets. I well remember that though the threads were efficiently designed to be independent of each other, and was writing to different sockets, there was a limitation ,... (0 Replies)
Discussion started by: binnyjeshan
0 Replies
PCAP-TSTAMP(7)						 Miscellaneous Information Manual					    PCAP-TSTAMP(7)

NAME
pcap-tstamp - packet time stamps in libpcap DESCRIPTION
When capturing traffic, each packet is given a time stamp representing, for incoming packets, the arrival time of the packet and, for out- going packets, the transmission time of the packet. This time is an approximation of the arrival or transmission time. If it is supplied by the operating system running on the host on which the capture is being done, there are several reasons why it might not precisely repre- sent the arrival or transmission time: if the time stamp is applied to the packet when the networking stack receives the packet, the networking stack might not see the packet until an interrupt is delivered for the packet or a timer event causes the networking device driver to poll for packets, and the time stamp might not be applied until the packet has had some processing done by other code in the networking stack, so there might be a significant delay between the time when the last bit of the packet is received by the capture device and when the net- working stack time-stamps the packet; the timer used to generate the time stamps might have low resolution, for example, it might be a timer updated once per host operat- ing system timer tick, with the host operating system timer ticking once every few milliseconds; a high-resolution timer might use a counter that runs at a rate dependent on the processor clock speed, and that clock speed might be adjusted upwards or downwards over time and the timer might not be able to compensate for all those adjustments; the host operating system's clock might be adjusted over time to match a time standard to which the host is being synchronized, which might be done by temporarily slowing down or speeding up the clock or by making a single adjustment; different CPU cores on a multi-core or multi-processor system might be running at different speeds, or might not have time counters all synchronized, so packets time-stamped by different cores might not have consistent time stamps. In addition, packets time-stamped by different cores might be time-stamped in one order and added to the queue of packets for libpcap to read in another order, so time stamps might not be monotonically increasing. Some capture devices on some platforms can provide time stamps for packets; those time stamps are usually high-resolution time stamps, and are usually applied to the packet when the first or last bit of the packet arrives, and are thus more accurate than time stamps provided by the host operating system. Those time stamps might not, however, be synchronized with the host operating system's clock, so that, for example, the time stamp of a packet might not correspond to the time stamp of an event on the host triggered by the arrival of that packet. Depending on the capture device and the software on the host, libpcap might allow different types of time stamp to be used. The pcap_list_tstamp_types(3PCAP) routine provides, for a packet capture handle created by pcap_create(3PCAP) but not yet activated by pcap_activate(3PCAP), a list of time stamp types supported by the capture device for that handle. The list might be empty, in which case no choice of time stamp type is offered for that capture device. If the list is not empty, the pcap_set_tstamp_type(3PCAP) routine can be used after a pcap_create() call and before a pcap_activate() call to specify the type of time stamp to be used on the device. The time stamp types are listed here; the first value is the #define to use in code, the second value is the value returned by pcap_tstamp_type_val_to_name() and accepted by pcap_tstamp_name_to_val(). PCAP_TSTAMP_HOST - host Time stamp provided by the host on which the capture is being done. The precision of this time stamp is unspecified; it might or might not be synchronized with the host operating system's clock. PCAP_TSTAMP_HOST_LOWPREC - host_lowprec Time stamp provided by the host on which the capture is being done. This is a low-precision time stamp, synchronized with the host operating system's clock. PCAP_TSTAMP_HOST_HIPREC - host_hiprec Time stamp provided by the host on which the capture is being done. This is a high-precision time stamp; it might or might not be synchronized with the host operating system's clock. It might be more expensive to fetch than PCAP_TSTAMP_HOST_LOWPREC. PCAP_TSTAMP_ADAPTER - adapter Time stamp provided by the network adapter on which the capture is being done. This is a high-precision time stamp, synchronized with the host operating system's clock. PCAP_TSTAMP_ADAPTER_UNSYNCED - adapter_unsynced Time stamp provided by the network adapter on which the capture is being done. This is a high-precision time stamp; it is not synchronized with the host operating system's clock. SEE ALSO
pcap_set_tstamp_type(3PCAP), pcap_list_tstamp_types(3PCAP), pcap_tstamp_type_val_to_name(3PCAP), pcap_tstamp_name_to_val(3PCAP) 22 August 2010 PCAP-TSTAMP(7)
All times are GMT -4. The time now is 09:48 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy