summaryrefslogtreecommitdiff
path: root/static/freebsd/man4/udp.4 3.html
blob: dfe337854dbde091ae5aba200e87873ac74a8dc8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
<table class="head">
  <tr>
    <td class="head-ltitle">UDP(4)</td>
    <td class="head-vol">Device Drivers Manual</td>
    <td class="head-rtitle">UDP(4)</td>
  </tr>
</table>
<div class="manual-text">
<section class="Sh">
<h1 class="Sh" id="NAME"><a class="permalink" href="#NAME">NAME</a></h1>
<p class="Pp"><code class="Nm">udp</code> &#x2014; <span class="Nd">Internet
    User Datagram Protocol</span></p>
</section>
<section class="Sh">
<h1 class="Sh" id="SYNOPSIS"><a class="permalink" href="#SYNOPSIS">SYNOPSIS</a></h1>
<p class="Pp"><code class="In">#include
    &lt;<a class="In">sys/types.h</a>&gt;</code>
  <br/>
  <code class="In">#include &lt;<a class="In">sys/socket.h</a>&gt;</code>
  <br/>
  <code class="In">#include &lt;<a class="In">netinet/in.h</a>&gt;</code></p>
<p class="Pp"><var class="Ft">int</var>
  <br/>
  <code class="Fn">socket</code>(<var class="Fa" style="white-space: nowrap;">AF_INET</var>,
    <var class="Fa" style="white-space: nowrap;">SOCK_DGRAM</var>,
    <var class="Fa" style="white-space: nowrap;">0</var>);</p>
</section>
<section class="Sh">
<h1 class="Sh" id="DESCRIPTION"><a class="permalink" href="#DESCRIPTION">DESCRIPTION</a></h1>
<p class="Pp">UDP is a simple, unreliable datagram protocol which is used to
    support the <code class="Dv">SOCK_DGRAM</code> abstraction for the Internet
    protocol family. UDP sockets are connectionless, and are normally used with
    the <a class="Xr">sendto(2)</a> and <a class="Xr">recvfrom(2)</a> calls,
    though the <a class="Xr">connect(2)</a> call may also be used to fix the
    destination for future packets (in which case the <a class="Xr">recv(2)</a>
    or <a class="Xr">read(2)</a> and <a class="Xr">send(2)</a> or
    <a class="Xr">write(2)</a> system calls may be used).</p>
<p class="Pp">UDP address formats are identical to those used by TCP. In
    particular UDP provides a port identifier in addition to the normal Internet
    address format. Note that the UDP port space is separate from the TCP port
    space (i.e., a UDP port may not be &#x201C;connected&#x201D; to a TCP port).
    In addition broadcast packets may be sent (assuming the underlying network
    supports this) by using a reserved &#x201C;broadcast address&#x201D;; this
    address is network interface dependent.</p>
<p class="Pp">Options at the IP transport level may be used with UDP; see
    <a class="Xr">ip(4)</a>. UDP_ENCAP socket option may be used at the
    IPPROTO_UDP level to encapsulate ESP packets in UDP. Only one value is
    supported for this option: UDP_ENCAP_ESPINUDP from RFC 3948, defined in
    <code class="In">&lt;<a class="In">netinet/udp.h</a>&gt;</code>.</p>
</section>
<section class="Sh">
<h1 class="Sh" id="FIB_support"><a class="permalink" href="#FIB_support">FIB
  support</a></h1>
<p class="Pp">UDP sockets are FIB-aware. They inherit the FIB of the process
    which created the socket. By default, a UDP socket bound to an address can
    receive datagrams originating from any FIB. If the
    <var class="Va">net.inet.udp.bind_all_fibs</var> tunable is set to 0, all
    UDP sockets will receive only datagrams originating from the same FIB as the
    socket. In this mode, multiple sockets can be bound to the same address, so
    long as each socket belongs to a different FIB, similar to the behavior of
    the <code class="Dv">SO_REUSEPORT</code> option.</p>
</section>
<section class="Sh">
<h1 class="Sh" id="MIB_(sysctl)_Variables"><a class="permalink" href="#MIB_(sysctl)_Variables">MIB
  (sysctl) Variables</a></h1>
<p class="Pp">The <code class="Nm">udp</code> protocol implements a number of
    variables in the <var class="Va">net.inet.udp</var> branch of the
    <a class="Xr">sysctl(3)</a> MIB, which can be also read or modified with
    <a class="Xr">sysctl(8)</a>:</p>
<dl class="Bl-tag">
  <dt id="blackhole"><var class="Va">blackhole</var></dt>
  <dd>When a datagram is received on a port where there is no socket listening,
      do not return an ICMP port unreachable message. (Disabled by default. See
      <a class="Xr">blackhole(4)</a>.)</dd>
  <dt id="checksum"><var class="Va">checksum</var></dt>
  <dd>Enable UDP checksums (enabled by default).</dd>
  <dt id="log_in_vain"><var class="Va">log_in_vain</var></dt>
  <dd>For all UDP datagrams, to ports on which there is no socket listening, log
      the connection attempt (disabled by default).</dd>
  <dt id="maxdgram"><var class="Va">maxdgram</var></dt>
  <dd>Maximum outgoing UDP datagram size</dd>
  <dt id="recvspace"><var class="Va">recvspace</var></dt>
  <dd>Maximum space for incoming UDP datagrams</dd>
</dl>
</section>
<section class="Sh">
<h1 class="Sh" id="ERRORS"><a class="permalink" href="#ERRORS">ERRORS</a></h1>
<p class="Pp">A socket operation may fail with one of the following errors
    returned:</p>
<dl class="Bl-tag">
  <dt id="EISCONN">[<a class="permalink" href="#EISCONN"><code class="Er">EISCONN</code></a>]</dt>
  <dd>when trying to establish a connection on a socket which already has one,
      or when trying to send a datagram with the destination address specified
      and the socket is already connected;</dd>
  <dt id="ENOTCONN">[<a class="permalink" href="#ENOTCONN"><code class="Er">ENOTCONN</code></a>]</dt>
  <dd>when trying to send a datagram, but no destination address is specified,
      and the socket has not been connected;</dd>
  <dt id="ENOBUFS">[<a class="permalink" href="#ENOBUFS"><code class="Er">ENOBUFS</code></a>]</dt>
  <dd>when the system runs out of memory for an internal data structure;</dd>
  <dt id="EADDRINUSE">[<a class="permalink" href="#EADDRINUSE"><code class="Er">EADDRINUSE</code></a>]</dt>
  <dd>when an attempt is made to create a socket with a port which has already
      been allocated;</dd>
  <dt id="EADDRNOTAVAIL">[<a class="permalink" href="#EADDRNOTAVAIL"><code class="Er">EADDRNOTAVAIL</code></a>]</dt>
  <dd>when an attempt is made to create a socket with a network address for
      which no network interface exists.</dd>
</dl>
</section>
<section class="Sh">
<h1 class="Sh" id="SEE_ALSO"><a class="permalink" href="#SEE_ALSO">SEE
  ALSO</a></h1>
<p class="Pp"><a class="Xr">getsockopt(2)</a>, <a class="Xr">recv(2)</a>,
    <a class="Xr">send(2)</a>, <a class="Xr">socket(2)</a>,
    <a class="Xr">blackhole(4)</a>, <a class="Xr">inet(4)</a>,
    <a class="Xr">intro(4)</a>, <a class="Xr">ip(4)</a>,
    <a class="Xr">udplite(4)</a></p>
</section>
<section class="Sh">
<h1 class="Sh" id="HISTORY"><a class="permalink" href="#HISTORY">HISTORY</a></h1>
<p class="Pp">The <code class="Nm">udp</code> protocol appeared in
    <span class="Ux">4.2BSD</span>.</p>
</section>
</div>
<table class="foot">
  <tr>
    <td class="foot-date">January 20, 2025</td>
    <td class="foot-os">FreeBSD 15.0</td>
  </tr>
</table>