2 .\" This man page is Copyright (C) 1999 Andi Kleen <ak@muc.de>.
4 .\" %%%LICENSE_START(VERBATIM_ONE_PARA)
5 .\" Permission is granted to distribute possibly modified copies
6 .\" of this page provided the header is included verbatim,
7 .\" and in case of nontrivial modification author and date
8 .\" of the modification is added to the header.
11 .\" $Id: raw.7,v 1.6 1999/06/05 10:32:08 freitag Exp $
13 .TH RAW 7 2012-05-10 "Linux" "Linux Programmer's Manual"
15 raw \- Linux IPv4 raw sockets
17 .B #include <sys/socket.h>
19 .B #include <netinet/in.h>
21 .BI "raw_socket = socket(AF_INET, SOCK_RAW, int " protocol );
23 Raw sockets allow new IPv4 protocols to be implemented in user space.
24 A raw socket receives or sends the raw datagram not
25 including link level headers.
27 The IPv4 layer generates an IP header when sending a packet unless the
29 socket option is enabled on the socket.
30 When it is enabled, the packet must contain an IP header.
31 For receiving the IP header is always included in the packet.
33 Only processes with an effective user ID of 0 or the
35 capability are allowed to open raw sockets.
37 All packets or errors matching the
40 for the raw socket are passed to this socket.
41 For a list of the allowed protocols see RFC\ 1700 assigned numbers and
42 .BR getprotobyname (3).
48 and is able to send any IP protocol that is specified in the passed
50 Receiving of all IP protocols via
52 is not possible using raw sockets.
58 IP Header fields modified on sending by \fBIP_HDRINCL\fP
59 IP Checksum:Always filled in.
60 Source Address:Filled in when zero.
61 Packet Id:Filled in when zero.
62 Total Length:Always filled in.
69 is specified and the IP header has a nonzero destination address, then
70 the destination address of the socket is used to route the packet.
73 is specified, the destination address should refer to a local interface,
74 otherwise a routing table lookup is done anyway but gatewayed routes
79 isn't set, then IP header options can be set on raw sockets with
85 In Linux 2.2, all IP header fields and options can be set using
87 This means raw sockets are usually needed only for new
88 protocols or protocols with no user interface (like ICMP).
90 When a packet is received, it is passed to any raw sockets which have
91 been bound to its protocol before it is passed to other protocol handlers
92 (e.g., kernel protocol modules).
94 Raw sockets use the standard
96 address structure defined in
100 field could be used to specify the IP protocol number,
101 but it is ignored for sending in Linux 2.2 and should be always
103 For incoming packets,
105 is set to the protocol of the packet.
108 include file for valid IP protocols.
110 Raw socket options can be set with
116 .\" Or SOL_RAW on Linux
120 Enable a special filter for raw sockets bound to the
123 The value has a bit set for each ICMP message type which
124 should be filtered out.
125 The default is to filter no ICMP messages.
130 socket options valid for datagram sockets are supported.
132 Errors originating from the network are passed to the user only when the
133 socket is connected or the
136 For connected sockets, only
140 are passed for compatibility.
143 all network errors are saved in the error queue.
147 User tried to send to a broadcast address without having the
148 broadcast flag set on the socket.
151 An invalid memory address was supplied.
158 Either Path MTU Discovery is enabled (the
160 socket flag) or the packet size exceeds the maximum allowed IPv4
164 Invalid flag has been passed to a socket call (like
168 The user doesn't have permission to open raw sockets.
169 Only processes with an effective user ID of 0 or the
171 attribute may do that.
174 An ICMP error has arrived reporting a parameter problem.
179 are new in Linux 2.2.
180 They are Linux extensions and should not be used in portable programs.
182 Linux 2.0 enabled some bug-to-bug compatibility with BSD in the
183 raw socket code when the
185 socket option was set \(em since Linux 2.2,
186 this option no longer has that effect.
188 By default, raw sockets do path MTU (Maximum Transmission Unit) discovery.
189 This means the kernel
190 will keep track of the MTU to a specific target IP address and return
192 when a raw packet write exceeds it.
193 When this happens, the application should decrease the packet size.
194 Path MTU discovery can be also turned off using the
197 .I /proc/sys/net/ipv4/ip_no_pmtu_disc
201 When turned off, raw sockets will fragment outgoing packets
202 that exceed the interface MTU.
203 However, disabling it is not recommended
204 for performance and reliability reasons.
206 A raw socket can be bound to a specific local address using the
209 If it isn't bound, all packets with the specified IP protocol are received.
210 In addition, a RAW socket can be bound to a specific network device using
211 .BR SO_BINDTODEVICE ;
218 If you really want to receive all IP packets, use a
223 Note that packet sockets don't reassemble IP fragments,
226 If you want to receive all ICMP packets for a datagram socket,
227 it is often better to use
229 on that particular socket; see
232 Raw sockets may tap all IP protocols in Linux, even
233 protocols like ICMP or TCP which have a protocol module in the kernel.
234 In this case, the packets are passed to both the kernel module and the raw
236 This should not be relied upon in portable programs, many other BSD
237 socket implementation have limitations here.
239 Linux never changes headers passed from the user (except for filling
240 in some zeroed fields as described for
242 This differs from many other implementations of raw sockets.
244 RAW sockets are generally rather unportable and should be avoided in
245 programs intended to be portable.
247 Sending on raw sockets should take the IP protocol from
249 this ability was lost in Linux 2.2.
250 The workaround is to use
253 Transparent proxy extensions are not described.
257 option is set, datagrams will not be fragmented and are limited to
260 Setting the IP protocol for sending in
262 got lost in Linux 2.2.
263 The protocol that the socket was bound to or that
264 was specified in the initial
268 .\" This man page was written by Andi Kleen.
272 .BR capabilities (7),
277 for path MTU discovery.
281 header file for the IP protocol.
283 This page is part of release 3.79 of the Linux
286 A description of the project,
287 information about reporting bugs,
288 and the latest version of this page,
290 \%http://www.kernel.org/doc/man\-pages/.