Пример #1
0
int processpacket(short* packet, size_t* packetindex, unsigned short* packetcount)
{
	if(!(IS_BYTE_1(packet[0])))
		{
			(*packetindex)--;//throw out packet
		}
	if((*packetindex) == 3)
	{
		display_packet(packet);
		(*packetindex)=0;
		(*packetcount)++;
	}
	return 0;
}
static void
on_packet_selected (GtkTreeSelection *selection, gpointer user_data)
{
        GtkTreeModel *model;
        GtkTreeIter iter;
        time_t *arrival_time;

        if (gtk_tree_selection_get_selected (selection, &model, &iter)) {
                SoupMessageHeaders *packet_headers;

                gtk_tree_model_get (model,
                                &iter, 
                                4, &packet_headers,
                                5, &arrival_time, -1);
                display_packet (*arrival_time, packet_headers);
                g_boxed_free (SOUP_TYPE_MESSAGE_HEADERS, packet_headers);
        }

        else
                update_packet_details ("", 0);
}
Пример #3
0
int main( int argc, char *argv[] )
{
    /*target address*/
    struct sockaddr_ll socket_address;

    /*buffer for ethernet frame*/
    void* buffer = (void*)malloc(ETH_FRAME_LEN);
     
    /*pointer to ethenet header*/
    unsigned char* etherhead = buffer;
        
    /*userdata in ethernet frame*/
    unsigned char* data = buffer + 14;
        
    /*another pointer to ethernet header*/
    struct ethhdr *eh = (struct ethhdr *)etherhead;
     
    int send_result = 0;

    /*our MAC address*/ /* eth0: 00:1B:21:5D:35:14 */
    unsigned char src_mac[6] = {0x00, 0x1B, 0x21, 0x5D, 0x35, 0x14};

    /*other host MAC address*/
    unsigned char dest_mac[6] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF};


	int i, j, n;
	int	sock, pkt_num;		// for socket-ID and packet-number 

	// allow user to modify the default number of packets to accept
	for (i = 1; i+1 < argc; i++)
		if ( strncmp( argv[ i ], "-c", 3 ) == 0 )
			packet_limit = atoi( argv[ i+1 ] );

	// create an unnamed socket for reception of ethernet packets 
	sock = socket( PF_PACKET, SOCK_RAW, htons( ETH_P_ALL ) ); 
	if ( sock < 0 ) { perror( "socket" ); exit( 1 ); }


	printf ("Foo! Index is: %d\n", get_netdev_index (sock, argc, argv));



    /*prepare sockaddr_ll*/

    /*RAW communication*/
    socket_address.sll_family   = PF_PACKET;    
    /*we don't use a protocoll above ethernet layer
      ->just use anything here*/
    socket_address.sll_protocol = htons(ETH_P_ALL);  

    /*index of the network device
    see full code later how to retrieve it*/
    socket_address.sll_ifindex = get_netdev_index (sock, argc, argv);
    printf ("Selected device index is: %d\n", get_netdev_index (sock, argc, argv));

    /*ARP hardware identifier is ethernet*/
/*
    socket_address.sll_hatype   = ARPHRD_ETHER;
*/
        
    /*target is another host*/
    socket_address.sll_pkttype  = PACKET_OTHERHOST;

    /*address length*/
    socket_address.sll_halen    = ETH_ALEN;     
    /*MAC - begin*/
    socket_address.sll_addr[0]  = 0xFF;     
    socket_address.sll_addr[1]  = 0xFF;     
    socket_address.sll_addr[2]  = 0xFF;
    socket_address.sll_addr[3]  = 0xFF;
    socket_address.sll_addr[4]  = 0xFF;
    socket_address.sll_addr[5]  = 0xFF;
    /*MAC - end*/
    socket_address.sll_addr[6]  = 0x00;/*not used*/
    socket_address.sll_addr[7]  = 0x00;/*not used*/


    /*set the frame header*/
    memcpy((void*)buffer, (void*)dest_mac, ETH_ALEN);
    memcpy((void*)(buffer+ETH_ALEN), (void*)src_mac, ETH_ALEN);
    eh->h_proto = 0x00;
    /*fill the frame with some data*/
    for (j = 0; j < 1500; j++) {
        data[j] = (unsigned char)((int) (255.0*rand()/(RAND_MAX+1.0)));
    }


    /*send the packet*/

    while (1)
    {
	    send_result = sendto(sock, buffer, ETH_FRAME_LEN, 0, 
		      (struct sockaddr*)&socket_address, sizeof(socket_address));
	    if (send_result == -1) 
	    { 
		fprintf (stderr, "Error in sendto(): %s\n", strerror(errno));
		/* exit (1); */
	    }
    }



#if 0

	// main loop to intercept and display the ethernet packets
	char	hostname[ 64 ], packet[ MAXPKT ];
	gethostname( hostname, sizeof( hostname ) );
	printf( "\nMonitoring network packets for interface \'%s\'", devname );
	printf( " on station \'%s\' \n", hostname );
	do	{
		struct sockaddr_ll	saddr = { 0 };
		socklen_t		slen = sizeof( saddr );
		size_t			plen = sizeof( packet );
		int			nbytes;

		nbytes = recvfrom( sock, packet, MAXPKT, 0, 
					(sockaddr*)&saddr, &slen );

		if ( saddr.sll_ifindex == ifindex )
			display_packet( packet, nbytes, saddr.sll_pkttype );
		}
	while ( pkt_num < packet_limit );
#endif
}
Пример #4
0
void dump_packets(void)
{
	display_packet(packet);
}