raw sockets, IP header

raw sockets, IP header

Post by Joshua Jone » Wed, 19 Feb 2003 02:26:01



[ This is a repost of the following article:                               ]

[ Subject: raw sockets, IP header                                          ]
[ Newsgroups: comp.unix.programmer                                         ]

Sorry for the multipost, but I posted this on CUP recently, and have
gotten no responses as of yet, and thought some of you guys might
have some information...

So, for learning experience and a future project I'm experimenting
with raw sockets.  I'm trying to send a raw packet with the 'don't
fragment' bit set in the IP header to try to determine the path MTU.
I will embed an ICMP packet as my IP payload, and do an echo request,
and thus hopefully get either:

1) an echo reply
2) a "message too long" error reply

So, I have a buffer that contains my IP header and ICMP header.  I
set the appropriate fields of the IP header and the ICMP header,
and I send the packet out with sendto().  However, recvfrom() blocks
and I never get a reply.  A few of questions (link to code at bottom):

1) Do I call socket() with a protocol of IPPROTO_RAW or IPPROTO_ICMP?
(note that I'm setting the IP_HDRINCL socket option so the kernel knows
that the first byte of data is the first byte of the IP header itself).

2) Do I need any payload for the ICMP packet?

3) Will the kernel do IP and ICMP checksum for me?  My intuition says yes,
but in UNPV1 Stevens manually computes an ICMP checksum (chapter 25).

4) Assuming I can get some response from my remote host at some point,
to actually get the path MTU discovery to work, do I actually have to
send large IP packets or can I just set the ip_len field in the IP header
to a large number to simulate a large packet?

5) Is there a way to get the kernel to fill in the proper source IP
address in the IP header? (supposedly setting ip_id=0 in the header
tells the kernel to set the packet ID, so maybe something for source IP?)
Depending on where this packet goes, it could be one of several IP
addresses for the machine.  If the kernel can't do it, am I going to have
to parse the routing table and find which interface the packet should be
sent out on?

Thanks for any help anyone can offer... the code is here:

http://www.intmain.net:800/mtu.c

--
 josh(at)cc.gatech.edu  |  http://intmain.net:800

 298322 local keystrokes since last reboot (26 days ago)

 
 
 

1. raw sockets, IP header

So, for learning experience and a future project I'm experimenting
with raw sockets.  I'm trying to send a raw packet with the 'don't
fragment' bit set in the IP header to try to determine the path MTU.
I will embed an ICMP packet as my IP payload, and do an echo request,
and thus hopefully get either:

1) an echo reply
2) a "message too long" error reply

So, I have a buffer that contains my IP header and ICMP header.  I
set the appropriate fields of the IP header and the ICMP header,
and I send the packet out with sendto().  However, recvfrom() blocks
and I never get a reply.  A few of questions (link to code at bottom):

1) Do I call socket() with a protocol of IPPROTO_RAW or IPPROTO_ICMP?
(note that I'm setting the IP_HDRINCL socket option so the kernel knows
that the first byte of data is the first byte of the IP header itself).

2) Do I need any payload for the ICMP packet?

3) Will the kernel do IP and ICMP checksum for me?  My intuition says yes,
but in UNPV1 Stevens manually computes an ICMP checksum (chapter 25).

4) Assuming I can get some response from my remote host at some point,
to actually get the path MTU discovery to work, do I actually have to
send large IP packets or can I just set the ip_len field in the IP header
to a large number to simulate a large packet?

5) Is there a way to get the kernel to fill in the proper source IP
address in the IP header? (supposedly setting ip_id=0 in the header
tells the kernel to set the packet ID, so maybe something for source IP?)
Depending on where this packet goes, it could be one of several IP
addresses for the machine.  If the kernel can't do it, am I going to have
to parse the routing table and find which interface the packet should be
sent out on?

Thanks for any help anyone can offer... the code is here:

http://www.intmain.net:800/mtu.c

--
 josh(at)cc.gatech.edu  |  http://intmain.net:800

 288611 local keystrokes since last reboot (25 days ago)

2. Kernel 2.4.20 ...

3. Incorrect IP header data in RAW Sockets

4. 3c515.o doesn't compile

5. IP header in Raw socket

6. chaintech 9PJL + acs-7500

7. raw IP and raw ICMP socket???

8. help with SpeedStar 24X

9. IP Checksum in Raw Sockets

10. Linux Raw Socket for IP Multicast

11. IP_HDRINCL Option for raw IP sockets

12. PATCH for Multicast bug in RAW IP sockets 2.4.0

13. Raw IP socket on Digital Unix