How can I get the source MAC address from a TCP socket?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi,

I am developing a TCP server using the standard, socket(), bind(),
listen() and accept() calls to implement a TCP server in user land.

I have searched the web but can't find anything useful regarding a
problem I am having...

My question is, given that I have a TCP socket file descriptor as
returned by accept() as follows:

sock = accept(s_sock, (struct sockaddr *)addr, (socklen_t *)&addr_length);

Is there a way, using an IOCTL or SYSCALL to get down the protocol
stack to retrieve the source MAC address of the new TCP socket that
accept() returns a file descriptor for?

My server needs to know the source MAC of TCP connections to it, so
that I can make decisions on how to handle the request based on the
source MAC address.

At present I am using a messy call to popen() calling the arp program
in a shell. I tried looking up /proc/net/arp directly, but sometimes
there is no ARP entry in the cache, even though the accept() call
succeeded and I have a new TCP socket.

Regards, Dan...

--

Dan Searle
Adelix Ltd
dan.searle@xxxxxxxxxx web: www.adelix.com
tel: 0845 230 9590 / fax: 0845 230 9591 / support: 0845 230 9592
snail: The Old Post Office, Bristol Rd, Hambrook, Bristol BS16 1RY. UK.

Adelix Ltd is a registered company in England & Wales No. 4232156
VAT registration number 779 4232 91
Adelix Ltd is BS EN ISO 9001:2000 Certified (No. GB 12763)

Any views expressed in this email communication are those
of the individual sender, except where the sender specifically states
them to be the views of a member of Adelix Ltd.  Adelix Ltd. does not
represent, warrant or guarantee that the integrity of this communication
has been maintained nor that the communication is free of errors or
interference.


------------------------------------------------------------------------------------
Scanned for viruses, spam and offensive content by CensorNet MailSafe

Professional Web & E-mail Filtering from www.censornet.com
-
To unsubscribe from this list: send the line "unsubscribe linux-net" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Netdev]     [Ethernet Bridging]     [Linux 802.1Q VLAN]     [Linux Wireless]     [Kernel Newbies]     [Security]     [Linux for Hams]     [Netfilter]     [Git]     [Bugtraq]     [Yosemite News and Information]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux PCI]     [Linux Admin]     [Samba]

  Powered by Linux