1IP(7)                      Linux Programmer's Manual                     IP(7)
2
3
4

NAME

6       ip - Linux IPv4 protocol implementation
7

SYNOPSIS

9       #include <sys/socket.h>
10       #include <netinet/in.h>
11       #include <netinet/ip.h> /* superset of previous */
12
13       tcp_socket = socket(AF_INET, SOCK_STREAM, 0);
14       udp_socket = socket(AF_INET, SOCK_DGRAM, 0);
15       raw_socket = socket(AF_INET, SOCK_RAW, protocol);
16

DESCRIPTION

18       Linux implements the Internet Protocol, version 4, described in RFC 791
19       and RFC 1122.  ip contains a level 2 multicasting  implementation  con‐
20       forming  to RFC 1112.  It also contains an IP router including a packet
21       filter.
22
23       The programming interface is BSD-sockets compatible.  For more informa‐
24       tion on sockets, see socket(7).
25
26       An   IP  socket  is  created  by  calling  the  socket(2)  function  as
27       socket(AF_INET,  socket_type,  protocol).   Valid  socket   types   are
28       SOCK_STREAM  to  open  a  tcp(7)  socket,  SOCK_DGRAM  to open a udp(7)
29       socket, or SOCK_RAW to open a raw(7) socket to access the  IP  protocol
30       directly.   protocol is the IP protocol in the IP header to be received
31       or sent.  The only valid values for protocol are 0 and IPPROTO_TCP  for
32       TCP  sockets,  and 0 and IPPROTO_UDP for UDP sockets.  For SOCK_RAW you
33       may specify a valid IANA IP protocol defined in RFC 1700 assigned  num‐
34       bers.
35
36       When a process wants to receive new incoming packets or connections, it
37       should bind a socket to a local interface address using bind(2).   Only
38       one  IP  socket  may  be bound to any given local (address, port) pair.
39       When INADDR_ANY is specified in the bind call, the socket will be bound
40       to all local interfaces.  When listen(2) or connect(2) are called on an
41       unbound socket, it is automatically bound to a random  free  port  with
42       the local address set to INADDR_ANY.
43
44       A  TCP local socket address that has been bound is unavailable for some
45       time after closing, unless the SO_REUSEADDR flag has  been  set.   Care
46       should be taken when using this flag as it makes TCP less reliable.
47
48   Address Format
49       An  IP  socket  address  is defined as a combination of an IP interface
50       address and a 16-bit port number.  The basic IP protocol does not  sup‐
51       ply  port  numbers, they are implemented by higher level protocols like
52       udp(7) and tcp(7).  On raw sockets sin_port is set to the IP protocol.
53
54           struct sockaddr_in {
55               sa_family_t    sin_family; /* address family: AF_INET */
56               in_port_t      sin_port;   /* port in network byte order */
57               struct in_addr sin_addr;   /* internet address */
58           };
59
60           /* Internet address. */
61           struct in_addr {
62               uint32_t       s_addr;     /* address in network byte order */
63           };
64
65       sin_family is always set to AF_INET.  This is required;  in  Linux  2.2
66       most  networking  functions return EINVAL when this setting is missing.
67       sin_port contains the port in network byte  order.   The  port  numbers
68       below  1024 are called privileged ports (or sometimes: reserved ports).
69       Only privileged processes (i.e., those having the  CAP_NET_BIND_SERVICE
70       capability)  may bind(2) to these sockets.  Note that the raw IPv4 pro‐
71       tocol as such has no concept of a port, they are  only  implemented  by
72       higher protocols like tcp(7) and udp(7).
73
74       sin_addr  is  the IP host address.  The s_addr member of struct in_addr
75       contains the host interface address in  network  byte  order.   in_addr
76       should be assigned one of the INADDR_* values (e.g., INADDR_ANY) or set
77       using the inet_aton(3), inet_addr(3),  inet_makeaddr(3)  library  func‐
78       tions or directly with the name resolver (see gethostbyname(3)).
79
80       IPv4  addresses  are  divided  into  unicast,  broadcast  and multicast
81       addresses.  Unicast addresses specify a single  interface  of  a  host,
82       broadcast  addresses  specify  all  hosts  on  a  network and multicast
83       addresses address all hosts in a multicast group.  Datagrams to  broad‐
84       cast  addresses  can  be  only  sent  or received when the SO_BROADCAST
85       socket flag is set.  In the current implementation, connection-oriented
86       sockets are only allowed to use unicast addresses.
87
88       Note  that  the  address and the port are always stored in network byte
89       order.  In particular, this means that you need to call htons(3) on the
90       number that is assigned to a port.  All address/port manipulation func‐
91       tions in the standard library work in network byte order.
92
93       There are several special addresses: INADDR_LOOPBACK (127.0.0.1) always
94       refers  to the local host via the loopback device; INADDR_ANY (0.0.0.0)
95       means any address for binding; INADDR_BROADCAST (255.255.255.255) means
96       any  host  and has the same effect on bind as INADDR_ANY for historical
97       reasons.
98
99   Socket Options
100       IP supports some protocol-specific socket options that can be set  with
101       setsockopt(2) and read with getsockopt(2).  The socket option level for
102       IP is IPPROTO_IP.  A boolean integer flag is zero  when  it  is  false,
103       otherwise true.
104
105       IP_ADD_MEMBERSHIP (since Linux 1.2)
106              Join a multicast group.  Argument is an ip_mreqn structure.
107
108                  struct ip_mreqn {
109                      struct in_addr imr_multiaddr; /* IP multicast group
110                                                       address */
111                      struct in_addr imr_address;   /* IP address of local
112                                                       interface */
113                      int            imr_ifindex;   /* interface index */
114                  };
115
116              imr_multiaddr  contains  the  address of the multicast group the
117              application wants to join or leave.  It must be a  valid  multi‐
118              cast  address  (or  setsockopt(2)  fails with the error EINVAL).
119              imr_address is the address of the local interface with which the
120              system  should  join  the  multicast  group;  if  it is equal to
121              INADDR_ANY an appropriate interface is  chosen  by  the  system.
122              imr_ifindex  is the interface index of the interface that should
123              join/leave the imr_multiaddr group, or 0 to indicate any  inter‐
124              face.
125
126              The ip_mreqn is available only since Linux 2.2.  For compatibil‐
127              ity, the old ip_mreq structure  (present  since  Linux  1.2)  is
128              still supported.  It differs from ip_mreqn only by not including
129              the imr_ifindex field.  Only valid as a setsockopt(2).
130
131       IP_DROP_MEMBERSHIP (since Linux 1.2)
132              Leave a multicast group.  Argument is  an  ip_mreqn  or  ip_mreq
133              structure similar to IP_ADD_MEMBERSHIP.
134
135       IP_HDRINCL (since Linux 2.0)
136              If  enabled, the user supplies an IP header in front of the user
137              data.  Only valid for SOCK_RAW sockets.   See  raw(7)  for  more
138              information.   When  this  flag  is  enabled  the  values set by
139              IP_OPTIONS, IP_TTL and IP_TOS are ignored.
140
141       IP_MTU (since Linux 2.2)
142              Retrieve the current known path MTU of the current socket.  Only
143              valid  when  the socket has been connected.  Returns an integer.
144              Only valid as a getsockopt(2).
145
146       IP_MTU_DISCOVER (since Linux 2.2)
147              Set or receive the Path MTU  Discovery  setting  for  a  socket.
148              When  enabled,  Linux will perform Path MTU Discovery as defined
149              in RFC 1191 on this socket.  The don't-fragment flag is  set  on
150              all  outgoing  datagrams.  The system-wide default is controlled
151              by the /proc/sys/net/ipv4/ip_no_pmtu_disc file  for  SOCK_STREAM
152              sockets,  and disabled on all others.  For non-SOCK_STREAM sock‐
153              ets, it is the user's responsibility to packetize  the  data  in
154              MTU  sized  chunks  and to do the retransmits if necessary.  The
155              kernel will reject packets that are bigger than the  known  path
156              MTU if this flag is set (with EMSGSIZE ).
157
158              Path MTU discovery flags   Meaning
159              IP_PMTUDISC_WANT           Use per-route settings.
160              IP_PMTUDISC_DONT           Never do Path MTU Discovery.
161              IP_PMTUDISC_DO             Always do Path MTU Discovery.
162              IP_PMTUDISC_PROBE          Set DF but ignore Path MTU.
163
164              When  PMTU  discovery is enabled, the kernel automatically keeps
165              track of the path MTU per destination host.   When  it  is  con‐
166              nected  to  a specific peer with connect(2), the currently known
167              path MTU can be retrieved conveniently using the  IP_MTU  socket
168              option  (e.g.,  after a EMSGSIZE error occurred).  It may change
169              over time.  For connectionless sockets with  many  destinations,
170              the  new  MTU for a given destination can also be accessed using
171              the error queue (see IP_RECVERR).  A new error  will  be  queued
172              for every incoming MTU update.
173
174              While  MTU  discovery is in progress, initial packets from data‐
175              gram sockets may be dropped.  Applications using UDP  should  be
176              aware  of  this  and  not  take it into account for their packet
177              retransmit strategy.
178
179              To bootstrap the path MTU discovery process on unconnected sock‐
180              ets,  it  is  possible  to start with a big datagram size (up to
181              64K-headers bytes long) and let it shrink by updates of the path
182              MTU.
183
184              To  get  an initial estimate of the path MTU, connect a datagram
185              socket to the destination address using connect(2) and  retrieve
186              the MTU by calling getsockopt(2) with the IP_MTU option.
187
188              It is possible to implement RFC 4821 MTU probing with SOCK_DGRAM
189              or SOCK_RAW sockets by  setting  a  value  of  IP_PMTUDISC_PROBE
190              (available  since Linux 2.6.22).  This is also particularly use‐
191              ful for diagnostic tools  such  as  tracepath(8)  that  wish  to
192              deliberately  send  probe  packets larger than the observed Path
193              MTU.
194
195       IP_MULTICAST_IF (since Linux 1.2)
196              Set the local device for a multicast  socket.   Argument  is  an
197              ip_mreqn or ip_mreq structure similar to IP_ADD_MEMBERSHIP.
198
199              When   an  invalid  socket  option  is  passed,  ENOPROTOOPT  is
200              returned.
201
202       IP_MULTICAST_LOOP (since Linux 1.2)
203              Set or read a boolean integer argument that  determines  whether
204              sent  multicast packets should be looped back to the local sock‐
205              ets.
206
207       IP_MULTICAST_TTL (since Linux 1.2)
208              Set or read the time-to-live value of outgoing multicast packets
209              for  this socket.  It is very important for multicast packets to
210              set the smallest TTL possible.  The default  is  1  which  means
211              that  multicast packets don't leave the local network unless the
212              user program explicitly requests it.  Argument is an integer.
213
214       IP_OPTIONS (since Linux 2.0)
215              Set or get the IP options to be sent with every packet from this
216              socket.  The arguments are a pointer to a memory buffer contain‐
217              ing the options and the option length.  The  setsockopt(2)  call
218              sets  the  IP  options  associated  with  a socket.  The maximum
219              option size for IPv4 is 40 bytes.  See RFC 791 for  the  allowed
220              options.   When  the  initial  connection  request  packet for a
221              SOCK_STREAM socket contains IP options, the IP options  will  be
222              set  automatically  to  the options from the initial packet with
223              routing headers reversed.  Incoming packets are not  allowed  to
224              change  options  after  the connection is established.  The pro‐
225              cessing of all incoming source routing options  is  disabled  by
226              default  and  can  be  enabled  by using the accept_source_route
227              /proc interface.  Other options like timestamps are  still  han‐
228              dled.   For  datagram sockets, IP options can be only set by the
229              local user.  Calling getsockopt(2) with IP_OPTIONS puts the cur‐
230              rent IP options used for sending into the supplied buffer.
231
232       IP_PKTINFO (since Linux 2.2)
233              Pass  an  IP_PKTINFO  ancillary  message that contains a pktinfo
234              structure that supplies  some  information  about  the  incoming
235              packet.   This  only  works  for datagram oriented sockets.  The
236              argument is a flag that tells the socket whether the  IP_PKTINFO
237              message should be passed or not.  The message itself can only be
238              sent/retrieved as control message with a packet using recvmsg(2)
239              or sendmsg(2).
240
241                  struct in_pktinfo {
242                      unsigned int   ipi_ifindex;  /* Interface index */
243                      struct in_addr ipi_spec_dst; /* Local address */
244                      struct in_addr ipi_addr;     /* Header Destination
245                                                      address */
246                  };
247
248              ipi_ifindex  is the unique index of the interface the packet was
249              received on.  ipi_spec_dst is the local address  of  the  packet
250              and  ipi_addr  is  the destination address in the packet header.
251              If IP_PKTINFO is passed to sendmsg(2) and  ipi_spec_dst  is  not
252              zero,  then it is used as the local source address for the rout‐
253              ing table lookup and for setting up  IP  source  route  options.
254              When  ipi_ifindex  is not zero, the primary local address of the
255              interface specified by the index overwrites ipi_spec_dst for the
256              routing table lookup.
257
258       IP_RECVERR (since Linux 2.2)
259              Enable extended reliable error message passing.  When enabled on
260              a datagram socket, all generated errors will be queued in a per-
261              socket  error  queue.   When  the  user receives an error from a
262              socket  operation,  the  errors  can  be  received  by   calling
263              recvmsg(2)    with    the    MSG_ERRQUEUE    flag    set.    The
264              sock_extended_err structure describing the error will be  passed
265              in  an  ancillary message with the type IP_RECVERR and the level
266              IPPROTO_IP.  This is  useful  for  reliable  error  handling  on
267              unconnected  sockets.   The  received  data portion of the error
268              queue contains the error packet.
269
270              The IP_RECVERR  control  message  contains  a  sock_extended_err
271              structure:
272
273                  #define SO_EE_ORIGIN_NONE    0
274                  #define SO_EE_ORIGIN_LOCAL   1
275                  #define SO_EE_ORIGIN_ICMP    2
276                  #define SO_EE_ORIGIN_ICMP6   3
277
278                  struct sock_extended_err {
279                      uint32_t ee_errno;   /* error number */
280                      uint8_t  ee_origin;  /* where the error originated */
281                      uint8_t  ee_type;    /* type */
282                      uint8_t  ee_code;    /* code */
283                      uint8_t  ee_pad;
284                      uint32_t ee_info;    /* additional information */
285                      uint32_t ee_data;    /* other data */
286                      /* More data may follow */
287                  };
288
289                  struct sockaddr *SO_EE_OFFENDER(struct sock_extended_err *);
290
291              ee_errno contains the errno number of the queued error.  ee_ori‐
292              gin is the origin code of where the error originated.  The other
293              fields  are protocol-specific.  The macro SO_EE_OFFENDER returns
294              a pointer to the address of the network object where  the  error
295              originated  from  given  a pointer to the ancillary message.  If
296              this address is not known, the sa_family member of the  sockaddr
297              contains  AF_UNSPEC  and  the  other  fields of the sockaddr are
298              undefined.
299
300              IP uses the sock_extended_err structure as follows: ee_origin is
301              set  to SO_EE_ORIGIN_ICMP for errors received as an ICMP packet,
302              or SO_EE_ORIGIN_LOCAL for  locally  generated  errors.   Unknown
303              values  should be ignored.  ee_type and ee_code are set from the
304              type and code fields of the ICMP header.  ee_info  contains  the
305              discovered  MTU  for EMSGSIZE errors.  The message also contains
306              the sockaddr_in of the node  caused  the  error,  which  can  be
307              accessed with the SO_EE_OFFENDER macro.  The sin_family field of
308              the SO_EE_OFFENDER address is  AF_UNSPEC  when  the  source  was
309              unknown.   When  the  error  originated from the network, all IP
310              options (IP_OPTIONS, IP_TTL, etc.) enabled  on  the  socket  and
311              contained  in  the  error packet are passed as control messages.
312              The payload of the packet causing the error is returned as  nor‐
313              mal  payload.  Note that TCP has no error queue; MSG_ERRQUEUE is
314              not permitted on SOCK_STREAM sockets.  IP_RECVERR is  valid  for
315              TCP,  but  all  errors are returned by socket function return or
316              SO_ERROR only.
317
318              For raw sockets, IP_RECVERR enables passing of all received ICMP
319              errors to the application, otherwise errors are only reported on
320              connected sockets
321
322              It sets  or  retrieves  an  integer  boolean  flag.   IP_RECVERR
323              defaults to off.
324
325       IP_RECVOPTS (since Linux 2.2)
326              Pass all incoming IP options to the user in a IP_OPTIONS control
327              message.  The routing  header  and  other  options  are  already
328              filled  in  for  the  local host.  Not supported for SOCK_STREAM
329              sockets.
330
331       IP_RECVTOS (since Linux 2.2)
332              If enabled the IP_TOS ancillary message is passed with  incoming
333              packets.   It  contains  a byte which specifies the Type of Ser‐
334              vice/Precedence field of the packet header.  Expects  a  boolean
335              integer flag.
336
337       IP_RECVTTL (since Linux 2.2)
338              When  this  flag  is set, pass a IP_TTL control message with the
339              time to live field of the received packet as a byte.   Not  sup‐
340              ported for SOCK_STREAM sockets.
341
342       IP_RETOPTS (since Linux 2.2)
343              Identical  to  IP_RECVOPTS,  but returns raw unprocessed options
344              with timestamp and route record options not filled in  for  this
345              hop.
346
347       IP_ROUTER_ALERT (since Linux 2.2)
348              Pass all to-be forwarded packets with the IP Router Alert option
349              set to this socket.  Only valid for raw sockets.  This  is  use‐
350              ful,  for  instance,  for  user-space  RSVP daemons.  The tapped
351              packets are not forwarded  by  the  kernel;  it  is  the  user's
352              responsibility  to  send  them  out  again.   Socket  binding is
353              ignored, such packets are only filtered by protocol.  Expects an
354              integer flag.
355
356       IP_TOS (since Linux 1.0)
357              Set or receive the Type-Of-Service (TOS) field that is sent with
358              every IP packet originating from this socket.   It  is  used  to
359              prioritize  packets  on  the network.  TOS is a byte.  There are
360              some standard TOS  flags  defined:  IPTOS_LOWDELAY  to  minimize
361              delays  for  interactive  traffic,  IPTOS_THROUGHPUT to optimize
362              throughput,  IPTOS_RELIABILITY  to  optimize  for   reliability,
363              IPTOS_MINCOST should be used for "filler data" where slow trans‐
364              mission doesn't matter.  At most one of these TOS values can  be
365              specified.   Other bits are invalid and shall be cleared.  Linux
366              sends IPTOS_LOWDELAY datagrams first by default, but  the  exact
367              behavior  depends  on  the configured queueing discipline.  Some
368              high priority  levels  may  require  superuser  privileges  (the
369              CAP_NET_ADMIN  capability).   The  priority can also be set in a
370              protocol independent way by the (SOL_SOCKET, SO_PRIORITY) socket
371              option (see socket(7)).
372
373       IP_TTL (since Linux 1.0)
374              Set  or  retrieve the current time-to-live field that is used in
375              every packet sent from this socket.
376
377   /proc interfaces
378       The IP protocol supports a set of /proc interfaces  to  configure  some
379       global  parameters.  The parameters can be accessed by reading or writ‐
380       ing files in the directory /proc/sys/net/ipv4/.   Interfaces  described
381       as Boolean take an integer value, with a nonzero value ("true") meaning
382       that the corresponding option is enabled, and a  zero  value  ("false")
383       meaning that the option is disabled.
384
385       ip_always_defrag (Boolean; since Linux 2.2.13)
386              [New with kernel 2.2.13; in earlier kernel versions this feature
387              was controlled at compile time  by  the  CONFIG_IP_ALWAYS_DEFRAG
388              option; this option is not present in 2.4.x and later]
389
390              When  this boolean flag is enabled (not equal 0), incoming frag‐
391              ments (parts of IP packets that arose  when  some  host  between
392              origin  and  destination decided that the packets were too large
393              and cut them into pieces)  will  be  reassembled  (defragmented)
394              before being processed, even if they are about to be forwarded.
395
396              Only  enable  if running either a firewall that is the sole link
397              to your network or a transparent proxy; never ever use it for  a
398              normal  router  or host.  Otherwise fragmented communication can
399              be disturbed if  the  fragments  travel  over  different  links.
400              Defragmentation also has a large memory and CPU time cost.
401
402              This is automagically turned on when masquerading or transparent
403              proxying are configured.
404
405       ip_autoconfig (since Linux 2.2 to 2.6.17)
406              Not documented.
407
408       ip_default_ttl (integer; default: 64; since Linux 2.2)
409              Set the default time-to-live value of  outgoing  packets.   This
410              can be changed per socket with the IP_TTL option.
411
412       ip_dynaddr (Boolean; default: disabled; since Linux 2.0.31)
413              Enable  dynamic  socket address and masquerading entry rewriting
414              on interface address change.  This is useful for  dialup  inter‐
415              face  with changing IP addresses.  0 means no rewriting, 1 turns
416              it on and 2 enables verbose mode.
417
418       ip_forward (Boolean; default: disabled; since Linux 1.2)
419              Enable IP forwarding with a boolean flag.  IP forwarding can  be
420              also set on a per-interface basis.
421
422       ip_local_port_range (since Linux 2.2)
423              Contains  two  integers that define the default local port range
424              allocated to sockets.  Allocation starts with the  first  number
425              and  ends  with  the  second number.  Note that these should not
426              conflict with the ports used by masquerading (although the  case
427              is  handled).   Also  arbitrary  choices may cause problems with
428              some firewall packet filters that  make  assumptions  about  the
429              local  ports  in  use.   First number should be at least greater
430              than 1024, or better, greater than 4096, to avoid  clashes  with
431              well known ports and to minimize firewall problems.
432
433       ip_no_pmtu_disc (Boolean; default: disabled; since Linux 2.2)
434              If  enabled,  don't  do  Path  MTU  Discovery for TCP sockets by
435              default.  Path MTU discovery may fail if misconfigured firewalls
436              (that  drop all ICMP packets) or misconfigured interfaces (e.g.,
437              a point-to-point link where the both ends  don't  agree  on  the
438              MTU) are on the path.  It is better to fix the broken routers on
439              the path than to turn off Path MTU Discovery  globally,  because
440              not doing it incurs a high cost to the network.
441
442       ip_nonlocal_bind (Boolean; default: disabled; since Linux 2.4)
443              If  set,  allows  processes to bind(2) to nonlocal IP addresses,
444              which can be quite useful, but may break some applications.
445
446       ip6frag_time (integer; default 30)
447              Time in seconds to keep an IPv6 fragment in memory.
448
449       ip6frag_secret_interval (integer; default 600)
450              Regeneration interval (in seconds) of the hash secret (or  life‐
451              time for the hash secret) for IPv6 fragments.
452
453       ipfrag_high_thresh (integer), ipfrag_low_thresh (integer)
454              If the amount of queued IP fragments reaches ipfrag_high_thresh,
455              the queue is pruned  down  to  ipfrag_low_thresh.   Contains  an
456              integer with the number of bytes.
457
458       neigh/*
459              See arp(7).
460
461   Ioctls
462       All ioctls described in socket(7) apply to ip.
463
464       Ioctls  to  configure generic device parameters are described in netde‐
465       vice(7).
466

ERRORS

468       EACCES The user tried to execute an  operation  without  the  necessary
469              permissions.   These  include:  sending  a packet to a broadcast
470              address without having the  SO_BROADCAST  flag  set;  sending  a
471              packet via a prohibit route; modifying firewall settings without
472              superuser privileges (the CAP_NET_ADMIN capability); binding  to
473              a    privileged   port   without   superuser   privileges   (the
474              CAP_NET_BIND_SERVICE capability).
475
476       EADDRINUSE
477              Tried to bind to an address already in use.
478
479       EADDRNOTAVAIL
480              A nonexistent interface was requested or  the  requested  source
481              address was not local.
482
483       EAGAIN Operation on a nonblocking socket would block.
484
485       EALREADY
486              An  connection  operation  on a nonblocking socket is already in
487              progress.
488
489       ECONNABORTED
490              A connection was closed during an accept(2).
491
492       EHOSTUNREACH
493              No valid routing table entry matches  the  destination  address.
494              This  error can be caused by a ICMP message from a remote router
495              or for the local routing table.
496
497       EINVAL Invalid argument passed.  For send operations this can be caused
498              by sending to a blackhole route.
499
500       EISCONN
501              connect(2) was called on an already connected socket.
502
503       EMSGSIZE
504              Datagram  is  bigger  than  an  MTU on the path and it cannot be
505              fragmented.
506
507       ENOBUFS, ENOMEM
508              Not enough free memory.  This often means that the memory  allo‐
509              cation is limited by the socket buffer limits, not by the system
510              memory, but this is not 100% consistent.
511
512       ENOENT SIOCGSTAMP was called on a socket where no packet arrived.
513
514       ENOPKG A kernel subsystem was not configured.
515
516       ENOPROTOOPT and EOPNOTSUPP
517              Invalid socket option passed.
518
519       ENOTCONN
520              The operation is only defined on a  connected  socket,  but  the
521              socket wasn't connected.
522
523       EPERM  User  doesn't  have permission to set high priority, change con‐
524              figuration, or send signals to the requested process or group.
525
526       EPIPE  The connection was unexpectedly closed or shut down by the other
527              end.
528
529       ESOCKTNOSUPPORT
530              The  socket  is  not  configured  or  an unknown socket type was
531              requested.
532
533       Other errors may be generated by the overlaying protocols; see  tcp(7),
534       raw(7), udp(7) and socket(7).
535

NOTES

537       IP_MTU, IP_MTU_DISCOVER, IP_PKTINFO, IP_RECVERR and IP_ROUTER_ALERT are
538       Linux-specific and should not be used in programs intended to be porta‐
539       ble.   Be  very careful with the SO_BROADCAST option - it is not privi‐
540       leged in Linux.  It is easy  to  overload  the  network  with  careless
541       broadcasts.  For new application protocols it is better to use a multi‐
542       cast group instead of broadcasting.  Broadcasting is discouraged.
543
544       Some  other  BSD  sockets  implementations  provide  IP_RCVDSTADDR  and
545       IP_RECVIF  socket options to get the destination address and the inter‐
546       face of received datagrams.  Linux has the more general IP_PKTINFO  for
547       the same task.
548
549       Some BSD sockets implementations also provide an IP_RECVTTL option, but
550       an ancillary message with type IP_RECVTTL is passed with  the  incoming
551       packet.  This is different from the IP_TTL option used in Linux.
552
553       Using  SOL_IP socket options level isn't portable, BSD-based stacks use
554       IPPROTO_IP level.
555
556   Compatibility
557       For  compatibility  with  Linux  2.0,  the   obsolete   socket(AF_INET,
558       SOCK_PACKET,  protocol)  syntax  is still supported to open a packet(7)
559       socket.  This is deprecated and should be replaced by socket(AF_PACKET,
560       SOCK_RAW,  protocol)  instead.   The  main  difference is the new sock‐
561       addr_ll address structure for generic link layer information instead of
562       the old sockaddr_pkt.
563

BUGS

565       There are too many inconsistent error values.
566
567       The  ioctls  to  configure IP-specific interface options and ARP tables
568       are not described.
569
570       Some versions of glibc forget to declare in_pktinfo.   Workaround  cur‐
571       rently is to copy it into your program from this man page.
572
573       Receiving   the  original  destination  address  with  MSG_ERRQUEUE  in
574       msg_name by recvmsg(2) does not work in some 2.2 kernels.
575

SEE ALSO

577       recvmsg(2),   sendmsg(2),   byteorder(3),   ipfw(4),   capabilities(7),
578       netlink(7), raw(7), socket(7), tcp(7), udp(7)
579
580       RFC 791 for the original IP specification.
581       RFC 1122 for the IPv4 host requirements.
582       RFC 1812 for the IPv4 router requirements.
583

COLOPHON

585       This  page  is  part of release 3.25 of the Linux man-pages project.  A
586       description of the project, and information about reporting  bugs,  can
587       be found at http://www.kernel.org/doc/man-pages/.
588
589
590
591Linux                             2009-02-28                             IP(7)
Impressum