aboutsummaryrefslogtreecommitdiffstats
path: root/lib/kernel/doc/src/gen_udp.xml
blob: 1f428ce16f989324d657a15af015f7b451c4e192 (plain) (blame)
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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
<?xml version="1.0" encoding="utf-8" ?>
<!DOCTYPE erlref SYSTEM "erlref.dtd">

<erlref>
  <header>
    <copyright>
      <year>1997</year><year>2016</year>
      <holder>Ericsson AB. All Rights Reserved.</holder>
    </copyright>
    <legalnotice>
      Licensed under the Apache License, Version 2.0 (the "License");
      you may not use this file except in compliance with the License.
      You may obtain a copy of the License at
 
          http://www.apache.org/licenses/LICENSE-2.0

      Unless required by applicable law or agreed to in writing, software
      distributed under the License is distributed on an "AS IS" BASIS,
      WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
      See the License for the specific language governing permissions and
      limitations under the License.
    
    </legalnotice>

    <title>gen_udp</title>
    <prepared>[email protected]</prepared>
    <docno></docno>
    <date>1997-12-03</date>
    <rev>A</rev>
  </header>
  <module>gen_udp</module>
  <modulesummary>Interface to UDP sockets</modulesummary>
  <description>
    <p>The <c>gen_udp</c> module provides functions for communicating
      with sockets using the UDP protocol.</p>
  </description>

  <datatypes>
    <datatype>
      <name name="option"/>
    </datatype>
    <datatype>
      <name name="option_name"/>
    </datatype>
    <datatype>
      <name>socket()</name>
      <desc>
        <p><marker id="type-socket"/>As returned by open/1,2.</p>
      </desc>
    </datatype>
  </datatypes>

  <funcs>
    <func>
      <name name="open" arity="1"/>
      <name name="open" arity="2"/>
      <fsummary>Associate a UDP port number with the process calling it</fsummary>
      <desc>
        <p>Associates a UDP port number (<c><anno>Port</anno></c>) with the calling
          process.</p>
        <p>The available options are:</p>
        <taglist>
          <tag><c>list</c></tag>
          <item>
            <p>Received <c>Packet</c> is delivered as a list.</p>
          </item>
          <tag><c>binary</c></tag>
          <item>
            <p>Received <c>Packet</c> is delivered as a binary.</p>
          </item>
          <tag><c>{ip, ip_address()}</c></tag>
          <item>
            <p>If the host has several network interfaces, this option
              specifies which one to use.</p>
          </item>

		  <tag><c>{ifaddr, ip_address()}</c></tag>
          <item>
			  <p>Same as <c>{ip, ip_address()}</c>. If the host has several network interfaces, this option
              specifies which one to use.</p>
		  </item>


          <tag><c>{fd, integer() >= 0}</c></tag>
          <item>
            <p>If a socket has somehow been opened without using
              <c>gen_udp</c>, use this option to pass the file
              descriptor for it. If <c><anno>Port</anno></c> is not set to 0
              and/or <c>{ip, ip_address()}</c> is combined with this option
              the fd will be bound to the given interface and port after being
              opened. If these options are not given it is assumed that the fd
              is already bound appropriately.
            </p>
          </item>
          <tag><c>inet6</c></tag>
          <item>
            <p>Set up the socket for IPv6.</p>
          </item>
          <tag><c>inet</c></tag>
          <item>
            <p>Set up the socket for IPv4.</p>
          </item>

		  <tag><c>{udp_module, module()}</c></tag>
		  <item> <p>
				  Override which callback module is used. Defaults to
				  <c>inet_udp</c> for IPv4 and <c>inet6_udp</c> for IPv6.
			  </p>
		  </item>

          <tag><c>{multicast_if, Address}</c></tag>
          <item>
			  <p>Set the local device for a multicast socket.</p>
          </item>
 
          <tag><c>{multicast_loop, true | false}</c></tag>
          <item>
			  <p>
				  When <c>true</c> sent multicast packets will be looped back to the local
				  sockets.
			  </p>
          </item>

          <tag><c>{multicast_ttl, Integer}</c></tag>
          <item>
			  <p>
				  The <c>multicast_ttl</c> option changes the time-to-live (TTL) for
				  outgoing multicast datagrams in order to control the scope of the 
				  multicasts.
			  </p>
			  <p>
				  Datagrams with a TTL of 1 are not forwarded beyond the local
				  network.
				  <br />Default: 1
			  </p>
          </item>

		  <tag><c>{add_membership, {MultiAddress, InterfaceAddress}}</c></tag>
          <item>
			  <p>Join a multicast group. </p>
          </item>

		  <tag><c>{drop_membership, {MultiAddress, InterfaceAddress}}</c></tag>
          <item>
			  <p>Leave multicast group.</p>
          </item>

          <tag><c>Opt</c></tag>
          <item>
            <p>See
              <seealso marker="inet#setopts/2">inet:setopts/2</seealso>.</p>
          </item>
        </taglist>
        <p>The returned socket <c><anno>Socket</anno></c> is used to send
          packets from this port with <c>send/4</c>. When UDP packets arrive
          at the opened port, if the socket is in an active mode the packets
          are delivered as messages to the controlling process:</p>
        <code type="none">
{udp, Socket, IP, InPortNo, Packet}</code>
        <p>If the socket is not in an active mode, data can be
          retrieved via the <seealso marker="#recv/2">recv/2,3</seealso> calls.
          Note that arriving UDP packets that are longer than
          the receive buffer option specifies, might be truncated
          without warning.</p>
        <p>When a socket in <c>{active, N}</c> mode (see <seealso marker="inet#setopts/2">
          inet:setopts/2</seealso> for details) transitions to passive
          (<c>{active, false}</c>) mode, the controlling process is notified by a
          message of the following form:</p>
        <code type="none">
{udp_passive, Socket}</code>
        <p><c>IP</c> and <c>InPortNo</c> define the address from which
          <c>Packet</c> came. <c>Packet</c> is a list of bytes if
          the option <c>list</c> was specified. <c>Packet</c> is a
          binary if the option <c>binary</c> was specified.</p>
        <p>Default value for the receive buffer option is
          <c>{recbuf, 8192}</c>.</p>
        <p>If <c><anno>Port</anno> == 0</c>, the underlying OS assigns a free UDP
          port, use <c>inet:port/1</c> to retrieve it.</p>
      </desc>
    </func>
    <func>
      <name name="send" arity="4"/>
      <fsummary>Send a packet</fsummary>
      <desc>
        <p>Sends a packet to the specified address and port.
          The <c><anno>Address</anno></c> argument can be either a hostname, or an
          IP address.</p>
      </desc>
    </func>
    <func>
      <name name="recv" arity="2"/>
      <name name="recv" arity="3"/>
      <fsummary>Receive a packet from a passive socket</fsummary>
      <desc>
        <p>This function receives a packet from a socket in passive
          mode.</p>
        <p>The optional <c><anno>Timeout</anno></c> parameter specifies a timeout in
          milliseconds. The default value is <c>infinity</c>.</p>
      </desc>
    </func>
    <func>
      <name name="controlling_process" arity="2"/>
      <fsummary>Change controlling process of a socket</fsummary>
      <desc>
        <p>Assigns a new controlling process <c><anno>Pid</anno></c> to
          <c><anno>Socket</anno></c>. The controlling process is the process which
          receives messages from the socket. If called by any other
          process than the current controlling process,
          <c>{error, not_owner}</c> is returned.</p>
      </desc>
    </func>
    <func>
      <name name="close" arity="1"/>
      <fsummary>Close a UDP socket</fsummary>
      <desc>
        <p>Closes a UDP socket.</p>
      </desc>
    </func>
  </funcs>
</erlref>