From: "Miquel van Smoorenburg" <mikevs@xs4all.net>
To: savinov.guram@gmail.com
Cc: linux-kernel@vger.kernel.org
Subject: Re: Get interface MAC address in sys_accept4() syscall
Date: Fri, 30 Jul 2010 18:15:44 +0200 [thread overview]
Message-ID: <201007301615.o6UGFill008660@xs8.xs4all.nl> (raw)
In-Reply-To: <AANLkTin8vaiWTRTM+WzZ_PAWO6j-voP29n1jHfLv+=q3@mail.gmail.com>
In article <AANLkTin8vaiWTRTM+WzZ_PAWO6j-voP29n1jHfLv+=q3@mail.gmail.com> you write:
>Yes, I know, but sys_accept4() have int fd argument, that is socket
>descriptor, can I work with it like raw socket and get MAC from
>ethernet frame?
You can do getsockname(2) on the socket and you'll get the IP address
of the local interface.
You can then use getifaddrs(3) to get a list of local interfaces,
loop over all of them, and compare the IP address to the one you got
from getsockame().
Once you have the name of the interface, loop over the results
from getifaddrs() again, and find the AF_PACKET address of that
interface. The AF_PACKET address has the MAC address. See packet(7).
Mike.
prev parent reply other threads:[~2010-07-30 16:15 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-07-29 23:42 Guram Z. Savinov
2010-07-29 23:51 ` Guram Z. Savinov
2010-07-30 7:17 ` Américo Wang
[not found] ` <AANLkTi=bSLALO0xP3kWgX9ipRBroDsqzXp6=kPuwMtW2@mail.gmail.com>
2010-07-30 10:03 ` Américo Wang
2010-07-30 10:22 ` Guram Z. Savinov
2010-07-30 16:15 ` Miquel van Smoorenburg [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=201007301615.o6UGFill008660@xs8.xs4all.nl \
--to=mikevs@xs4all.net \
--cc=linux-kernel@vger.kernel.org \
--cc=savinov.guram@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®