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>.
5 .\" %%%LICENSE_START(VERBATIM_ONE_PARA)
6 .\" Permission is granted to distribute possibly modified copies
7 .\" of this page provided the header is included verbatim,
8 .\" and in case of nontrivial modification author and date
9 .\" of the modification is added to the header.
11 .\" $Id: raw.7,v 1.6 1999/06/05 10:32:08 freitag Exp $
12 .TH RAW 7 2012-05-10 "Linux" "Linux Programmer's Manual"
14 raw \- Linux IPv4 raw sockets
16 .B #include <sys/socket.h>
18 .B #include <netinet/in.h>
20 .BI "raw_socket = socket(AF_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
24 including link level headers.
26 The IPv4 layer generates an IP header when sending a packet unless the
28 socket option is enabled on the socket.
29 When it is enabled, the packet must contain an IP header.
30 For receiving the IP header is always included in the packet.
32 Only processes with an effective user ID of 0 or the
34 capability are allowed to open raw sockets.
36 All packets or errors matching the
39 for the raw socket are passed to this socket.
40 For a list of the allowed protocols see RFC\ 1700 assigned numbers and
41 .BR getprotobyname (3).
47 and is able to send any IP protocol that is specified in the passed
49 Receiving of all IP protocols via
51 is not possible using raw sockets.
57 IP Header fields modified on sending by \fBIP_HDRINCL\fP
58 IP Checksum:Always filled in.
59 Source Address:Filled in when zero.
60 Packet Id:Filled in when zero.
61 Total Length:Always filled in.
68 is specified and the IP header has a nonzero destination address then
69 the destination address of the socket is used to route the packet.
72 is specified, the destination address should refer to a local interface,
73 otherwise a routing table lookup is done anyway but gatewayed routes
78 isn't set, then IP header options can be set on raw sockets with
84 In Linux 2.2, all IP header fields and options can be set using
86 This means raw sockets are usually only needed for new
87 protocols or protocols with no user interface (like ICMP).
89 When a packet is received, it is passed to any raw sockets which have
90 been bound to its protocol before it is passed to other protocol handlers
91 (e.g., kernel protocol modules).
93 Raw sockets use the standard
95 address structure defined in
99 field could be used to specify the IP protocol number,
100 but it is ignored for sending in Linux 2.2 and should be always
102 For incoming packets,
104 is set to the protocol of the packet.
107 include file for valid IP protocols.
109 Raw socket options can be set with
115 .\" Or SOL_RAW on Linux
119 Enable a special filter for raw sockets bound to the
122 The value has a bit set for each ICMP message type which
123 should be filtered out.
124 The default is to filter no ICMP messages.
129 socket options valid for datagram sockets are supported.
131 Errors originating from the network are only passed to the user when the
132 socket is connected or the
135 For connected sockets, only
139 are passed for compatibility.
142 all network errors are saved in the error queue.
146 User tried to send to a broadcast address without having the
147 broadcast flag set on the socket.
150 An invalid memory address was supplied.
157 Either Path MTU Discovery is enabled (the
159 socket flag) or the packet size exceeds the maximum allowed IPv4
163 Invalid flag has been passed to a socket call (like
167 The user doesn't have permission to open raw sockets.
168 Only processes with an effective user ID of 0 or the
170 attribute may do that.
173 An ICMP error has arrived reporting a parameter problem.
178 are new in Linux 2.2.
179 They are Linux extensions and should not be used in portable programs.
181 Linux 2.0 enabled some bug-to-bug compatibility with BSD in the
182 raw socket code when the
184 socket option was set \(em since Linux 2.2,
185 this option no longer has that effect.
187 By default, raw sockets do path MTU (Maximum Transmission Unit) discovery.
188 This means the kernel
189 will keep track of the MTU to a specific target IP address and return
191 when a raw packet write exceeds it.
192 When this happens, the application should decrease the packet size.
193 Path MTU discovery can be also turned off using the
196 .I /proc/sys/net/ipv4/ip_no_pmtu_disc
200 When turned off, raw sockets will fragment outgoing packets
201 that exceed the interface MTU.
202 However, disabling it is not recommended
203 for performance and reliability reasons.
205 A raw socket can be bound to a specific local address using the
208 If it isn't bound, all packets with the specified IP protocol are received.
209 In addition, a RAW socket can be bound to a specific network device using
210 .BR SO_BINDTODEVICE ;
217 If you really want to receive all IP packets, use a
222 Note that packet sockets don't reassemble IP fragments,
225 If you want to receive all ICMP packets for a datagram socket,
226 it is often better to use
228 on that particular socket; see
231 Raw sockets may tap all IP protocols in Linux, even
232 protocols like ICMP or TCP which have a protocol module in the kernel.
233 In this case, the packets are passed to both the kernel module and the raw
235 This should not be relied upon in portable programs, many other BSD
236 socket implementation have limitations here.
238 Linux never changes headers passed from the user (except for filling
239 in some zeroed fields as described for
241 This differs from many other implementations of raw sockets.
243 RAW sockets are generally rather unportable and should be avoided in
244 programs intended to be portable.
246 Sending on raw sockets should take the IP protocol from
248 this ability was lost in Linux 2.2.
249 The workaround is to use
252 Transparent proxy extensions are not described.
256 option is set, datagrams will not be fragmented and are limited to
259 Setting the IP protocol for sending in
261 got lost in Linux 2.2.
262 The protocol that the socket was bound to or that
263 was specified in the initial
267 .\" This man page was written by Andi Kleen.
271 .BR capabilities (7),
276 for path MTU discovery.
280 header file for the IP protocol.