• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Porting Winsock DHCP Server; is OS/X ignoring Broadcast UDP in recvall()?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Porting Winsock DHCP Server; is OS/X ignoring Broadcast UDP in recvall()?


  • Subject: Re: Porting Winsock DHCP Server; is OS/X ignoring Broadcast UDP in recvall()?
  • From: Hostile Fork <email@hidden>
  • Date: Tue, 12 Feb 2008 18:36:43 -0800

Well... I'm down to finishing up this piece of code, which has now proven it works on at least a few linuxes and OS/Xes. It also turned out that a Fedora Core linux required the packet-level DHCP; it didn't just send the 255.255.255.255 to all the network cards in the system when you code at the socket level. It seems like the safe bet is to just never do world broadcast (sending or receiving) with sockets.

One issue I discovered was that OS/X 10.4 ships with a version of libpcap that doesn't have pcap_inject or pcap_sendpacket. So perhaps that's why old darwin code uses the bpf layer to send packets! To work around that, I just linked the 10.4 version with a newer libpcap I downloaded and built instead of "-lpcap" and that made the functions available.

But now I've returned to getting the ethernet address of the network card from pcap's device handle (it is necessary to stuff into the packet to send it). So here's the status on that:


On Feb 1, 2008, at 4:26 PM, Peter Sichel wrote:

I'm not too clear about cross platform mechanisms since
this is basically a function of the driver at the data link
layer.


I thought I might have found a sub-optimal (but at least workable) solution with the function ether_hostton:

	http://linux.die.net/man/3/ether_hostton

It seemed like it could be as easy as passing in the IP address of the adapter as reported by pcap, and then letting the person edit their / etc/ethers file to make sure they have an ethernet address registered for the IP. It's a little bit of manual labor, but as it seems to be common practice it would beat a home-grown INI file solution.

But the function didn't work. I did a little more investigation to see if had to do with the fact that I didn't have that host in the DNS, so I tried a little test instead (using the relevant numbers and not ? marks):

	In File /etc/ethers (was empty), add:
	??:??:??:??:??:?? testhostton

	In File /etc/hosts, add:
	?.?.?.? testhostton

Still... a call to ether_hostton("testhostton", &ether) returns non- zero, indicating failure. This even after running "sudo dscacheutil - flushcache". So I wonder... anyone ever successfully passed something to ether_hostton and succeeded? Or know why it would ignore my entries? The documentation suggests the file is re-read on every call to the routine... I'm surprised it wouldn't work.


In most UNIX systems, you can use Sysctl to get the
NET_RT_IFLIST and read it from there as described
in Stevens "UNIX Network Programming"

 CTL_NET.AF_ROUTE.0.AF_INET.NET_RT_IFLIST.0

This might at least cover other UNIX like systems
(versus the System Configuration Framework
which is Mac OS X only).

Thanks for the pointer! Though for the sake of simplicity/ portability, if ether_hostton() isn't going to work I'm going to self- send a packet with socket level that I know is going to the right adapter, capture it with pcap, and break out the ethernet header data to use later in my pcap_inject calls! :) Hopefully that will work...


---
http://hostilefork.com
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Macnetworkprog mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


References: 
 >Re: Porting Winsock DHCP Server; is OS/X ignoring Broadcast UDP in recvall()? (From: "Hostile Fork" <email@hidden>)
 >Re: Porting Winsock DHCP Server; is OS/X ignoring Broadcast UDP in recvall()? (From: Peter Sichel <email@hidden>)

  • Prev by Date: Persistent HTTP connections...
  • Next by Date: 10.5 and NT4 nbsession problem
  • Previous by thread: Re: Porting Winsock DHCP Server; is OS/X ignoring Broadcast UDP in recvall()?
  • Next by thread: WEP text-password to hex-key hashing formula
  • Index(es):
    • Date
    • Thread