Subject: Re: pcap and ICMP messages
To: =?iso-8859-1?q?J=F6rn_Seger?= <joern.seger@udo.edu>
From: Greg Troxel <gdt@ir.bbn.com>
List: tech-net
Date: 09/15/2004 07:40:51
man ip, and search for IP_HDRINCL:
RAW IP SOCKETS
Raw IP sockets are connectionless, and are normally used with the
sendto(2) and recvfrom(2) calls, though the connect(2) call may also be
used to fix the destination for future packets (in which case the read(2)
or recv(2) and write(2) or send(2) system calls may be used).
If proto is 0, the default protocol IPPROTO_RAW is used for outgoing
packets, and only incoming packets destined for that protocol are
received. If proto is non-zero, that protocol number will be used on
outgoing packets and to filter incoming packets.
Outgoing packets automatically have an IP header prepended to them (based
on the destination address and the protocol number the socket is created
with), unless the IP_HDRINCL option has been set. Incoming packets are
received with IP header and options intact.
IP_HDRINCL indicates the complete IP header is included with the data and
may be used only with the SOCK_RAW type.
#include <netinet/ip.h>
int hincl = 1; /* 1 = on, 0 = off */
setsockopt(s, IPPROTO_IP, IP_HDRINCL, &hincl, sizeof(hincl));
Unlike previous BSD releases, the program must set all the fields of the
IP header, including the following:
ip->ip_v = IPVERSION;
ip->ip_hl = hlen >> 2;
ip->ip_id = 0; /* 0 means kernel set appropriate value */
ip->ip_off = offset;
If the header source address is set to INADDR_ANY, the kernel will choose
an appropriate address.
--
Greg Troxel <gdt@ir.bbn.com>