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 04-26-2013, 06:55 AM   #1
sreeyeshns
LQ Newbie
 
Registered: Nov 2011
Location: Cochin, India
Distribution: Ubuntu 10.04
Posts: 2

Rep: Reputation: Disabled
sendto function does not use MAC address provided in struct sockaddr_ll when sending


I am trying to send an OAM ethernet frame using raw socket. I was successful in doing so.

The send function I have written is:

Code:
int send_frame(sock_info *info,char *buf,int length)
        {
	       struct sockaddr_ll dest_addr;
	       memset(&dest_addr,0,sizeof(struct sockaddr_ll));
	       dest_addr.sll_family = PF_PACKET;
	       dest_addr.sll_protocol = htons(8902);
	       dest_addr.sll_ifindex = info->if_index;
	       dest_addr.sll_halen = ETH_MAC_ADDR_LEN;
	       dest_addr.sll_pkttype = PACKET_OTHERHOST;
	       dest_addr.sll_hatype   = ARPHRD_ETHER;
	       memset(dest_addr.sll_addr,0,8);
	
	       dest_addr.sll_addr[0] = 0x00;
	       dest_addr.sll_addr[1] = 0xE0;
	       dest_addr.sll_addr[2] = 0x0C;
	       dest_addr.sll_addr[3] = 0x00;
	       dest_addr.sll_addr[4] = 0x95;
	       dest_addr.sll_addr[5] = 0x02;

	       return sendto(info->sock_fd, buf, length, 0, (struct sockaddr*) &dest_addr, sizeof(struct sockaddr_ll));
        }
I was unable to capture the packet using wireshark. After tryiing too many things, I found out that buffer used to send should have all ethernet frame fields (starting from destination address). When I added the destination and source address and other ethernet fields into the buffer, I was able to capture the packet using wireshark. So the send function doesn't use the MAC address stored in `dest_addr.sll_addr`.

My question is, Then what's the need of `sll_addr` field in the `struct sockaddr_ll`? Manuals say that it is the destination MAC address.
 
Old 04-29-2013, 04:45 PM   #2
smallpond
Senior Member
 
Registered: Feb 2011
Location: Massachusetts, USA
Distribution: Fedora
Posts: 1,606

Rep: Reputation: 386Reputation: 386Reputation: 386Reputation: 386
Normally you open an AF_INET socket and the system builds the header information. If you open a raw socket, you bypass the normal packet mechanism and build your own.
 
  


Reply

Tags
linux, socket


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
how do I find what MAC address web pages see as my MAC address rob.rice General 20 05-29-2010 02:08 AM
Determining address for UDP sendto calls after a prior TCP connection sh86 Programming 1 02-09-2010 10:53 AM
sendto function call in UDP client program chakka.lokesh Programming 1 01-05-2010 10:53 PM
[SOLVED] Find Physical address of memory provided by kmalloc raghu2383 Programming 3 10-23-2009 02:25 PM


All times are GMT -5. The time now is 10:54 AM.

Main Menu
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