Implementing Ping
Implementing Ping
- Subject: Implementing Ping
- From: Quinn <email@hidden>
- Date: Mon, 12 Jan 2004 17:38:56 +0000
Greetings
Igor has posted a couple of questions how to implement ping which
have illustrated that this topic is still a source of some confusion.
I hope that email will clear things up.
AFAIK there are 4 ways of implementing ping.
1. Using straight BSD sockets -- This is a reasonable technique for
all versions of Mac OS X. However, you have to be running as root,
which is a significant drawback. To get around this you can use a
setuid root helper tool to create a raw IP socket and pass it back to
your main application via descriptor passing, but this is a bunch of
work. If you decide to do this, see MoreAuthSample for details.
<
http://developer.apple.com/samplecode/Sample_Code/Security/MoreAuthSample.htm>
2. Using an ICMP socket -- This facility was introduced in Mac OS X
10.2. It allows you to ping without running as root. The code is
/very/ similar to option 1 (you just change a few constants to the
"socket" call) but without the privileges issue. See SimplePing for
an example.
<
http://developer.apple.com/samplecode/Sample_Code/Networking/SimplePing.htm>
3. Using the Open Transport API -- You should only do this on
traditional Mac OS. See OTPingSample for an example.
<
http://developer.apple.com/samplecode/Sample_Code/Archive/Networking/OTPingSample.htm>
You shouldn't use this technique on Mac OS X because a) the Open
Transport API is deprecated on Mac OS X, and b) you have to be
running as root (your EUID must be 0) for it to work. You can work
around b) using a setuid root helper tool, but it's not as neat
because you can't use descriptor passing. Besides, once you've got
involved with setuid helper tools, you lose whatever source-level
compatibility benefits that the OT compatibility library provides.
4. fork/exec the "ping" command line tool -- I strongly recommend
against this because it requires you to treat the user interface of
"ping" as a programming interface.
Thus, the best approach depends on your system requirements.
o If you require 10.2 or later, use option 2.
o If you require 10.x or later, use option 2 on 10.2 and later, and
option 1 or 4 on earlier systems (option 4 is acceptable in this case
because you know that the "ping" tool can't change on 10.0 and 10.1).
o If you only run on traditional Mac OS, use option 3.
o If you run on traditional Mac OS and Mac OS X, use option 3 *and*
whatever is the appropriate Mac OS X option. Yes, I know that this
requires you to have two sets of code but, given the complexities of
supporting 10.0 and 10.1, this is probably the least of your worries.
S+E
--
Quinn "The Eskimo!" <
http://www.apple.com/developer/>
Apple Developer Technical Support * Networking, Communications, Hardware
_______________________________________________
macnetworkprog mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/macnetworkprog
Do not post admin requests to the list. They will be ignored.