Re: Sample code for sending raw packets?
Re: Sample code for sending raw packets?
- Subject: Re: Sample code for sending raw packets?
- From: Dave Camp <email@hidden>
- Date: Fri, 13 Oct 2006 12:17:14 -0700
If consensus is messing with the ARP table is an okay thing to, I'll
explore that route.
Thanks for the feedback.
Dave
On Oct 13, 2006, at 12:11 PM, Duane Murphy wrote:
Dave,
I'd go with Dalton on this one. Messing with the ARP table is legit,
especially when it is just a few seconds.
Also, arp and ping are built-in, you don't have to do anything.
But here are my caveats.
I am obligated to start off with:
1. the command line is not an API. You might have to parser results.
This is error prone and fragile for changes from OS version to
version.
2. Using system() is a sledge hammer. I prefer to use fork/exec in
situations like this.
3. You can't use system or fork/exec for running arp in order to
add or
delete items because you have to be root in order to write to the
routing socket. In this case you should read up on Authorization
Services, which will allow you to run the tool while authorized.
Good luck,
...Duane
--- At Fri, 13 Oct 2006 14:38:40 -0400, Dalton Hamilton wrote:
I've got socket code that sends out ICMP packets generating my own
ping and my own traceroute packets. However, I did this in sockets
for efficiency and speed. In your case, you don't need the code to
fast; therefore, I suggest you build a string and call the system()
call. string = "/sbin/ping x.x.x.x" and then use system(string).
You build you program using the existing ping and arp code -- i.e.
likewise, you can add the arp entry doing the same.
Why spend multiple days writing code that does the same thing as code
already written?
If you really want the ping socket code, I can email it to you
offline next week -- I'm on vacation and away from my src at the
moment.
Dalton Hamilton
On Oct 13, 2006, at 2:03 PM, Dave Camp wrote:
The list search engine seems to be down at the moment....
I'm working on a utility for a networked laser printer. The printer
will default to an IP address of 192.0.0.192 if it cannot get a
DHCP address. Given that the printer also has no front panel
display or controls, the only way for the user to change the IP
address will be to use my utility.
I will caveat what I'm about to write with: I'm just the poor guy
writing the utility, I have no control over the firmware
implementation.
The documentation I have been given indicates they change the IP
address of the printer in this case by performing the following on
Windows:
- 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 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?
Thanks,
Dave
...Duane
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Macnetworkprog mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
40criticalpath.com
This email sent to email@hidden
---
You are in a maze of testy little Java VMs, all subtly different.
_______________________________________________
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