|
Part 2: Setting a Course with Code
by Fred Eady
Start
ı Packet Whacker Utilities
ı Receiving Packets ı Who
ARP You?ı Ping ı UDP
ı TCP ı FIN
ı Sources and PDF
PING
On the PGA tour, the right Ping can make
you a bunch of money. Our ping makes us no money at all in the financial
sense, but itıs worth a million dollars when your Packet Whacker code
on the PICDEM.net answers a ping request on the LAN. Donıt go looking
for a ping function in the Packet Whacker source code because I didnıt
implement a ping utility like the one youıre used to seeing in an
operating system like Windows. Looking at the crossroads code in Listing
5 once again, you find that if the incoming packet doesnıt match up
to an ARP request, it falls into the it-must-be-IP bucket. After some
sifting, the ping request falls into the category of Internet control
message protocol (ICMP).
ICMP does a lot of neat things and brings
a wealth of functionality to the IP world. It is the simplest of the
procedures Iıve had to write yet. Listing
7 lays it out. Most of the work is
done in the setipaddrs function. The setipaddrs code
swaps the source and destination IP addresses, swaps the source and
destination MAC addresses, and calculates the IP header checksum.
After the IP side of the packet is secured, the icmp code chunk
simply changes the type from Echo (0x08) to Echo reply (0x00) and
calculates the ICMP header checksum before sending the ICMP echo reply
packet on its way back to the golf course. Because, at this point,
Iım only interested in the PICDEM.net code, Photo 7 is the PICDEM.net
side of a ping operation as seen by the Sniffer.
| Listing
7ıAlthough the ICMP function is sometimes used as a carrier
of bad news, the ping process is simply an echo of the incoming
ICMP packet with the source and destination addresses swapped,
a redefinition of the echo/reply field, and a recalculation
of the ICMP checksum. |
| Photo
7ıThereıs nothing complicated about constructing an ICMP
Echo reply packet. The most that has to be done is the calculation
of the checksum. The rest of the mind exercise is keeping up
with the address swaps. |
ARPing and pinging are good things as
far as Internet devices go, but itıs really difficult to move data
using these processes. So, letıs add some information moving code
to our existing "here I am" code.
PREVIOUS
NEXT
Circuit Cellar provides up-to-date information for engineers. Visit
www.circuitcellar.com for
more information and additional articles.
For subscription information, call (860) 875-2199, subscribe@circuitcellar.com
or subscribe online.
ıCircuit Cellar, the Magazine for Computer Applications. Posted with
permission. |