Help answer threads with 0 replies.
Go Back > Forums > Non-*NIX Forums > Programming
User Name
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.


  Search this Thread
Old 08-16-2005, 01:24 PM   #1
Registered: Jul 2002
Location: Florida
Distribution: Centos, Slackware
Posts: 260

Rep: Reputation: 30
source mac from SOCK_DGRAM

sock = socket(AF_INET, SOCK_DGRAM, 0)
recvfrom(sock, msg, MaxSocketsize, 0,
(struct sockaddr*)&clntaddr,

I want to know the value of the source mac address
from the ethhdr of the just recv'd msg.

Any help?


Old 08-17-2005, 04:38 PM   #2
Registered: Feb 2002
Location: Grenoble
Distribution: Debian
Posts: 9,696

Rep: Reputation: 232Reputation: 232Reputation: 232
The level is too high. You need raw sockets (SOCK_RAW) but it's much complicated to work with it than to use standard socket. You can make a trick and add libpcap and listen using the lib. It gives your everything from the packet from datalink level (MAC address and such things), but you need to match the right standard socket data with addresses from libpcap. It shouldn't be hard, however, because you can use source IPs.
Old 08-17-2005, 06:17 PM   #3
Registered: Jul 2002
Location: Florida
Distribution: Centos, Slackware
Posts: 260

Original Poster
Rep: Reputation: 30
Yeah, I know about SOCK_RAW, but this code already exists and I wanted to not
change anything I didn't have to. I have not looked at libpcap, I guess it is now
the time.

Thanks for your response.
Old 08-17-2005, 11:57 PM   #4
Registered: May 2004
Posts: 552

Rep: Reputation: 31
Also, when you receive a TCP/IP or UDP packet the mac address is kept in the kernel arp database, you can take the IP address and look it up. For example from the command line type "arp <ipaddr>" and the mac will be displayed. There may be a more direct means to do it in a program.


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
Mac fans! A few questions about an old Mac... Mega Man X General 11 01-03-2007 10:01 PM
how to use iptables -m mac --mac-source DeployedOne Linux - Security 3 08-06-2004 04:03 AM
Using streams over AF_INET SOCK_DGRAM in C programs worldmagic Programming 2 12-03-2003 05:54 AM
Compiling Linux Source on Mac OS X? ttge Linux - Software 2 02-26-2002 10:27 AM
How would i log the source MAC address w/ iptables? phek Linux - Security 12 12-14-2001 01:18 PM > Forums > Non-*NIX Forums > Programming

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

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