Re: 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,

Thanks to everyone for their responses, I've now looked at the way
squid does the MAC resolution in it's acl.c source code and I've
implimented it using the IOCTL: SIOCGARP. First with a blank interface
name, then looping through each physical ethernet interface using the
IOCTL: SIOCGIFCONF.

Many thanks, Dan...

Thursday, June 28, 2007, 11:38:08 PM, you wrote:

> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1

> Dan Searle wrote:
>> 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...
>> 
>> --

> After reading Matti's response, I'd like you to clarify this.  Are you
> looking for the MAC address of the machine that the code is running on,
> or some remote client?



--

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