[go: up one dir, main page]

File: xioopts.c

package info (click to toggle)
socat 1.4.3.1-1
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 2,192 kB
  • ctags: 3,709
  • sloc: ansic: 19,348; sh: 3,435; makefile: 154
file content (3080 lines) | stat: -rwxr-xr-x 85,251 bytes parent folder | download
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
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
/* $Id: xioopts.c,v 1.76 2005/09/04 09:43:28 gerhard Exp $ */
/* Copyright Gerhard Rieger 2001-2005 */
/* Published under the GNU General Public License V.2, see file COPYING */

/* this file contains the source for address options handling */

#include "xiosysincludes.h"
#include "xioopen.h"

#include "xiomodes.h"
#include "xiolockfile.h"

bool xioopts_ignoregroups;

#define IF_ANY(a,b) {a,b},

#if WITH_NAMED
#  define IF_NAMED(a,b) {a,b},
#else
#  define IF_NAMED(a,b) 
#endif

#if WITH_PIPE || WITH_GOPEN
#  define IF_OPEN(a,b) {a,b},
#else
#  define IF_OPEN(a,b) 
#endif

#if WITH_TERMIOS
#  define IF_TERMIOS(a,b) {a,b},
#else
#  define IF_TERMIOS(a,b) 
#endif

#if WITH_EXEC
#  define IF_EXEC(a,b) {a,b},
#else
#  define IF_EXEC(a,b) 
#endif

#if WITH_SOCKET
#  define IF_SOCKET(a,b) {a,b},
#else
#  define IF_SOCKET(a,b) 
#endif

#if WITH_LISTEN
#  define IF_LISTEN(a,b) {a,b},
#else
#  define IF_LISTEN(a,b) 
#endif

#if (WITH_UDP || WITH_TCP) && WITH_LISTEN
#  define IF_RANGE(a,b) {a,b},
#else
#  define IF_RANGE(a,b)
#endif

#if WITH_IP4 || WITH_IP6
#  define IF_IP(a,b) {a,b},
#else
#  define IF_IP(a,b) 
#endif

#if WITH_TCP|WITH_UDP
#  define IF_IPAPP(a,b) {a,b},
#else
#  define IF_IPAPP(a,b) 
#endif

#if WITH_TCP
#  define IF_TCP(a,b) {a,b},
#else
#  define IF_TCP(a,b) 
#endif

#if WITH_SOCKS4
#  define IF_SOCKS4(a,b) {a,b},
#else
#  define IF_SOCKS4(a,b) 
#endif

#if WITH_PROXY
#  define IF_PROXY(a,b) {a,b},
#else
#  define IF_PROXY(a,b) 
#endif

#if WITH_READLINE
#  define IF_READLINE(a,b) {a,b},
#else
#  define IF_READLINE(a,b)
#endif

#if WITH_PTY
#  define IF_PTY(a,b) {a,b},
#else
#  define IF_PTY(a,b)
#endif

#if WITH_OPENSSL
#  define IF_OPENSSL(a,b) {a,b},
#else
#  define IF_OPENSSL(a,b)
#endif

#if WITH_RETRY
#  define IF_RETRY(a,b) {a,b},
#else
#  define IF_RETRY(a,b) 
#endif


/* address options - keep this array strictly alphabetically sorted for
   binary search! */
/* NULL terminated */
const struct optname optionnames[] = {
#ifdef TCP_ABORT_THRESHOLD  /* HP_UX */
	IF_TCP    ("abort-threshold",	&opt_tcp_abort_threshold)
#endif
#ifdef SO_ACCEPTCONN /* AIX433 */
	IF_SOCKET ("acceptconn",	&opt_so_acceptconn)
#endif /* SO_ACCEPTCONN */
	IF_ANY    ("append",	&opt_append)
#ifdef O_ASYNC
	IF_ANY    ("async",	&opt_async)
#endif
#ifdef SO_ATTACH_FILTER
	IF_SOCKET ("attach-filter",	&opt_so_attach_filter)
	IF_SOCKET ("attachfilter",	&opt_so_attach_filter)
#endif
#ifdef SO_AUDIT	/* AIX 4.3.3 */
	IF_SOCKET ("audit",	&opt_so_audit)
#endif /* SO_AUDIT */
#ifdef CBAUD
	IF_TERMIOS("b0",	&opt_b0)
#ifdef B1000000
	IF_TERMIOS("b1000000",	&opt_b1000000)
#endif
	IF_TERMIOS("b110",	&opt_b110)
#ifdef B115200
	IF_TERMIOS("b115200",	&opt_b115200)
#endif
#ifdef B1152000
	IF_TERMIOS("b1152000",	&opt_b1152000)
#endif
	IF_TERMIOS("b1200",	&opt_b1200)
	IF_TERMIOS("b134",	&opt_b134)
	IF_TERMIOS("b150",	&opt_b150)
#ifdef B1500000
	IF_TERMIOS("b1500000",	&opt_b1500000)
#endif
	IF_TERMIOS("b1800",	&opt_b1800)
	IF_TERMIOS("b19200",	&opt_b19200)
	IF_TERMIOS("b200",	&opt_b200)
#ifdef B2000000
	IF_TERMIOS("b2000000",	&opt_b2000000)
#endif
#ifdef B230400
	IF_TERMIOS("b230400",	&opt_b230400)
#endif
	IF_TERMIOS("b2400",	&opt_b2400)
#ifdef B2500000
	IF_TERMIOS("b2500000",	&opt_b2500000)
#endif
	IF_TERMIOS("b300",	&opt_b300)
#ifdef B3000000
	IF_TERMIOS("b3000000",	&opt_b3000000)
#endif
#ifdef B3500000
	IF_TERMIOS("b3500000",	&opt_b3500000)
#endif
#ifdef B3600	/* HP-UX */
	IF_TERMIOS("b3600",	&opt_b3600)
#endif
	IF_TERMIOS("b38400",	&opt_b38400)
#ifdef B4000000
	IF_TERMIOS("b4000000",	&opt_b4000000)
#endif
#ifdef B460800
	IF_TERMIOS("b460800",	&opt_b460800)
#endif
	IF_TERMIOS("b4800",	&opt_b4800)
	IF_TERMIOS("b50",	&opt_b50)
#ifdef B500000
	IF_TERMIOS("b500000",	&opt_b500000)
#endif
#ifdef B57600
	IF_TERMIOS("b57600",	&opt_b57600)
#endif
#ifdef B576000
	IF_TERMIOS("b576000",	&opt_b576000)
#endif
	IF_TERMIOS("b600",	&opt_b600)
#ifdef B7200	/* HP-UX */
	IF_TERMIOS("b7200",	&opt_b7200)
#endif
	IF_TERMIOS("b75",	&opt_b75)
#ifdef B900	/* HP-UX */
	IF_TERMIOS("b900",	&opt_b900)
#endif
#ifdef B921600
	IF_TERMIOS("b921600",	&opt_b921600)
#endif
	IF_TERMIOS("b9600",	&opt_b9600)
#endif /* defined(CBAUD) */
	IF_LISTEN ("backlog",	&opt_backlog)
#ifdef O_BINARY
	IF_OPEN   ("bin",		&opt_o_binary)
	IF_OPEN   ("binary",		&opt_o_binary)
#endif
	IF_SOCKET ("bind",	&opt_bind)
#ifdef SO_BINDTODEVICE
	IF_SOCKET ("bindtodevice",	&opt_so_bindtodevice)
#endif
	IF_TERMIOS("brkint",	&opt_brkint)
	IF_SOCKET ("broadcast",	&opt_so_broadcast)
#ifdef BSDLY
#  ifdef BS0
	IF_TERMIOS("bs0",	&opt_bs0)
#  endif
#  ifdef BS1
	IF_TERMIOS("bs1",	&opt_bs1)
#  endif
#endif
#ifdef SO_BSDCOMPAT
	IF_SOCKET ("bsdcompat",	&opt_so_bsdcompat)
#endif
#ifdef BSDLY
	IF_TERMIOS("bsdly",	&opt_bsdly)
#endif
	IF_ANY    ("bytes",     &opt_readbytes)
	IF_OPENSSL("cafile",	&opt_openssl_cafile)
	IF_OPENSSL("capath",	&opt_openssl_capath)
	IF_OPENSSL("cert",	&opt_openssl_certificate)
	IF_OPENSSL("certificate",	&opt_openssl_certificate)
	IF_ANY    ("chroot",	&opt_chroot)
	IF_ANY    ("chroot-early",	&opt_chroot_early)
	/*IF_TERMIOS("cibaud",	&opt_cibaud)*/
	IF_OPENSSL("cipher",	&opt_openssl_cipherlist)
	IF_OPENSSL("cipherlist",	&opt_openssl_cipherlist)
	IF_OPENSSL("ciphers",	&opt_openssl_cipherlist)
#ifdef SO_CKSUMRECV
	IF_SOCKET ("cksumrecv",	&opt_so_cksumrecv)
#endif /* SO_CKSUMRECV */
	/*IF_NAMED  ("cleanup",	&opt_cleanup)*/
	IF_TERMIOS("clocal",	&opt_clocal)
	IF_ANY    ("cloexec",	&opt_cloexec)
#ifdef TCP_CONN_ABORT_THRESHOLD  /* HP_UX */
	IF_TCP    ("conn-abort-threshold",	&opt_tcp_conn_abort_threshold)
#endif
	IF_SOCKET ("connect-timeout",	&opt_connect_timeout)
#ifdef TCP_CORK
	IF_TCP    ("cork",	&opt_tcp_cork)
#endif
	IF_ANY    ("cr",        &opt_cr)
#ifdef CRDLY
#  ifdef CR0
	IF_TERMIOS("cr0",	&opt_cr0)
#  endif
#  ifdef CR1
	IF_TERMIOS("cr1",	&opt_cr1)
#  endif
#  ifdef CR2
	IF_TERMIOS("cr2",	&opt_cr2)
#  endif
#  ifdef CR3
	IF_TERMIOS("cr3",	&opt_cr3)
#  endif
	IF_TERMIOS("crdly",	&opt_crdly)
#endif /* defined(CRDLY) */
	IF_TERMIOS("cread",	&opt_cread)
	IF_OPEN   ("creat",	&opt_o_create)
	IF_OPEN   ("create",	&opt_o_create)
	IF_ANY    ("crlf",      &opt_crnl)
	IF_ANY    ("crnl",      &opt_crnl)
	IF_TERMIOS("crterase",	&opt_echoe)
	IF_TERMIOS("crtkill",	&opt_echoke)
#ifdef CRTSCTS
	IF_TERMIOS("crtscts",	&opt_crtscts)
#endif
	IF_TERMIOS("cs5",	&opt_cs5)
	IF_TERMIOS("cs6",	&opt_cs6)
	IF_TERMIOS("cs7",	&opt_cs7)
	IF_TERMIOS("cs8",	&opt_cs8)
	IF_TERMIOS("csize",	&opt_csize)
	IF_TERMIOS("cstopb",	&opt_cstopb)
	IF_TERMIOS("ctlecho",	&opt_echoctl)
	IF_TERMIOS("ctty",	&opt_tiocsctty)
	IF_EXEC   ("dash",	&opt_dash)
	IF_SOCKET ("debug",	&opt_so_debug)
#ifdef O_DEFER
	IF_OPEN   ("defer",	&opt_o_defer)
#endif
#ifdef TCP_DEFER_ACCEPT	/* Linux 2.4.0 */
	IF_TCP    ("defer-accept",	&opt_tcp_defer_accept)
#endif
#ifdef O_DELAY
	IF_OPEN   ("delay",	&opt_o_delay)
#endif
	IF_NAMED  ("delete",	&opt_unlink)
#ifdef SO_DETACH_FILTER
	IF_SOCKET ("detach-filter", &opt_so_detach_filter)
	IF_SOCKET ("detachfilter",  &opt_so_detach_filter)
#endif
#ifdef SO_DGRAM_ERRIND
	IF_SOCKET ("dgram-errind",	&opt_so_dgram_errind)
	IF_SOCKET ("dgramerrind",	&opt_so_dgram_errind)
#endif
	IF_OPENSSL("dh",	&opt_openssl_dhparam)
	IF_OPENSSL("dhparam",	&opt_openssl_dhparam)
#ifdef O_DIRECT
	IF_OPEN   ("direct",	&opt_o_direct)
#endif
#ifdef O_DIRECTORY
	IF_OPEN   ("directory",	&opt_o_directory)
#endif
#ifdef VDISCARD
	IF_TERMIOS("discard",	&opt_vdiscard)
#endif
#ifdef SO_DONTLINGER
	IF_SOCKET ("dontlinger",	&opt_so_dontlinger)
#endif
	IF_SOCKET ("dontroute",	&opt_so_dontroute)
#ifdef VDSUSP	/* HP-UX */
	IF_TERMIOS("dsusp",	&opt_vdsusp)
#endif
#ifdef O_DSYNC
	IF_OPEN   ("dsync",	&opt_o_dsync)
#endif
	IF_TERMIOS("echo",	&opt_echo)
	IF_TERMIOS("echoctl",	&opt_echoctl)
	IF_TERMIOS("echoe",	&opt_echoe)
	IF_TERMIOS("echok",	&opt_echok)
	IF_TERMIOS("echoke",	&opt_echoke)
	IF_TERMIOS("echonl",	&opt_echonl)
#ifdef ECHOPRT
	IF_TERMIOS("echoprt",	&opt_echoprt)
#endif
	IF_OPENSSL("egd",	&opt_openssl_egd)
	IF_TERMIOS("eof",	&opt_veof)
	IF_TERMIOS("eol",	&opt_veol)
	IF_TERMIOS("eol2",	&opt_veol2)
	IF_TERMIOS("erase",	&opt_verase)
	IF_SOCKET ("error",	&opt_so_error)
	IF_OPEN   ("excl",	&opt_o_excl)
	IF_ANY 	  ("f-setlk",	&opt_f_setlk)
	IF_ANY 	  ("f-setlkw",	&opt_f_setlkw)
	IF_EXEC   ("fdin",	&opt_fdin)
	IF_EXEC   ("fdout",	&opt_fdout)
#ifdef FFDLY
#  ifdef FF0
	IF_TERMIOS("ff0",	&opt_ff0)
#  endif
#  ifdef FF1
	IF_TERMIOS("ff1",	&opt_ff1)
#  endif
	IF_TERMIOS("ffdly",	&opt_ffdly)
#endif
#ifdef FIOSETOWN
	IF_SOCKET ("fiosetown",	&opt_fiosetown)
#endif
#if HAVE_FLOCK
	IF_ANY    ("flock",	&opt_flock_ex)
	IF_ANY    ("flock-ex",	&opt_flock_ex)
	IF_ANY    ("flock-ex-nb",	&opt_flock_ex_nb)
	IF_ANY    ("flock-nb",	&opt_flock_ex_nb)
	IF_ANY    ("flock-sh",	&opt_flock_sh)
	IF_ANY    ("flock-sh-nb",	&opt_flock_sh_nb)
#endif
	IF_TERMIOS("flusho",	&opt_flusho)
	/*0 IF_NAMED  ("force",	&opt_force)*/
	IF_RETRY  ("forever",	&opt_forever)
	IF_LISTEN ("fork",	&opt_fork)
#ifdef IP_FREEBIND
	IF_IP     ("freebind",	&opt_ip_freebind)
#endif
#if HAVE_FTRUNCATE64
	IF_ANY    ("ftruncate",	&opt_ftruncate64)
#else
	IF_ANY    ("ftruncate",	&opt_ftruncate32)
#endif
	IF_ANY    ("ftruncate32",	&opt_ftruncate32)
#if HAVE_FTRUNCATE64
	IF_ANY    ("ftruncate64",	&opt_ftruncate64)
#endif
	IF_ANY    ("gid",	&opt_group)
	IF_NAMED  ("gid-e",	&opt_group_early)
	IF_ANY    ("gid-l",	&opt_group_late)
	IF_ANY    ("group",	&opt_group)
	IF_NAMED  ("group-early",	&opt_group_early)
	IF_ANY    ("group-late",	&opt_group_late)
#ifdef IP_HDRINCL
	IF_IP     ("hdrincl",	&opt_ip_hdrincl)
#endif
	IF_READLINE("history",	&opt_history_file)
	IF_READLINE("history-file",	&opt_history_file)
	IF_TERMIOS("hup",	&opt_hupcl)
	IF_TERMIOS("hupcl",	&opt_hupcl)
	IF_TERMIOS("icanon",	&opt_icanon)
	IF_TERMIOS("icrnl",	&opt_icrnl)
	IF_TERMIOS("iexten",	&opt_iexten)
#ifdef SO_BINDTODEVICE
	IF_SOCKET ("if",	&opt_so_bindtodevice)
#endif
	IF_TERMIOS("ignbrk",	&opt_ignbrk)
	IF_TERMIOS("igncr",	&opt_igncr)
  /* you might need to terminate socat manually if you use this option: */
	IF_PROXY  ("ignorecr",	&opt_ignorecr)
	IF_ANY    ("ignoreeof",	&opt_ignoreeof)
	IF_ANY    ("ignoreof",	&opt_ignoreeof)
	IF_TERMIOS("ignpar",	&opt_ignpar)
	IF_TERMIOS("imaxbel",	&opt_imaxbel)
#ifdef TCP_INFO	/* Linux 2.4.0 */
	IF_TCP    ("info",	&opt_tcp_info)
#endif
	IF_TERMIOS("inlcr",	&opt_inlcr)
	IF_TERMIOS("inpck",	&opt_inpck)
#ifdef SO_BINDTODEVICE
	IF_SOCKET ("interface",	&opt_so_bindtodevice)
#endif
	IF_RETRY  ("intervall",	&opt_intervall)
	IF_TERMIOS("intr",	&opt_vintr)
#ifdef IP_FREEBIND
	IF_IP     ("ip-freebind",	&opt_ip_freebind)
#endif
#ifdef IP_HDRINCL
	IF_IP     ("ip-hdrincl",	&opt_ip_hdrincl)
#endif
#ifdef IP_MTU
	IF_IP     ("ip-mtu",	&opt_ip_mtu)
#endif
#ifdef IP_MTU_DISCOVER
	IF_IP     ("ip-mtu-discover",	&opt_ip_mtu_discover)
#endif
	IF_IP     ("ip-multicast-loop",	&opt_ip_multicast_loop)
	IF_IP     ("ip-multicast-ttl",	&opt_ip_multicast_ttl)
#ifdef IP_OPTIONS
	IF_IP     ("ip-options",	&opt_ip_options)
#endif
#ifdef IP_PKTINFO
	IF_IP     ("ip-pktinfo",	&opt_ip_pktinfo)
#endif
#ifdef IP_PKTOPTIONS
	IF_IP     ("ip-pktoptions",	&opt_ip_pktoptions)
#endif
#ifdef IP_RECVERR
	IF_IP     ("ip-recverr",	&opt_ip_recverr)
#endif
#ifdef IP_RECVOPTS
	IF_IP     ("ip-recvopts",	&opt_ip_recvopts)
#endif
#ifdef IP_RECVTOS
	IF_IP     ("ip-recvtos",	&opt_ip_recvtos)
#endif
#ifdef IP_RECVTTL
	IF_IP     ("ip-recvttl",	&opt_ip_recvttl)
#endif
#ifdef IP_RETOPTS
	IF_IP     ("ip-retopts",	&opt_ip_retopts)
#endif
#ifdef IP_ROUTER_ALERT
	IF_IP     ("ip-router-alert",	&opt_ip_router_alert)
#endif
	IF_IP     ("ip-tos",	&opt_ip_tos)
	IF_IP     ("ip-ttl",	&opt_ip_ttl)
#ifdef IP_FREEBIND
	IF_IP     ("ipfreebind",	&opt_ip_freebind)
#endif
#ifdef IP_HDRINCL
	IF_IP     ("iphdrincl",	&opt_ip_hdrincl)
#endif
#ifdef IP_MTU
	IF_IP     ("ipmtu",	&opt_ip_mtu)
#endif
#ifdef IP_MTU_DISCOVER
	IF_IP     ("ipmtudiscover",	&opt_ip_mtu_discover)
#endif
	IF_IP     ("ipmulticastloop",	&opt_ip_multicast_loop)
	IF_IP     ("ipmulticastttl",	&opt_ip_multicast_ttl)
#ifdef IP_OPTIONS
	IF_IP     ("ipoptions",	&opt_ip_options)
#endif
#ifdef IP_PKTINFO
	IF_IP     ("ippktinfo",	&opt_ip_pktinfo)
#endif
#ifdef IP_PKTOPTIONS
	IF_IP     ("ippktoptions",	&opt_ip_pktoptions)
#endif
#ifdef IP_RECVERR
	IF_IP     ("iprecverr",	&opt_ip_recverr)
#endif
#ifdef IP_RECVOPTS
	IF_IP     ("iprecvopts",	&opt_ip_recvopts)
#endif
#ifdef IP_RECVTOS
	IF_IP     ("iprecvtos",	&opt_ip_recvtos)
#endif
#ifdef IP_RECVTTL
	IF_IP     ("iprecvttl",	&opt_ip_recvttl)
#endif
#ifdef IP_RETOPTS
	IF_IP     ("ipretopts",	&opt_ip_retopts)
#endif
#ifdef IP_ROUTER_ALERT
	IF_IP     ("iprouteralert",	&opt_ip_router_alert)
#endif
	IF_IP     ("iptos",	&opt_ip_tos)
	IF_IP     ("ipttl",	&opt_ip_ttl)
	IF_TERMIOS("isig",	&opt_isig)
#ifdef HAVE_TERMIOS_ISPEED
	IF_TERMIOS("ispeed",	&opt_ispeed)
#endif
	IF_TERMIOS("istrip",	&opt_istrip)
#ifdef IUCLC
	IF_TERMIOS("iuclc",	&opt_iuclc)
#endif
	IF_TERMIOS("ixany",	&opt_ixany)
	IF_TERMIOS("ixoff",	&opt_ixoff)
	IF_TERMIOS("ixon",	&opt_ixon)
	IF_SOCKET ("keepalive",	&opt_so_keepalive)
#ifdef TCP_KEEPCNT	/* Linux 2.4.0 */
	IF_TCP    ("keepcnt",	&opt_tcp_keepcnt)
#endif
#ifdef TCP_KEEPIDLE	/* Linux 2.4.0 */
	IF_TCP    ("keepidle",	&opt_tcp_keepidle)
#endif
#ifdef TCP_KEEPINIT	/* OSF1 */
	IF_TCP    ("keepinit",	&opt_tcp_keepinit)
#endif
#ifdef TCP_KEEPINTVL	/* Linux 2.4.0 */
	IF_TCP    ("keepintvl",	&opt_tcp_keepintvl)
#endif
#ifdef SO_KERNACCEPT	/* AIX 4.3.3 */
	IF_SOCKET ("kernaccept",	&opt_so_kernaccept)
#endif /* SO_KERNACCEPT */
	IF_OPENSSL("key",	&opt_openssl_key)
	IF_TERMIOS("kill",	&opt_vkill)
#ifdef O_LARGEFILE
	IF_OPEN   ("largefile",	&opt_o_largefile)
#endif
#if WITH_LIBWRAP
	IF_IPAPP  ("libwrap",		&opt_tcpwrappers)
#endif
	IF_SOCKET ("linger",	&opt_so_linger)
#ifdef TCP_LINGER2	/* Linux 2.4.0 */
	IF_TCP    ("linger2",	&opt_tcp_linger2)
#endif
	IF_PTY    ("link",	&opt_symbolic_link)
	IF_TERMIOS("lnext",	&opt_vlnext)
#if defined(F_SETLKW)
	IF_ANY    ("lock",	&opt_f_setlkw)	/* POSIX, first choice */
#elif defined(HAVE_FLOCK)
	IF_ANY    ("lock",	&opt_flock_ex)	/* BSD, fallback */
#endif
	IF_ANY    ("lockfile",	&opt_lockfile)
#if defined(F_SETLKW)
	IF_ANY    ("lockw",	&opt_f_setlkw)	/* POSIX, first choice */
#elif defined(HAVE_FLOCK)
	IF_ANY    ("lockw",	&opt_flock_ex_nb)	/* BSD, fallback */
#endif
	IF_EXEC   ("login",	&opt_dash)
	IF_IPAPP  ("lowport",	&opt_lowport)
#if HAVE_LSEEK64
	IF_ANY    ("lseek",	&opt_lseek64_set)
#else
	IF_ANY    ("lseek",	&opt_lseek32_set)
#endif
	IF_ANY    ("lseek32",		&opt_lseek32_set)
	IF_ANY    ("lseek32-cur",	&opt_lseek32_cur)
	IF_ANY    ("lseek32-end",	&opt_lseek32_end)
	IF_ANY    ("lseek32-set",	&opt_lseek32_set)
#if HAVE_LSEEK64
	IF_ANY    ("lseek64",		&opt_lseek64_set)
	IF_ANY    ("lseek64-cur",	&opt_lseek64_cur)
	IF_ANY    ("lseek64-end",	&opt_lseek64_end)
	IF_ANY    ("lseek64-set",	&opt_lseek64_set)
#endif
#ifdef TCP_MAXSEG
	IF_TCP    ("maxseg",	&opt_tcp_maxseg)
	IF_TCP    ("maxseg-late",	&opt_tcp_maxseg_late)
#endif
#ifdef TCP_MD5SUM
	IF_TCP    ("md5sig",	&opt_tcp_md5sig)
#endif
	IF_OPENSSL("method",	&opt_openssl_method)
	IF_TERMIOS("min",	&opt_vmin)
	IF_ANY    ("mode",	&opt_perm)
#ifdef TCP_MAXSEG
	IF_TCP    ("mss",	&opt_tcp_maxseg)
	IF_TCP    ("mss-late",	&opt_tcp_maxseg_late)
#endif
#ifdef IP_MTU
	IF_IP     ("mtu",	&opt_ip_mtu)
#endif
#ifdef IP_MTU_DISCOVER
	IF_IP     ("mtudiscover",	&opt_ip_mtu_discover)
#endif
	IF_IP     ("multicastloop",	&opt_ip_multicast_loop)
	IF_IP     ("multicastttl",	&opt_ip_multicast_ttl)
#if defined(O_NDELAY) && (!defined(O_NONBLOCK) || O_NDELAY != O_NONBLOCK)
	IF_ANY    ("ndelay",	&opt_o_ndelay)
#else
	IF_ANY    ("ndelay",	&opt_nonblock)
#endif
	IF_NAMED  ("new",	&opt_unlink_early)
#ifdef NLDLY
#  ifdef NL0
	IF_TERMIOS("nl0",	&opt_nl0)
#  endif
#  ifdef NL1
	IF_TERMIOS("nl1",	&opt_nl1)
#  endif
	IF_TERMIOS("nldly",	&opt_nldly)
#endif /* defined(NLDLY) */
#ifdef SO_NO_CHECK
	IF_SOCKET ("no-check",	&opt_so_no_check)
	IF_SOCKET ("nocheck",	&opt_so_no_check)
#endif
	IF_OPEN   ("noctty",	&opt_o_noctty)
#ifdef TCP_NODELAY
	IF_TCP    ("nodelay",	&opt_tcp_nodelay)
#endif
#if HAVE_REGEX_H
	IF_READLINE("noecho",	&opt_noecho)
#endif /* HAVE_REGEX_H */
	IF_TERMIOS("noflsh",	&opt_noflsh)
#ifdef O_NOFOLLOW
	IF_OPEN   ("nofollow",	&opt_o_nofollow)
#endif
	IF_EXEC   ("nofork",	&opt_nofork) 
#ifdef O_NOINHERIT
	IF_ANY    ("noinherit",		&opt_o_noinherit)
#endif
	IF_ANY    ("nonblock",	&opt_nonblock)
#ifdef TCP_NOOPT
	IF_TCP    ("noopt",		&opt_tcp_noopt)
#endif
	IF_READLINE("noprompt",	&opt_noprompt)
#ifdef TCP_NOPUSH
	IF_TCP    ("nopush",	&opt_tcp_nopush)
#endif
#ifdef SO_NOREUSEADDR	/* AIX 4.3.3 */
	IF_SOCKET ("noreuseaddr",	&opt_so_noreuseaddr)
#endif /* SO_NOREUSEADDR */
#ifdef O_NSHARE
	IF_OPEN   ("nshare",	&opt_o_nshare)
#endif
#ifdef O_ASYNC
	IF_ANY    ("o-async",		&opt_async)
#endif
#ifdef O_BINARY
	IF_OPEN   ("o-binary",		&opt_o_binary)
#endif
	IF_OPEN   ("o-create",	&opt_o_create)
#ifdef O_DEFER
	IF_OPEN   ("o-defer",	&opt_o_defer)
#endif
#ifdef O_DELAY
	IF_OPEN   ("o-delay",	&opt_o_delay)
#endif
#ifdef O_DIRECT
	IF_OPEN   ("o-direct",	&opt_o_direct)
#endif
#ifdef O_DIRECTORY
	IF_OPEN   ("o-directory",	&opt_o_directory)
#endif
#ifdef O_DSYNC
	IF_OPEN   ("o-dsync",	&opt_o_dsync)
#endif
	IF_OPEN   ("o-excl",	&opt_o_excl)
#ifdef O_LARGEFILE
	IF_OPEN   ("o-largefile",	&opt_o_largefile)
#endif
#if defined(O_NDELAY) && (!defined(O_NONBLOCK) || O_NDELAY != O_NONBLOCK)
	IF_ANY    ("o-ndelay",	&opt_o_ndelay)
#else
	IF_ANY    ("o-ndelay",	&opt_nonblock)
#endif
	IF_OPEN   ("o-noctty",	&opt_o_noctty)
#ifdef O_NOFOLLOW
	IF_OPEN   ("o-nofollow",	&opt_o_nofollow)
#endif
#ifdef O_NOINHERIT
	IF_ANY    ("o-noinherit",	&opt_o_noinherit)
#endif
#ifdef O_NSHARE
	IF_OPEN   ("o-nshare",	&opt_o_nshare)
#endif
#ifdef O_PRIV
	IF_OPEN   ("o-priv",	&opt_o_priv)
#endif
	IF_OPEN   ("o-rdonly",	&opt_o_rdonly)
	IF_OPEN   ("o-rdwr",	&opt_o_rdwr)
#ifdef O_RSHARE
	IF_OPEN   ("o-rshare",	&opt_o_rshare)
#endif
#ifdef O_RSYNC
	IF_OPEN   ("o-rsync",	&opt_o_rsync)
#endif
#ifdef O_SYNC
	IF_OPEN   ("o-sync",	&opt_o_sync)
#endif
#ifdef O_TEXT
	IF_ANY    ("o-text",		&opt_o_text)
#endif
	IF_OPEN   ("o-trunc",	&opt_o_trunc)
	IF_OPEN   ("o-wronly",	&opt_o_wronly)
	IF_OPEN   ("o_create",	&opt_o_create)
#ifdef O_DEFER
	IF_OPEN   ("o_defer",	&opt_o_defer)
#endif
#ifdef O_DELAY
	IF_OPEN   ("o_delay",	&opt_o_delay)
#endif
#ifdef O_DIRECT
	IF_OPEN   ("o_direct",	&opt_o_direct)
#endif
#ifdef O_DIRECTORY
	IF_OPEN   ("o_directory",	&opt_o_directory)
#endif
#ifdef O_DSYNC
	IF_OPEN   ("o_dsync",	&opt_o_dsync)
#endif
	IF_OPEN   ("o_excl",	&opt_o_excl)
#ifdef O_LARGEFILE
	IF_OPEN   ("o_largefile",	&opt_o_largefile)
#endif
#if defined(O_NDELAY) && (!defined(O_NONBLOCK) || O_NDELAY != O_NONBLOCK)
	IF_ANY    ("o_ndelay",	&opt_o_ndelay)
#else
	IF_ANY    ("o_ndelay",	&opt_nonblock)
#endif
	IF_OPEN   ("o_noctty",	&opt_o_noctty)
#ifdef O_NOFOLLOW
	IF_OPEN   ("o_nofollow",	&opt_o_nofollow)
#endif
#ifdef O_NSHARE
	IF_OPEN   ("o_nshare",	&opt_o_nshare)
#endif
#ifdef O_PRIV
	IF_OPEN   ("o_priv",	&opt_o_priv)
#endif
	IF_OPEN   ("o_rdonly",	&opt_o_rdonly)
	IF_OPEN   ("o_rdwr",	&opt_o_rdwr)
#ifdef O_RSHARE
	IF_OPEN   ("o_rshare",	&opt_o_rshare)
#endif
#ifdef O_RSYNC
	IF_OPEN   ("o_rsync",	&opt_o_rsync)
#endif
#ifdef O_SYNC
	IF_OPEN   ("o_sync",	&opt_o_sync)
#endif
	IF_OPEN   ("o_wronly",	&opt_o_wronly)
#ifdef OCRNL
	IF_TERMIOS("ocrnl",	&opt_ocrnl)
#endif
#ifdef OFDEL
	IF_TERMIOS("ofdel",	&opt_ofdel)
#endif
#ifdef OFILL
	IF_TERMIOS("ofill",	&opt_ofill)
#endif
#ifdef OLCUC
	IF_TERMIOS("olcuc",	&opt_olcuc)
#endif
	IF_TERMIOS("onlcr",	&opt_onlcr)
#ifdef ONLRET
	IF_TERMIOS("onlret",	&opt_onlret)
#endif
#ifdef ONOCR
	IF_TERMIOS("onocr",	&opt_onocr)
#endif
	IF_SOCKET ("oobinline",	&opt_so_oobinline)
#if HAVE_OPENPTY
	IF_EXEC   ("openpty",	&opt_openpty)
#endif /* HAVE_OPENPTY */
	IF_OPENSSL("openssl-cafile",	&opt_openssl_cafile)
	IF_OPENSSL("openssl-capath",	&opt_openssl_capath)
	IF_OPENSSL("openssl-certificate",	&opt_openssl_certificate)
	IF_OPENSSL("openssl-cipherlist",	&opt_openssl_cipherlist)
	IF_OPENSSL("openssl-dhparam",	&opt_openssl_dhparam)
	IF_OPENSSL("openssl-egd",	&opt_openssl_egd)
	IF_OPENSSL("openssl-key",	&opt_openssl_key)
	IF_OPENSSL("openssl-method",	&opt_openssl_method)
	IF_OPENSSL("openssl-pseudo",	&opt_openssl_pseudo)
	IF_OPENSSL("openssl-verify",	&opt_openssl_verify)
	IF_TERMIOS("opost",	&opt_opost)
#ifdef HAVE_TERMIOS_ISPEED
	IF_TERMIOS("ospeed",	&opt_ospeed)
#endif
	IF_ANY    ("owner",	&opt_user)
	IF_TERMIOS("parenb",	&opt_parenb)
	IF_TERMIOS("parmrk",	&opt_parmrk)
	IF_TERMIOS("parodd",	&opt_parodd)
#ifdef SO_PASSCRED
	IF_SOCKET ("passcred",	&opt_so_passcred)
#endif
	IF_EXEC   ("path",	&opt_path)
#ifdef TCP_PAWS	/* OSF1 */
	IF_TCP    ("paws",	&opt_tcp_paws)
#endif
#ifdef SO_PEERCRED
	IF_SOCKET ("peercred",	&opt_so_peercred)
#endif
#ifdef PENDIN
	IF_TERMIOS("pendin",	&opt_pendin)
#endif
	IF_ANY    ("perm",	&opt_perm)
	IF_NAMED  ("perm-early",	&opt_perm_early)
	IF_ANY    ("perm-late",	&opt_perm_late)
	IF_EXEC   ("pgid",	&opt_setpgid)
	IF_EXEC   ("pipes",	&opt_pipes)
#ifdef IP_PKTINFO
	IF_IP     ("pktinfo",	&opt_ip_pktinfo)
#endif
#ifdef IP_PKTOPTIONS
	IF_IP     ("pktoptions",	&opt_ip_pktoptions)
	IF_IP     ("pktopts",	&opt_ip_pktoptions)
#endif
	/*IF_IPAPP("port",	&opt_port)*/
#ifdef SO_PRIORITY
	IF_SOCKET ("priority",	&opt_so_priority)
#endif
#ifdef O_PRIV
	IF_OPEN   ("priv",	&opt_o_priv)
#endif
	IF_READLINE("prompt",	&opt_prompt)
#ifdef SO_PROTOTYPE
	IF_SOCKET ("prototype",	&opt_so_prototype)
#endif
	IF_PROXY  ("proxy-authorization",	&opt_proxy_authorization)
	IF_PROXY  ("proxy-auth",	&opt_proxy_authorization)
	IF_PROXY  ("proxy-resolve",	&opt_proxy_resolve)
	IF_PROXY  ("proxyauth",	&opt_proxy_authorization)
	IF_PROXY  ("proxyport",	&opt_proxyport)
#ifdef ECHOPRT
	IF_TERMIOS("prterase",	&opt_echoprt)
#endif
	IF_OPENSSL("pseudo",	&opt_openssl_pseudo)
#if HAVE_DEV_PTMX || HAVE_DEV_PTC
	IF_EXEC   ("ptmx",	&opt_ptmx)
#endif
#if HAVE_PTY
	IF_EXEC   ("pty",	&opt_pty)
#endif
#if HAVE_PTY && HAVE_POLL
	IF_PTY    ("pty-intervall",	&opt_pty_intervall)
	IF_PTY    ("pty-wait-slave",	&opt_pty_wait_slave)
#endif /* HAVE_PTY && HAVE_POLL */
#ifdef TCP_QUICKACK
	IF_TCP    ("quickack",	&opt_tcp_quickack)
#endif
	IF_TERMIOS("quit",	&opt_vquit)
	IF_RANGE  ("range",	&opt_range)
	IF_TERMIOS("raw",	&opt_raw)
	IF_SOCKET ("rcvbuf",	&opt_so_rcvbuf)
	IF_SOCKET ("rcvbuf-late",	&opt_so_rcvbuf_late)
#ifdef SO_RCVLOWAT
	IF_SOCKET ("rcvlowat",	&opt_so_rcvlowat)
#endif
#ifdef SO_RCVTIMEO
	IF_SOCKET ("rcvtimeo",	&opt_so_rcvtimeo)
#endif
	IF_OPEN   ("rdonly",	&opt_o_rdonly)
	IF_OPEN   ("rdwr",	&opt_o_rdwr)
	IF_ANY    ("readbytes", &opt_readbytes)
#ifdef IP_RECVERR
	IF_IP     ("recverr",	&opt_ip_recverr)
#endif
#ifdef IP_RECVOPTS
	IF_IP     ("recvopts",	&opt_ip_recvopts)
#endif
#ifdef IP_RECVTOS
	IF_IP     ("recvtos",	&opt_ip_recvtos)
#endif
#ifdef IP_RECVTTL
	IF_IP     ("recvttl",	&opt_ip_recvttl)
#endif
	IF_NAMED  ("remove",	&opt_unlink)
#ifdef VREPRINT
	IF_TERMIOS("reprint",	&opt_vreprint)
#endif
	IF_PROXY  ("resolv",	&opt_proxy_resolve)
	IF_PROXY  ("resolve",	&opt_proxy_resolve)
#ifdef IP_RETOPTS
	IF_IP     ("retopts",	&opt_ip_retopts)
#endif
	IF_RETRY  ("retry",	&opt_retry)
	IF_SOCKET ("reuseaddr",	&opt_so_reuseaddr)
#ifdef SO_REUSEPORT	/* AIX 4.3.3 */
	IF_SOCKET ("reuseport",	&opt_so_reuseport)
#endif /* defined(SO_REUSEPORT) */
#ifdef TCP_RFC1323
	IF_TCP    ("rfc1323",	&opt_tcp_rfc1323)
#endif
#ifdef IP_ROUTER_ALERT
	IF_IP     ("routeralert",	&opt_ip_router_alert)
#endif
#ifdef VREPRINT
	IF_TERMIOS("rprnt",	&opt_vreprint)
#endif
#ifdef O_RSHARE
	IF_OPEN   ("rshare",	&opt_o_rshare)
#endif
#ifdef O_RSYNC
	IF_OPEN   ("rsync",	&opt_o_rsync)
#endif
#ifdef TCP_SACK_DISABLE
	IF_TCP    ("sack-disable",	&opt_tcp_sack_disable)
#endif
#ifdef TCP_SACKENA	/* OSF1 */
	IF_TCP    ("sackena",	&opt_tcp_sackena)
#endif
	IF_TERMIOS("sane",	&opt_sane)
#ifdef SO_SECURITY_AUTHENTICATION
	IF_SOCKET ("security-authentication",	&opt_so_security_authentication)
#endif
#ifdef SO_SECURITY_ENCRYPTION_NETWORK
	IF_SOCKET ("security-encryption-network",	&opt_so_security_encryption_network)
#endif
#ifdef SO_SECURITY_ENCRYPTION_TRANSPORT
	IF_SOCKET ("security-encryption-transport",	&opt_so_security_encryption_transport)
#endif
#ifdef SO_SECURITY_AUTHENTICATION
	IF_SOCKET ("securityauthentication",	&opt_so_security_authentication)
#endif
#ifdef SO_SECURITY_ENCRYPTION_NETWORK
	IF_SOCKET ("securityencryptionnetwork",	&opt_so_security_encryption_network)
#endif
#ifdef SO_SECURITY_ENCRYPTION_TRANSPORT
	IF_SOCKET ("securityencryptiontransport",	&opt_so_security_encryption_transport)
#endif
#if HAVE_LSEEK64
	IF_ANY    ("seek",		&opt_lseek64_set)
	IF_ANY    ("seek-cur",		&opt_lseek64_cur)
	IF_ANY    ("seek-end",		&opt_lseek64_end)
	IF_ANY    ("seek-set",		&opt_lseek64_set)
#else
	IF_ANY    ("seek",		&opt_lseek32_set)
	IF_ANY    ("seek-cur",		&opt_lseek32_cur)
	IF_ANY    ("seek-end",		&opt_lseek32_end)
	IF_ANY    ("seek-set",		&opt_lseek32_set)
#endif
	IF_ANY    ("setgid",	&opt_setgid)
	IF_ANY    ("setgid-early",	&opt_setgid_early)
	IF_ANY 	  ("setlk",	&opt_f_setlk)
	IF_ANY 	  ("setlkw",	&opt_f_setlkw)
	IF_EXEC   ("setpgid",	&opt_setpgid)
#if WITH_EXEC || WITH_SYSTEM
	IF_EXEC   ("setsid",	&opt_setsid)
#endif
	IF_ANY    ("setuid",	&opt_setuid)
	IF_ANY    ("setuid-early",	&opt_setuid_early)
#if WITH_EXEC || WITH_SYSTEM
	IF_ANY    ("sid",	&opt_setsid)
#endif
	IF_EXEC   ("sighup",	&opt_sighup)
	IF_EXEC   ("sigint",	&opt_sigint)
#ifdef TCP_SIGNATURE_ENABLE
	IF_TCP    ("signature-enable",	&opt_tcp_signature_enable)
#endif
	IF_EXEC   ("sigquit",	&opt_sigquit)
#ifdef SIOCSPGRP
	IF_SOCKET ("siocspgrp",	&opt_siocspgrp)
#endif
	IF_SOCKET ("sndbuf",	&opt_so_sndbuf)
	IF_SOCKET ("sndbuf-late",	&opt_so_sndbuf_late)
#ifdef SO_SNDLOWAT
	IF_SOCKET ("sndlowat",	&opt_so_sndlowat)
#endif
#ifdef SO_SNDTIMEO
	IF_SOCKET ("sndtimeo",	&opt_so_sndtimeo)
#endif
#ifdef SO_ACCEPTCONN /* AIX433 */
	IF_SOCKET ("so-acceptconn",	&opt_so_acceptconn)
#endif /* SO_ACCEPTCONN */
#ifdef SO_ATTACH_FILTER
	IF_SOCKET ("so-attach-filter",	&opt_so_attach_filter)
#endif
#ifdef SO_AUDIT	/* AIX 4.3.3 */
	IF_SOCKET ("so-audit",	&opt_so_audit)
#endif /* SO_AUDIT */
#ifdef SO_BINDTODEVICE
	IF_SOCKET ("so-bindtodevice",	&opt_so_bindtodevice)
#endif
	IF_SOCKET ("so-broadcast",	&opt_so_broadcast)
#ifdef SO_BSDCOMPAT
	IF_SOCKET ("so-bsdcompat",	&opt_so_bsdcompat)
#endif
#ifdef SO_CKSUMRECV
	IF_SOCKET ("so-cksumrecv",	&opt_so_cksumrecv)
#endif /* SO_CKSUMRECV */
	IF_SOCKET ("so-debug",	&opt_so_debug)
#ifdef SO_DETACH_FILTER
	IF_SOCKET ("so-detach-filter", &opt_so_detach_filter)
#endif
#ifdef SO_DGRAM_ERRIND
	IF_SOCKET ("so-dgram-errind",	&opt_so_dgram_errind)
#endif
#ifdef SO_DONTLINGER
	IF_SOCKET ("so-dontlinger",	&opt_so_dontlinger)
#endif
	IF_SOCKET ("so-dontroute",	&opt_so_dontroute)
	IF_SOCKET ("so-error",	&opt_so_error)
	IF_SOCKET ("so-keepalive",	&opt_so_keepalive)
#ifdef SO_KERNACCEPT	/* AIX 4.3.3 */
	IF_SOCKET ("so-kernaccept",	&opt_so_kernaccept)
#endif /* SO_KERNACCEPT */
	IF_SOCKET ("so-linger",	&opt_so_linger)
#ifdef SO_NO_CHECK
	IF_SOCKET ("so-no-check",	&opt_so_no_check)
#endif
#ifdef SO_NOREUSEADDR	/* AIX 4.3.3 */
	IF_SOCKET ("so-noreuseaddr",	&opt_so_noreuseaddr)
#endif /* SO_NOREUSEADDR */
	IF_SOCKET ("so-oobinline",	&opt_so_oobinline)
#ifdef SO_PASSCRED
	IF_SOCKET ("so-passcred",	&opt_so_passcred)
#endif
#ifdef SO_PEERCRED
	IF_SOCKET ("so-peercred",	&opt_so_peercred)
#endif
#ifdef SO_PRIORITY
	IF_SOCKET ("so-priority",	&opt_so_priority)
#endif
#ifdef SO_PROTOTYPE
	IF_SOCKET ("so-prototype",	&opt_so_prototype)
#endif
	IF_SOCKET ("so-rcvbuf",	&opt_so_rcvbuf)
	IF_SOCKET ("so-rcvbuf-late",	&opt_so_rcvbuf_late)
#ifdef SO_RCVLOWAT
	IF_SOCKET ("so-rcvlowat",	&opt_so_rcvlowat)
#endif
#ifdef SO_RCVTIMEO
	IF_SOCKET ("so-rcvtimeo",	&opt_so_rcvtimeo)
#endif
	IF_SOCKET ("so-reuseaddr",	&opt_so_reuseaddr)
#ifdef SO_REUSEPORT	/* AIX 4.3.3 */
	IF_SOCKET ("so-reuseport",	&opt_so_reuseport)
#endif /* defined(SO_REUSEPORT) */
#ifdef SO_SECURITY_AUTHENTICATION
	IF_SOCKET ("so-security-authentication",	&opt_so_security_authentication)
#endif
#ifdef SO_SECURITY_ENCRYPTION_NETWORK
	IF_SOCKET ("so-security-encryption-network",	&opt_so_security_encryption_network)
#endif
#ifdef SO_SECURITY_ENCRYPTION_TRANSPORT
	IF_SOCKET ("so-security-encryption-transport",	&opt_so_security_encryption_transport)
#endif
	IF_SOCKET ("so-sndbuf",	&opt_so_sndbuf)
	IF_SOCKET ("so-sndbuf-late",	&opt_so_sndbuf_late)
#ifdef SO_SNDLOWAT
	IF_SOCKET ("so-sndlowat",	&opt_so_sndlowat)
#endif
#ifdef SO_SNDTIMEO
	IF_SOCKET ("so-sndtimeo",	&opt_so_sndtimeo)
#endif
	IF_SOCKET ("so-type",	&opt_so_type)
#ifdef SO_USE_IFBUFS
	IF_SOCKET ("so-use-ifbufs",	&opt_so_use_ifbufs)
#endif /* SO_USE_IFBUFS */
#ifdef SO_USELOOPBACK /* AIX433, Solaris */
	IF_SOCKET ("so-useloopback",	&opt_so_useloopback)
#endif /* SO_USELOOPBACK */
 	IF_SOCKS4 ("socksport",	&opt_socksport)
	IF_SOCKS4 ("socksuser",	&opt_socksuser)
	IF_IPAPP  ("sourceport",	&opt_sourceport)
	IF_IPAPP  ("sp",	&opt_sourceport)
	IF_TERMIOS("start",	&opt_vstart)
	IF_EXEC   ("stderr",    &opt_stderr)
#ifdef TCP_STDURG
	IF_TCP    ("stdurg",	&opt_tcp_stdurg)
#endif
	IF_TERMIOS("stop",	&opt_vstop)
	IF_ANY    ("su",	&opt_substuser)
	IF_ANY    ("su-d",	&opt_substuser_delayed)
	IF_ANY    ("substuser",	&opt_substuser)
	IF_ANY    ("substuser-delayed",	&opt_substuser_delayed)
	IF_TERMIOS("susp",	&opt_vsusp)
#ifdef VSWTC
	IF_TERMIOS("swtc",	&opt_vswtc)
	IF_TERMIOS("swtch",	&opt_vswtc)
#endif
	IF_PTY    ("symbolic-link",	&opt_symbolic_link)
#ifdef O_SYNC
	IF_OPEN   ("sync",	&opt_o_sync)
#endif
#ifdef TCP_SYNCNT
	IF_TCP    ("syncnt",	&opt_tcp_syncnt)
#endif
#ifdef TABDLY
#  ifdef TAB0
	IF_TERMIOS("tab0",	&opt_tab0)
#  endif
#  ifdef TAB1
	IF_TERMIOS("tab1",	&opt_tab1)
#  endif
#  ifdef TAB2
	IF_TERMIOS("tab2",	&opt_tab2)
#  endif
#  ifdef TAB3
	IF_TERMIOS("tab3",	&opt_tab3)
#  endif
	IF_TERMIOS("tabdly",	&opt_tabdly)
#endif
	IF_TERMIOS("tandem",	&opt_ixoff)
#ifdef TCP_ABORT_THRESHOLD  /* HP_UX */
	IF_TCP    ("tcp-abort-threshold",	&opt_tcp_abort_threshold)
#endif
#ifdef TCP_CONN_ABORT_THRESHOLD  /* HP_UX */
	IF_TCP    ("tcp-conn-abort-threshold",	&opt_tcp_conn_abort_threshold)
#endif
#ifdef TCP_CORK
	IF_TCP    ("tcp-cork",	&opt_tcp_cork)
#endif
#ifdef TCP_DEFER_ACCEPT	/* Linux 2.4.0 */
	IF_TCP    ("tcp-defer-accept",	&opt_tcp_defer_accept)
#endif
#ifdef TCP_INFO	/* Linux 2.4.0 */
	IF_TCP    ("tcp-info",	&opt_tcp_info)
#endif
#ifdef TCP_KEEPCNT	/* Linux 2.4.0 */
	IF_TCP    ("tcp-keepcnt",	&opt_tcp_keepcnt)
#endif
#ifdef TCP_KEEPIDLE	/* Linux 2.4.0 */
	IF_TCP    ("tcp-keepidle",	&opt_tcp_keepidle)
#endif
#ifdef TCP_KEEPINIT	/* OSF1 */
	IF_TCP    ("tcp-keepinit",	&opt_tcp_keepinit)
#endif
#ifdef TCP_KEEPINTVL	/* Linux 2.4.0 */
	IF_TCP    ("tcp-keepintvl",	&opt_tcp_keepintvl)
#endif
#ifdef TCP_LINGER2	/* Linux 2.4.0 */
	IF_TCP    ("tcp-linger2",	&opt_tcp_linger2)
#endif
#ifdef TCP_MAXSEG
	IF_TCP    ("tcp-maxseg",	&opt_tcp_maxseg)
	IF_TCP    ("tcp-maxseg-late",	&opt_tcp_maxseg_late)
#endif
#ifdef TCP_MD5SIG
	IF_TCP    ("tcp-md5sig",	&opt_tcp_md5sig)
#endif
#ifdef TCP_NODELAY
	IF_TCP    ("tcp-nodelay",	&opt_tcp_nodelay)
#endif
#ifdef TCP_NOOPT
	IF_TCP    ("tcp-noopt",		&opt_tcp_noopt)
#endif
#ifdef TCP_NOPUSH
	IF_TCP    ("tcp-nopush",	&opt_tcp_nopush)
#endif
#ifdef TCP_PAWS	/* OSF1 */
	IF_TCP    ("tcp-paws",		&opt_tcp_paws)
#endif
#ifdef TCP_QUICKACK
	IF_TCP    ("tcp-quickack",	&opt_tcp_quickack)
#endif
#ifdef TCP_RFC1323
	IF_TCP    ("tcp-rfc1323",	&opt_tcp_rfc1323)
#endif
#ifdef TCP_SACK_DISABLE
	IF_TCP    ("tcp-sack-disable",	&opt_tcp_sack_disable)
#endif
#ifdef TCP_SACKENA	/* OSF1 */
	IF_TCP    ("tcp-sackena",	&opt_tcp_sackena)
#endif
#ifdef TCP_SIGNATURE_ENABLE
	IF_TCP    ("tcp-signature-enable",	&opt_tcp_signature_enable)
#endif
#ifdef TCP_STDURG
	IF_TCP    ("tcp-stdurg",	&opt_tcp_stdurg)
#endif
#ifdef TCP_SYNCNT	/* Linux 2.4.0 */
	IF_TCP    ("tcp-syncnt",	&opt_tcp_syncnt)
#endif
#ifdef TCP_TSOPTENA	/* OSF1 */
	IF_TCP    ("tcp-tsoptena",	&opt_tcp_tsoptena)
#endif
#ifdef TCP_WINDOW_CLAMP	/* Linux 2.4.0 */
	IF_TCP    ("tcp-window-clamp",	&opt_tcp_window_clamp)
#endif
#if WITH_LIBWRAP
	IF_IPAPP  ("tcpwrap",		&opt_tcpwrappers)
	IF_IPAPP  ("tcpwrapper",	&opt_tcpwrappers)
	IF_IPAPP  ("tcpwrappers",	&opt_tcpwrappers)
#endif
#ifdef O_TEXT
	IF_ANY    ("text",	&opt_o_text)
#endif
	IF_TERMIOS("time",	&opt_vtime)
	IF_TERMIOS("tiocsctty",	&opt_tiocsctty)
	IF_IP     ("tos",	&opt_ip_tos)
	IF_TERMIOS("tostop",	&opt_tostop)
	IF_OPEN   ("trunc",	&opt_o_trunc)
#if HAVE_FTRUNCATE64
	IF_ANY    ("truncate",	&opt_ftruncate64)
#else
	IF_ANY    ("truncate",	&opt_ftruncate32)
#endif
#ifdef TCP_TSOPTENA	/* OSF1 */
	IF_TCP    ("tsoptena",	&opt_tcp_tsoptena)
#endif
	IF_IP     ("ttl",	&opt_ip_ttl)
	IF_SOCKET ("type",	&opt_so_type)
	IF_ANY    ("uid",	&opt_user)
	IF_NAMED  ("uid-e",	&opt_user_early)
	IF_ANY    ("uid-l",	&opt_user_late)
	IF_NAMED  ("umask",	&opt_umask)
	IF_NAMED  ("unlink",	&opt_unlink)
	IF_NAMED  ("unlink-close",	&opt_unlink_close)
	IF_NAMED  ("unlink-early",	&opt_unlink_early)
	IF_NAMED  ("unlink-late",	&opt_unlink_late)
#ifdef SO_USE_IFBUFS
	IF_SOCKET ("use-ifbufs",	&opt_so_use_ifbufs)
	IF_SOCKET ("useifbufs",		&opt_so_use_ifbufs)
#endif /* SO_USE_IFBUFS */
#ifdef SO_USELOOPBACK /* AIX433, Solaris */
	IF_SOCKET ("useloopback",	&opt_so_useloopback)
#endif /* SO_USELOOPBACK */
	IF_ANY    ("user",	&opt_user)
	IF_NAMED  ("user-early",	&opt_user_early)
	IF_ANY    ("user-late",	&opt_user_late)
#ifdef VDISCARD
	IF_TERMIOS("vdiscard",	&opt_vdiscard)
#endif
#ifdef VDSUSP	/* HP-UX */
	IF_TERMIOS("vdsusp",	&opt_vdsusp)
#endif
	IF_TERMIOS("veof",	&opt_veof)
	IF_TERMIOS("veol",	&opt_veol)
	IF_TERMIOS("veol2",	&opt_veol2)
	IF_TERMIOS("verase",	&opt_verase)
	IF_OPENSSL("verify",	&opt_openssl_verify)
	IF_TERMIOS("vintr",	&opt_vintr)
	IF_TERMIOS("vkill",	&opt_vkill)
	IF_TERMIOS("vlnext",	&opt_vlnext)
	IF_TERMIOS("vmin",	&opt_vmin)
	IF_TERMIOS("vquit",	&opt_vquit)
#ifdef VREPRINT
	IF_TERMIOS("vreprint",	&opt_vreprint)
#endif
	IF_TERMIOS("vstart",	&opt_vstart)
	IF_TERMIOS("vstop",	&opt_vstop)
	IF_TERMIOS("vsusp",	&opt_vsusp)
#ifdef VSWTC
	IF_TERMIOS("vswtc",	&opt_vswtc)
#endif
#ifdef VTDLY
#  ifdef VT0
	IF_TERMIOS("vt0",	&opt_vt0)
#  endif
#  ifdef VT1
	IF_TERMIOS("vt1",	&opt_vt1)
#  endif
	IF_TERMIOS("vtdly",	&opt_vtdly)
#endif
	IF_TERMIOS("vtime",	&opt_vtime)
#ifdef VWERASE
	IF_TERMIOS("vwerase",	&opt_vwerase)
#endif
#if HAVE_PTY && HAVE_POLL
	IF_PTY    ("wait-slave",	&opt_pty_wait_slave)
	IF_ANY    ("waitlock",	&opt_waitlock)
	IF_PTY    ("waitslave",	&opt_pty_wait_slave)
#endif /* HAVE_PTY && HAVE_POLL */
#ifdef VWERASE
	IF_TERMIOS("werase",	&opt_vwerase)
#endif
#ifdef TCP_WINDOW_CLAMP	/* Linux 2.4.0 */
	IF_TCP    ("window-clamp",	&opt_tcp_window_clamp)
#endif
#if WITH_LIBWRAP
	IF_IPAPP  ("wrap",		&opt_tcpwrappers)
#endif
	IF_OPEN   ("wronly",	&opt_o_wronly)
#ifdef XCASE
	IF_TERMIOS("xcase",	&opt_xcase)
#endif
#if defined(TABDLY) && defined(XTABS)
	IF_TERMIOS("xtabs",	&opt_xtabs)
#endif
	{ NULL }
} ;


/* walks the text argument a and writes its options that conform to groups 
   to the array opts
   returns 0 on success, -1 on error, 1 on unknown/wrong option  
*/
int parseopts(char *a, unsigned int groups, struct opt **opts) {
   int i=0;
   char *equal, *comma = a, *a0, *a2, *pisep;
   unsigned long ulongval;
   long slongval;
   long long slonglongval;
   char optr = ',';
   int result;
   char optbuf[256];  size_t optlen;

   *opts = Malloc((i+8)*sizeof(struct opt));
   if (*opts == NULL) {
      return -1;
   }
   if (a == NULL) {
      (*opts)[i].desc = ODESC_END;
      return 0;
   }

   while (optr == ',' || optr == '=') {
      const struct optname *ent;

      if (a == NULL || *a == '\0')
	 break;

      if (*a == ',') ++a;
      a0 = a;
      equal = strchr(a, '=');
      comma = strchr(a, ',');
      pisep = strchr(a, xioopts.pipesep[0]);
      if (comma == NULL) {
	 comma = pisep;
      } else if (pisep != NULL) {
	 comma = Min(comma, pisep);
      }
      /* find the termination of the next option name:
	 is nearest of '=' or ',' or '\0' */
      if (equal != NULL) {
	 if (comma != NULL) {
	    if (equal < comma) {
	       optr = *equal;  *equal = *comma++ = '\0'; a2 = equal+1;
	    } else {
	       optr = *comma;  *comma++ = '\0'; a2 = NULL;
	    }
	 } else {
	    optr = *equal;  *equal = '\0'; a2 = equal+1;
	 }
      } else {
	 if (comma != NULL) {
	    optr = *comma;  *comma++ = '\0'; a2 = NULL;
	 } else {
	    optr = ','; a2 = NULL;
	 }
      }
      a = comma;

      /* the option name in a0 is \0 separated; optr contains the orig char */
      ent = (struct optname *)
	 keyw((struct wordent *)optionnames, a0,
	      sizeof(optionnames)/sizeof(struct optname)-1);
      if (ent == NULL) {
	 Error1("parseopts(): unknown option \"%s\"", a0);
	 continue;
      }
      if (!(ent->desc->group & groups) && !(ent->desc->group & GROUP_ANY) &&
	  !xioopts_ignoregroups) {
	 Error1("parseopts(): option \"%s\" not supported with this address type",
		a0);
	 Info2("parseopts()  groups=%08x, ent->group=%08x",
	       groups, ent->desc->group);
	 continue;
      }
      (*opts)[i].desc = ent->desc;
      switch (ent->desc->type) {
      case TYPE_CONST:
	 if (optr == '=') {
	    Error1("no value permitted for option \"%s\"",
		   ent->desc->defname);
	    continue;
	 }
	 Info1("setting option \"%s\"", ent->desc->defname);
	 break;
      case TYPE_BIN:
	 if (a2 == NULL) { Error1("option \"%s\": value required", a0);
	    continue; }
	 optlen = 0;
	 if ((result = dalan(a2, optbuf, &optlen, sizeof(optbuf))) != 0) {
	    Error1("parseopts(): problem with \"%s\" data", a2);
	    continue;
	 }
	 if (((*opts)[i].value.u_bin.b_data = memdup(optbuf, optlen)) == NULL) {
	    Error1("memdup(, "F_Zu"): out of memory", optlen);
	    return -1;
	 }
	 (*opts)[i].value.u_bin.b_len = optlen;
	 break;
      case TYPE_BYTE:
	 {
	  unsigned long ul;
	  if (a2) {
	    ul = strtoul(a2, &a2, 0);
	  } else {
	    ul = 1;
	  }
	  if (ul > UCHAR_MAX) {
	    Error3("parseopts(%s): byte value exceeds limit (%u vs. %u), using max",
		   a0, ul, UCHAR_MAX);
	    (*opts)[i].value.u_byte = UCHAR_MAX;
	  } else {
	    Info2("setting option \"%s\" to %d", ent->desc->defname,
		  (*opts)[i].value.u_byte);
	    (*opts)[i].value.u_byte = ul;
	  }
	 }
	 break;
      case TYPE_INT:
	 if (a2) {
	    (*opts)[i].value.u_int = strtoul(a2, &a2, 0);
	 } else {
	    (*opts)[i].value.u_int = 1;
	 }
	 Info2("setting option \"%s\" to %d", ent->desc->defname,
	       (*opts)[i].value.u_int);
	 break;
      case TYPE_BOOL:
	 if (optr != '=') {
	    (*opts)[i].value.u_bool = 1;
	 } else {
	    (*opts)[i].value.u_bool = strtoul(a2, &a2, 0);
	 }
	 if (a2 && *a2) {
	    Error1("error in option \"%s\": \"0\" or \"1\" required", a0);
	 }
	 Info2("setting option \"%s\" to %d", ent->desc->defname,
	       (*opts)[i].value.u_bool);
	 break;

#if HAVE_BASIC_SIZE_T==4
      case TYPE_SIZE_T:
#endif
      case TYPE_UINT:
	 if (optr != '=') {
	    (*opts)[i].value.u_uint = 1;
	 } else {
	    ulongval = strtoul(a2, &a2, 0);
	    if (ulongval > UINT_MAX) {
	       Error3("parseopts(%s): unsigned int value exceeds limit (%u vs. %u), using max",
		      a0, ulongval, UINT_MAX);
	    }
	    (*opts)[i].value.u_uint = ulongval;
	 }
	 Info2("setting option \"%s\" to %u", ent->desc->defname,
	       (*opts)[i].value.u_uint);
	 break;

#if HAVE_BASIC_SIZE_T==2
      case TYPE_SIZE_T:
#endif
      case TYPE_USHORT:
	 if (optr != '=') {
	    (*opts)[i].value.u_ushort = 1;
	 } else {
	    ulongval = strtoul(a2, &a2, 0);
	    if (ulongval > USHRT_MAX) {
	       Error3("parseopts(%s): unsigned short value exceeds limit (%u vs. %u), using max",
		      a0, ulongval, USHRT_MAX);
	    }
	    (*opts)[i].value.u_ushort = ulongval;
	 }
	 Info2("setting option \"%s\" to %u", ent->desc->defname,
	       (*opts)[i].value.u_ushort);
	 break;

      case TYPE_OFF32:
#if HAVE_STAT64 && defined(HAVE_BASIC_OFF64_T) && HAVE_BASIC_OFF64_T==5
      case TYPE_OFF64:
#endif
      case TYPE_LONG:
	 if (optr != '=') {
	    (*opts)[i].value.u_long = 1;
	 } else {
	    slongval = strtol(a2, &a2, 0);
	    (*opts)[i].value.u_long = slongval;
	 }
	 Info2("setting option \"%s\" to %u", ent->desc->defname,
	       (*opts)[i].value.u_long);
	 break;

#if HAVE_BASIC_SIZE_T==6
      case TYPE_SIZE_T:
#endif
      case TYPE_ULONG:
	 if (optr != '=') {
	    (*opts)[i].value.u_ulong = 1;
	 } else {
	    ulongval = strtoul(a2, &a2, 0);
	    (*opts)[i].value.u_ulong = ulongval;
	 }
	 Info2("setting option \"%s\" to %u", ent->desc->defname,
	       (*opts)[i].value.u_ulong);
	 break;

#if HAVE_TYPE_LONGLONG
      case TYPE_LONGLONG:
#  if HAVE_STAT64 && defined(HAVE_BASIC_OFF64_T) && HAVE_BASIC_OFF64_T==7
      case TYPE_OFF64:
#  endif
	 if (optr != '=') {
	    (*opts)[i].value.u_longlong = 1;
	 } else {
#  if HAVE_STRTOLL
	    slonglongval = strtoll(a2, &a2, 0);
#  else
	    /* in this case, input value range is limited */
	    slonglongval = strtol(a2, &a2, 0);
#  endif /* HAVE_STRTOLL */
	    (*opts)[i].value.u_longlong = slonglongval;
	 }
	 Info2("setting option \"%s\" to %u", ent->desc->defname,
	       (*opts)[i].value.u_longlong);
	 break;
#endif /* HAVE_TYPE_LONGLONG */
      case TYPE_UIDT:
	 if (a2 == NULL) { Error1("option \"%s\": value required", a0);
	    continue; }
	 if (isdigit((*a2)&0xff)) {
	    (*opts)[i].value.u_uidt = strtoul(a2, &a2, 0);
	 } else {
	    struct passwd *pwd;
	    if ((pwd = getpwnam(a2)) == NULL) {
	       Error1("getpwnam(\"%s\"): no such user", a2);
	       continue;
	    }
	    (*opts)[i].value.u_uidt = getpwnam(a2)->pw_uid;
	 }
	 Info2("setting option \"%s\" to %u", ent->desc->defname,
	       (*opts)[i].value.u_uidt);
	 break;
      case TYPE_GIDT:
	 if (a2 == NULL) { Error1("option \"%s\": value required", a0);
	    continue; }
	 if (isdigit((*a2)&0xff)) {
	    (*opts)[i].value.u_gidt = strtoul(a2, &a2, 0);
	 } else {
	    struct group *grp;
	    grp = getgrnam(a2);
	    if (grp == NULL) {
	       Error1("getgrnam(\"%s\"): no such group", a2);
	       continue;
	    }
	    (*opts)[i].value.u_gidt = grp->gr_gid;
	 }
	 Info2("setting option \"%s\" to %u", ent->desc->defname,
	       (*opts)[i].value.u_gidt);
	 break;
      case TYPE_MODET:
	 if (optr != '=') { Error1("option \"%s\": value required", a0);
	    continue;
	 }
	 (*opts)[i].value.u_modet = strtoul(a2, &a2, 8);
	 Info2("setting option \"%s\" to %u", ent->desc->defname,
	       (*opts)[i].value.u_modet);
	 break;
      case TYPE_STRING:
	 if (optr != '=') {
	    Error1("option \"%s\": value required", a0);
	    continue;
	 }
	 (*opts)[i].value.u_string = a2;
	 Info2("setting option \"%s\" to \"%s\"", ent->desc->defname,
	       (*opts)[i].value.u_string);
	 break;
      case TYPE_STRING_NULL:
	 if (optr != '=') {
	    (*opts)[i].value.u_string = NULL;
	    Info1("setting option \"%s\" to NULL", ent->desc->defname);
	 } else {
	    (*opts)[i].value.u_string = a2;
	    Info2("setting option \"%s\" to \"%s\"", ent->desc->defname,
		  (*opts)[i].value.u_string);
	 }
	 break;
#if LATER
      case TYPE_INT3:
	 
	 break;
#endif
      case TYPE_TIMEVAL:
	 if (optr != '=') {
	    Error1("option \"%s\": value required", a0);
	    continue;
	 } else {
	    double val;
	    val = strtod(a2, NULL);
	    if (val == HUGE_VAL || val == -HUGE_VAL ||
		val == 0.0 && errno == ERANGE) {
	       Error2("strtod(\"%s\", NULL): %s", a2, strerror(errno));
	       val = 0.0;
	    }
	    (*opts)[i].value.u_timeval.tv_sec  = val;
	    (*opts)[i].value.u_timeval.tv_usec =
	       (val-(*opts)[i].value.u_timeval.tv_sec) * 1000000;
	 }
	 break;
#if HAVE_STRUCT_TIMESPEC
      case TYPE_TIMESPEC:
	 if (optr != '=') {
	    Error1("option \"%s\": value required", a0);
	    continue;
	 } else {
	    double val;
	    val = strtod(a2, NULL);
	    if (val == HUGE_VAL || val == -HUGE_VAL ||
		val == 0.0 && errno == ERANGE) {
	       Error2("strtod(\"%s\", NULL): %s", a2, strerror(errno));
	       val = 0.0;
	    }
	    (*opts)[i].value.u_timespec.tv_sec  = val;
	    (*opts)[i].value.u_timespec.tv_nsec =
	       (val-(*opts)[i].value.u_timespec.tv_sec) * 1000000000.;
	 }
	 break;
#endif /* HAVE_STRUCT_TIMESPEC */
#if HAVE_STRUCT_LINGER
      case TYPE_LINGER:
	 if (optr != '=') {
	    Error1("option \"%s\": value required", a0);
	    continue;
	 }
	 (*opts)[i].value.u_linger.l_onoff = 1;
	 (*opts)[i].value.u_linger.l_linger = strtoul(a2, &a2, 0);
	 Info3("setting option \"%s\" to {%d,%d}", ent->desc->defname,
	       (*opts)[i].value.u_linger.l_onoff,
	       (*opts)[i].value.u_linger.l_linger);
	 break;
#endif /* HAVE_STRUCT_LINGER */
      default:
	 Error2("parseopts(): internal error on option \"%s\": unimplemented type %d",
		ent->desc->defname, ent->desc->type);
	 continue;
      }
      if (comma) {
	 a = comma;
      } else {
	 optr = '\0';
      }

      ++i;
      if ((i % 8) == 0) {
	 *opts = Realloc(*opts, (i+8) * sizeof(struct opt));
	 if (*opts == NULL) {
	    return -1;
	 }
      }
   }
   /*(*opts)[i+1].desc = ODESC_END;*/
   (*opts)[i].desc = ODESC_END;
   return 0;
}

/* copy the already parsed options for repeated application, but only those
   matching groups ANY and <groups> */
struct opt *copyopts(const struct opt *opts, unsigned int groups) {
   struct opt *new;
   int i, j, n;

   if (!opts)  return NULL;

   /* just count the options in the array */
   i = 0; while (opts[i].desc != ODESC_END) {
      ++i;
   }
   n = i+1;

   new = Malloc(n * sizeof(struct opt));
   if (new == NULL) {
      return NULL;
   }

   /*0 memcpy(new, opts, (i+1)*sizeof(struct opt)); */
   i = 0, j = 0;
   while (i < n-1) {
      if (opts[i].desc == ODESC_DONE) {
	 new[j].desc = ODESC_DONE;
      } else if ((opts[i].desc->group & (GROUP_ANY&~GROUP_PROCESS)) ||
		 (opts[i].desc->group & groups)) {
	 new[j++] = opts[i];
      }
      ++i;
   }
   new[j].desc = ODESC_END;
   return new;
}

/* move options to a new options list
   move only those matching <groups> */
struct opt *moveopts(struct opt *opts, unsigned int groups) {
   struct opt *new;
   int i, j, n;

   if (!opts)  return NULL;

   /* just count the options in the array */
   i = 0; j = 0; while (opts[i].desc != ODESC_END) {
      if (opts[i].desc != ODESC_DONE &&
	  opts[i].desc != ODESC_ERROR)
	 ++j;
      ++i;
   }
   n = i;

   new = Malloc((j+1) * sizeof(struct opt));
   if (new == NULL) {
      return NULL;
   }

   /*0 memcpy(new, opts, (i+1)*sizeof(struct opt)); */
   i = 0, j = 0;
   while (i < n) {
      if (opts[i].desc == ODESC_DONE ||
	  opts[i].desc == ODESC_ERROR) {
	 ++i; continue;
      } else if (opts[i].desc->group & groups) {
	 new[j++] = opts[i];
	 opts[i].desc = ODESC_DONE;
      }
      ++i;
   }
   new[j].desc = ODESC_END;
   return new;
}

/* return the number of yet unconsumed options; -1 on error */
int leftopts(const struct opt *opts) {
   const struct opt *opt = opts;
   int num = 0;

   if (!opts)  return 0;

   while (opt->desc != ODESC_END) {
      if (opt->desc != ODESC_DONE) {
	 ++num;
      }
      ++opt;
   }
   return num;
}

/* show as warning which options are still unused */
int showleft(const struct opt *opts) {
   const struct opt *opt = opts;

   while (opt->desc != ODESC_END) {
      if (opt->desc != ODESC_DONE) {
	 Warn1("showleft(): option \"%s\" not inquired", opt->desc->defname);
      }
      ++opt;
   }
   return 0;
}


/* determines the address group from mode_t */
/* does not set GROUP_FD; cannot determine GROUP_TERMIOS ! */
int _groupbits(mode_t mode) {
   unsigned int result = 0;
  
   switch ((mode&S_IFMT)>>12) {
   case (S_IFIFO>>12):	/* 1, FIFO */
      result = GROUP_FIFO;   break;
   case (S_IFCHR>>12):	/* 2, character device */
      result = GROUP_CHR|GROUP_TERMIOS;    break;
   case (S_IFDIR>>12):	/* 4, directory !!! not supported */
      result = GROUP_NONE;   break;
   case (S_IFBLK>>12):	/* 6, block device */
      result = GROUP_BLK;    break;
   case (S_IFREG>>12):	/* 8, regular file */
      result = GROUP_REG;    break;
   case (S_IFLNK>>12):	/* 10, symbolic link !!! not supported */
      result = GROUP_NONE;   break;
#ifdef S_IFSOCK
   case (S_IFSOCK>>12): /* 12, socket */
      result = GROUP_SOCKET|GROUP_SOCK_UNIX; break;
#else
   default: /* some systems (pure POSIX.1) do not know S_IFSOCK */
      result = GROUP_SOCKET|GROUP_SOCK_UNIX; break;
#endif
   }
   Debug2("_groupbits(%d) -> %d", mode, result);
   return result;
}

/* does not set GROUP_FD */
int groupbits(int fd) {
#if HAVE_STAT64
   struct stat64 buf;
#else
   struct stat buf;
#endif /* !HAVE_STAT64 */
   int result;

   if (
#if HAVE_STAT64
       Fstat64(fd, &buf) < 0
#else
       Fstat(fd, &buf) < 0
#endif /* !HAVE_STAT64 */
      ) {
      Error4("groupbits(%d): fstat(%d, %p): %s",
	     fd, fd, &buf, strerror(errno));
      return -1;
   }
   result = _groupbits(buf.st_mode&S_IFMT);
   if (result == GROUP_CHR) {
      if (Isatty(fd) > 0) {
	 result |= GROUP_TERMIOS;
      }
   }
   return result;
}

#if 0	/* currently not used */
int retropt(struct opt *opts, int optcode, union integral *result) {
   struct opt *opt = opts;

   while (opt->desc != ODESC_END) {
      if (opt->desc != ODESC_DONE && opt->desc->optcode == optcode) {
	 *result = opt->value;
	 opt->desc = ODESC_DONE;
	 return 0;
      }
      ++opt;
   }
   return -1;
}
#endif

static struct opt *xio_findopt(struct opt *opts, int optcode) {
   struct opt *opt = opts;

   while (opt->desc != ODESC_END) {
      if (opt->desc != ODESC_DONE && opt->desc->optcode == optcode) {
	 return opt;
      }
      ++opt;
   }
   return NULL;
}

int retropt_timespec(struct opt *opts, int optcode, struct timespec *result) {
   struct opt *opt;

   if (!(opt = xio_findopt(opts, optcode))) {
      return -1;
   }
   *result = opt->value.u_timespec;
   opt->desc = ODESC_DONE;
   return 0;
}
      
   
/* Looks for the first option of type <optcode>. If the option is found,
   this function stores its bool value in *result, "consumes" the
   option, and returns 0.
   If the option is not found, *result is not modified, and -1 is returned. */
int retropt_bool(struct opt *opts, int optcode, bool *result) {
   struct opt *opt = opts;

   while (opt->desc != ODESC_END) {
      if (opt->desc != ODESC_DONE && opt->desc->optcode == optcode) {
	 *result = opt->value.u_bool;
	 opt->desc = ODESC_DONE;
	 return 0;
      }
      ++opt;
   }
   return -1;
}

#if 0	/* currently not used */
/* Looks for the first option of type <optcode>. If the option is found,
   this function stores its short value in *result, "consumes" the
   option, and returns 0.
   If the option is not found, *result is not modified, and -1 is returned. */
int retropt_short(struct opt *opts, int optcode, short *result) {
   struct opt *opt = opts;

   while (opt->desc != ODESC_END) {
      if (opt->desc != ODESC_DONE && opt->desc->optcode == optcode) {
	 *result = opt->value.u_short;
	 opt->desc = ODESC_DONE;
	 return 0;
      }
      ++opt;
   }
   return -1;
}
#endif

/* Looks for the first option of type <optcode>. If the option is found,
   this function stores its unsigned short value in *result, "consumes" the
   option, and returns 0.
   If the option is not found, *result is not modified, and -1 is returned. */
int retropt_ushort(struct opt *opts, int optcode, unsigned short *result) {
   struct opt *opt = opts;

   while (opt->desc != ODESC_END) {
      if (opt->desc != ODESC_DONE && opt->desc->optcode == optcode) {
	 *result = opt->value.u_ushort;
	 opt->desc = ODESC_DONE;
	 return 0;
      }
      ++opt;
   }
   return -1;
}

/* Looks for the first option of type <optcode>. If the option is found,
   this function stores its int value in *result, "consumes" the
   option, and returns 0.
   If the option is not found, *result is not modified, and -1 is returned. */
int retropt_int(struct opt *opts, int optcode, int *result) {
   struct opt *opt = opts;

   while (opt->desc != ODESC_END) {
      if (opt->desc != ODESC_DONE && opt->desc->optcode == optcode) {
	 *result = opt->value.u_int;
	 opt->desc = ODESC_DONE;
	 return 0;
      }
      ++opt;
   }
   return -1;
}

/* Looks for the first option of type <optcode>. If the option is found,
   this function stores its unsigned int value in *result, "consumes" the
   option, and returns 0.
   If the option is not found, *result is not modified, and -1 is returned. */
int retropt_uint(struct opt *opts, int optcode, unsigned int *result) {
   struct opt *opt = opts;

   while (opt->desc != ODESC_END) {
      if (opt->desc != ODESC_DONE && opt->desc->optcode == optcode) {
	 *result = opt->value.u_uint;
	 opt->desc = ODESC_DONE;
	 return 0;
      }
      ++opt;
   }
   return -1;
}

/* Looks for the first option of type <optcode>. If the option is found,
   this function stores its long value in *result, "consumes" the option,
   and returns 0.
   If the option is not found, *result is not modified, and -1 is returned. */
int retropt_long(struct opt *opts, int optcode, long *result) {
   struct opt *opt = opts;

   while (opt->desc != ODESC_END) {
      if (opt->desc != ODESC_DONE && opt->desc->optcode == optcode) {
	 *result = opt->value.u_long;
	 opt->desc = ODESC_DONE;
	 return 0;
      }
      ++opt;
   }
   return -1;
}

/* Looks for the first option of type <optcode>. If the option is found,
   this function stores its unsigned long value in *result, "consumes" the
   option, and returns 0.
   If the option is not found, *result is not modified, and -1 is returned. */
int retropt_ulong(struct opt *opts, int optcode, unsigned long *result) {
   struct opt *opt = opts;

   while (opt->desc != ODESC_END) {
      if (opt->desc != ODESC_DONE && opt->desc->optcode == optcode) {
	 *result = opt->value.u_ulong;
	 opt->desc = ODESC_DONE;
	 return 0;
      }
      ++opt;
   }
   return -1;
}

#if 0	/* currently not used */
/* get the value of a FLAG typed option, and apply it to the appropriate
   bit position. Mark the option as consumed (done). return 0 if options was found and successfully applied,
   or -1 if option was not in opts */
int retropt_flag(struct opt *opts, int optcode, flags_t *result) {
   struct opt *opt = opts;

   while (opt->desc != ODESC_END) {
      if (opt->desc != ODESC_DONE && opt->desc->optcode == optcode) {
	 if (opt->value.u_bool) {
	    *result |= opt->desc->major;
	 } else {
	    *result &= ~opt->desc->major;
	 }
	 opt->desc = ODESC_DONE;
	 return 0;
      }
      ++opt;
   }
   return -1;
}
#endif

/* Looks for the first option of type <optcode>. If the option is found,
   this function stores its character pointer value in *result, "consumes" the
   option, and returns 0. Note that, for options of type STRING_NULL, the
   character pointer might degenerate to NULL.
   If the option is not found, *result is not modified, and -1 is returned. */
int retropt_string(struct opt *opts, int optcode, char **result) {
   struct opt *opt = opts;

   while (opt->desc != ODESC_END) {
      if (opt->desc != ODESC_DONE && opt->desc->optcode == optcode) {
	 if (opt->value.u_string == NULL) {
	    *result = NULL;
	 } else if ((*result = strdup(opt->value.u_string)) == NULL) {
	    Error1("strdup("F_Zu"): out of memory",
		   strlen(opt->value.u_string));
	    return -1;
	 }
	 opt->desc = ODESC_DONE;
	 return 0;
      }
      ++opt;
   }
   return -1;
}


#if WITH_SOCKET
int retropt_bind(struct opt *opts,
		 int af,
		 const char *protoname,	/* for service resolution */
		 struct sockaddr *sa,
		 int feats	/* TCP etc: 1..address allowed,
				   3..address and port allowed */
		 ) {
   char *bindname;
   /*0 struct hostent *usaddr;*/

   if (retropt_string(opts, OPT_BIND, &bindname) < 0) {
      return -1;
   }

   switch (af) {
#if WITH_IP4
   case AF_INET:
      return
	 parseip4addr(bindname, (struct sockaddr_in *)sa, protoname,
		      0, (feats>=2)?0:-1);
      break;
#endif /* WITH_IP4 */

#if WITH_UNIX
   case AF_UNIX:
      {
	 struct sockaddr_un *s_un = (struct sockaddr_un *)sa;
	 strncpy(s_un->sun_path, bindname, UNIX_PATH_MAX);
      }
      break;
#endif /* WITH_UNIX */

#if WITH_IP6
   case AF_INET6:
      switch (bindname[0]) {
	 char *np;
	 struct sockaddr_in6 *sin6;
      case '.': case ':': /* only port */
	 sin6 = (struct sockaddr_in6 *) sa;
	 if (!(feats & 2)) {
	    Error("bind cannot set port here");
	    return -1;
	 } else {
	    sin6 = (struct sockaddr_in6 *)sa;
	    sin6->sin6_port = htons(strtoul(bindname+1, &np, 0));
	    if (*np) {
	      Error1("option \"bind\": port number with extra data \"%s\"",
		     np);
	    }
	 }
	 break;
      default:
	 sin6 = (struct sockaddr_in6 *) sa;
	 return parseip6addr(bindname, sin6, protoname,
			     (feats&1)?9:-1, (feats&2)?0:-1);
      }
      break;
#endif /* WITH_IP6 */
   default:
      Error1("bind: unknown address family type %d", af);
      return -1;
   }
   return 0;
}
#endif /* WITH_SOCKET */


/* applies to fd all options belonging to phase */
/* note: not all options can be applied this way (e.g. OFUNC_SPEC with PH_OPEN)
   implemented are: OFUNC_FCNTL, OFUNC_SOCKOPT (probably not all types),
   OFUNC_TERMIOS_FLAG, OFUNC_TERMIOS_PATTERN, and some OFUNC_SPEC */
int applyopts(int fd, struct opt *opts, unsigned int phase) {
   struct opt *opt;

   opt = opts; while (opt && opt->desc != ODESC_END) {
      if (opt->desc == ODESC_DONE ||
	  (phase != PH_ALL && opt->desc->phase != phase)) {
	 ++opt; continue; }

      if (opt->desc->func == OFUNC_SEEK32) {
	 if (Lseek(fd, opt->value.u_long, opt->desc->major) < 0) {
	    Error4("lseek(%d, %ld, %d): %s",
		   fd, opt->value.u_long, opt->desc->major, strerror(errno));
	 }
#if HAVE_LSEEK64
      } else if (opt->desc->func == OFUNC_SEEK64) {

	 /*! this depends on off64_t atomic type */
	 if (Lseek64(fd, opt->value.u_off64, opt->desc->major) < 0) {
	    Error4("lseek64(%d, %Ld, %d): %s",
		   fd, opt->value.u_off64, opt->desc->major, strerror(errno));
	 }
#endif /* HAVE_LSEEK64 */

      } else if (opt->desc->func == OFUNC_FCNTL) {
	 int flag;

	 /* retrieve existing flag setttings */
	 if ((flag = Fcntl(fd, opt->desc->major-1)) < 0) {
	    Error3("fcntl(%d, %d): %s",
		   fd, opt->desc->major, strerror(errno));
	    opt->desc = ODESC_ERROR; continue;
	 } else {
	    if (opt->value.u_bool) {
	       flag |= opt->desc->minor;
	    } else {
	       flag &= ~opt->desc->minor;
	    }
	    if (Fcntl_l(fd, opt->desc->major, flag) < 0) {
	       Error4("fcntl(%d, %d, %d): %s",
		      fd, opt->desc->major, flag, strerror(errno));
	       opt->desc = ODESC_ERROR; continue;
	    }
	 }

      } else if (opt->desc->func == OFUNC_IOCTL) {
	 if (Ioctl(fd, opt->desc->major, (void *)&opt->value) < 0) {
	    Error4("ioctl(%d, 0x%x, %p): %s",
		   fd, opt->desc->major, (void *)&opt->value, strerror(errno));
	    opt->desc = ODESC_ERROR; continue;
	 }

#if WITH_SOCKET
      } else if (opt->desc->func == OFUNC_SOCKOPT) {
#if 0 && HAVE_STRUCT_LINGER
	 if (opt->desc->optcode == OPT_SO_LINGER) {
	    struct linger lingstru;
	    lingstru.l_onoff = (opt->value.u_int>=0 ? 1 : 0);
	    lingstru.l_linger = opt->value.u_int;
	    if (Setsockopt(fd, opt->desc->major, opt->desc->minor, &lingstru,
			   sizeof(lingstru)) < 0) {
	       Error6("setsockopt(%d, %d, %d, {%d,%d}, "F_Zu,
		      fd, opt->desc->major, opt->desc->minor, lingstru.l_onoff,
		      lingstru.l_linger, sizeof(lingstru));
	       opt->desc = ODESC_ERROR; continue;
	    }
	 } else {
#endif /* HAVE_STRUCT_LINGER */
	    switch (opt->desc->type) {
	    case TYPE_BIN:
	       if (Setsockopt(fd, opt->desc->major, opt->desc->minor,
			      opt->value.u_bin.b_data, opt->value.u_bin.b_len)
		   < 0) {
		  Error6("setsockopt(%d, %d, %d, %p, %d): %s",
			 fd, opt->desc->major, opt->desc->minor,
			 opt->value.u_bin.b_data, opt->value.u_bin.b_len,
			 strerror(errno));
		  opt->desc = ODESC_ERROR; continue;
	       }
	       break;
	    case TYPE_BOOL:
	       if (Setsockopt(fd, opt->desc->major, opt->desc->minor,
			      &opt->value.u_bool, sizeof(opt->value.u_bool))
		   < 0) {
		  Error6("setsockopt(%d, %d, %d, {%d}, "F_Zu"): %s", fd,
			 opt->desc->major, opt->desc->minor,
			 opt->value.u_bool, sizeof(opt->value.u_bool),
			 strerror(errno));
		  opt->desc = ODESC_ERROR; continue;
	       }
	       break;
	    case TYPE_BYTE:
	       if (Setsockopt(fd, opt->desc->major, opt->desc->minor,
			      &opt->value.u_byte, sizeof(byte_t)) < 0) {
		  Error6("setsockopt(%d, %d, %d, {%u}, "F_Zu"): %s",
			 fd, opt->desc->major, opt->desc->minor,
			 opt->value.u_byte, sizeof(byte_t), strerror(errno));
		  opt->desc = ODESC_ERROR; continue;
	       }
	       break;
	    case TYPE_INT:
	       if (Setsockopt(fd, opt->desc->major, opt->desc->minor,
			      &opt->value.u_int, sizeof(int)) < 0) {
		  Error6("setsockopt(%d, %d, %d, {%d}, "F_Zu"): %s",
			 fd, opt->desc->major, opt->desc->minor,
			 opt->value.u_int, sizeof(int), strerror(errno));
		  opt->desc = ODESC_ERROR; continue;
	       }
	       break;
	    case TYPE_LONG:
	       if (Setsockopt(fd, opt->desc->major, opt->desc->minor,
			      &opt->value.u_long, sizeof(long)) < 0) {
		  Error6("setsockopt(%d, %d, %d, {%ld}, "F_Zu"): %s",
			 fd, opt->desc->major, opt->desc->minor,
			 opt->value.u_long, sizeof(long), strerror(errno));
		  opt->desc = ODESC_ERROR; continue;
	       }
	       break;
	    case TYPE_STRING:
	       if (Setsockopt(fd, opt->desc->major, opt->desc->minor,
			      opt->value.u_string,
			      strlen(opt->value.u_string)+1) < 0) {
		  Error6("setsockopt(%d, %d, %d, \"%s\", "F_Zu"): %s",
			 fd, opt->desc->major, opt->desc->minor,
			 opt->value.u_string, strlen(opt->value.u_string)+1,
			 strerror(errno));
		  opt->desc = ODESC_ERROR; continue;
	       }
	       break;
	    case TYPE_UINT:
	       if (Setsockopt(fd, opt->desc->major, opt->desc->minor,
			      &opt->value.u_uint, sizeof(unsigned int)) < 0) {
		  Error6("setsockopt(%d, %d, %d, {%u}, "F_Zu"): %s",
			 fd, opt->desc->major, opt->desc->minor,
			 opt->value.u_uint, sizeof(unsigned int),
			 strerror(errno));
		  opt->desc = ODESC_ERROR; continue;
	       }
	       break;
	    case TYPE_TIMEVAL:
	       if (Setsockopt(fd, opt->desc->major, opt->desc->minor,
			      &opt->value.u_timeval, sizeof(struct timeval)) < 0) {
		  Error7("setsockopt(%d, %d, %d, {%ld,%ld}, "F_Zu"): %s",
			 fd, opt->desc->major, opt->desc->minor,
			 opt->value.u_timeval.tv_sec, opt->value.u_timeval.tv_usec,
			 sizeof(struct timeval), strerror(errno));
		  opt->desc = ODESC_ERROR; continue;
	       }
	       break;
#if HAVE_STRUCT_LINGER
	    case TYPE_LINGER:
	       {
		  struct linger lingstru;
		  lingstru.l_onoff = (opt->value.u_linger.l_onoff>=0 ? 1 : 0);
		  lingstru.l_linger = opt->value.u_linger.l_linger;
		  if (Setsockopt(fd, opt->desc->major, opt->desc->minor,
				 &lingstru, sizeof(lingstru)) < 0) {
		     Error6("setsockopt(%d, %d, %d, {%d,%d}): %s",
			    fd, opt->desc->major, opt->desc->minor,
			    lingstru.l_onoff, lingstru.l_linger,
			    strerror(errno));
		    opt->desc = ODESC_ERROR; continue;
		  }
	       }
	       break;
#endif /* HAVE_STRUCT_LINGER */
	       /*! still many types missing; implement on demand */
#if !NDEBUG
	    default: Error1("applyopts(): type %d not implemented",
			    opt->desc->type);
	       opt->desc = ODESC_ERROR; continue;
#endif
	    }
#if 0 && HAVE_STRUCT_LINGER
	 }
#endif /* HAVE_STRUCT_LINGER */

      } else if (opt->desc->func == OFUNC_SOCKOPT_APPEND) {
	 switch (opt->desc->type) {
	    byte_t data[256];
	    socklen_t oldlen, newlen;
	 case TYPE_BIN:
	    oldlen = sizeof(data);
	    if (Getsockopt(fd, opt->desc->major, opt->desc->minor,
			   data, &oldlen)
		< 0) {
	       Error6("getsockopt(%d, %d, %d, %p, {F_Zu}): %s",
		      fd, opt->desc->major, opt->desc->minor, data, oldlen,
		      strerror(errno));
	       opt->desc = ODESC_ERROR; continue;
	    }
	    memcpy(&data[oldlen], opt->value.u_bin.b_data,
		   MIN(opt->value.u_bin.b_len, sizeof(data)-oldlen));
	    newlen = oldlen + MIN(opt->value.u_bin.b_len, sizeof(data)-oldlen);
	    if (Setsockopt(fd, opt->desc->major, opt->desc->minor,
			   data, newlen)
		< 0) {
	       Error6("setsockopt(%d, %d, %d, %p, %d): %s",
		      fd, opt->desc->major, opt->desc->minor, data, newlen,
		      strerror(errno));
	       opt->desc = ODESC_ERROR; continue;
	    }
	    break;
	 default:
	    Error2("internal: option \"%s\": unimplemented type %d",
		   opt->desc->defname, opt->desc->type);
	    break;
	 }
#endif /* WITH_SOCKET */
	 
#if HAVE_FLOCK
      } else if (opt->desc->func == OFUNC_FLOCK) {
	 if (Flock(fd, opt->desc->major) < 0) {
	    Error3("flock(%d, %d): %s",
		   fd, opt->desc->major, strerror(errno));
	    opt->desc = ODESC_ERROR; continue;
	 }
#endif /* defined(HAVE_FLOCK) */

      } else if (opt->desc->func == OFUNC_SPEC ||
		 opt->desc->func == OFUNC_FLAG) {
	 switch (opt->desc->optcode) {
	 case OPT_USER:
	 case OPT_USER_LATE:
	    if (Fchown(fd, opt->value.u_uidt, -1) < 0) {
	       Error3("fchown(%d, "F_uid", -1): %s",
		      fd, opt->value.u_uidt, strerror(errno));
	       opt->desc = ODESC_ERROR; continue;
	    }
	    break;
	 case OPT_GROUP:
	 case OPT_GROUP_LATE:
	    if (Fchown(fd, -1, opt->value.u_gidt) < 0) {
	       Error3("fchown(%d, -1, "F_gid"): %s",
		      fd, opt->value.u_gidt, strerror(errno));
	       opt->desc = ODESC_ERROR; continue;
	    }
	    break;
	 case OPT_PERM:
	 case OPT_PERM_LATE:
	    if (Fchmod(fd, opt->value.u_modet) < 0) {
	       Error3("fchmod(%d, %u): %s",
		      fd, opt->value.u_modet, strerror(errno));
	       opt->desc = ODESC_ERROR; continue;
	    }
	    break;
	 case OPT_FTRUNCATE32:
	    if (Ftruncate(fd, opt->value.u_long) < 0) {
	       Error3("ftruncate(%d, %ld): %s",
		      fd, opt->value.u_long, strerror(errno));
	       opt->desc = ODESC_ERROR; continue;
	    }
	    break;
#if HAVE_FTRUNCATE64
	 case OPT_FTRUNCATE64:
	    if (Ftruncate64(fd, opt->value.u_long) < 0) {
	       Error3("ftruncate64(%d, %ld): %s",
		      fd, opt->value.u_long, strerror(errno));
	       opt->desc = ODESC_ERROR; continue;
	    }
#endif /* HAVE_FTRUNCATE64 */
	    break; 
	 case OPT_F_SETLK:
	 case OPT_F_SETLKW:
	    {
	       struct flock l;	/* Linux: <asm/fcntl.h> */
	       l.l_type   = F_WRLCK;
	       l.l_whence = SEEK_SET;
	       l.l_start  = 0;
	       l.l_len    = LONG_MAX;
	       l.l_pid    = 0;	/* hope this uses our current process */
	       if (Fcntl_lock(fd, opt->desc->major, &l) < 0) {
		  Error3("fcntl(%d, %d, {type=F_WRLCK,whence=SEEK_SET,start=0,len=LONG_MAX,pid=0}): %s", fd, opt->desc->major, strerror(errno));
		  opt->desc	 = ODESC_ERROR; continue;
	       }
	    }
	    break; 
	 case OPT_SETUID_EARLY:
	 case OPT_SETUID:
	    if (Setuid(opt->value.u_uidt) < 0) {
	       Error2("setuid("F_uid"): %s", opt->value.u_uidt,
		      strerror(errno));
	       opt->desc = ODESC_ERROR; continue;
	    }
	    break;
	 case OPT_SETGID_EARLY:
	 case OPT_SETGID:
	    if (Setgid(opt->value.u_gidt) < 0) {
	       Error2("setgid("F_gid"): %s", opt->value.u_gidt,
		      strerror(errno));
	       opt->desc = ODESC_ERROR; continue;
	    }
	    break;
	 case OPT_SUBSTUSER:
	    {
	       struct passwd *pwd;
	       if ((pwd = getpwuid(opt->value.u_uidt)) == NULL) {
		  Error1("getpwuid("F_uid"): no such user",
			 opt->value.u_uidt);
		  opt->desc = ODESC_ERROR; continue;
	       }
	       if (Initgroups(pwd->pw_name, pwd->pw_gid) < 0) {
		  Error3("initgroups(%s, "F_gid"): %s",
			 pwd->pw_name, pwd->pw_gid, strerror(errno));
		  opt->desc = ODESC_ERROR; continue;
	       }
	       if (Setgid(pwd->pw_gid) < 0) {
		  Error2("setgid("F_gid"): %s", pwd->pw_gid,
			 strerror(errno));
		  opt->desc = ODESC_ERROR; continue;
	       }
	       if (Setuid(opt->value.u_uidt) < 0) {
		  Error2("setuid("F_uid"): %s", opt->value.u_uidt,
			 strerror(errno));
		  opt->desc = ODESC_ERROR; continue;
	       }
#if 1
	       if (setenv("USER", pwd->pw_name, 1) < 0)
		  Error1("setenv(\"USER\", \"%s\", 1): insufficient space",
			 pwd->pw_name);
	       if (setenv("LOGNAME", pwd->pw_name, 1) < 0)
		  Error1("setenv(\"LOGNAME\", \"%s\", 1): insufficient space",
			 pwd->pw_name);
	       if (setenv("HOME", pwd->pw_dir, 1) < 0)
		  Error1("setenv(\"HOME\", \"%s\", 1): insufficient space",
			 pwd->pw_dir);
	       if (setenv("SHELL", pwd->pw_shell, 1) < 0)
		  Error1("setenv(\"SHELL\", \"%s\", 1): insufficient space",
			 pwd->pw_shell);
#endif
	    }
	    break;
	 case OPT_SUBSTUSER_DELAYED:
	    {
	       struct passwd *pwd;

	       if ((pwd = getpwuid(opt->value.u_uidt)) == NULL) {
		  Error1("getpwuid("F_uid"): no such user",
			 opt->value.u_uidt);
		  opt->desc = ODESC_ERROR; continue;
	       }
	       delayeduser_uid = opt->value.u_uidt;
	       delayeduser_gid = pwd->pw_gid;
	       if ((delayeduser_name = strdup(pwd->pw_name)) == NULL) {
		  Error1("strdup("F_Zu"): out of memory",
			 strlen(pwd->pw_name)+1);
		  opt->desc = ODESC_ERROR; continue;
	       }
	       if ((delayeduser_dir = strdup(pwd->pw_dir)) == NULL) {
		  Error1("strdup("F_Zu"): out of memory",
			 strlen(pwd->pw_dir)+1);
		  opt->desc = ODESC_ERROR; continue;
	       }
	       if ((delayeduser_shell = strdup(pwd->pw_shell)) == NULL) {
		  Error1("strdup("F_Zu"): out of memory",
			 strlen(pwd->pw_shell)+1);
		  opt->desc = ODESC_ERROR; continue;
	       }
	       /* function to get all supplementary groups of user */
	       delayeduser_ngids = sizeof(delayeduser_gids)/sizeof(gid_t);
	       getusergroups(delayeduser_name, delayeduser_gids,
			     &delayeduser_ngids);
	       delayeduser = true;
	    }
	    break;
	 case OPT_CHROOT_EARLY:
	 case OPT_CHROOT:
	    if (Chroot(opt->value.u_string) < 0) {
	       Error2("chroot(\"%s\"): %s", opt->value.u_string,
		      strerror(errno));
	       opt->desc = ODESC_ERROR; continue;
	    }
	    if (Chdir("/") < 0) {
	       Error1("chdir(\"/\"): %s", strerror(errno));
	    }
	    break;
	 case OPT_SETSID:
	    if (Setsid() < 0) {
	       Warn1("setsid(): %s", strerror(errno));
	       if (Setpgid(getpid(), getppid()) < 0) {
		  Warn3("setpgid(%d, %d): %s",
			getpid(), getppid(), strerror(errno));
	       } else {
		  if (Setsid() < 0) {
		     Error1("setsid(): %s", strerror(errno));
		  }		  
	       }
	    }
	    break;
	 case OPT_SETPGID:
	    if (Setpgid(0, opt->value.u_int) < 0) {
	       Warn2("setpgid(0, "F_pid"): %s",
		     opt->value.u_int, strerror(errno));
	    }
	    break;
	 case OPT_TIOCSCTTY:
	    {
	       int mytty;
	       /* this code idea taken from ssh/pty.c: make pty controlling term. */
	       if ((mytty = Open("/dev/tty", O_NOCTTY, 0640)) < 0) {
		  Warn1("open(\"/dev/tty\", O_NOCTTY, 0640): %s", strerror(errno));
	       } else {
		  /*0 Info1("open(\"/dev/tty\", O_NOCTTY, 0640) -> %d", mytty);*/
#ifdef TIOCNOTTY
		  if (Ioctl(mytty, TIOCNOTTY, NULL) < 0) {
		     Warn2("ioctl(%d, TIOCNOTTY, NULL): %s",
			   mytty, strerror(errno));
		  }
#endif
		  if (Close(mytty) < 0) {
		     Warn2("close(%d): %s",
			   mytty, strerror(errno));
		  }
	       }
#ifdef TIOCSCTTY
	       if (Ioctl(fd, TIOCSCTTY, NULL) < 0) {
		  Warn2("ioctl(%d, TIOCSCTTY, NULL): %s", fd, strerror(errno));
	       }
#endif
	       if (Tcsetpgrp(0, getpid()) < 0) {
		  Warn2("tcsetpgrp("F_pid"): %s", getpid(), strerror(errno));
	       }
	    }
	    break;
	 default: Error1("applyopts(): option \"%s\" not implemented",
			 opt->desc->defname);
	    opt->desc = ODESC_ERROR; continue;
	 }

#if WITH_TERMIOS
      } else if (opt->desc->func == OFUNC_TERMIOS_FLAG) {
#if 0
	 union {
	    struct termios termarg;
	    tcflag_t flags[4];
	 } tdata;
	 if (Tcgetattr(fd, &tdata.termarg) < 0) {
	    Error3("tcgetattr(%d, %p): %s",
		   fd, &tdata.termarg, strerror(errno));
	    opt->desc = ODESC_ERROR; continue;
	 }
	 if (opt->value.u_bool) {
	    tdata.flags[opt->desc->major] |= opt->desc->minor;
	 } else {
	    tdata.flags[opt->desc->major] &= ~opt->desc->minor;
	 }
	 if (Tcsetattr(fd, TCSADRAIN, &tdata.termarg) < 0) {
	    Error3("tcsetattr(%d, TCSADRAIN, %p): %s",
		   fd, &tdata.termarg, strerror(errno));
	    opt->desc = ODESC_ERROR; continue;
	 }
#else
	 if (xiotermiosflag_applyopt(fd, opt) < 0) {
	    continue;
	 }
#endif

      } else if (opt->desc->func == OFUNC_TERMIOS_VALUE) {
	 union {
	    struct termios termarg;
	    tcflag_t flags[4];
	 } tdata;
	 if (((opt->value.u_uint << opt->desc->arg3) & opt->desc->minor) !=
	     (opt->value.u_uint << opt->desc->arg3)) {
	    Error2("option %s: invalid value %u",
		   opt->desc->defname, opt->value.u_uint);
	    opt->desc = ODESC_ERROR; continue;
	 }
	 if (Tcgetattr(fd, &tdata.termarg) < 0) {
	    Error3("tcgetattr(%d, %p): %s",
		   fd, &tdata.termarg, strerror(errno));
	    opt->desc = ODESC_ERROR; continue;
	 }

	 tdata.flags[opt->desc->major] &= ~opt->desc->minor;
	 tdata.flags[opt->desc->major] |=
	    ((opt->value.u_uint << opt->desc->arg3) & opt->desc->minor);
	 if (Tcsetattr(fd, TCSADRAIN, &tdata.termarg) < 0) {
	    Error3("tcsetattr(%d, TCSADRAIN, %p): %s",
		   fd, &tdata.termarg, strerror(errno));
	    opt->desc = ODESC_ERROR; continue;
	 }

      } else if (opt->desc->func == OFUNC_TERMIOS_PATTERN) {
	 union {
	    struct termios termarg;
	    tcflag_t flags[4];
	 } tdata;
	 if (Tcgetattr(fd, &tdata.termarg) < 0) {
	    Error3("tcgetattr(%d, %p): %s",
		   fd, &tdata.termarg, strerror(errno));
	    opt->desc = ODESC_ERROR; continue;
	 }
	 tdata.flags[opt->desc->major] &= ~opt->desc->arg3;
	 tdata.flags[opt->desc->major] |= opt->desc->minor;
	 if (Tcsetattr(fd, TCSADRAIN, &tdata.termarg) < 0) {
	    Error3("tcsetattr(%d, TCSADRAIN, %p): %s",
		   fd, &tdata.termarg, strerror(errno));
	    opt->desc = ODESC_ERROR; continue;
	 }

      } else if (opt->desc->func == OFUNC_TERMIOS_CHAR) {
	 struct termios termarg;
	 if (Tcgetattr(fd, &termarg) < 0) {
	    Error3("tcgetattr(%d, %p): %s",
		   fd, &termarg, strerror(errno));
	    opt->desc = ODESC_ERROR; continue;
	 }
	 termarg.c_cc[opt->desc->major] = opt->value.u_byte;
	 if (Tcsetattr(fd, TCSADRAIN, &termarg) < 0) {
	    Error3("tcsetattr(%d, TCSADRAIN, %p): %s",
		   fd, &termarg, strerror(errno));
	    opt->desc = ODESC_ERROR; continue;
	 }

#ifdef HAVE_TERMIOS_ISPEED
      } else if (opt->desc->func == OFUNC_TERMIOS_SPEED) {
	 union {
	    struct termios termarg;
	    speed_t speeds[sizeof(struct termios)/sizeof(speed_t)];
	 } tdata;
	 if (Tcgetattr(fd, &tdata.termarg) < 0) {
	    Error3("tcgetattr(%d, %p): %s",
		   fd, &tdata.termarg, strerror(errno));
	    opt->desc = ODESC_ERROR; continue;
	 }
	 tdata.speeds[opt->desc->major] = opt->value.u_uint;
	 if (Tcsetattr(fd, TCSADRAIN, &tdata.termarg) < 0) {
	    Error3("tcsetattr(%d, TCSADRAIN, %p): %s",
		   fd, &tdata.termarg, strerror(errno));
	    opt->desc = ODESC_ERROR; continue;
	 }
#endif /* HAVE_TERMIOS_ISPEED */

      } else if (opt->desc->func == OFUNC_TERMIOS_SPEC) {
	 struct termios termarg;
	 if (Tcgetattr(fd, &termarg) < 0) {
	    Error3("tcgetattr(%d, %p): %s",
		   fd, &termarg, strerror(errno));
	    opt->desc = ODESC_ERROR; continue;
	 }
	 switch (opt->desc->optcode) {
	 case OPT_RAW:
	    termarg.c_iflag &=
	      ~(IGNBRK|BRKINT|IGNPAR|PARMRK|INPCK|ISTRIP|INLCR|IGNCR|ICRNL|IXON|IXOFF
#ifdef IUCLC
		|IUCLC
#endif
		|IXANY|IMAXBEL);
	    termarg.c_iflag |= (0);
	    termarg.c_oflag &= ~(OPOST);
	    termarg.c_oflag |= (0);
	    termarg.c_cflag &= ~(0);
	    termarg.c_cflag |= (0);
	    termarg.c_lflag &= ~(ISIG|ICANON
#ifdef XCASE
				 |XCASE
#endif
				 );
	    termarg.c_lflag |= (0);
	    termarg.c_cc[VMIN] = 1;
	    termarg.c_cc[VTIME] = 0;
	    break;
	 case OPT_SANE:
	    /* cread -ignbrk brkint  -inlcr  -igncr  icrnl
              -ixoff  -iuclc  -ixany  imaxbel opost -olcuc -ocrnl
              onlcr -onocr -onlret -ofill -ofdel nl0 cr0 tab0 bs0
              vt0 ff0 isig icanon iexten echo echoe echok -echonl
              -noflsh -xcase -tostop -echoprt echoctl echoke, and
              also  sets  all special characters to their default
              values.
*/
	    termarg.c_iflag &= ~(IGNBRK|INLCR|IGNCR|IXOFF
#ifdef IUCLC
				 |IUCLC
#endif
				 |IXANY);
	    termarg.c_iflag |= (BRKINT|ICRNL|IMAXBEL);
	    termarg.c_oflag &= ~(0	/* for canonical reasons */
#ifdef OLCUC
				 |OLCUC
#endif
#ifdef OCRNL
				 |OCRNL
#endif
#ifdef ONOCR
				 |ONOCR
#endif
#ifdef ONLRET
				 |ONLRET
#endif
#ifdef OFILL
				 |OFILL
#endif
#ifdef OFDEL
				 |OFDEL
#endif
#ifdef NLDLY
				 |NLDLY
#endif
#ifdef CRDLY
				 |CRDLY
#endif
#ifdef TABDLY
				 |TABDLY
#endif
#ifdef BSDLY
				 |BSDLY
#endif
#ifdef VTDLY
				 |VTDLY
#endif
#ifdef FFDLY
				 |FFDLY
#endif
				 );
	    termarg.c_oflag |= (OPOST|ONLCR
#ifdef NL0
				|NL0
#endif
#ifdef CR0
				|CR0
#endif
#ifdef TAB0
				|TAB0
#endif
#ifdef BS0
				|BS0
#endif
#ifdef VT0
				|VT0
#endif
#ifdef FF0
				|FF0
#endif
				);
	    termarg.c_cflag &= ~(0);
	    termarg.c_cflag |= (CREAD);
	    termarg.c_lflag &= ~(ECHONL|NOFLSH
#ifdef XCASE
				 |XCASE
#endif
				 |TOSTOP
#ifdef ECHOPRT
				 |ECHOPRT
#endif
				 );
	    termarg.c_lflag |= (ISIG|ICANON|IEXTEN|ECHO|ECHOE|ECHOK|ECHOCTL|ECHOKE);
	    /*! "sets characters to their default values... - which? */
	    break;
	 default:
	    Error("TERMIOS option not handled - internal error?");
	 }
	 if (Tcsetattr(fd, TCSADRAIN, &termarg) < 0) {
	    Error3("tcsetattr(%d, TCSADRAIN, %p): %s",
		   fd, &termarg, strerror(errno));
	    opt->desc = ODESC_ERROR; continue;
	 }

#endif /* WITH_TERMIOS */

      } else {
	/*Error1("applyopts(): function %d not implemented",
	  opt->desc->func);*/
	 if (opt->desc->func != OFUNC_EXT && opt->desc->func != OFUNC_SIGNAL) {
	    Error1("applyopts(): option \"%s\" does not apply",
		   opt->desc->defname);
	    opt->desc = ODESC_ERROR;
	    ++opt;
	    continue;
	 }
	 ++opt;
	 continue;
      }
      opt->desc = ODESC_DONE;
      ++opt;
   }
   return 0;
}

/* applies to fd all options belonging to phases */
/* note: not all options can be applied this way (e.g. OFUNC_SPEC with PH_OPEN)
   implemented are: OFUNC_FCNTL, OFUNC_SOCKOPT (probably not all types),
   OFUNC_TERMIOS_FLAG, OFUNC_TERMIOS_PATTERN, and some OFUNC_SPEC */
int applyopts2(int fd, struct opt *opts, unsigned int from, unsigned int to) {
   unsigned int i;
   int stat;

   for (i = from; i <= to; ++i) {
      if ((stat = applyopts(fd, opts, i)) < 0)
	 return stat;
   }
   return 0;
}

/* apply and consume all options of type FLAG and group.
   Return 0 if everything went right, or -1 if an error occurred. */
int applyopts_flags(struct opt *opts, int group, flags_t *result) {
   struct opt *opt = opts;

   if (!opts)  return 0;

   while (opt->desc != ODESC_END) {
      if (opt->desc != ODESC_DONE && 
	  (opt->desc->group & group)) {
	 if (opt->desc->func == OFUNC_FLAG) {
	    if (opt->value.u_bool) {
	       *result |= opt->desc->major;
	    } else {
	       *result &= ~opt->desc->major;
	    }
	    opt->desc = ODESC_DONE;
	 } else if (opt->desc->func == OFUNC_FLAG_PATTERN) {
	    *result &= ~opt->desc->minor;
	    *result |= opt->desc->major;
	    opt->desc = ODESC_DONE;
	 }
      }
      ++opt;
   }
   return 0;
}



/* set the FD_CLOEXEC fcntl if the options do not set it to 0 */
int applyopts_cloexec(int fd, struct opt *opts) {
   bool docloexec = 1;

   if (!opts)  return 0;

   retropt_bool(opts, OPT_CLOEXEC, &docloexec);
   if (docloexec) {
      if (Fcntl_l(fd, F_SETFD, FD_CLOEXEC) < 0) {
	 Warn2("fcntl(%d, F_SETFD, FD_CLOEXEC): %s", fd, strerror(errno));
      }
   }
   return 0;
}

#if 0
/* apply options of 'early' phase, groups PROCESS and NAMED. path should exist
   for NAMED (not checked here). */
int applyopts_early(const char *path, struct opt *opts) {
   uid_t uid = -1;
   gid_t gid = -1;
   mode_t perm = 0666;

   if (retropt_uidt(opts, OPT_SETUID, &uid) >= 0) {
     Setuid()}
   retropt_uidt(opts, OPT_SETGID, &gid);
   /*retropt_uidt(opts, OPT_USER, &user);*/
   retropt_gidt(opts, OPT_GROUP_EARLY, &group);
   /*retropt_gidt(opts, OPT_GROUP, &group);*/

   if (uid != (uid_t)-1 || gid != (gid_t)-1) {
      if (Chown(path, user, group) < 0) {
	 Error4("chown(\"%s\", "F_uid", "F_gid"): %s", path, user, group,
		strerror(errno));
      }
   }

   if (retropt_modet(opts, OPT_PERM_EARLY, &perm) >= 0 /*||
       retropt_modet(opts, OPT_PERM, &perm) >= 0*/) {
      if (Chmod(path, perm) < 0) {
	 Error3("chmod(\"%s\", "F_mode"): %s", path, perm, strerror(errno));
      }
   }

   return 0;
}
#endif /* 0 */

int applyopts_fchown(int fd, struct opt *opts) {
   uid_t user = -1;
   gid_t group = -1;

   retropt_uidt(opts, OPT_USER, &user);
   retropt_gidt(opts, OPT_GROUP, &group);

   if (user != (uid_t)-1 || group != (gid_t)-1) {
      if (Fchown(fd, user, group) < 0) {
	 Error4("fchown(%d, "F_uid", "F_gid"): %s", fd, user, group,
		strerror(errno));
	 return STAT_RETRYLATER;
      }
   }
   return 0;
}

int applyopts_offset(struct single *xfd, struct opt *opts) {
   struct opt *opt;
   unsigned char *ptr;

   opt = opts; while (opt->desc != ODESC_END) {
      if ((opt->desc == ODESC_DONE) ||
	  opt->desc->func != OFUNC_OFFSET)  {
	 ++opt; continue; }

      ptr = (unsigned char *)xfd + opt->desc->major;
      switch (opt->desc->type) {
      case TYPE_DOUBLE:
	 *(double *)ptr = opt->value.u_double;  break;
      case TYPE_TIMEVAL:
	 *(struct timeval *)ptr = opt->value.u_timeval;  break;
      case TYPE_STRING_NULL:
	 if (opt->value.u_string == NULL) {
	    *(char **)ptr = NULL;
	    break;
	 }
	 /* PASSTHROUGH */
      case TYPE_STRING:
	 if ((*(char **)ptr = strdup(opt->value.u_string)) == NULL) {
	    Error1("strdup("F_Zu"): out of memory",
		   strlen(opt->value.u_string)+1);
	 }
 	 break;
      default:
	 Error1("applyopts_offset(): type %d not implemented",
	       opt->desc->type);
      }
      opt->desc = ODESC_DONE;
      ++opt;
   }
   return 0;
}

/* applies to xfd all OFUNC_EXT options belonging to phase
   returns -1 if an error occurred */
int applyopts_single(struct single *fd, struct opt *opts, enum e_phase phase) {
   struct opt *opt;
   int lockrc;

   if (!opts)  return 0;

   opt = opts; while (opt->desc != ODESC_END) {
      if ((opt->desc == ODESC_DONE) ||
	  (opt->desc->phase != phase && phase != PH_ALL) ||
	  opt->desc->func != OFUNC_EXT)  {
	 ++opt; continue; }
      switch (opt->desc->optcode) {
#if 0
      case OPT_IGNOREEOF:
	 fd->ignoreeof = true;
	 break;
      case OPT_CR:
	 fd->lineterm = LINETERM_CR;
	 break;
      case OPT_CRNL:
	 fd->lineterm = LINETERM_CRNL;
	 break;
#endif /* 0 */
      case OPT_READBYTES:
	 fd->readbytes = opt->value.u_sizet;
	 fd->actbytes  = fd->readbytes;
	 break;
      case OPT_LOCKFILE:
	 if (fd->lock.lockfile) {
	    Error("only one use of options lockfile and waitlock allowed");
	 }
	 fd->lock.lockfile = strdup(opt->value.u_string);
	 fd->lock.intervall.tv_sec  = 1;
	 fd->lock.intervall.tv_nsec = 0;

	 if ((lockrc = xiolock(&fd->lock)) < 0) {
	    /* error message already printed */
	    return -1;
	 }
	 if (lockrc) {
	    Error1("could not obtain lock \"%s\"", fd->lock.lockfile);
	 } else {
	    fd->havelock = true;
	    /*0 Info1("obtained lock \"%s\"", fd->lock.lockfile);*/
	 }
	 break;
      case OPT_WAITLOCK:
	 if (fd->lock.lockfile) {
	    Error("only one use of options lockfile and waitlock allowed");
	 }
	 fd->lock.lockfile = strdup(opt->value.u_string);
	 fd->lock.waitlock = true;
	 fd->lock.intervall.tv_sec  = 1;
	 fd->lock.intervall.tv_nsec = 0;

	 /*! this should be integrated into central select loop */
	 if (xiolock(&fd->lock) < 0) {
	    return -1;
	 }
	 fd->havelock = true;
	 /*0 Info1("obtained lock \"%s\"", fd->lock.lockfile);*/
	 break;
      default:
	 /* just store the value in the correct component of struct single */
	 if (opt->desc->type == TYPE_CONST) {
	    /* only for integral types compatible to int */
	    *(int *)(&((char *)fd)[opt->desc->major]) = opt->desc->arg3;
	 } else {
	    memcpy(&((char *)fd)[opt->desc->major], &opt->value, opt->desc->minor);
	 }
      }
      opt->desc = ODESC_DONE;
      ++opt;
   }
   return 0;
}

/* xfd->para.exec.pid must be set */
int applyopts_signal(struct single *xfd, struct opt *opts) {
   struct opt *opt;

   if (!opts)  return 0;

   opt = opts; while (opt->desc != ODESC_END) {
      if (opt->desc == ODESC_DONE || opt->desc->func != OFUNC_SIGNAL) {
	 ++opt; continue;
      }

      if (xio_opt_signal(xfd->para.exec.pid, opt->desc->major) < 0) {
	 opt->desc = ODESC_ERROR; continue;
      }
      opt->desc = ODESC_DONE;
      ++opt;
   }
   return 0;
}

/* apply remaining options to file descriptor, and tell us if something is
   still unused */
int _xio_openlate(struct single *fd, struct opt *opts) {
   int numleft;
   int result;

   _xioopen_setdelayeduser();

   if ((result = applyopts(fd->fd, opts, PH_LATE)) < 0) {
      return result;
   }
   if ((result = applyopts_single(fd, opts, PH_LATE)) < 0) {
      return result;
   }
   if ((result = applyopts(fd->fd, opts, PH_LATE2)) < 0) {
      return result;
   }

   if ((numleft = leftopts(opts)) > 0) {
      Error1("%d option(s) could not be used", numleft);
      showleft(opts);
      return STAT_NORETRY;
   }
   return 0;
}

int dropopts(struct opt *opts, unsigned int phase) {
   struct opt *opt;

   /*!*/
   if (phase == PH_ALL) {
      free(opts);
      return 0;
   }
   opt = opts; while (opt && opt->desc != ODESC_END) {
      if (opt->desc != ODESC_DONE && opt->desc->phase == phase) {
	 Debug1("ignoring option \"%s\"", opt->desc->defname);
	 opt->desc = ODESC_DONE;
      }
      ++opt;
   }
   return 0;
}

int dropopts2(struct opt *opts, unsigned int from, unsigned int to) {
   unsigned int i;

   for (i = from; i <= to; ++i) {
      dropopts(opts, i);
   }
   return 0;
}