• 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: Sample code for sending raw packets?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Sample code for sending raw packets?


  • Subject: Re: Sample code for sending raw packets?
  • From: "Peter Sichel" <email@hidden>
  • Date: Fri, 13 Oct 2006 15:02:05 -0400

On 10/13/06, Dave Camp wrote:

>  - Add a static entry to the ARP table for x.x.x.x  -> Printer MAC
>Address, where x.x.x.x is the new IP address they want to set the
>printer to and the Printer MAC address is the MAC address of the
>printer.
>  - Send an ICMP ping to the printer.
>  - Remove the ARP entry
>
>Yes, they set the IP address of the printer by pinging it. I'll wait
>here for a bit while you cry.
>
>I'm going to guess that fiddling with the local ARP table is probably
>not such a swell idea

It turns out DHCP Servers do this all the time.  The client broadcasts a
request saying can someone configure me, and the DHCP server responds
saying here's a configuration.  In order to send the configuration to
the requesting client, it stuffs the clients hardware address into the
ARP cache and then does a UDP send to the corresponding IP address
[IPNetRouter did this on Mac OS 9].  The technique they're using is not
uncommon.

The easy way to do this on Mac OS X is to invoke the UNIX arp command to
do it for you.  It's not as if you will be responding to dozens of
requests per second.

Alternatively, if you really want to send a raw Ethernet frame, you can
do something like "bpftransmit" in the Darwin "bootp" project.  You'll
need a privileged helper tool to open a BPF socket, but it's not too bad
once you get the pattern (see Quinn's MoreAuthorization" sample code).
[IPNetRouterX does this.]

> and that I'd be better off hand rolling my own
>raw ICMP ping packet at the ethernet level to get the job done. I
>think it would have to be at the ethernet level as I need to specify
>the IP address and destination MAC address myself. I know I will have
>to have a SUID root helper tool to do this.
>
>Assuming that is the case, I was wondering if someone could point me
>to some sample code illustrating how to build a raw ethernet packet.
>I've looked in the Unix Programming Book, but it only covers raw
>IPv4/6 packets, not raw ethernet packets. Most of the sample code
>I've found on the net is for Linux which appears to use different AF_
>and protocol constants than BSD.
>
>Thoughts?

If you have any influence on future device firmware, there's open source
sample code for doing Bonjour, and a basic DHCP client is not that hard
in the scale of everything else the device is doing that requires a
multitasking OS and TCP/IP stack.  [I've written both a DHCP Server and
DHCP Tester (client simulator) for my own products.]

Enjoy!

- Peter Sichel
  Sustainable Softworks
  www.sustworks.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: 
 >Sample code for sending raw packets? (From: Dave Camp <email@hidden>)

  • Prev by Date: Re: Sample code for sending raw packets?
  • Next by Date: Re: Sample code for sending raw packets?
  • Previous by thread: Re: Sample code for sending raw packets?
  • Next by thread: how to enumerate TCP and UDP listeners
  • Index(es):
    • Date
    • Thread