summaryrefslogtreecommitdiff
path: root/lib/kernel/doc/src/socket_usage.xml
blob: dfa551426db8fc0cca12d4e38f744bc82d60f6de (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
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
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
<?xml version="1.0" encoding="utf-8" ?>
<!DOCTYPE chapter SYSTEM "chapter.dtd">

<chapter>
  <header>
    <copyright>
      <year>2018</year><year>2023</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>Socket Usage</title>
    <prepared>Micael Karlberg</prepared>
    <docno></docno>
    <date>2018-07-17</date>
    <rev>PA1</rev>
    <file>socket_usage.xml</file>
  </header>

  <section>
    <title>Introduction</title>
    <p>The socket interface (module) is basically a "thin" layer on top of
    the OS socket interface. It is assumed that, unless you have special needs,
    gen_[tcp|udp|sctp] should be sufficient (when they become available). </p>
    <p>Note that just because we have a documented and described option,
    it does <em>not</em> mean that the OS supports it. So its recommended
    that the user reads the platform specific documentation for the
    option used. </p>
    <section>
      <title>Asynchronous calls</title>
      <p>
	Some functions allow for an <i>asynchronous</i> call
	(<seeerl marker="socket#accept-nowait"><c>accept/2</c></seeerl>,
	<seeerl marker="socket#connect-nowait"><c>connect/3</c></seeerl>,
	<seeerl marker="socket#recv-nowait"><c>recv/3,4</c></seeerl>,
	<seeerl marker="socket#recvfrom-nowait"><c>recvfrom/3,4</c></seeerl>,
	<seeerl marker="socket#recvmsg-nowait"><c>recvmsg/2,3,5</c></seeerl>,
	<seeerl marker="socket#send-nowait"><c>send/3,4</c></seeerl>,
	<seeerl marker="socket#sendmsg-nowait"><c>sendmsg/3,4</c></seeerl> and
	<seeerl marker="socket#sendto-nowait"><c>sendto/4,5</c></seeerl>).
	This is achieved by setting the <c>Timeout</c> argument to
	<c>nowait</c>. For instance, if calling the
	<seeerl marker="socket#recv-nowait"><c>recv/3</c></seeerl>
	function with Timeout set to <c>nowait</c> (i.e. 
	<c>recv(Sock, 0, nowait)</c>)
	when there is actually nothing to read, it will return with:
      </p>
      <taglist>
	<tag>On Unix</tag>
	<item>
	  <p>
	    <c>{select, </c>
	    <seetype marker="socket#select_info"><c>SelectInfo</c></seetype><c>}</c>
	  </p>
	  <p>
	    <c>SelectInfo</c> contains the
	    <seetype marker="socket#select_handle"><c>SelectHandle</c></seetype>.
	  </p>
	</item>

	<tag>On Windows</tag>
	<item>
	  <p>
	    <c>{completion, </c>
	    <seetype marker="socket#completion_info"><c>CompletionInfo</c></seetype><c>}</c>
	  </p>
	  <p>
	    <c>CompletionInfo</c> contains the
	    <seetype marker="socket#completion_handle"><c>CompletionHandle</c></seetype>.
	  </p>
	</item>
      </taglist>
      <p>When data eventually arrives a 'select' or 'completion' message
      will be sent to the caller:</p>
      <taglist>
	<tag>On Unix</tag>
	<item>
	  <p>
	    <c>{'$socket', socket(), select, SelectHandle}</c>
	  </p>
	  <p>
	    The caller can then make another
	    call to the recv function and now expect data.
	  </p>
	  <p>
	    Note that all other users are <em>locked out</em> until the
	    'current user' has called the function (recv in this case).
	    So either immediately call the function or
	    <seemfa marker="socket#cancel/2"><c>cancel</c></seemfa>.
	  </p>
	</item>

	<tag>On Windows</tag>
	<item>
	  <p>
	    <c>{'$socket', socket(), completion, {CompletionHandle, CompletionStatus}}</c>
	  </p>
	  <p>
	    The <c>CompletionStatus</c> contains the result of the
	    operation (read).
	  </p>
	</item>
      </taglist>
      <p>The user must also be prepared to receive an abort message: </p>
      <taglist>
	<!-- NOTE THAT THE EMPTY TAG IS INTENTIONAL -->
	<tag></tag>
	<item><c>{'$socket', socket(), abort, Info}</c></item>
      </taglist>
      <p>If the operation is aborted
      for whatever reason (e.g. if the socket is closed "by someone else").
      The <c>Info</c> part contains the abort reason (in this case that
      the socket has been closed <c>Info = {SelectHandle, closed}</c>). </p>

      <p>The general form of the 'socket' message is: </p>
      <taglist>
	<!-- NOTE THAT THE EMPTY TAG IS INTENTIONAL -->
	<tag></tag>
	<item><c>{'$socket', Sock :: socket(), Tag :: atom(), Info :: term()}</c></item>
      </taglist>
      <p>Where the format of <c>Info</c> is a function of <c>Tag</c>:</p>
      <table>
	<row>
	  <cell><em>Tag</em></cell>
	  <cell><em>Info value type</em></cell>
	</row>
	<row>
	  <cell>select</cell>
	  <cell>select_handle()</cell>
	</row>
	<row>
	  <cell>completion</cell>
	  <cell>{completion_handle(), CompletionStatus}</cell>
	</row>
	<row>
	  <cell>abort</cell>
	  <cell>{select_handle(), Reason :: term()}</cell>
	</row>
	<tcaption>socket message info value type</tcaption>
      </table>
      <p>The <c>select_handle()</c> is the same as was returned in the
      <seetype marker="socket#select_info"><c>SelectInfo</c></seetype>. </p>
      <p>The <c>completion_handle()</c> is the same as was returned in the
      <seetype marker="socket#completion_info"><c>CompletionInfo</c></seetype>. </p>
    </section>
  </section>

  <section>
    <title>Socket Registry</title>
    <p>The <em>socket registry</em> is how we keep track of sockets.
    There are two functions that can be used for interaction:
    <seemfa marker="socket#number_of/0"><c>socket:number_of/0</c></seemfa>
    and
    <seemfa marker="socket#which_sockets/1"><c>socket:which_sockets/1</c></seemfa>.
    </p>
    <p>In systems which create and delete <em>many</em> sockets
    dynamically, it (the socket registry) could become a bottleneck.
    For such systems, there are a couple of
    ways to control the use of the socket registry. </p>

    <p>Firstly, its possible to effect the global default value when
    building OTP from source with the two configure options:</p>
    <code type="none">--enable-esock-socket-registry (default) | --disable-esock-socket-registry</code>

    <p>Second, its possible to effect the global default value by
    setting the environment variable <c>ESOCK_USE_SOCKET_REGISTRY</c>
    (boolean) before starting the erlang. </p>

    <p>Third, its possible to alter the global default value in runtime
    by calling the function
    <seemfa marker="socket#use_registry/1"><c>use_registry/1</c></seemfa>.</p>

    <p>And finally, its possible to override the global default when creating
    a socket (with <seemfa marker="socket#open/2"><c>open/2</c></seemfa> and
    <seemfa marker="socket#open/4"><c>open/4</c></seemfa>) by providing
    the attribute <c>use_registry</c> (boolean) in the their <c>Opts</c>
    argument (which effects <em>that</em> specific
    socket).</p>

  </section>

  <section>
    <marker id="socket_options"></marker>
    <title>Socket Options</title>

    <p>Options for level <c>otp</c>: </p>
    <table>
      <row>
	<cell><em>Option Name</em></cell>
	<cell><em>Value Type</em></cell>
	<cell><em>Set</em></cell>
	<cell><em>Get</em></cell>
	<cell><em>Other Requirements and comments</em></cell>
      </row>
      <row>
	<cell>assoc_id</cell>
	<cell>integer()</cell>
	<cell>no</cell>
	<cell>yes</cell>
	<cell>type = seqpacket, protocol = sctp, is an association</cell>
      </row>
      <row>
	<cell>debug</cell>
	<cell>boolean()</cell>
	<cell>yes</cell>
	<cell>yes</cell>
	<cell>none</cell>
      </row>
      <row>
	<cell>iow</cell>
	<cell>boolean()</cell>
	<cell>yes</cell>
	<cell>yes</cell>
	<cell>none</cell>
      </row>
      <row>
	<cell>controlling_process</cell>
	<cell>pid()</cell>
	<cell>yes</cell>
	<cell>yes</cell>
	<cell>none</cell>
      </row>
      <row>
	<cell>rcvbuf</cell>
	<cell>default | pos_integer() | {pos_integer(), pos_ineteger()}</cell>
	<cell>yes</cell>
	<cell>yes</cell>
	<cell>
	  The tuple format is <em>not</em> allowed on Windows.
	  'default' only valid for set.
	  The tuple form is only valid for type 'stream' and protocol 'tcp'.
	</cell>
      </row>
      <row>
	<cell>rcvctrlbuf</cell>
	<cell>default | pos_integer()</cell>
	<cell>yes</cell>
	<cell>yes</cell>
	<cell>default only valid for set</cell>
      </row>
      <row>
	<cell>sndctrlbuf</cell>
	<cell>default | pos_integer()</cell>
	<cell>yes</cell>
	<cell>yes</cell>
	<cell>default only valid for set</cell>
      </row>
      <row>
	<cell>fd</cell>
	<cell>integer()</cell>
	<cell>no</cell>
	<cell>yes</cell>
	<cell>none</cell>
      </row>
      <row>
	<cell>use_registry</cell>
	<cell>boolean()</cell>
	<cell>no</cell>
	<cell>yes</cell>
	<cell>the value is set when the socket is created, by a call to
	<seemfa marker="socket#open/2"><c>open/2</c></seemfa> or
	<seemfa marker="socket#open/4"><c>open/4</c></seemfa>.</cell>
      </row>
      <tcaption>option levels</tcaption>
    </table>
    
    <p>Options for level <c>socket</c>: </p>
    <table>
      <row>
	<cell><em>Option Name</em></cell>
	<cell><em>Value Type</em></cell>
	<cell><em>Set</em></cell>
	<cell><em>Get</em></cell>
	<cell><em>Other Requirements and comments</em></cell>
      </row>
      <row>
	<cell>acceptconn</cell>
	<cell>boolean()</cell>
	<cell>no</cell>
	<cell>yes</cell>
	<cell>none</cell>
      </row>
      <row>
	<cell>bindtodevice</cell>
	<cell>string()</cell>
	<cell>yes</cell>
	<cell>yes</cell>
	<cell>Before Linux 3.8, this socket option could be set, but not get.
	Only works for some socket types (e.g. <c>inet</c>).
	If empty value is set, the binding is removed.</cell>
      </row>
      <row>
	<cell>broadcast</cell>
	<cell>boolean()</cell>
	<cell>yes</cell>
	<cell>yes</cell>
	<cell>type = dgram</cell>
      </row>
      <row>
	<cell>debug</cell>
	<cell>integer()</cell>
	<cell>yes</cell>
	<cell>yes</cell>
	<cell>may require admin capability</cell>
      </row>
      <row>
	<cell>domain</cell>
	<cell>domain()</cell>
	<cell>no</cell>
	<cell>yes</cell>
	<cell><em>Not</em> on FreeBSD (for instance)</cell>
      </row>
      <row>
	<cell>dontroute</cell>
	<cell>boolean()</cell>
	<cell>yes</cell>
	<cell>yes</cell>
	<cell>none</cell>
      </row>
      <row>
	<cell>keepalive</cell>
	<cell>boolean()</cell>
	<cell>yes</cell>
	<cell>yes</cell>
	<cell>none</cell>
      </row>
      <row>
	<cell>linger</cell>
	<cell>abort | linger()</cell>
	<cell>yes</cell>
	<cell>yes</cell>
	<cell>none</cell>
      </row>
      <row>
	<cell>oobinline</cell>
	<cell>boolean()</cell>
	<cell>yes</cell>
	<cell>yes</cell>
	<cell>none</cell>
      </row>
      <row>
	<cell>peek_off</cell>
	<cell>integer()</cell>
	<cell>yes</cell>
	<cell>yes</cell>
	<cell>domain = local (unix).
	Currently disabled due to a possible infinite loop when
	calling recv([peek]) the second time.
	</cell>
      </row>
      <row>
	<cell>priority</cell>
	<cell>integer()</cell>
	<cell>yes</cell>
	<cell>yes</cell>
	<cell>none</cell>
      </row>
      <row>
	<cell>protocol</cell>
	<cell>protocol()</cell>
	<cell>no</cell>
	<cell>yes</cell>
	<cell><em>Not</em> on (some) Darwin (for instance)</cell>
      </row>
      <row>
	<cell>rcvbuf</cell>
	<cell>non_neg_integer()</cell>
	<cell>yes</cell>
	<cell>yes</cell>
	<cell>none</cell>
      </row>
      <row>
	<cell>rcvlowat</cell>
	<cell>non_neg_integer()</cell>
	<cell>yes</cell>
	<cell>yes</cell>
	<cell>none</cell>
      </row>
      <row>
	<cell>rcvtimeo</cell>
	<cell>timeval()</cell>
	<cell>yes</cell>
	<cell>yes</cell>
	<cell>
	  This option is not normally supported (see why below).
	  OTP has to be explicitly built with the
	  <c>--enable-esock-rcvsndtime</c> configure option for this
	  to be available.
	  Since our implementation is <em>nonblocking</em>,
	  its unknown if and how this option works, or even if
	  it may cause malfunctions.
	  Therefore, we do not recommend setting this option.
	  Instead, use the <c>Timeout</c> argument to, for instance,
	  the
	  <seemfa marker="socket#recv/3"><c>recv/3</c></seemfa>
	  function.
	</cell>
      </row>
      <row>
	<cell>reuseaddr</cell>
	<cell>boolean()</cell>
	<cell>yes</cell>
	<cell>yes</cell>
	<cell>none</cell>
      </row>
      <row>
	<cell>reuseport</cell>
	<cell>boolean()</cell>
	<cell>yes</cell>
	<cell>yes</cell>
	<cell>domain = inet | inet6</cell>
      </row>
      <row>
	<cell>sndbuf</cell>
	<cell>non_neg_integer()</cell>
	<cell>yes</cell>
	<cell>yes</cell>
	<cell>none</cell>
      </row>
      <row>
	<cell>sndlowat</cell>
	<cell>non_neg_integer()</cell>
	<cell>yes</cell>
	<cell>yes</cell>
	<cell>not changeable on Linux</cell>
      </row>
      <row>
	<cell>sndtimeo</cell>
	<cell>timeval()</cell>
	<cell>yes</cell>
	<cell>yes</cell>
	<cell>
	  This option is not normally supported (see why below).
	  OTP has to be explicitly built with the
	  <c>--enable-esock-rcvsndtime</c> configure option for this
	  to be available.
	  Since our implementation is <em>nonblocking</em>,
	  its unknown if and how this option works, or even if
	  it may cause malfunctions.
	  Therefore, we do not recommend setting this option.
	  Instead, use the <c>Timeout</c> argument to, for instance,
	  the
	  <seemfa marker="socket#send/3"><c>send/3</c></seemfa>
	  function.
	</cell>
      </row>
      <row>
	<cell>timestamp</cell>
	<cell>boolean()</cell>
	<cell>yes</cell>
	<cell>yes</cell>
	<cell>none</cell>
      </row>
      <row>
	<cell>type</cell>
	<cell>type()</cell>
	<cell>no</cell>
	<cell>yes</cell>
	<cell>none</cell>
      </row>
      <tcaption>socket options</tcaption>
    </table>
    
    <p>Options for level <c>ip</c>: </p>
    <table>
      <row>
	<cell><em>Option Name</em></cell>
	<cell><em>Value Type</em></cell>
	<cell><em>Set</em></cell>
	<cell><em>Get</em></cell>
	<cell><em>Other Requirements and comments</em></cell>
      </row>
      <row>
	<cell>add_membership</cell>
	<cell>ip_mreq()</cell>
	<cell>yes</cell>
	<cell>no</cell>
	<cell>none</cell>
      </row>
      <row>
	<cell>add_source_membership</cell>
	<cell>ip_mreq_source()</cell>
	<cell>yes</cell>
	<cell>no</cell>
	<cell>none</cell>
      </row>
      <row>
	<cell>block_source</cell>
	<cell>ip_mreq_source()</cell>
	<cell>yes</cell>
	<cell>no</cell>
	<cell>none</cell>
      </row>
      <row>
	<cell>drop_membership</cell>
	<cell>ip_mreq()</cell>
	<cell>yes</cell>
	<cell>no</cell>
	<cell>none</cell>
      </row>
      <row>
	<cell>drop_source_membership</cell>
	<cell>ip_mreq_source()</cell>
	<cell>yes</cell>
	<cell>no</cell>
	<cell>none</cell>
      </row>
      <row>
	<cell>freebind</cell>
	<cell>boolean()</cell>
	<cell>yes</cell>
	<cell>yes</cell>
	<cell>none</cell>
      </row>
      <row>
	<cell>hdrincl</cell>
	<cell>boolean()</cell>
	<cell>yes</cell>
	<cell>yes</cell>
	<cell>type = raw</cell>
      </row>
      <row>
	<cell>minttl</cell>
	<cell>integer()</cell>
	<cell>yes</cell>
	<cell>yes</cell>
	<cell>type = raw</cell>
      </row>
      <row>
	<cell>msfilter</cell>
	<cell>null | ip_msfilter()</cell>
	<cell>yes</cell>
	<cell>no</cell>
	<cell>none</cell>
      </row>
      <row>
	<cell>mtu</cell>
	<cell>integer()</cell>
	<cell>no</cell>
	<cell>yes</cell>
	<cell>type = raw</cell>
      </row>
      <row>
	<cell>mtu_discover</cell>
	<cell>ip_pmtudisc()</cell>
	<cell>yes</cell>
	<cell>yes</cell>
	<cell>none</cell>
      </row>
      <row>
	<cell>multicast_all</cell>
	<cell>boolean()</cell>
	<cell>yes</cell>
	<cell>yes</cell>
	<cell>none</cell>
      </row>
      <row>
	<cell>multicast_if</cell>
	<cell>any | ip4_address()</cell>
	<cell>yes</cell>
	<cell>yes</cell>
	<cell>none</cell>
      </row>
      <row>
	<cell>multicast_loop</cell>
	<cell>boolean()</cell>
	<cell>yes</cell>
	<cell>yes</cell>
	<cell>none</cell>
      </row>
      <row>
	<cell>multicast_ttl</cell>
	<cell>uint8()</cell>
	<cell>yes</cell>
	<cell>yes</cell>
	<cell>none</cell>
      </row>
      <row>
	<cell>nodefrag</cell>
	<cell>boolean()</cell>
	<cell>yes</cell>
	<cell>yes</cell>
	<cell>type = raw</cell>
      </row>
      <row>
	<cell>pktinfo</cell>
	<cell>boolean()</cell>
	<cell>yes</cell>
	<cell>yes</cell>
	<cell>type = dgram</cell>
      </row>
      <row>
	<cell>recvdstaddr</cell>
	<cell>boolean()</cell>
	<cell>yes</cell>
	<cell>yes</cell>
	<cell>type = dgram</cell>
      </row>
      <row>
	<cell>recverr</cell>
	<cell>boolean()</cell>
	<cell>yes</cell>
	<cell>yes</cell>
	<cell>none</cell>
      </row>
      <row>
	<cell>recvif</cell>
	<cell>boolean()</cell>
	<cell>yes</cell>
	<cell>yes</cell>
	<cell>type = dgram | raw</cell>
      </row>
      <row>
	<cell>recvopts</cell>
	<cell>boolean()</cell>
	<cell>yes</cell>
	<cell>yes</cell>
	<cell>type =/= stream</cell>
      </row>
      <row>
	<cell>recvorigdstaddr</cell>
	<cell>boolean()</cell>
	<cell>yes</cell>
	<cell>yes</cell>
	<cell>none</cell>
      </row>
      <row>
	<cell>recvttl</cell>
	<cell>boolean()</cell>
	<cell>yes</cell>
	<cell>yes</cell>
	<cell>type =/= stream</cell>
      </row>
      <row>
	<cell>retopts</cell>
	<cell>boolean()</cell>
	<cell>yes</cell>
	<cell>yes</cell>
	<cell>type =/= stream</cell>
      </row>
      <row>
	<cell>router_alert</cell>
	<cell>integer()</cell>
	<cell>yes</cell>
	<cell>yes</cell>
	<cell>type = raw</cell>
      </row>
      <row>
	<cell>sendsrcaddr</cell>
	<cell>boolean()</cell>
	<cell>yes</cell>
	<cell>yes</cell>
	<cell>none</cell>
      </row>
      <row>
	<cell>tos</cell>
	<cell>ip_tos()</cell>
	<cell>yes</cell>
	<cell>yes</cell>
	<cell>some high-priority levels may require superuser capability</cell>
      </row>
      <row>
	<cell>transparent</cell>
	<cell>boolean()</cell>
	<cell>yes</cell>
	<cell>yes</cell>
	<cell>requires admin capability</cell>
      </row>
      <row>
	<cell>ttl</cell>
	<cell>integer()</cell>
	<cell>yes</cell>
	<cell>yes</cell>
	<cell>none</cell>
      </row>
      <row>
	<cell>unblock_source</cell>
	<cell>ip_mreq_source()</cell>
	<cell>yes</cell>
	<cell>no</cell>
	<cell>none</cell>
      </row>
      <tcaption>ip options</tcaption>
    </table>
    
    <p>Options for level <c>ipv6</c>: </p>
    <table>
      <row>
	<cell><em>Option Name</em></cell>
	<cell><em>Value Type</em></cell>
	<cell><em>Set</em></cell>
	<cell><em>Get</em></cell>
	<cell><em>Other Requirements and comments</em></cell>
      </row>
      <row>
	<cell>addrform</cell>
	<cell>inet</cell>
	<cell>yes</cell>
	<cell>no</cell>
	<cell>allowed only for IPv6 sockets that are connected and bound to a
	v4-mapped-on-v6 address</cell>
      </row>
      <row>
	<cell>add_membership</cell>
	<cell>ipv6_mreq()</cell>
	<cell>yes</cell>
	<cell>no</cell>
	<cell>none</cell>
      </row>
      <row>
	<cell>authhdr</cell>
	<cell>boolean()</cell>
	<cell>yes</cell>
	<cell>yes</cell>
	<cell>type = dgram | raw, obsolete?</cell>
      </row>
      <row>
	<cell>drop_membership</cell>
	<cell>ipv6_mreq()</cell>
	<cell>yes</cell>
	<cell>no</cell>
	<cell>none</cell>
      </row>
      <row>
	<cell>dstopts</cell>
	<cell>boolean()</cell>
	<cell>yes</cell>
	<cell>yes</cell>
	<cell>type = dgram | raw, requires superuser privileges to update</cell>
      </row>
      <row>
	<cell>flowinfo</cell>
	<cell>boolean()</cell>
	<cell>yes</cell>
	<cell>yes</cell>
	<cell>type = dgram | raw, requires superuser privileges to update</cell>
      </row>
      <row>
	<cell>hoplimit</cell>
	<cell>boolean()</cell>
	<cell>yes</cell>
	<cell>yes</cell>
	<cell>type = dgram | raw.
	On some platforms (e.g. FreeBSD) is used to set in order to
	get <c>hoplimit</c> as a control message heeader.
	On others (e.g. Linux), <c>recvhoplimit</c> is set in order to get
	<c>hoplimit</c>. </cell>
      </row>
      <row>
	<cell>hopopts</cell>
	<cell>boolean()</cell>
	<cell>yes</cell>
	<cell>yes</cell>
	<cell>type = dgram | raw, requires superuser privileges to update</cell>
      </row>
      <row>
	<cell>mtu</cell>
	<cell>boolean()</cell>
	<cell>yes</cell>
	<cell>yes</cell>
	<cell>Get: Only after the socket has been connected</cell>
      </row>
      <row>
	<cell>mtu_discover</cell>
	<cell>ipv6_pmtudisc()</cell>
	<cell>yes</cell>
	<cell>yes</cell>
	<cell>none</cell>
      </row>
      <row>
	<cell>multicast_hops</cell>
	<cell>default | uint8()</cell>
	<cell>yes</cell>
	<cell>yes</cell>
	<cell>none</cell>
      </row>
      <row>
	<cell>multicast_if</cell>
	<cell>integer()</cell>
	<cell>yes</cell>
	<cell>yes</cell>
	<cell>type = dgram | raw</cell>
      </row>
      <row>
	<cell>multicast_loop</cell>
	<cell>boolean()</cell>
	<cell>yes</cell>
	<cell>yes</cell>
	<cell>none</cell>
      </row>
      <row>
	<cell>recverr</cell>
	<cell>boolean()</cell>
	<cell>yes</cell>
	<cell>yes</cell>
	<cell>none</cell>
      </row>
      <row>
	<cell>recvhoplimit</cell>
	<cell>boolean()</cell>
	<cell>yes</cell>
	<cell>yes</cell>
	<cell>type = dgram | raw.
	On some platforms (e.g. Linux), <c>recvhoplimit</c>
	is set in order to get <c>hoplimit</c></cell>
      </row>
      <row>
	<cell>recvpktinfo | pktinfo</cell>
	<cell>boolean()</cell>
	<cell>yes</cell>
	<cell>yes</cell>
	<cell>type = dgram | raw.
	On some platforms (e.g. FreeBSD) is used to set in order to
	get <c>hoplimit</c> as a control message heeader.
	On others (e.g. Linux), <c>recvhoplimit</c> is set in order to get
	<c>hoplimit</c>. </cell>
      </row>
      <row>
	<cell>recvtclass</cell>
	<cell>boolean()</cell>
	<cell>yes</cell>
	<cell>yes</cell>
	<cell>type = dgram | raw.
	On some platforms is used to set (=true) in order to
	get the <c>tclass</c> control message heeader.
	On others, <c>tclass</c> is set in order to get
	<c>tclass</c> control message heeader. </cell>
      </row>
      <row>
	<cell>router_alert</cell>
	<cell>integer()</cell>
	<cell>yes</cell>
	<cell>yes</cell>
	<cell>type = raw</cell>
      </row>
      <row>
	<cell>rthdr</cell>
	<cell>boolean()</cell>
	<cell>yes</cell>
	<cell>yes</cell>
	<cell>type = dgram | raw, requires superuser privileges to update</cell>
      </row>
      <row>
	<cell>tclass</cell>
	<cell>integer()</cell>
	<cell>yes</cell>
	<cell>yes</cell>
	<cell>Set the traffic class associated with outgoing packets.
	RFC3542. </cell>
      </row>
      <row>
	<cell>unicast_hops</cell>
	<cell>default | uint8()</cell>
	<cell>yes</cell>
	<cell>yes</cell>
	<cell>none</cell>
      </row>
      <row>
	<cell>v6only</cell>
	<cell>boolean()</cell>
	<cell>yes</cell>
	<cell>no</cell>
	<cell>none</cell>
      </row>
      <tcaption>ipv6 options</tcaption>
    </table>
    
    <p>Options for level <c>tcp</c>: </p>
    <table>
      <row>
	<cell><em>Option Name</em></cell>
	<cell><em>Value Type</em></cell>
	<cell><em>Set</em></cell>
	<cell><em>Get</em></cell>
	<cell><em>Other Requirements and comments</em></cell>
      </row>
      <row>
	<cell>congestion</cell>
	<cell>string()</cell>
	<cell>yes</cell>
	<cell>yes</cell>
	<cell>none</cell>
      </row>
      <row>
	<cell>maxseg</cell>
	<cell>integer()</cell>
	<cell>yes</cell>
	<cell>yes</cell>
	<cell>Set not allowed on all platforms.</cell>
      </row>
      <row>
	<cell>nodelay</cell>
	<cell>boolean()</cell>
	<cell>yes</cell>
	<cell>yes</cell>
	<cell>none</cell>
      </row>
      <tcaption>tcp options</tcaption>
    </table>
    
    <p>Options for level <c>udp</c>: </p>
    <table>
      <row>
	<cell><em>Option Name</em></cell>
	<cell><em>Value Type</em></cell>
	<cell><em>Set</em></cell>
	<cell><em>Get</em></cell>
	<cell><em>Other Requirements and comments</em></cell>
      </row>
      <row>
	<cell>cork</cell>
	<cell>boolean()</cell>
	<cell>yes</cell>
	<cell>yes</cell>
	<cell>none</cell>
      </row>
      <tcaption>udp options</tcaption>
    </table>
    
    <p>Options for level <c>sctp</c>: </p>
    <table>
      <row>
	<cell><em>Option Name</em></cell>
	<cell><em>Value Type</em></cell>
	<cell><em>Set</em></cell>
	<cell><em>Get</em></cell>
	<cell><em>Other Requirements and comments</em></cell>
      </row>
      <row>
	<cell>associnfo</cell>
	<cell>sctp_assocparams()</cell>
	<cell>yes</cell>
	<cell>yes</cell>
	<cell>none</cell>
      </row>
      <row>
	<cell>autoclose</cell>
	<cell>non_neg_integer()</cell>
	<cell>yes</cell>
	<cell>yes</cell>
	<cell>none</cell>
      </row>
      <row>
	<cell>disable_fragments</cell>
	<cell>boolean()</cell>
	<cell>yes</cell>
	<cell>yes</cell>
	<cell>none</cell>
      </row>
      <row>
	<cell>events</cell>
	<cell>sctp_event_subscribe()</cell>
	<cell>yes</cell>
	<cell>no</cell>
	<cell>none</cell>
      </row>
      <row>
	<cell>initmsg</cell>
	<cell>sctp_initmsg()</cell>
	<cell>yes</cell>
	<cell>yes</cell>
	<cell>none</cell>
      </row>
      <row>
	<cell>maxseg</cell>
	<cell>non_neg_integer()</cell>
	<cell>yes</cell>
	<cell>yes</cell>
	<cell>none</cell>
      </row>
      <row>
	<cell>nodelay</cell>
	<cell>boolean()</cell>
	<cell>yes</cell>
	<cell>yes</cell>
	<cell>none</cell>
      </row>
      <row>
	<cell>rtoinfo</cell>
	<cell>sctp_rtoinfo()</cell>
	<cell>yes</cell>
	<cell>yes</cell>
	<cell>none</cell>
      </row>
      <tcaption>sctp options</tcaption>
    </table>
    
  </section>
</chapter>