2 .\" Don't change the first line, it tells man that we need tbl.
3 .\" This man page is Copyright (C) 1999 Andi Kleen <ak@muc.de>.
4 .\" Permission is granted to distribute possibly modified copies
5 .\" of this page provided the header is included verbatim,
6 .\" and in case of nontrivial modification author and date
7 .\" of the modification is added to the header.
8 .\" Please send bug reports, corrections and suggestions for improvements to
10 .\" $Id: raw.7,v 1.6 1999/06/05 10:32:08 freitag Exp $
11 .TH RAW 7 1998-10-02 "Linux Man Page" "Linux Programmer's Manual"
13 raw, SOCK_RAW \- Linux IPv4 raw sockets
15 .B #include <sys/socket.h>
17 .B #include <netinet/in.h>
19 .BI "raw_socket = socket(PF_INET, SOCK_RAW, int " protocol );
22 Raw sockets allow new IPv4 protocols to be implemented in user space.
23 A raw socket receives or sends the raw datagram not including link level headers.
25 The IPv4 layer generates an IP header when sending a packet unless the
27 socket option is enabled on the socket.
28 When it is enabled, the packet must contain an IP header.
29 For receiving the IP header is always included in the packet.
31 Only processes with an effective user id of 0 or the
33 capability are allowed to open raw sockets.
35 All packets or errors matching the
38 for the raw socket are passed to this socket. For a list of the
39 allowed protocols see RFC\ 1700 assigned numbers and
40 .BR getprotobyname (3).
46 and is able to send any IP protocol that is specified in the passed header.
47 Receiving of all IP protocols via
49 is not possible using raw sockets.
55 IP Header fields modified on sending by IP_HDRINCL
56 IP Checksum:Always filled in.
57 Source Address:Filled in when zero.
58 Packet Id:Filled in when zero.
59 Total Length:Always filled in.
65 is specified and the IP header has a non-zero destination address then
66 the destination address of the socket is used to route the packet. When
68 is specified the destination address should refer to a local interface,
69 otherwise a routing table lookup is done anyways but gatewayed routes
74 isn't set then IP header options can be set on raw sockets with
80 In Linux 2.2 all IP header fields and options can be set using
81 IP socket options. This means raw sockets are usually only needed for new
82 protocols or protocols with no user interface (like ICMP).
84 When a packet is received, it is passed to any raw sockets which have
85 been bound to its protocol before it is passed to other protocol handlers
86 (e.g. kernel protocol modules).
90 Raw sockets use the standard
92 address structure defined in
97 field could be used to specify the IP protocol number,
98 but it is ignored for sending in Linux 2.2 and should be always
102 is set to the protocol of the packet.
105 include file for valid IP protocols.
108 Raw socket options can be set with
118 Enable a special filter for raw sockets bound to the
120 protocol. The value has a bit set for each ICMP message type which
121 should be filtered out. The default is to filter no ICMP messages.
127 socket options valid for datagram sockets are supported.
130 Raw sockets fragment a packet when its total length exceeds the interface MTU
132 A more network friendly and faster alternative is to implement path MTU
133 discovery as described in the
138 A raw socket can be bound to a specific local address using the
140 call. If it isn't bound all packets with the specified IP protocol are received.
141 In addition a RAW socket can be bound to a specific network device using
149 If you really want to receive all IP packets use a
153 protocol. Note that packet sockets don't reassemble IP fragments, unlike raw sockets.
155 If you want to receive all ICMP packets for a datagram socket it is often better
158 on that particular socket; see
161 Raw sockets may tap all IP protocols in Linux, even
162 protocols like ICMP or TCP which have a protocol module in the kernel. In
163 this case the packets are passed to both the kernel module and the raw
164 socket(s). This should not be relied upon in portable programs, many other BSD
165 socket implementation have limitations here.
167 Linux never changes headers passed from the user (except for filling in some
168 zeroed fields as described for
170 This differs from many other implementations of raw sockets.
172 RAW sockets are generally rather unportable and should be avoided in programs
173 intended to be portable.
175 Sending on raw sockets should take the IP protocol from
177 this ability was lost in Linux 2.2. Work around is to use
181 Errors originating from the network are only passed to the user when the
182 socket is connected or the
184 flag is enabled. For connected sockets only
188 are passed for compatibility. With
190 all network errors are saved in the error queue.
194 Packet too big. Either Path MTU Discovery is enabled (the
196 socket flag) or the packet size exceeds the maximum allowed IPv4 packet size
200 User tried to send to a broadcast address without having the broadcast flag
204 An ICMP error has arrived reporting a parameter problem.
207 An invalid memory address was supplied.
210 Invalid flag has been passed to a socket call (like
217 The user doesn't have permission to open raw sockets. Only processes
218 with a effective user id of 0 or the
220 attribute may do that.
226 are new in Linux 2.2. They are Linux extensions
227 and should not be used in portable programs.
229 Linux 2.0 enabled some bug-to-bug compatibility with BSD in the raw socket code
230 when the SO_BSDCOMPAT flag was set - that has been removed in 2.2.
233 Transparent proxy extensions are not described.
237 option is set datagrams will not be fragmented and are limited to the interface
238 MTU. This is a limitation in Linux 2.2.
240 Setting the IP protocol for sending in
242 got lost in Linux 2.2. The protocol that socket was bound to or that
243 was specified in the initial
248 This man page was written by Andi Kleen.
253 .BR capabilities (7),
258 for path MTU discovery.
263 include file for the IP protocol.