[Edu-sig] Re: socket-module
Jeremy Hylton
jeremy@beopen.com
Thu, 29 Jun 2000 12:31:19 -0400 (EDT)
>>>>> "A" == <A> writes:
A> A stupid question maybe. I want to find the parts where is
A> described HOW a TCP-packet is created. Something like:
A> -IP from sender
A> -IP from receiver
A> -data
A> Is it possible?
The socket interface hides the all the details of TCP/IP from you. If
you call send on a socket, the socket library implementation handles
all the details. It handles buffering of the data, putting into
appropriately-sized TCP packets, retransmission of packets, etc.
If you're interested in TCP at that level of detail, you're going to
have to look at a TCP stack implementation in the OS kernel. I
*strongly* recommend W. Richard Steven's TCP/IP Illustrated series if
you go this route.
http://www.kohala.com/start/tcpipiv1.html -- protocols
http://www.kohala.com/start/tcpipiv2.html -- BSD implementation
One thing you can play with is sending raw IP packets, using the a
socket create with the SOCK_RAW protocol. I believe this just works
on Windows, but requires a setuid root script on Unix. An example:
s = socket.socket(socket.AF_INET, socket.SOCK_RAW,
socket.IPPROTO_ICMP)
The OS kernel still does some work for you in this case. The only
example I can think of is that it computes the checksum for the
packet.
My ping and traceroute code in Python, while a little buggy and out of
date, might get you started. http://www-tech.mit.edu/~jeremy/python/
Jeremy