LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 12-12-2012, 06:40 AM   #1
franmf
LQ Newbie
 
Registered: Oct 2012
Posts: 28

Rep: Reputation: Disabled
send a frame to the router. libnet.


hi. I'd like to know how to send a frame once I've created it.

I've got the next:

Code:
int
arp_send(libnet_t *l, int op, u_char *sha, in_addr_t spa, u_char *tha, in_addr_t tpa)
{	
	libnet_ptag_t t;	
	
	if (sha == NULL &&
	    (sha = (u_char *)libnet_get_hwaddr(l)) == NULL) {
		return (-1);
	}
	if (spa == 0) {
		if ((spa = libnet_get_ipaddr4(l)) == -1)
			return (-1);		
	}
	if (tha == NULL)
		tha = (u_char *)"\xff\xff\xff\xff\xff\xff";
        
    libnet_clear_packet(l);

	/*
     *  Build the packet, remmebering that order IS important.  We must
     *  build the packet from lowest protocol type on up as it would
     *  appear on the wire.  So for our ARP packet:
     *
     *  -------------------------------------------
     *  |  Ethernet   |           ARP             |
     *  -------------------------------------------
     *         ^                     ^
     *         |------------------   |
     *  libnet_build_ethernet()--|   |
     *                               |
     *  libnet_build_arp()-----------|
     */

	t = libnet_build_arp(
            ARPHRD_ETHER,                           /* hardware addr */
            ETHERTYPE_IP,                           /* protocol addr */
            6,                                      /* hardware addr size */
            4,                                      /* protocol addr size */
            op,                                     /* operation type */
            sha,                                    /* sender hardware addr */
            (u_int8_t *)&spa,                       /* sender protocol addr */
            tha,                                    /* target hardware addr */
            (u_int8_t *)&tpa,                       /* target protocol addr */
            NULL,                                   /* payload */
            0,                                      /* payload size */
            l,                                      /* libnet context */
            0);                                     /* libnet id */

	if (t == -1)
    {
        fprintf(stderr, "Can't build ARP header: %s\n", libnet_geterror(l));
        return -1;
    }

	t = libnet_autobuild_ethernet(
            tha,                                    /* ethernet destination */
            ETHERTYPE_ARP,                          /* protocol type */
            l);                                     /* libnet handle */

    if (t == -1)
    {
        fprintf(stderr, "Can't build ethernet header: %s\n",
                libnet_geterror(l));
        return -1;
    }    
    return libnet_write(l);    		
}
I found that code on the net, which creates from nothing an arp packet. I do understand everything but the return, because I don't find the "send" command.

thank you.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Not able to send the ethernet frame along with ip to the given mac address sowpra Linux - Wireless Networking 2 02-08-2012 01:07 AM
how to send custom frame in socket programming rahb20 Programming 4 10-24-2008 10:56 PM
3Com 3c905 - Problems trying to send a frame in my own kernel module gambuzo Linux - Networking 0 05-06-2008 08:30 AM
Error & warnings in installing Libnet-1.1.x & Libnet-config not found error. sakthivelbatusai Linux - Networking 0 03-15-2007 12:14 AM
Wireless broke with NetGear router -- unknown frame f202 Ima Sudonim Linux - Wireless Networking 2 05-04-2005 11:36 AM


All times are GMT -5. The time now is 11:12 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration