LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Networking
User Name
Password
Linux - Networking This forum is for any issue related to networks or networking.
Routing, network cards, OSI, etc. Anything is fair game.

Notices


Reply
  Search this Thread
Old 03-24-2007, 11:31 PM   #1
bhupeshchawda
LQ Newbie
 
Registered: Mar 2007
Posts: 11

Rep: Reputation: 0
Question Injecting packets ...sockets??


Hi all,
Friends I have built an IP packet and I need to inject this packet to another computer on the same LAN and hence with a different ethernet header. I have used sockets and managed to inject a raw packet on to the wire but what exactly I want is that the kernel should build the ethernet header for me.

Here is my code ...
Code:
inject(u_char *pkt, int nr)
{
/*open socket*/
fd = socket(PF_PACKET, SOCK_RAW, htons(ETH_P_ALL));
if (fd == -1)
{
printf("\nSocket failed!!");
}

if(setsockopt (fd, IPPROTO_IP, IP_HDRINCL, val, sizeof (one))<0)
printf("iphdrincl error");

/*Select interface*/
memset(&ifr, 0, sizeof(ifr));
strncpy (ifr.ifr_name, iftext, sizeof(ifr.ifr_name) - 1);
ifr.ifr_name[sizeof(ifr.ifr_name)-1] = '\0';

if (ioctl(fd, SIOCGIFINDEX, &ifr) == -1)
{
printf("No such interface: %s\n", iftext);
return -1;
}

ioctl(fd, SIOCGIFFLAGS, &ifr);

if ( (ifr.ifr_flags & IFF_UP) == 0)
{
printf("Interface %s is down\n", iftext);
return -1;
}

ioctl(fd, SIOCGIFINDEX, &ifr);
memset(&sa, 0, sizeof (sa));
sa.sll_family = AF_PACKET;
sa.sll_ifindex = ifr.ifr_ifindex;
sa.sll_protocol = htons(ETH_P_ALL);

/*Send*/
c = sendto(fd, pkt, nr, 0, (struct sockaddr *)&sa, sizeof (sa));
}
Note: The setsockopt() IP_HDRINCL option gives an error with errno = 92.

Please help me...any help will be appreciated.
 
  


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
Packets gets repeated in raw sockets??????? fpfernando Programming 5 03-08-2006 02:20 AM
Capturing a Socket and Injecting a Packet Chryzmo Programming 5 12-07-2005 01:17 AM
packets sent VS packets received fsasya Linux - Networking 0 07-18-2004 07:11 PM
encapsulating TCP packets in UDP packets... yoshi95 Programming 3 06-03-2004 02:53 PM
sockets santiagosilva Linux - Networking 0 02-14-2004 07:09 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Networking

All times are GMT -5. The time now is 12:37 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
Open Source Consulting | Domain Registration