Training courses

Kernel and Embedded Linux

Bootlin training courses

Embedded Linux, kernel,
Yocto Project, Buildroot, real-time,
graphics, boot time, debugging...

Bootlin logo

Elixir Cross Referencer

   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
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
/*	$NetBSD: ntpdc_ops.c,v 1.10 2018/04/07 00:19:53 christos Exp $	*/

/*
 * ntpdc_ops.c - subroutines which are called to perform operations by
 *		 ntpdc
 */

#ifdef HAVE_CONFIG_H
# include <config.h>
#endif

#include <stdio.h>
#include <stddef.h>

#include "ntpdc.h"
#include "ntp_net.h"
#include "ntp_control.h"
#include "ntp_refclock.h"
#include "ntp_stdlib.h"

#include <ctype.h>
#ifdef HAVE_SYS_TIMEX_H
# include <sys/timex.h>
#endif
#if !defined(__bsdi__) && !defined(apollo)
#ifdef HAVE_NETINET_IN_H
#include <netinet/in.h>
#endif
#endif

#include <arpa/inet.h>

/*
 * utility functions
 */
static	int	checkitems	(size_t, FILE *);
static	int	checkitemsize	(size_t, size_t);
static	int	check1item	(size_t, FILE *);

/*
 * Declarations for command handlers in here
 */
static	void	peerlist	(struct parse *, FILE *);
static	void	peers		(struct parse *, FILE *);
static void	doconfig	(struct parse *pcmd, FILE *fp, int mode, int refc);
static	void	dmpeers		(struct parse *, FILE *);
static	void	dopeers		(struct parse *, FILE *, int);
static	void	printpeer	(struct info_peer *, FILE *);
static	void	showpeer	(struct parse *, FILE *);
static	void	peerstats	(struct parse *, FILE *);
static	void	loopinfo	(struct parse *, FILE *);
static	void	sysinfo		(struct parse *, FILE *);
static	void	sysstats	(struct parse *, FILE *);
static	void	iostats		(struct parse *, FILE *);
static	void	memstats	(struct parse *, FILE *);
static	void	timerstats	(struct parse *, FILE *);
static	void	addpeer		(struct parse *, FILE *);
static	void	addserver	(struct parse *, FILE *);
static	void	addrefclock	(struct parse *, FILE *);
static	void	broadcast	(struct parse *, FILE *);
static	void	doconfig	(struct parse *, FILE *, int, int);
static	void	unconfig	(struct parse *, FILE *);
static	void	set		(struct parse *, FILE *);
static	void	sys_clear	(struct parse *, FILE *);
static	void	doset		(struct parse *, FILE *, int);
static	void	reslist		(struct parse *, FILE *);
static	void	new_restrict	(struct parse *, FILE *);
static	void	unrestrict	(struct parse *, FILE *);
static	void	delrestrict	(struct parse *, FILE *);
static	void	do_restrict	(struct parse *, FILE *, int);
static	void	monlist		(struct parse *, FILE *);
static	void	reset		(struct parse *, FILE *);
static	void	preset		(struct parse *, FILE *);
static	void	readkeys	(struct parse *, FILE *);
static	void	trustkey	(struct parse *, FILE *);
static	void	untrustkey	(struct parse *, FILE *);
static	void	do_trustkey	(struct parse *, FILE *, int);
static	void	authinfo	(struct parse *, FILE *);
static	void	traps		(struct parse *, FILE *);
static	void	addtrap		(struct parse *, FILE *);
static	void	clrtrap		(struct parse *, FILE *);
static	void	do_addclr_trap	(struct parse *, FILE *, int);
static	void	requestkey	(struct parse *, FILE *);
static	void	controlkey	(struct parse *, FILE *);
static	void	do_changekey	(struct parse *, FILE *, int);
static	void	ctlstats	(struct parse *, FILE *);
static	void	clockstat	(struct parse *, FILE *);
static	void	fudge		(struct parse *, FILE *);
static	void	clkbug		(struct parse *, FILE *);
static	void	kerninfo	(struct parse *, FILE *);
static	void	get_if_stats	(struct parse *, FILE *);
static	void	do_if_reload	(struct parse *, FILE *);

/*
 * Commands we understand.  Ntpdc imports this.
 */
struct xcmd opcmds[] = {
	{ "listpeers",	peerlist,	{ OPT|IP_VERSION, NO, NO, NO },
	  { "-4|-6", "", "", "" },
	  "display list of peers the server knows about [IP Version]" },
	{ "peers",	peers,	{ OPT|IP_VERSION, NO, NO, NO },
	  { "-4|-6", "", "", "" },
	  "display peer summary information [IP Version]" },
	{ "dmpeers",	dmpeers,	{ OPT|IP_VERSION, NO, NO, NO },
	  { "-4|-6", "", "", "" },
	  "display peer summary info the way Dave Mills likes it (IP Version)" },
	{ "showpeer",	showpeer, 	{ NTP_ADD, OPT|NTP_ADD, OPT|NTP_ADD, OPT|NTP_ADD},
	  { "peer_address", "peer2_addr", "peer3_addr", "peer4_addr" },
	  "display detailed information for one or more peers" },
	{ "pstats",	peerstats,	{ NTP_ADD, OPT|NTP_ADD, OPT|NTP_ADD, OPT|NTP_ADD },
	  { "peer_address", "peer2_addr", "peer3_addr", "peer4_addr" },
	  "display statistical information for one or more peers" },
	{ "loopinfo",	loopinfo,	{ OPT|NTP_STR, NO, NO, NO },
	  { "oneline|multiline", "", "", "" },
	  "display loop filter information" },
	{ "sysinfo",	sysinfo,	{ NO, NO, NO, NO },
	  { "", "", "", "" },
	  "display local server information" },
	{ "sysstats",	sysstats,	{ NO, NO, NO, NO },
	  { "", "", "", "" },
	  "display local server statistics" },
	{ "memstats",	memstats,	{ NO, NO, NO, NO },
	  { "", "", "", "" },
	  "display peer memory usage statistics" },
	{ "iostats",	iostats,	{ NO, NO, NO, NO },
	  { "", "", "", "" },
	  "display I/O subsystem statistics" },
	{ "timerstats",	timerstats,	{ NO, NO, NO, NO },
	  { "", "", "", "" },
	  "display event timer subsystem statistics" },
	{ "addpeer",	addpeer,	{ NTP_ADD, OPT|NTP_STR, OPT|NTP_STR, OPT|NTP_STR },
	  { "addr", "keyid", "version", "minpoll#|prefer|burst|iburst|'minpoll N'|'maxpoll N'|'keyid N'|'version N' ..." },
	  "configure a new peer association" },
	{ "addserver",	addserver,	{ NTP_ADD, OPT|NTP_STR, OPT|NTP_STR, OPT|NTP_STR },
	  { "addr", "keyid", "version", "minpoll#|prefer|burst|iburst|'minpoll N'|'maxpoll N'|'keyid N'|'version N' ..." },
	  "configure a new server" },
	{ "addrefclock",addrefclock,	{ NTP_ADD, OPT|NTP_UINT, OPT|NTP_STR, OPT|NTP_STR },
	  { "addr", "mode", "minpoll|prefer", "minpoll|prefer" },
	  "configure a new server" },
	{ "broadcast",	broadcast,	{ NTP_ADD, OPT|NTP_STR, OPT|NTP_STR, OPT|NTP_STR },
	  { "addr", "keyid", "version", "minpoll" },
	  "configure broadcasting time service" },
	{ "unconfig",	unconfig,	{ NTP_ADD, OPT|NTP_ADD, OPT|NTP_ADD, OPT|NTP_ADD },
	  { "peer_address", "peer2_addr", "peer3_addr", "peer4_addr" },
	  "unconfigure existing peer assocations" },
	{ "enable",	set,		{ NTP_STR, OPT|NTP_STR, OPT|NTP_STR, OPT|NTP_STR },
	  { "auth|bclient|monitor|pll|kernel|stats", "...", "...", "..." },
	  "set a system flag (auth, bclient, monitor, pll, kernel, stats)" },
	{ "disable",	sys_clear,	{ NTP_STR, OPT|NTP_STR, OPT|NTP_STR, OPT|NTP_STR },
	  { "auth|bclient|monitor|pll|kernel|stats", "...", "...", "..." },
	  "clear a system flag (auth, bclient, monitor, pll, kernel, stats)" },
	{ "reslist",	reslist,	{OPT|IP_VERSION, NO, NO, NO },
	  { "-4|-6", "", "", "" },
	  "display the server's restrict list" },
	{ "restrict",	new_restrict,	{ NTP_ADD, NTP_ADD, NTP_STR, OPT|NTP_STR },
	  { "address", "mask",
	    "ntpport|ignore|noserve|notrust|noquery|nomodify|nopeer|version|kod",
	    "..." },
	  "create restrict entry/add flags to entry" },
	{ "unrestrict", unrestrict,	{ NTP_ADD, NTP_ADD, NTP_STR, OPT|NTP_STR },
	  { "address", "mask",
	    "ntpport|ignore|noserve|notrust|noquery|nomodify|nopeer|version|kod",
	    "..." },
	  "remove flags from a restrict entry" },
	{ "delrestrict", delrestrict,	{ NTP_ADD, NTP_ADD, OPT|NTP_STR, NO },
	  { "address", "mask", "ntpport", "" },
	  "delete a restrict entry" },
	{ "monlist",	monlist,	{ OPT|NTP_INT, NO, NO, NO },
	  { "version", "", "", "" },
	  "display data the server's monitor routines have collected" },
	{ "reset",	reset,		{ NTP_STR, OPT|NTP_STR, OPT|NTP_STR, OPT|NTP_STR },
	  { "io|sys|mem|timer|auth|ctl|allpeers", "...", "...", "..." },
	  "reset various subsystem statistics counters" },
	{ "preset",	preset,		{ NTP_ADD, OPT|NTP_ADD, OPT|NTP_ADD, OPT|NTP_ADD },
	  { "peer_address", "peer2_addr", "peer3_addr", "peer4_addr" },
	  "reset stat counters associated with particular peer(s)" },
	{ "readkeys",	readkeys,	{ NO, NO, NO, NO },
	  { "", "", "", "" },
	  "request a reread of the keys file and re-init of system keys" },
	{ "trustedkey",	trustkey,	{ NTP_UINT, OPT|NTP_UINT, OPT|NTP_UINT, OPT|NTP_UINT },
	  { "keyid", "keyid", "keyid", "keyid" },
	  "add one or more key ID's to the trusted list" },
	{ "untrustedkey", untrustkey,	{ NTP_UINT, OPT|NTP_UINT, OPT|NTP_UINT, OPT|NTP_UINT },
	  { "keyid", "keyid", "keyid", "keyid" },
	  "remove one or more key ID's from the trusted list" },
	{ "authinfo",	authinfo,	{ NO, NO, NO, NO },
	  { "", "", "", "" },
	  "display the state of the authentication code" },
	{ "traps",	traps,		{ NO, NO, NO, NO },
	  { "", "", "", "" },
	  "display the traps set in the server" },
	{ "addtrap",	addtrap,	{ NTP_ADD, OPT|NTP_UINT, OPT|NTP_ADD, NO },
	  { "address", "port", "interface", "" },
	  "configure a trap in the server" },
	{ "clrtrap",	clrtrap,	{ NTP_ADD, OPT|NTP_UINT, OPT|NTP_ADD, NO },
	  { "address", "port", "interface", "" },
	  "remove a trap (configured or otherwise) from the server" },
	{ "requestkey",	requestkey,	{ NTP_UINT, NO, NO, NO },
	  { "keyid", "", "", "" },
	  "change the keyid the server uses to authenticate requests" },
	{ "controlkey",	controlkey,	{ NTP_UINT, NO, NO, NO },
	  { "keyid", "", "", "" },
	  "change the keyid the server uses to authenticate control messages" },
	{ "ctlstats",	ctlstats,	{ NO, NO, NO, NO },
	  { "", "", "", "" },
	  "display packet count statistics from the control module" },
	{ "clockstat",	clockstat,	{ NTP_ADD, OPT|NTP_ADD, OPT|NTP_ADD, OPT|NTP_ADD },
	  { "address", "address", "address", "address" },
	  "display clock status information" },
	{ "fudge",	fudge,		{ NTP_ADD, NTP_STR, NTP_STR, NO },
	  { "address", "time1|time2|val1|val2|flags", "value", "" },
	  "set/change one of a clock's fudge factors" },
	{ "clkbug",	clkbug,		{ NTP_ADD, OPT|NTP_ADD, OPT|NTP_ADD, OPT|NTP_ADD },
	  { "address", "address", "address", "address" },
	  "display clock debugging information" },
	{ "kerninfo",	kerninfo,	{ NO, NO, NO, NO },
	  { "", "", "", "" },
	  "display the kernel pll/pps variables" },
	{ "ifstats",	get_if_stats,	{ NO, NO, NO, NO },
	  { "", "", "", "" },
	  "list interface statistics" },
	{ "ifreload",	do_if_reload,	{ NO, NO, NO, NO },
	  { "", "", "", "" },
	  "reload interface configuration" },
	{ 0,		0,		{ NO, NO, NO, NO },
	  { "", "", "", "" }, "" }
};

/*
 * For quick string comparisons
 */
#define	STREQ(a, b)	(*(a) == *(b) && strcmp((a), (b)) == 0)

/*
 * SET_SS_LEN_IF_PRESENT - used by SET_ADDR, SET_ADDRS macros
 */

#ifdef ISC_PLATFORM_HAVESALEN
#define SET_SS_LEN_IF_PRESENT(psau)				\
	do {							\
		(psau)->sa.sa_len = SOCKLEN(psau);		\
	} while (0)
#else
#define SET_SS_LEN_IF_PRESENT(psau)	do { } while (0)
#endif

/*
 * SET_ADDR - setup address for v4/v6 as needed
 */
#define SET_ADDR(address, v6flag, v4addr, v6addr)		\
do {								\
	ZERO(address);						\
	if (v6flag) {						\
		AF(&(address)) = AF_INET6;			\
		SOCK_ADDR6(&(address)) = (v6addr);		\
	} else {						\
		AF(&(address)) = AF_INET;			\
		NSRCADR(&(address)) = (v4addr);			\
	}							\
	SET_SS_LEN_IF_PRESENT(&(address));			\
} while (0)


/*
 * SET_ADDRS - setup source and destination addresses for 
 * v4/v6 as needed
 */
#define SET_ADDRS(a1, a2, info, a1prefix, a2prefix)		\
do {								\
	ZERO(a1);						\
	ZERO(a2);						\
	if ((info)->v6_flag) {					\
		AF(&(a1)) = AF_INET6;				\
		AF(&(a2)) = AF_INET6;				\
		SOCK_ADDR6(&(a1)) = (info)->a1prefix##6;	\
		SOCK_ADDR6(&(a2)) = (info)->a2prefix##6;	\
	} else {						\
		AF(&(a1)) = AF_INET;				\
		AF(&(a2)) = AF_INET;				\
		NSRCADR(&(a1)) = (info)->a1prefix;		\
		NSRCADR(&(a2)) = (info)->a2prefix;		\
	}							\
	SET_SS_LEN_IF_PRESENT(&(a1));				\
	SET_SS_LEN_IF_PRESENT(&(a2));				\
} while (0)


/*
 * checkitems - utility to print a message if no items were returned
 */
static int
checkitems(
	size_t items,
	FILE *fp
	)
{
	if (items == 0) {
		(void) fprintf(fp, "No data returned in response to query\n");
		return 0;
	}
	return 1;
}


/*
 * checkitemsize - utility to print a message if the item size is wrong
 */
static int
checkitemsize(
	size_t itemsize,
	size_t expected
	)
{
	if (itemsize != expected) {
		(void) fprintf(stderr,
			       "***Incorrect item size returned by remote host (%lu should be %lu)\n",
			       (u_long)itemsize, (u_long)expected);
		return 0;
	}
	return 1;
}


/*
 * check1item - check to make sure we have exactly one item
 */
static int
check1item(
	size_t items,
	FILE *fp
	)
{
	if (items == 0) {
		(void) fprintf(fp, "No data returned in response to query\n");
		return 0;
	}
	if (items > 1) {
		(void) fprintf(fp, "Expected one item in response, got %lu\n",
			       (u_long)items);
		return 0;
	}
	return 1;
}


/*
 * peerlist - get a short list of peers
 */
/*ARGSUSED*/
static void
peerlist(
	struct parse *pcmd,
	FILE *fp
	)
{
	struct info_peer_list *plist;
	sockaddr_u paddr;
	size_t items;
	size_t itemsize;
	int res;

again:
	res = doquery(impl_ver, REQ_PEER_LIST, 0, 0, 0, (char *)NULL, &items,
		      &itemsize, (void *)&plist, 0, 
		      sizeof(struct info_peer_list));
	
	if (res == INFO_ERR_IMPL && impl_ver == IMPL_XNTPD) {
		impl_ver = IMPL_XNTPD_OLD;
		goto again;
	}

	if (res != 0)
	    return;

	if (!checkitems(items, fp))
	    return;

	if (!checkitemsize(itemsize, sizeof(struct info_peer_list)) &&
	    !checkitemsize(itemsize, v4sizeof(struct info_peer_list)))
	    return;

	while (items > 0) {
		SET_ADDR(paddr, plist->v6_flag, plist->addr, plist->addr6);
		if ((pcmd->nargs == 0) ||
		    ((pcmd->argval->ival == 6) && (plist->v6_flag != 0)) ||
		    ((pcmd->argval->ival == 4) && (plist->v6_flag == 0)))
			(void) fprintf(fp, "%-9s %s\n",
				modetoa(plist->hmode),
				nntohost(&paddr));
		plist++;
		items--;
	}
}


/*
 * peers - show peer summary
 */
static void
peers(
	struct parse *pcmd,
	FILE *fp
	)
{
	dopeers(pcmd, fp, 0);
}

/*
 * dmpeers - show peer summary, Dave Mills style
 */
static void
dmpeers(
	struct parse *pcmd,
	FILE *fp
	)
{
	dopeers(pcmd, fp, 1);
}


/*
 * peers - show peer summary
 */
/*ARGSUSED*/
static void
dopeers(
	struct parse *pcmd,
	FILE *fp,
	int dmstyle
	)
{
	struct info_peer_summary *plist;
	sockaddr_u dstadr;
	sockaddr_u srcadr;
	size_t items;
	size_t itemsize;
	int ntp_poll;
	int res;
	int c;
	l_fp tempts;

again:
	res = doquery(impl_ver, REQ_PEER_LIST_SUM, 0, 0, 0, (char *)NULL,
		      &items, &itemsize, (void *)&plist, 0, 
		      sizeof(struct info_peer_summary));
	
	if (res == INFO_ERR_IMPL && impl_ver == IMPL_XNTPD) {
		impl_ver = IMPL_XNTPD_OLD;
		goto again;
	}

	if (res != 0)
	    return;

	if (!checkitems(items, fp))
	    return;

	if (!checkitemsize(itemsize, sizeof(struct info_peer_summary)) &&
	    !checkitemsize(itemsize, v4sizeof(struct info_peer_summary)))
		return;

	(void) fprintf(fp,
		       "     remote           local      st poll reach  delay   offset    disp\n");
	(void) fprintf(fp,
		       "=======================================================================\n");
	while (items > 0) {
		if (!dmstyle) {
			if (plist->flags & INFO_FLAG_SYSPEER)
			    c = '*';
			else if (plist->hmode == MODE_ACTIVE)
			    c = '+';
			else if (plist->hmode == MODE_PASSIVE)
			    c = '-';
			else if (plist->hmode == MODE_CLIENT)
			    c = '=';
			else if (plist->hmode == MODE_BROADCAST)
			    c = '^';
			else if (plist->hmode == MODE_BCLIENT)
			    c = '~';
			else
			    c = ' ';
		} else {
			if (plist->flags & INFO_FLAG_SYSPEER)
			    c = '*';
			else if (plist->flags & INFO_FLAG_SHORTLIST)
			    c = '+';
			else if (plist->flags & INFO_FLAG_SEL_CANDIDATE)
			    c = '.';
			else
			    c = ' ';
		}
		NTOHL_FP(&(plist->offset), &tempts);
		ntp_poll = 1<<max(min3(plist->ppoll, plist->hpoll, NTP_MAXPOLL),
				  NTP_MINPOLL);
		SET_ADDRS(dstadr, srcadr, plist, dstadr, srcadr);
		if ((pcmd->nargs == 0) ||
		    ((pcmd->argval->ival == 6) && (plist->v6_flag != 0)) ||
		    ((pcmd->argval->ival == 4) && (plist->v6_flag == 0)))
			(void) fprintf(fp,
			    "%c%-15.15s %-15.15s %2u %4d  %3o %7.7s %9.9s %7.7s\n",
			    c, nntohost(&srcadr), stoa(&dstadr),
			    plist->stratum, ntp_poll, plist->reach,
			    fptoa(NTOHS_FP(plist->delay), 5),
			    lfptoa(&tempts, 6),
			    ufptoa(NTOHS_FP(plist->dispersion), 5));
		plist++;
		items--;
	}
}

/* Convert a refid & stratum (in host order) to a string */
static char *
refid_string(
	u_int32 refid,
	int stratum
	)
{
	if (stratum <= 1) {
		static char junk[5];
		junk[4] = 0;
		memcpy(junk, &refid, 4);
		return junk;
	}

	return numtoa(refid);
}

static void
print_pflag(
	FILE *	fp,
	u_int32	flags
	)
{
	static const char none[] = "";
	static const char comma[] = ",";
	const char *dlim;

	if (0 == flags) {
		fprintf(fp, " none\n");
		return;
	}
	dlim = none;
	if (flags & INFO_FLAG_SYSPEER) {
		fprintf(fp, " system_peer");
		dlim = comma;
	}
	if (flags & INFO_FLAG_CONFIG) {
		fprintf(fp, "%s config", dlim);
		dlim = comma;
	}
	if (flags & INFO_FLAG_REFCLOCK) {
		fprintf(fp, "%s refclock", dlim);
		dlim = comma;
	}
	if (flags & INFO_FLAG_AUTHENABLE) {
		fprintf(fp, "%s auth", dlim);
		dlim = comma;
	}
	if (flags & INFO_FLAG_PREFER) {
		fprintf(fp, "%s prefer", dlim);
		dlim = comma;
	}
	if (flags & INFO_FLAG_IBURST) {
		fprintf(fp, "%s iburst", dlim);
		dlim = comma;
	}
	if (flags & INFO_FLAG_BURST) {
		fprintf(fp, "%s burst", dlim);
		dlim = comma;
	}
	if (flags & INFO_FLAG_SEL_CANDIDATE) {
		fprintf(fp, "%s candidate", dlim);
		dlim = comma;
	}
	if (flags & INFO_FLAG_SHORTLIST) {
		fprintf(fp, "%s shortlist", dlim);
		dlim = comma;
	}
	fprintf(fp, "\n");
}
/*
 * printpeer - print detail information for a peer
 */
static void
printpeer(
	register struct info_peer *pp,
	FILE *fp
	)
{
	register int i;
	l_fp tempts;
	sockaddr_u srcadr, dstadr;
	
	SET_ADDRS(dstadr, srcadr, pp, dstadr, srcadr);
	
	(void) fprintf(fp, "remote %s, local %s\n",
		       stoa(&srcadr), stoa(&dstadr));
	(void) fprintf(fp, "hmode %s, pmode %s, stratum %d, precision %d\n",
		       modetoa(pp->hmode), modetoa(pp->pmode),
		       pp->stratum, pp->precision);
	
	(void) fprintf(fp,
		       "leap %c%c, refid [%s], rootdistance %s, rootdispersion %s\n",
		       pp->leap & 0x2 ? '1' : '0',
		       pp->leap & 0x1 ? '1' : '0',
		       refid_string(pp->refid, pp->stratum), fptoa(NTOHS_FP(pp->rootdelay), 5),
		       ufptoa(NTOHS_FP(pp->rootdispersion), 5));
	
	(void) fprintf(fp,
		       "ppoll %d, hpoll %d, keyid %lu, version %d, association %u\n",
		       pp->ppoll, pp->hpoll, (u_long)pp->keyid, pp->version, ntohs(pp->associd));

	(void) fprintf(fp,
		       "reach %03o, unreach %d, flash 0x%04x, ",
		       pp->reach, pp->unreach, pp->flash2);

	(void) fprintf(fp, "boffset %s, ttl/mode %d\n",
		       fptoa(NTOHS_FP(pp->estbdelay), 5), pp->ttl);
	
	(void) fprintf(fp, "timer %lds, flags", (long)ntohl(pp->timer));
	print_pflag(fp, pp->flags); 

	NTOHL_FP(&pp->reftime, &tempts);
	(void) fprintf(fp, "reference time:      %s\n",
		       prettydate(&tempts));
	NTOHL_FP(&pp->org, &tempts);
	(void) fprintf(fp, "originate timestamp: %s\n",
		       prettydate(&tempts));
	NTOHL_FP(&pp->rec, &tempts);
	(void) fprintf(fp, "receive timestamp:   %s\n",
		       prettydate(&tempts));
	NTOHL_FP(&pp->xmt, &tempts);
	(void) fprintf(fp, "transmit timestamp:  %s\n",
		       prettydate(&tempts));
	
	(void) fprintf(fp, "filter delay: ");
	for (i = 0; i < NTP_SHIFT; i++) {
		(void) fprintf(fp, " %-8.8s",
			       fptoa(NTOHS_FP(pp->filtdelay[i]), 5));
		if (i == (NTP_SHIFT>>1)-1)
		    (void) fprintf(fp, "\n              ");
	}
	(void) fprintf(fp, "\n");

	(void) fprintf(fp, "filter offset:");
	for (i = 0; i < NTP_SHIFT; i++) {
		NTOHL_FP(&pp->filtoffset[i], &tempts);
		(void) fprintf(fp, " %-8.8s", lfptoa(&tempts, 6));
		if (i == (NTP_SHIFT>>1)-1)
		    (void) fprintf(fp, "\n              ");
	}
	(void) fprintf(fp, "\n");

	(void) fprintf(fp, "filter order: ");
	for (i = 0; i < NTP_SHIFT; i++) {
		(void) fprintf(fp, " %-8d", pp->order[i]);
		if (i == (NTP_SHIFT>>1)-1)
		    (void) fprintf(fp, "\n              ");
	}
	(void) fprintf(fp, "\n");
	

	NTOHL_FP(&pp->offset, &tempts);
	(void) fprintf(fp,
		       "offset %s, delay %s, error bound %s, filter error %s\n",
		       lfptoa(&tempts, 6), fptoa(NTOHS_FP(pp->delay), 5),
		       ufptoa(NTOHS_FP(pp->dispersion), 5),
		       ufptoa(NTOHS_FP(pp->selectdisp), 5));
}


/*
 * showpeer - show detailed information for a peer
 */
static void
showpeer(
	struct parse *pcmd,
	FILE *fp
	)
{
	struct info_peer *pp;
	/* 4 is the maximum number of peers which will fit in a packet */
	struct info_peer_list *pl, plist[min(MAXARGS, 4)];
	size_t qitemlim;
	size_t qitems;
	size_t items;
	size_t itemsize;
	int res;
	int sendsize;

again:
	if (impl_ver == IMPL_XNTPD)
		sendsize = sizeof(struct info_peer_list);
	else
		sendsize = v4sizeof(struct info_peer_list);

	qitemlim = min(pcmd->nargs, COUNTOF(plist));
	for (qitems = 0, pl = plist; qitems < qitemlim; qitems++) {
		if (IS_IPV4(&pcmd->argval[qitems].netnum)) {
			pl->addr = NSRCADR(&pcmd->argval[qitems].netnum);
			if (impl_ver == IMPL_XNTPD)
				pl->v6_flag = 0;
		} else {
			if (impl_ver == IMPL_XNTPD_OLD) {
				fprintf(stderr,
				    "***Server doesn't understand IPv6 addresses\n");
				return;
			}
			pl->addr6 = SOCK_ADDR6(&pcmd->argval[qitems].netnum);
			pl->v6_flag = 1;
		}
		pl->port = (u_short)s_port;
		pl->hmode = pl->flags = 0;
		pl = (void *)((char *)pl + sendsize);
	}

	res = doquery(impl_ver, REQ_PEER_INFO, 0, qitems,
		      sendsize, (char *)plist, &items,
		      &itemsize, (void *)&pp, 0, sizeof(struct info_peer));
	
	if (res == INFO_ERR_IMPL && impl_ver == IMPL_XNTPD) {
		impl_ver = IMPL_XNTPD_OLD;
		goto again;
	}

	if (res != 0)
		return;

	if (!checkitems(items, fp))
		return;

	if (!checkitemsize(itemsize, sizeof(struct info_peer)) &&
	    !checkitemsize(itemsize, v4sizeof(struct info_peer)))
		return;

	while (items-- > 0) {
		printpeer(pp, fp);
		if (items > 0)
			fprintf(fp, "\n");
		pp++;
	}
}


/*
 * peerstats - return statistics for a peer
 */
static void
peerstats(
	struct parse *pcmd,
	FILE *fp
	)
{
	struct info_peer_stats *pp;
	/* 4 is the maximum number of peers which will fit in a packet */
	struct info_peer_list *pl, plist[min(MAXARGS, 4)];
	sockaddr_u src, dst;
	size_t qitemlim;
	size_t qitems;
	size_t items;
	size_t itemsize;
	int res;
	size_t sendsize;

again:
	if (impl_ver == IMPL_XNTPD)
		sendsize = sizeof(struct info_peer_list);
	else
		sendsize = v4sizeof(struct info_peer_list);

	ZERO(plist);

	qitemlim = min(pcmd->nargs, COUNTOF(plist));
	for (qitems = 0, pl = plist; qitems < qitemlim; qitems++) {
		if (IS_IPV4(&pcmd->argval[qitems].netnum)) {
			pl->addr = NSRCADR(&pcmd->argval[qitems].netnum);
			if (impl_ver == IMPL_XNTPD)
				pl->v6_flag = 0;
		} else {
			if (impl_ver == IMPL_XNTPD_OLD) {
				fprintf(stderr,
				    "***Server doesn't understand IPv6 addresses\n");
				return;
			}
			pl->addr6 = SOCK_ADDR6(&pcmd->argval[qitems].netnum);
			pl->v6_flag = 1;
		}
		pl->port = (u_short)s_port;
		pl->hmode = plist[qitems].flags = 0;
		pl = (void *)((char *)pl + sendsize);
	}

	res = doquery(impl_ver, REQ_PEER_STATS, 0, qitems,
		      sendsize, (char *)plist, &items,
		      &itemsize, (void *)&pp, 0, 
		      sizeof(struct info_peer_stats));
	
	if (res == INFO_ERR_IMPL && impl_ver == IMPL_XNTPD) {
		impl_ver = IMPL_XNTPD_OLD;
		goto again;
	}

	if (res != 0)
		return;

	if (!checkitems(items, fp))
	    return;

	if (!checkitemsize(itemsize, sizeof(struct info_peer_stats)) &&
	    !checkitemsize(itemsize, v4sizeof(struct info_peer_stats)))
	    return;

	while (items-- > 0) {
		ZERO_SOCK(&dst);
		ZERO_SOCK(&src);
		if (pp->v6_flag != 0) {
			AF(&dst) = AF_INET6;
			AF(&src) = AF_INET6;
			SOCK_ADDR6(&dst) = pp->dstadr6;
			SOCK_ADDR6(&src) = pp->srcadr6;
		} else {
			AF(&dst) = AF_INET;
			AF(&src) = AF_INET;
			NSRCADR(&dst) = pp->dstadr;
			NSRCADR(&src) = pp->srcadr;
		}
#ifdef ISC_PLATFORM_HAVESALEN
		src.sa.sa_len = SOCKLEN(&src);
		dst.sa.sa_len = SOCKLEN(&dst);
#endif
		fprintf(fp, "remote host:          %s\n",
			nntohost(&src));
		fprintf(fp, "local interface:      %s\n",
			stoa(&dst));
		fprintf(fp, "time last received:   %lus\n",
			(u_long)ntohl(pp->timereceived));
		fprintf(fp, "time until next send: %lus\n",
			(u_long)ntohl(pp->timetosend));
		fprintf(fp, "reachability change:  %lus\n",
			(u_long)ntohl(pp->timereachable));
		fprintf(fp, "packets sent:         %lu\n",
			(u_long)ntohl(pp->sent));
		fprintf(fp, "packets received:     %lu\n",
			(u_long)ntohl(pp->processed));
		fprintf(fp, "bad authentication:   %lu\n",
			(u_long)ntohl(pp->badauth));
		fprintf(fp, "bogus origin:         %lu\n",
			(u_long)ntohl(pp->bogusorg));
		fprintf(fp, "duplicate:            %lu\n",
			(u_long)ntohl(pp->oldpkt));
		fprintf(fp, "bad dispersion:       %lu\n",
			(u_long)ntohl(pp->seldisp));
		fprintf(fp, "bad reference time:   %lu\n",
			(u_long)ntohl(pp->selbroken));
		fprintf(fp, "candidate order:      %u\n",
			pp->candidate);
		if (items > 0)
			fprintf(fp, "\n");
		fprintf(fp, "flags:	");
		print_pflag(fp, ntohs(pp->flags));
		pp++;
	}
}


/*
 * loopinfo - show loop filter information
 */
static void
loopinfo(
	struct parse *pcmd,
	FILE *fp
	)
{
	struct info_loop *il;
	size_t items;
	size_t itemsize;
	int oneline = 0;
	int res;
	l_fp tempts;

	if (pcmd->nargs > 0) {
		if (STREQ(pcmd->argval[0].string, "oneline"))
		    oneline = 1;
		else if (STREQ(pcmd->argval[0].string, "multiline"))
		    oneline = 0;
		else {
			(void) fprintf(stderr, "How many lines?\n");
			return;
		}
	}

again:
	res = doquery(impl_ver, REQ_LOOP_INFO, 0, 0, 0, (char *)NULL,
		      &items, &itemsize, (void *)&il, 0, 
		      sizeof(struct info_loop));
	
	if (res == INFO_ERR_IMPL && impl_ver == IMPL_XNTPD) {
		impl_ver = IMPL_XNTPD_OLD;
		goto again;
	}

	if (res != 0)
	    return;

	if (!check1item(items, fp))
	    return;

	if (!checkitemsize(itemsize, sizeof(struct info_loop)))
	    return;

	if (oneline) {
		l_fp temp2ts;

		NTOHL_FP(&il->last_offset, &tempts);
		NTOHL_FP(&il->drift_comp, &temp2ts);

		(void) fprintf(fp,
			       "offset %s, frequency %s, time_const %ld, watchdog %ld\n",
			       lfptoa(&tempts, 6),
			       lfptoa(&temp2ts, 3),
			       (long)(int32)ntohl((u_long)il->compliance),
			       (u_long)ntohl((u_long)il->watchdog_timer));
	} else {
		NTOHL_FP(&il->last_offset, &tempts);
		(void) fprintf(fp, "offset:               %s s\n",
			       lfptoa(&tempts, 6));
		NTOHL_FP(&il->drift_comp, &tempts);
		(void) fprintf(fp, "frequency:            %s ppm\n",
			       lfptoa(&tempts, 3));
		(void) fprintf(fp, "poll adjust:          %ld\n",
			       (long)(int32)ntohl(il->compliance));
		(void) fprintf(fp, "watchdog timer:       %ld s\n",
			       (u_long)ntohl(il->watchdog_timer));
	}
}


/*
 * sysinfo - show current system state
 */
/*ARGSUSED*/
static void
sysinfo(
	struct parse *pcmd,
	FILE *fp
	)
{
	struct info_sys *is;
	sockaddr_u peeraddr;
	size_t items;
	size_t itemsize;
	int res;
	l_fp tempts;

again:
	res = doquery(impl_ver, REQ_SYS_INFO, 0, 0, 0, (char *)NULL,
		      &items, &itemsize, (void *)&is, 0,
		      sizeof(struct info_sys));
	
	if (res == INFO_ERR_IMPL && impl_ver == IMPL_XNTPD) {
		impl_ver = IMPL_XNTPD_OLD;
		goto again;
	}

	if (res != 0)
	    return;

	if (!check1item(items, fp))
	    return;

	if (!checkitemsize(itemsize, sizeof(struct info_sys)) &&
	    !checkitemsize(itemsize, v4sizeof(struct info_sys)))
	    return;

	SET_ADDR(peeraddr, is->v6_flag, is->peer, is->peer6);

	(void) fprintf(fp, "system peer:          %s\n", nntohost(&peeraddr));
	(void) fprintf(fp, "system peer mode:     %s\n", modetoa(is->peer_mode));
	(void) fprintf(fp, "leap indicator:       %c%c\n",
		       is->leap & 0x2 ? '1' : '0',
		       is->leap & 0x1 ? '1' : '0');
	(void) fprintf(fp, "stratum:              %d\n", (int)is->stratum);
	(void) fprintf(fp, "precision:            %d\n", (int)is->precision);
	(void) fprintf(fp, "root distance:        %s s\n",
		       fptoa(NTOHS_FP(is->rootdelay), 5));
	(void) fprintf(fp, "root dispersion:      %s s\n",
		       ufptoa(NTOHS_FP(is->rootdispersion), 5));
	(void) fprintf(fp, "reference ID:         [%s]\n",
		       refid_string(is->refid, is->stratum));
	NTOHL_FP(&is->reftime, &tempts);
	(void) fprintf(fp, "reference time:       %s\n", prettydate(&tempts));

	(void) fprintf(fp, "system flags:         ");
	if ((is->flags & (INFO_FLAG_BCLIENT | INFO_FLAG_AUTHENABLE |
	    INFO_FLAG_NTP | INFO_FLAG_KERNEL| INFO_FLAG_CAL |
	    INFO_FLAG_PPS_SYNC | INFO_FLAG_MONITOR | INFO_FLAG_FILEGEN)) == 0) {
		(void) fprintf(fp, "none\n");
	} else {
		if (is->flags & INFO_FLAG_BCLIENT)
		    (void) fprintf(fp, "bclient ");
		if (is->flags & INFO_FLAG_AUTHENTICATE)
		    (void) fprintf(fp, "auth ");
		if (is->flags & INFO_FLAG_MONITOR)
		    (void) fprintf(fp, "monitor ");
		if (is->flags & INFO_FLAG_NTP)
		    (void) fprintf(fp, "ntp ");
		if (is->flags & INFO_FLAG_KERNEL)
		    (void) fprintf(fp, "kernel ");
		if (is->flags & INFO_FLAG_FILEGEN)
		    (void) fprintf(fp, "stats ");
		if (is->flags & INFO_FLAG_CAL)
		    (void) fprintf(fp, "calibrate ");
		if (is->flags & INFO_FLAG_PPS_SYNC)
		    (void) fprintf(fp, "pps ");
		(void) fprintf(fp, "\n");
	}
	(void) fprintf(fp, "jitter:               %s s\n",
		       fptoa(ntohl(is->frequency), 6));
	(void) fprintf(fp, "stability:            %s ppm\n",
		       ufptoa(ntohl(is->stability), 3));
	(void) fprintf(fp, "broadcastdelay:       %s s\n",
		       fptoa(NTOHS_FP(is->bdelay), 6));
	NTOHL_FP(&is->authdelay, &tempts);
	(void) fprintf(fp, "authdelay:            %s s\n", lfptoa(&tempts, 6));
}


/*
 * sysstats - print system statistics
 */
/*ARGSUSED*/
static void
sysstats(
	struct parse *pcmd,
	FILE *fp
	)
{
	struct info_sys_stats *ss;
	size_t items;
	size_t itemsize;
	int res;

again:
	res = doquery(impl_ver, REQ_SYS_STATS, 0, 0, 0, (char *)NULL,
		      &items, &itemsize, (void *)&ss, 0, 
		      sizeof(struct info_sys_stats));
	
	if (res == INFO_ERR_IMPL && impl_ver == IMPL_XNTPD) {
		impl_ver = IMPL_XNTPD_OLD;
		goto again;
	}

	if (res != 0)
	    return;

	if (!check1item(items, fp))
	    return;

	if (itemsize != sizeof(struct info_sys_stats) &&
	    itemsize != sizeof(struct old_info_sys_stats)) {
		/* issue warning according to new structure size */
		checkitemsize(itemsize, sizeof(struct info_sys_stats));
		return;
	}
	fprintf(fp, "time since restart:     %lu\n",
		(u_long)ntohl(ss->timeup));
	fprintf(fp, "time since reset:       %lu\n",
		(u_long)ntohl(ss->timereset));
	fprintf(fp, "packets received:       %lu\n",
		(u_long)ntohl(ss->received));
	fprintf(fp, "packets processed:      %lu\n",
		(u_long)ntohl(ss->processed));
	fprintf(fp, "current version:        %lu\n",
		(u_long)ntohl(ss->newversionpkt));
	fprintf(fp, "previous version:       %lu\n",
		(u_long)ntohl(ss->oldversionpkt));
	fprintf(fp, "declined:               %lu\n",
		(u_long)ntohl(ss->unknownversion));
	fprintf(fp, "access denied:          %lu\n",
		(u_long)ntohl(ss->denied));
	fprintf(fp, "bad length or format:   %lu\n",
		(u_long)ntohl(ss->badlength));
	fprintf(fp, "bad authentication:     %lu\n",
		(u_long)ntohl(ss->badauth));
	if (itemsize != sizeof(struct info_sys_stats))
	    return;
	
	fprintf(fp, "rate exceeded:          %lu\n",
	       (u_long)ntohl(ss->limitrejected));
}



/*
 * iostats - print I/O statistics
 */
/*ARGSUSED*/
static void
iostats(
	struct parse *pcmd,
	FILE *fp
	)
{
	struct info_io_stats *io;
	size_t items;
	size_t itemsize;
	int res;

again:
	res = doquery(impl_ver, REQ_IO_STATS, 0, 0, 0, NULL, &items,
		      &itemsize, (void *)&io, 0, sizeof(*io));
	
	if (res == INFO_ERR_IMPL && impl_ver == IMPL_XNTPD) {
		impl_ver = IMPL_XNTPD_OLD;
		goto again;
	}

	if (res != 0)
		return;

	if (!check1item(items, fp))
		return;

	if (!checkitemsize(itemsize, sizeof(*io)))
		return;

	fprintf(fp, "time since reset:     %lu\n",
		(u_long)ntohl(io->timereset));
	fprintf(fp, "receive buffers:      %u\n",
		(u_int)ntohs(io->totalrecvbufs));
	fprintf(fp, "free receive buffers: %u\n",
		(u_int)ntohs(io->freerecvbufs));
	fprintf(fp, "used receive buffers: %u\n",
		(u_int)ntohs(io->fullrecvbufs));
	fprintf(fp, "low water refills:    %u\n",
		(u_int)ntohs(io->lowwater));
	fprintf(fp, "dropped packets:      %lu\n",
		(u_long)ntohl(io->dropped));
	fprintf(fp, "ignored packets:      %lu\n",
		(u_long)ntohl(io->ignored));
	fprintf(fp, "received packets:     %lu\n",
		(u_long)ntohl(io->received));
	fprintf(fp, "packets sent:         %lu\n",
		(u_long)ntohl(io->sent));
	fprintf(fp, "packets not sent:     %lu\n",
		(u_long)ntohl(io->notsent));
	fprintf(fp, "interrupts handled:   %lu\n",
		(u_long)ntohl(io->interrupts));
	fprintf(fp, "received by int:      %lu\n",
		(u_long)ntohl(io->int_received));
}


/*
 * memstats - print peer memory statistics
 */
/*ARGSUSED*/
static void
memstats(
	struct parse *pcmd,
	FILE *fp
	)
{
	struct info_mem_stats *mem;
	int i;
	size_t items;
	size_t itemsize;
	int res;

again:
	res = doquery(impl_ver, REQ_MEM_STATS, 0, 0, 0, NULL, &items,
		      &itemsize, (void *)&mem, 0, sizeof(*mem));
	
	if (res == INFO_ERR_IMPL && impl_ver == IMPL_XNTPD) {
		impl_ver = IMPL_XNTPD_OLD;
		goto again;
	}

	if (res != 0)
		return;

	if (!check1item(items, fp))
		return;

	if (!checkitemsize(itemsize, sizeof(*mem)))
		return;

	fprintf(fp, "time since reset:     %lu\n",
		(u_long)ntohl(mem->timereset));
	fprintf(fp, "total peer memory:    %u\n",
		(u_int)ntohs(mem->totalpeermem));
	fprintf(fp, "free peer memory:     %u\n",
		(u_int)ntohs(mem->freepeermem));
	fprintf(fp, "calls to findpeer:    %lu\n",
		(u_long)ntohl(mem->findpeer_calls));
	fprintf(fp, "new peer allocations: %lu\n",
		(u_long)ntohl(mem->allocations));
	fprintf(fp, "peer demobilizations: %lu\n",
		(u_long)ntohl(mem->demobilizations));

	fprintf(fp, "hash table counts:   ");
	for (i = 0; i < NTP_HASH_SIZE; i++) {
		fprintf(fp, "%4d", (int)mem->hashcount[i]);
		if ((i % 8) == 7 && i != (NTP_HASH_SIZE-1))
			fprintf(fp, "\n                     ");
	}
	fprintf(fp, "\n");
}



/*
 * timerstats - print timer statistics
 */
/*ARGSUSED*/
static void
timerstats(
	struct parse *pcmd,
	FILE *fp
	)
{
	struct info_timer_stats *tim;
	size_t items;
	size_t itemsize;
	int res;

again:
	res = doquery(impl_ver, REQ_TIMER_STATS, 0, 0, 0, NULL, &items,
		      &itemsize, (void *)&tim, 0, sizeof(*tim));
	
	if (res == INFO_ERR_IMPL && impl_ver == IMPL_XNTPD) {
		impl_ver = IMPL_XNTPD_OLD;
		goto again;
	}

	if (res != 0)
		return;

	if (!check1item(items, fp))
		return;

	if (!checkitemsize(itemsize, sizeof(*tim)))
		return;

	fprintf(fp, "time since reset:  %lu\n",
		(u_long)ntohl(tim->timereset));
	fprintf(fp, "alarms handled:    %lu\n",
		(u_long)ntohl(tim->alarms));
	fprintf(fp, "alarm overruns:    %lu\n",
		(u_long)ntohl(tim->overflows));
	fprintf(fp, "calls to transmit: %lu\n",
		(u_long)ntohl(tim->xmtcalls));
}


/*
 * addpeer - configure an active mode association
 */
static void
addpeer(
	struct parse *pcmd,
	FILE *fp
	)
{
	doconfig(pcmd, fp, MODE_ACTIVE, 0);
}


/*
 * addserver - configure a client mode association
 */
static void
addserver(
	struct parse *pcmd,
	FILE *fp
	)
{
	doconfig(pcmd, fp, MODE_CLIENT, 0);
}

/*
 * addrefclock - configure a reference clock association
 */
static void
addrefclock(
	struct parse *pcmd,
	FILE *fp
	)
{
	doconfig(pcmd, fp, MODE_CLIENT, 1);
}

/*
 * broadcast - configure a broadcast mode association
 */
static void
broadcast(
	struct parse *pcmd,
	FILE *fp
	)
{
	doconfig(pcmd, fp, MODE_BROADCAST, 0);
}


/*
 * config - configure a new peer association
 */
static void
doconfig(
	struct parse *pcmd,
	FILE *fp,
	int mode,
	int refc
	)
{
	struct conf_peer cpeer;
	size_t items;
	size_t itemsize;
	const char *dummy;
	u_long keyid;
	u_int version;
	u_char minpoll;
	u_char maxpoll;
	u_int flags;
	u_char cmode;
	int res;
	int sendsize;
	int numtyp;
	long val;

again:
	keyid = 0;
	version = 3;
	flags = 0;
	res = FALSE;
	cmode = 0;
	minpoll = NTP_MINDPOLL;
	maxpoll = NTP_MAXDPOLL;
	numtyp = 1;
	if (refc)
		numtyp = 5;

	if (impl_ver == IMPL_XNTPD)
		sendsize = sizeof(struct conf_peer);
	else
		sendsize = v4sizeof(struct conf_peer);

	items = 1;
	while (pcmd->nargs > (size_t)items) {
		if (STREQ(pcmd->argval[items].string, "prefer"))
			flags |= CONF_FLAG_PREFER;
		else if (STREQ(pcmd->argval[items].string, "burst"))
			flags |= CONF_FLAG_BURST;
		else if (STREQ(pcmd->argval[items].string, "iburst"))
			flags |= CONF_FLAG_IBURST;
		else if (!refc && STREQ(pcmd->argval[items].string, "keyid"))
			numtyp = 1;
		else if (!refc && STREQ(pcmd->argval[items].string, "version"))
			numtyp = 2;
		else if (STREQ(pcmd->argval[items].string, "minpoll"))
			numtyp = 3;
		else if (STREQ(pcmd->argval[items].string, "maxpoll"))
			numtyp = 4;
		else {
			if (!atoint(pcmd->argval[items].string, &val))
				numtyp = 0;
			switch (numtyp) {
			case 1:
				keyid = val;
				numtyp = 2;
				break;

			case 2:
				version = (u_int)val;
				numtyp = 0;
				break;

			case 3:
				minpoll = (u_char)val;
				numtyp = 0;
				break;

			case 4:
				maxpoll = (u_char)val;
				numtyp = 0;
				break;

			case 5:
				cmode = (u_char)val;
				numtyp = 0;
				break;

			default:
				fprintf(fp, "*** '%s' not understood\n",
					pcmd->argval[items].string);
				res = TRUE;
				numtyp = 0;
			}
			if (val < 0) {
				fprintf(stderr,
					"*** Value '%s' should be unsigned\n",
					pcmd->argval[items].string);
				res = TRUE;
			}
		}
		items++;
	}
	if (keyid > 0)
		flags |= CONF_FLAG_AUTHENABLE;
	if (version > NTP_VERSION || version < NTP_OLDVERSION) {
		fprintf(fp, "***invalid version number: %u\n",
			version);
		res = TRUE;
	}
	if (minpoll < NTP_MINPOLL || minpoll > NTP_MAXPOLL || 
	    maxpoll < NTP_MINPOLL || maxpoll > NTP_MAXPOLL || 
	    minpoll > maxpoll) {
		fprintf(fp, "***min/max-poll must be within %d..%d\n",
			NTP_MINPOLL, NTP_MAXPOLL);
		res = TRUE;
	}					

	if (res)
		return;

	ZERO(cpeer);

	if (IS_IPV4(&pcmd->argval[0].netnum)) {
		cpeer.peeraddr = NSRCADR(&pcmd->argval[0].netnum);
		if (impl_ver == IMPL_XNTPD)
			cpeer.v6_flag = 0;
	} else {
		if (impl_ver == IMPL_XNTPD_OLD) {
			fprintf(stderr,
			    "***Server doesn't understand IPv6 addresses\n");
			return;
		}
		cpeer.peeraddr6 = SOCK_ADDR6(&pcmd->argval[0].netnum);
		cpeer.v6_flag = 1;
	}
	cpeer.hmode = (u_char) mode;
	cpeer.keyid = keyid;
	cpeer.version = (u_char) version;
	cpeer.minpoll = minpoll;
	cpeer.maxpoll = maxpoll;
	cpeer.flags = (u_char)flags;
	cpeer.ttl = cmode;

	res = doquery(impl_ver, REQ_CONFIG, 1, 1,
		      sendsize, (char *)&cpeer, &items,
		      &itemsize, &dummy, 0, sizeof(struct conf_peer));
	
	if (res == INFO_ERR_IMPL && impl_ver == IMPL_XNTPD) {
		impl_ver = IMPL_XNTPD_OLD;
		goto again;
	}

	if (res == INFO_ERR_FMT) {
		(void) fprintf(fp,
		    "***Retrying command with old conf_peer size\n");
		res = doquery(impl_ver, REQ_CONFIG, 1, 1,
			      sizeof(struct old_conf_peer), (char *)&cpeer,
			      &items, &itemsize, &dummy, 0,
			      sizeof(struct conf_peer));
	}
	if (res == 0)
	    (void) fprintf(fp, "done!\n");
	return;
}


/*
 * unconfig - unconfigure some associations
 */
static void
unconfig(
	struct parse *pcmd,
	FILE *fp
	)
{
	/* 8 is the maximum number of peers which will fit in a packet */
	struct conf_unpeer *pl, plist[min(MAXARGS, 8)];
	size_t qitemlim;
	size_t qitems;
	size_t items;
	size_t itemsize;
	const char *dummy;
	int res;
	size_t sendsize;

again:
	if (impl_ver == IMPL_XNTPD)
		sendsize = sizeof(struct conf_unpeer);
	else
		sendsize = v4sizeof(struct conf_unpeer);

	qitemlim = min(pcmd->nargs, COUNTOF(plist));
	for (qitems = 0, pl = plist; qitems < qitemlim; qitems++) {
		if (IS_IPV4(&pcmd->argval[0].netnum)) {
			pl->peeraddr = NSRCADR(&pcmd->argval[qitems].netnum);
			if (impl_ver == IMPL_XNTPD)
				pl->v6_flag = 0;
		} else {
			if (impl_ver == IMPL_XNTPD_OLD) {
				fprintf(stderr,
				    "***Server doesn't understand IPv6 addresses\n");
				return;
			}
			pl->peeraddr6 =
			    SOCK_ADDR6(&pcmd->argval[qitems].netnum);
			pl->v6_flag = 1;
		}
		pl = (void *)((char *)pl + sendsize);
	}

	res = doquery(impl_ver, REQ_UNCONFIG, 1, qitems,
		      sendsize, (char *)plist, &items,
		      &itemsize, &dummy, 0, sizeof(struct conf_unpeer));
	
	if (res == INFO_ERR_IMPL && impl_ver == IMPL_XNTPD) {
		impl_ver = IMPL_XNTPD_OLD;
		goto again;
	}

	if (res == 0)
	    (void) fprintf(fp, "done!\n");
}


/*
 * set - set some system flags
 */
static void
set(
	struct parse *pcmd,
	FILE *fp
	)
{
	doset(pcmd, fp, REQ_SET_SYS_FLAG);
}


/*
 * clear - clear some system flags
 */
static void
sys_clear(
	struct parse *pcmd,
	FILE *fp
	)
{
	doset(pcmd, fp, REQ_CLR_SYS_FLAG);
}


/*
 * doset - set/clear system flags
 */
static void
doset(
	struct parse *pcmd,
	FILE *fp,
	int req
	)
{
	struct conf_sys_flags sys;
	size_t items;
	size_t itemsize;
	const char *dummy;
	int res;

	sys.flags = 0;
	res = 0;
	for (items = 0; (size_t)items < pcmd->nargs; items++) {
		if (STREQ(pcmd->argval[items].string, "auth"))
			sys.flags |= SYS_FLAG_AUTH;
		else if (STREQ(pcmd->argval[items].string, "bclient"))
			sys.flags |= SYS_FLAG_BCLIENT;
		else if (STREQ(pcmd->argval[items].string, "calibrate"))
			sys.flags |= SYS_FLAG_CAL;
		else if (STREQ(pcmd->argval[items].string, "kernel"))
			sys.flags |= SYS_FLAG_KERNEL;
		else if (STREQ(pcmd->argval[items].string, "monitor"))
			sys.flags |= SYS_FLAG_MONITOR;
		else if (STREQ(pcmd->argval[items].string, "ntp"))
			sys.flags |= SYS_FLAG_NTP;
		else if (STREQ(pcmd->argval[items].string, "pps"))
			sys.flags |= SYS_FLAG_PPS;
		else if (STREQ(pcmd->argval[items].string, "stats"))
			sys.flags |= SYS_FLAG_FILEGEN;
		else {
			(void) fprintf(fp, "Unknown flag %s\n",
			    pcmd->argval[items].string);
			res = 1;
		}
	}

	sys.flags = htonl(sys.flags);
	if (res || sys.flags == 0)
	    return;

again:
	res = doquery(impl_ver, req, 1, 1,
		      sizeof(struct conf_sys_flags), (char *)&sys, &items,
		      &itemsize, &dummy, 0, sizeof(struct conf_sys_flags));
	
	if (res == INFO_ERR_IMPL && impl_ver == IMPL_XNTPD) {
		impl_ver = IMPL_XNTPD_OLD;
		goto again;
	}

	if (res == 0)
	    (void) fprintf(fp, "done!\n");
}


/*
 * data for printing/interrpreting the restrict flags
 */
struct resflags {
  const char *str;
	int bit;
};

/* XXX: HMS: we apparently don't report set bits we do not recognize. */

static struct resflags resflagsV2[] = {
	{ "ignore",	0x001 },
	{ "noserve",	0x002 },
	{ "notrust",	0x004 },
	{ "noquery",	0x008 },
	{ "nomodify",	0x010 },
	{ "nopeer",	0x020 },
	{ "notrap",	0x040 },
	{ "lptrap",	0x080 },
	{ "limited",	0x100 },
	{ "",		0 }
};

static struct resflags resflagsV3[] = {
	{ "ignore",	RES_IGNORE },
	{ "noserve",	RES_DONTSERVE },
	{ "notrust",	RES_DONTTRUST },
	{ "noquery",	RES_NOQUERY },
	{ "nomodify",	RES_NOMODIFY },
	{ "nopeer",	RES_NOPEER },
	{ "notrap",	RES_NOTRAP },
	{ "lptrap",	RES_LPTRAP },
	{ "limited",	RES_LIMITED },
	{ "version",	RES_VERSION },
	{ "kod",	RES_KOD },
	{ "flake",	RES_FLAKE },

	{ "",		0 }
};

static struct resflags resmflags[] = {
	{ "ntpport",	RESM_NTPONLY },
	{ "interface",	RESM_INTERFACE },
	{ "source",	RESM_SOURCE },
	{ "",		0 }
};


/*
 * reslist - obtain and print the server's restrict list
 */
/*ARGSUSED*/
static void
reslist(
	struct parse *pcmd,
	FILE *fp
	)
{
	struct info_restrict *rl;
	sockaddr_u resaddr;
	sockaddr_u maskaddr;
	size_t items;
	size_t itemsize;
	int res;
	int skip;
	const char *addr;
	const char *mask;
	struct resflags *rf;
	u_int32 count;
	u_short rflags;
	u_short mflags;
	char flagstr[300];
	static const char *comma = ", ";

again:
	res = doquery(impl_ver, REQ_GET_RESTRICT, 0, 0, 0, (char *)NULL,
		      &items, &itemsize, (void *)&rl, 0, 
		      sizeof(struct info_restrict));
	
	if (res == INFO_ERR_IMPL && impl_ver == IMPL_XNTPD) {
		impl_ver = IMPL_XNTPD_OLD;
		goto again;
	}

	if (res != 0)
		return;

	if (!checkitems(items, fp))
		return;

	if (!checkitemsize(itemsize, sizeof(struct info_restrict)) &&
	    !checkitemsize(itemsize, v4sizeof(struct info_restrict)))
		return;

	fprintf(fp,
		"   address          mask            count        flags\n");
	fprintf(fp,
		"=====================================================================\n");

	while (items > 0) {
		SET_ADDRS(resaddr, maskaddr, rl, addr, mask);
		if (rl->v6_flag != 0) {
			addr = nntohost(&resaddr);
		} else {
			if (rl->mask == (u_int32)0xffffffff)
				addr = nntohost(&resaddr);
			else
				addr = stoa(&resaddr);
		}
		mask = stoa(&maskaddr);
		skip = 1;
		if ((pcmd->nargs == 0) ||
		    ((pcmd->argval->ival == 6) && (rl->v6_flag != 0)) ||
		    ((pcmd->argval->ival == 4) && (rl->v6_flag == 0)))
			skip = 0;
		count = ntohl(rl->count);
		rflags = ntohs(rl->rflags);
		mflags = ntohs(rl->mflags);
		flagstr[0] = '\0';

		res = 1;
		rf = &resmflags[0];
		while (rf->bit != 0) {
			if (mflags & rf->bit) {
				if (!res)
					strlcat(flagstr, comma,
						sizeof(flagstr));
				res = 0;
				strlcat(flagstr, rf->str,
					sizeof(flagstr));
			}
			rf++;
		}

		rf = (impl_ver == IMPL_XNTPD_OLD)
			 ? &resflagsV2[0]
			 : &resflagsV3[0];

		while (rf->bit != 0) {
			if (rflags & rf->bit) {
				if (!res)
					strlcat(flagstr, comma,
						sizeof(flagstr));
				res = 0;
				strlcat(flagstr, rf->str,
					sizeof(flagstr));
			}
			rf++;
		}

		if (flagstr[0] == '\0')
			strlcpy(flagstr, "none", sizeof(flagstr));

		if (!skip)
			fprintf(fp, "%-15.15s %-15.15s %9lu  %s\n",
				addr, mask, (u_long)count, flagstr);
		rl++;
		items--;
	}
}



/*
 * new_restrict - create/add a set of restrictions
 */
static void
new_restrict(
	struct parse *pcmd,
	FILE *fp
	)
{
	do_restrict(pcmd, fp, REQ_RESADDFLAGS);
}


/*
 * unrestrict - remove restriction flags from existing entry
 */
static void
unrestrict(
	struct parse *pcmd,
	FILE *fp
	)
{
	do_restrict(pcmd, fp, REQ_RESSUBFLAGS);
}


/*
 * delrestrict - delete an existing restriction
 */
static void
delrestrict(
	struct parse *pcmd,
	FILE *fp
	)
{
	do_restrict(pcmd, fp, REQ_UNRESTRICT);
}


/*
 * do_restrict - decode commandline restrictions and make the request
 */
static void
do_restrict(
	struct parse *pcmd,
	FILE *fp,
	int req_code
	)
{
	struct conf_restrict cres;
	size_t items;
	size_t itemsize;
	const char *dummy;
	u_int32 num;
	u_long bit;
	int i;
	size_t res;
	int err;
	int sendsize;

	/* Initialize cres */
	cres.addr = 0;
	cres.mask = 0;
	cres.flags = 0;
	cres.mflags = 0;
	cres.v6_flag = 0;

again:
	if (impl_ver == IMPL_XNTPD)
		sendsize = sizeof(struct conf_restrict);
	else
		sendsize = v4sizeof(struct conf_restrict);

	if (IS_IPV4(&pcmd->argval[0].netnum)) {
		cres.addr = NSRCADR(&pcmd->argval[0].netnum);
		cres.mask = NSRCADR(&pcmd->argval[1].netnum);
		if (impl_ver == IMPL_XNTPD)
			cres.v6_flag = 0;
	} else {
		if (impl_ver == IMPL_XNTPD_OLD) {
			fprintf(stderr,
				"***Server doesn't understand IPv6 addresses\n");
			return;
		}
		cres.addr6 = SOCK_ADDR6(&pcmd->argval[0].netnum);
		cres.v6_flag = 1;
	}
	cres.flags = 0;
	cres.mflags = 0;
	err = FALSE;
	for (res = 2; res < pcmd->nargs; res++) {
		if (STREQ(pcmd->argval[res].string, "ntpport")) {
			cres.mflags |= RESM_NTPONLY;
		} else {
			for (i = 0; resflagsV3[i].bit != 0; i++) {
				if (STREQ(pcmd->argval[res].string,
					  resflagsV3[i].str))
					break;
			}
			if (resflagsV3[i].bit != 0) {
				cres.flags |= resflagsV3[i].bit;
				if (req_code == REQ_UNRESTRICT) {
					fprintf(fp,
						"Flag %s inappropriate\n",
						resflagsV3[i].str);
					err = TRUE;
				}
			} else {
				fprintf(fp, "Unknown flag %s\n",
					pcmd->argval[res].string);
				err = TRUE;
			}
		}
	}
	cres.flags = htons(cres.flags);
	cres.mflags = htons(cres.mflags);

	/*
	 * Make sure mask for default address is zero.  Otherwise,
	 * make sure mask bits are contiguous.
	 */
	if (IS_IPV4(&pcmd->argval[0].netnum)) {
		if (cres.addr == 0) {
			cres.mask = 0;
		} else {
			num = ntohl(cres.mask);
			for (bit = 0x80000000; bit != 0; bit >>= 1)
				if ((num & bit) == 0)
					break;
			for ( ; bit != 0; bit >>= 1)
				if ((num & bit) != 0)
					break;
			if (bit != 0) {
				fprintf(fp, "Invalid mask %s\n",
					numtoa(cres.mask));
				err = TRUE;
			}
		}
	} else {
		/* XXX IPv6 sanity checking stuff */
	}

	if (err)
		return;

	res = doquery(impl_ver, req_code, 1, 1, sendsize, (char *)&cres,
		      &items, &itemsize, &dummy, 0, sizeof(cres));
	
	if (res == INFO_ERR_IMPL && impl_ver == IMPL_XNTPD) {
		impl_ver = IMPL_XNTPD_OLD;
		goto again;
	}

	if (res == 0)
	    (void) fprintf(fp, "done!\n");
	return;
}


/*
 * monlist - obtain and print the server's monitor data
 */
/*ARGSUSED*/
static void
monlist(
	struct parse *pcmd,
	FILE *fp
	)
{
	const char *struct_star;
	const struct info_monitor *ml;
	const struct info_monitor_1 *m1;
	const struct old_info_monitor *oml;
	sockaddr_u addr;
	sockaddr_u dstadr;
	size_t items;
	size_t itemsize;
	int res;
	int version = -1;

	if (pcmd->nargs > 0)
		version = pcmd->argval[0].ival;

again:
	res = doquery(impl_ver,
		      (version == 1 || version == -1) ? REQ_MON_GETLIST_1 :
		      REQ_MON_GETLIST, 0, 0, 0, NULL,
		      &items, &itemsize, &struct_star,
		      (version < 0) ? (1 << INFO_ERR_REQ) : 0, 
		      sizeof(struct info_monitor_1));

	if (res == INFO_ERR_IMPL && impl_ver == IMPL_XNTPD) {
		impl_ver = IMPL_XNTPD_OLD;
		goto again;
	}

	if (res == INFO_ERR_REQ && version < 0) 
		res = doquery(impl_ver, REQ_MON_GETLIST, 0, 0, 0, NULL,
			      &items, &itemsize, &struct_star, 0,
			      sizeof(struct info_monitor));
	
	if (res != 0)
		return;

	if (!checkitems(items, fp))
		return;

	if (itemsize == sizeof(struct info_monitor_1) ||
	    itemsize == v4sizeof(struct info_monitor_1)) {

	    m1 = (const void*)struct_star;
		fprintf(fp,
			"remote address          port local address      count m ver rstr avgint  lstint\n");
		fprintf(fp,
			"===============================================================================\n");
		while (items > 0) {
			SET_ADDRS(dstadr, addr, m1, daddr, addr);
			if ((pcmd->nargs == 0) ||
			    ((pcmd->argval->ival == 6) && (m1->v6_flag != 0)) ||
			    ((pcmd->argval->ival == 4) && (m1->v6_flag == 0)))
				fprintf(fp, 
				    "%-22.22s %5d %-15s %8lu %1u %1u %6lx %6lu %7lu\n",
				    nntohost(&addr), 
				    ntohs(m1->port),
				    stoa(&dstadr),
				    (u_long)ntohl(m1->count),
				    m1->mode,
				    m1->version,
				    (u_long)ntohl(m1->restr),
				    (u_long)ntohl(m1->avg_int),
				    (u_long)ntohl(m1->last_int));
			m1++;
			items--;
		}
	} else if (itemsize == sizeof(struct info_monitor) ||
	    itemsize == v4sizeof(struct info_monitor)) {

		ml = (const void *)struct_star;
		fprintf(fp,
			"     address               port     count mode ver rstr avgint  lstint\n");
		fprintf(fp,
			"===============================================================================\n");
		while (items > 0) {
			SET_ADDR(dstadr, ml->v6_flag, ml->addr, ml->addr6);
			if ((pcmd->nargs == 0) ||
			    ((pcmd->argval->ival == 6) && (ml->v6_flag != 0)) ||
			    ((pcmd->argval->ival == 4) && (ml->v6_flag == 0)))
				fprintf(fp,
				    "%-25.25s %5u %9lu %4u %2u %9lx %9lu %9lu\n",
				    nntohost(&dstadr),
				    ntohs(ml->port),
				    (u_long)ntohl(ml->count),
				    ml->mode,
				    ml->version,
				    (u_long)ntohl(ml->restr),
				    (u_long)ntohl(ml->avg_int),
				    (u_long)ntohl(ml->last_int));
			ml++;
			items--;
		}
	} else if (itemsize == sizeof(struct old_info_monitor)) {

		oml = (const void *)struct_star;
		fprintf(fp,
			"     address          port     count  mode version  lasttime firsttime\n");
		fprintf(fp,
			"======================================================================\n");
		while (items > 0) {
			SET_ADDR(dstadr, oml->v6_flag, oml->addr, oml->addr6);
			fprintf(fp, "%-20.20s %5u %9lu %4u   %3u %9lu %9lu\n",
				nntohost(&dstadr),
				ntohs(oml->port),
				(u_long)ntohl(oml->count),
				oml->mode,
				oml->version,
				(u_long)ntohl(oml->lasttime),
				(u_long)ntohl(oml->firsttime));
			oml++;
			items--;
		}
	} else {
		/* issue warning according to new info_monitor size */
		checkitemsize(itemsize, sizeof(struct info_monitor));
	}
}


/*
 * Mapping between command line strings and stat reset flags
 */
struct statreset {
	const char * const	str;
	const int		flag;
} sreset[] = {
	{ "allpeers",	RESET_FLAG_ALLPEERS },
	{ "io",		RESET_FLAG_IO },
	{ "sys",	RESET_FLAG_SYS },
	{ "mem",	RESET_FLAG_MEM },
	{ "timer",	RESET_FLAG_TIMER },
	{ "auth",	RESET_FLAG_AUTH },
	{ "ctl",	RESET_FLAG_CTL },
	{ "",		0 }
};

/*
 * reset - reset statistic counters
 */
static void
reset(
	struct parse *pcmd,
	FILE *fp
	)
{
	struct reset_flags rflags;
	size_t items;
	size_t itemsize;
	const char *dummy;
	int i;
	size_t res;
	int err;

	err = 0;
	rflags.flags = 0;
	for (res = 0; res < pcmd->nargs; res++) {
		for (i = 0; sreset[i].flag != 0; i++) {
			if (STREQ(pcmd->argval[res].string, sreset[i].str))
				break;
		}
		if (sreset[i].flag == 0) {
			fprintf(fp, "Flag %s unknown\n",
				pcmd->argval[res].string);
			err = 1;
		} else {
			rflags.flags |= sreset[i].flag;
		}
	}
	rflags.flags = htonl(rflags.flags);

	if (err) {
		(void) fprintf(fp, "Not done due to errors\n");
		return;
	}

again:
	res = doquery(impl_ver, REQ_RESET_STATS, 1, 1,
		      sizeof(struct reset_flags), (char *)&rflags, &items,
		      &itemsize, &dummy, 0, sizeof(struct reset_flags));
	
	if (res == INFO_ERR_IMPL && impl_ver == IMPL_XNTPD) {
		impl_ver = IMPL_XNTPD_OLD;
		goto again;
	}

	if (res == 0)
	    (void) fprintf(fp, "done!\n");
	return;
}



/*
 * preset - reset stat counters for particular peers
 */
static void
preset(
	struct parse *pcmd,
	FILE *fp
	)
{
	/* 8 is the maximum number of peers which will fit in a packet */
	struct conf_unpeer *pl, plist[min(MAXARGS, 8)];
	size_t qitemlim;
	size_t qitems;
	size_t items;
	size_t itemsize;
	const char *dummy;
	int res;
	size_t sendsize;

again:
	if (impl_ver == IMPL_XNTPD)
		sendsize = sizeof(struct conf_unpeer);
	else
		sendsize = v4sizeof(struct conf_unpeer);

	qitemlim = min(pcmd->nargs, COUNTOF(plist));
	for (qitems = 0, pl = plist; qitems < qitemlim; qitems++) {
		if (IS_IPV4(&pcmd->argval[qitems].netnum)) {
			pl->peeraddr = NSRCADR(&pcmd->argval[qitems].netnum);
			if (impl_ver == IMPL_XNTPD)
				pl->v6_flag = 0;
		} else {
			if (impl_ver == IMPL_XNTPD_OLD) {
				fprintf(stderr,
				    "***Server doesn't understand IPv6 addresses\n");
				return;
			}
			pl->peeraddr6 =
			    SOCK_ADDR6(&pcmd->argval[qitems].netnum);
			pl->v6_flag = 1;
		}
		pl = (void *)((char *)pl + sendsize);
	}

	res = doquery(impl_ver, REQ_RESET_PEER, 1, qitems,
		      sendsize, (char *)plist, &items,
		      &itemsize, &dummy, 0, sizeof(struct conf_unpeer));
	
	if (res == INFO_ERR_IMPL && impl_ver == IMPL_XNTPD) {
		impl_ver = IMPL_XNTPD_OLD;
		goto again;
	}

	if (res == 0)
	    (void) fprintf(fp, "done!\n");
}


/*
 * readkeys - request the server to reread the keys file
 */
/*ARGSUSED*/
static void
readkeys(
	struct parse *pcmd,
	FILE *fp
	)
{
	size_t items;
	size_t itemsize;
	const char *dummy;
	int res;

again:
	res = doquery(impl_ver, REQ_REREAD_KEYS, 1, 0, 0, (char *)0,
		      &items, &itemsize, &dummy, 0, sizeof(dummy));
	
	if (res == INFO_ERR_IMPL && impl_ver == IMPL_XNTPD) {
		impl_ver = IMPL_XNTPD_OLD;
		goto again;
	}

	if (res == 0)
	    (void) fprintf(fp, "done!\n");
	return;
}


/*
 * trustkey - add some keys to the trusted key list
 */
static void
trustkey(
	struct parse *pcmd,
	FILE *fp
	)
{
	do_trustkey(pcmd, fp, REQ_TRUSTKEY);
}


/*
 * untrustkey - remove some keys from the trusted key list
 */
static void
untrustkey(
	struct parse *pcmd,
	FILE *fp
	)
{
	do_trustkey(pcmd, fp, REQ_UNTRUSTKEY);
}


/*
 * do_trustkey - do grunge work of adding/deleting keys
 */
static void
do_trustkey(
	struct parse *pcmd,
	FILE *fp,
	int req
	)
{
	u_long keyids[MAXARGS];
	size_t i;
	size_t items;
	size_t itemsize;
	const char *dummy;
	int ritems;
	int res;

	ritems = 0;
	for (i = 0; i < pcmd->nargs; i++) {
		keyids[ritems++] = pcmd->argval[i].uval;
	}

again:
	res = doquery(impl_ver, req, 1, ritems, sizeof(u_long),
		      (char *)keyids, &items, &itemsize, &dummy, 0, 
		      sizeof(dummy));
	
	if (res == INFO_ERR_IMPL && impl_ver == IMPL_XNTPD) {
		impl_ver = IMPL_XNTPD_OLD;
		goto again;
	}

	if (res == 0)
	    (void) fprintf(fp, "done!\n");
	return;
}



/*
 * authinfo - obtain and print info about authentication
 */
/*ARGSUSED*/
static void
authinfo(
	struct parse *pcmd,
	FILE *fp
	)
{
	struct info_auth *ia;
	size_t items;
	size_t itemsize;
	int res;

again:
	res = doquery(impl_ver, REQ_AUTHINFO, 0, 0, 0, NULL, &items,
		      &itemsize, (void *)&ia, 0, sizeof(*ia));
	
	if (res == INFO_ERR_IMPL && impl_ver == IMPL_XNTPD) {
		impl_ver = IMPL_XNTPD_OLD;
		goto again;
	}

	if (res != 0)
		return;

	if (!check1item(items, fp))
		return;

	if (!checkitemsize(itemsize, sizeof(*ia)))
		return;

	fprintf(fp, "time since reset:     %lu\n",
		(u_long)ntohl(ia->timereset));
	fprintf(fp, "stored keys:          %lu\n",
		(u_long)ntohl(ia->numkeys));
	fprintf(fp, "free keys:            %lu\n",
		(u_long)ntohl(ia->numfreekeys));
	fprintf(fp, "key lookups:          %lu\n",
		(u_long)ntohl(ia->keylookups));
	fprintf(fp, "keys not found:       %lu\n",
		(u_long)ntohl(ia->keynotfound));
	fprintf(fp, "uncached keys:        %lu\n",
		(u_long)ntohl(ia->keyuncached));
	fprintf(fp, "encryptions:          %lu\n",
		(u_long)ntohl(ia->encryptions));
	fprintf(fp, "decryptions:          %lu\n",
		(u_long)ntohl(ia->decryptions));
	fprintf(fp, "expired keys:         %lu\n",
		(u_long)ntohl(ia->expired));
}



/*
 * traps - obtain and print a list of traps
 */
/*ARGSUSED*/
static void
traps(
	struct parse *pcmd,
	FILE *fp
	)
{
	size_t i;
	struct info_trap *it;
	sockaddr_u trap_addr, local_addr;
	size_t items;
	size_t itemsize;
	int res;

again:
	res = doquery(impl_ver, REQ_TRAPS, 0, 0, 0, NULL, &items,
		      &itemsize, (void *)&it, 0, sizeof(*it));
	
	if (res == INFO_ERR_IMPL && impl_ver == IMPL_XNTPD) {
		impl_ver = IMPL_XNTPD_OLD;
		goto again;
	}

	if (res != 0)
		return;

	if (!checkitems(items, fp))
		return;

	if (!checkitemsize(itemsize, sizeof(struct info_trap)) &&
	    !checkitemsize(itemsize, v4sizeof(struct info_trap)))
		return;

	for (i = 0; i < items; i++ ) {
		SET_ADDRS(trap_addr, local_addr, it, trap_address, local_address);
		fprintf(fp, "%saddress %s, port %d\n",
			(0 == i)
			    ? ""
			    : "\n",
			stoa(&trap_addr), ntohs(it->trap_port));
		fprintf(fp, "interface: %s, ",
			(0 == it->local_address)
			    ? "wildcard"
			    : stoa(&local_addr));
		if (ntohl(it->flags) & TRAP_CONFIGURED)
			fprintf(fp, "configured\n");
		else if (ntohl(it->flags) & TRAP_NONPRIO)
			fprintf(fp, "low priority\n");
		else
			fprintf(fp, "normal priority\n");
		
		fprintf(fp, "set for %ld secs, last set %ld secs ago\n",
			(long)ntohl(it->origtime),
			(long)ntohl(it->settime));
		fprintf(fp, "sequence %d, number of resets %ld\n",
			ntohs(it->sequence), (long)ntohl(it->resets));
	}
}


/*
 * addtrap - configure a trap
 */
static void
addtrap(
	struct parse *pcmd,
	FILE *fp
	)
{
	do_addclr_trap(pcmd, fp, REQ_ADD_TRAP);
}


/*
 * clrtrap - clear a trap from the server
 */
static void
clrtrap(
	struct parse *pcmd,
	FILE *fp
	)
{
	do_addclr_trap(pcmd, fp, REQ_CLR_TRAP);
}


/*
 * do_addclr_trap - do grunge work of adding/deleting traps
 */
static void
do_addclr_trap(
	struct parse *pcmd,
	FILE *fp,
	int req
	)
{
	struct conf_trap ctrap;
	size_t items;
	size_t itemsize;
	const char *dummy;
	int res;
	int sendsize;

again:
	if (impl_ver == IMPL_XNTPD)
		sendsize = sizeof(struct conf_trap);
	else
		sendsize = v4sizeof(struct conf_trap);

	if (IS_IPV4(&pcmd->argval[0].netnum)) {
		ctrap.trap_address = NSRCADR(&pcmd->argval[0].netnum);
		if (impl_ver == IMPL_XNTPD)
			ctrap.v6_flag = 0;
	} else {
		if (impl_ver == IMPL_XNTPD_OLD) {
			fprintf(stderr,
			    "***Server doesn't understand IPv6 addresses\n");
			return;
		}
		ctrap.trap_address6 = SOCK_ADDR6(&pcmd->argval[0].netnum);
		ctrap.v6_flag = 1;
	}
	ctrap.local_address = 0;
	ctrap.trap_port = htons(TRAPPORT);
	ctrap.unused = 0;

	if (pcmd->nargs > 1) {
		ctrap.trap_port	= htons((u_short)pcmd->argval[1].uval);
		if (pcmd->nargs > 2) {
			if (AF(&pcmd->argval[2].netnum) !=
			    AF(&pcmd->argval[0].netnum)) {
				fprintf(stderr,
				    "***Cannot mix IPv4 and IPv6 addresses\n");
				return;
			}
			if (IS_IPV4(&pcmd->argval[2].netnum))
				ctrap.local_address = NSRCADR(&pcmd->argval[2].netnum);
			else
				ctrap.local_address6 = SOCK_ADDR6(&pcmd->argval[2].netnum);
		}
	}

	res = doquery(impl_ver, req, 1, 1, sendsize,
		      (char *)&ctrap, &items, &itemsize, &dummy, 0, 
		      sizeof(struct conf_trap));
	
	if (res == INFO_ERR_IMPL && impl_ver == IMPL_XNTPD) {
		impl_ver = IMPL_XNTPD_OLD;
		goto again;
	}

	if (res == 0)
	    (void) fprintf(fp, "done!\n");
	return;
}



/*
 * requestkey - change the server's request key (a dangerous request)
 */
static void
requestkey(
	struct parse *pcmd,
	FILE *fp
	)
{
	do_changekey(pcmd, fp, REQ_REQUEST_KEY);
}


/*
 * controlkey - change the server's control key
 */
static void
controlkey(
	struct parse *pcmd,
	FILE *fp
	)
{
	do_changekey(pcmd, fp, REQ_CONTROL_KEY);
}



/*
 * do_changekey - do grunge work of changing keys
 */
static void
do_changekey(
	struct parse *pcmd,
	FILE *fp,
	int req
	)
{
	u_long key;
	size_t items;
	size_t itemsize;
	const char *dummy;
	int res;


	key = htonl((u_int32)pcmd->argval[0].uval);

again:
	res = doquery(impl_ver, req, 1, 1, sizeof(u_int32),
		      (char *)&key, &items, &itemsize, &dummy, 0, 
		      sizeof(dummy));
	
	if (res == INFO_ERR_IMPL && impl_ver == IMPL_XNTPD) {
		impl_ver = IMPL_XNTPD_OLD;
		goto again;
	}

	if (res == 0)
	    (void) fprintf(fp, "done!\n");
	return;
}



/*
 * ctlstats - obtain and print info about authentication
 */
/*ARGSUSED*/
static void
ctlstats(
	struct parse *pcmd,
	FILE *fp
	)
{
	struct info_control *ic;
	size_t items;
	size_t itemsize;
	int res;

again:
	res = doquery(impl_ver, REQ_GET_CTLSTATS, 0, 0, 0, NULL, &items,
		      &itemsize, (void *)&ic, 0, sizeof(*ic));
	
	if (res == INFO_ERR_IMPL && impl_ver == IMPL_XNTPD) {
		impl_ver = IMPL_XNTPD_OLD;
		goto again;
	}

	if (res != 0)
		return;

	if (!check1item(items, fp))
		return;

	if (!checkitemsize(itemsize, sizeof(*ic)))
		return;

	fprintf(fp, "time since reset:       %lu\n",
		(u_long)ntohl(ic->ctltimereset));
	fprintf(fp, "requests received:      %lu\n",
		(u_long)ntohl(ic->numctlreq));
	fprintf(fp, "responses sent:         %lu\n",
		(u_long)ntohl(ic->numctlresponses));
	fprintf(fp, "fragments sent:         %lu\n",
		(u_long)ntohl(ic->numctlfrags));
	fprintf(fp, "async messages sent:    %lu\n",
		(u_long)ntohl(ic->numasyncmsgs));
	fprintf(fp, "error msgs sent:        %lu\n",
		(u_long)ntohl(ic->numctlerrors));
	fprintf(fp, "total bad pkts:         %lu\n",
		(u_long)ntohl(ic->numctlbadpkts));
	fprintf(fp, "packet too short:       %lu\n",
		(u_long)ntohl(ic->numctltooshort));
	fprintf(fp, "response on input:      %lu\n",
		(u_long)ntohl(ic->numctlinputresp));
	fprintf(fp, "fragment on input:      %lu\n",
		(u_long)ntohl(ic->numctlinputfrag));
	fprintf(fp, "error set on input:     %lu\n",
		(u_long)ntohl(ic->numctlinputerr));
	fprintf(fp, "bad offset on input:    %lu\n",
		(u_long)ntohl(ic->numctlbadoffset));
	fprintf(fp, "bad version packets:    %lu\n",
		(u_long)ntohl(ic->numctlbadversion));
	fprintf(fp, "data in pkt too short:  %lu\n",
		(u_long)ntohl(ic->numctldatatooshort));
	fprintf(fp, "unknown op codes:       %lu\n",
		(u_long)ntohl(ic->numctlbadop));
}


/*
 * clockstat - get and print clock status information
 */
static void
clockstat(
	struct parse *pcmd,
	FILE *fp
	)
{
	struct info_clock *cl;
	/* 8 is the maximum number of clocks which will fit in a packet */
	u_long clist[min(MAXARGS, 8)];
	size_t qitemlim;
	size_t qitems;
	size_t items;
	size_t itemsize;
	int res;
	l_fp ts;
	struct clktype *clk;

	qitemlim = min(pcmd->nargs, COUNTOF(clist));
	for (qitems = 0; qitems < qitemlim; qitems++)
		clist[qitems] = NSRCADR(&pcmd->argval[qitems].netnum);

again:
	res = doquery(impl_ver, REQ_GET_CLOCKINFO, 0, qitems,
		      sizeof(u_int32), (char *)clist, &items,
		      &itemsize, (void *)&cl, 0, sizeof(struct info_clock));
	
	if (res == INFO_ERR_IMPL && impl_ver == IMPL_XNTPD) {
		impl_ver = IMPL_XNTPD_OLD;
		goto again;
	}

	if (res != 0)
		return;

	if (!checkitems(items, fp))
		return;

	if (!checkitemsize(itemsize, sizeof(struct info_clock)))
		return;

	while (items-- > 0) {
		(void) fprintf(fp, "clock address:        %s\n",
			       numtoa(cl->clockadr));
		for (clk = clktypes; clk->code >= 0; clk++)
		    if (clk->code == cl->type)
			break;
		if (clk->code >= 0)
		    (void) fprintf(fp, "clock type:           %s\n",
				   clk->clocktype);
		else
		    (void) fprintf(fp, "clock type:           unknown type (%d)\n",
				   cl->type);
		(void) fprintf(fp, "last event:           %d\n",
			       cl->lastevent);
		(void) fprintf(fp, "current status:       %d\n",
			       cl->currentstatus);
		(void) fprintf(fp, "number of polls:      %lu\n",
			       (u_long)ntohl(cl->polls));
		(void) fprintf(fp, "no response to poll:  %lu\n",
			       (u_long)ntohl(cl->noresponse));
		(void) fprintf(fp, "bad format responses: %lu\n",
			       (u_long)ntohl(cl->badformat));
		(void) fprintf(fp, "bad data responses:   %lu\n",
			       (u_long)ntohl(cl->baddata));
		(void) fprintf(fp, "running time:         %lu\n",
			       (u_long)ntohl(cl->timestarted));
		NTOHL_FP(&cl->fudgetime1, &ts);
		(void) fprintf(fp, "fudge time 1:         %s\n",
			       lfptoa(&ts, 6));
		NTOHL_FP(&cl->fudgetime2, &ts);
		(void) fprintf(fp, "fudge time 2:         %s\n",
			       lfptoa(&ts, 6));
		(void) fprintf(fp, "stratum:              %ld\n",
			       (u_long)ntohl(cl->fudgeval1));
		(void) fprintf(fp, "reference ID:         %s\n",
			       refid_string(ntohl(cl->fudgeval2), 0));
		(void) fprintf(fp, "fudge flags:          0x%x\n",
			       cl->flags);

		if (items > 0)
		    (void) fprintf(fp, "\n");
		cl++;
	}
}


/*
 * fudge - set clock fudge factors
 */
static void
fudge(
	struct parse *pcmd,
	FILE *fp
	)
{
	struct conf_fudge fudgedata;
	size_t items;
	size_t itemsize;
	const char *dummy;
	l_fp ts;
	int res;
	long val;
	u_long u_val;
	int err;


	err = 0;
	ZERO(fudgedata);
	fudgedata.clockadr = NSRCADR(&pcmd->argval[0].netnum);

	if (STREQ(pcmd->argval[1].string, "time1")) {
		fudgedata.which = htonl(FUDGE_TIME1);
		if (!atolfp(pcmd->argval[2].string, &ts))
		    err = 1;
		else
		    NTOHL_FP(&ts, &fudgedata.fudgetime);
	} else if (STREQ(pcmd->argval[1].string, "time2")) {
		fudgedata.which = htonl(FUDGE_TIME2);
		if (!atolfp(pcmd->argval[2].string, &ts))
		    err = 1;
		else
		    NTOHL_FP(&ts, &fudgedata.fudgetime);
	} else if (STREQ(pcmd->argval[1].string, "val1")) {
		fudgedata.which = htonl(FUDGE_VAL1);
		if (!atoint(pcmd->argval[2].string, &val))
		    err = 1;
		else
		    fudgedata.fudgeval_flags = htonl(val);
	} else if (STREQ(pcmd->argval[1].string, "val2")) {
		fudgedata.which = htonl(FUDGE_VAL2);
		if (!atoint(pcmd->argval[2].string, &val))
		    err = 1;
		else
		    fudgedata.fudgeval_flags = htonl((u_int32)val);
	} else if (STREQ(pcmd->argval[1].string, "flags")) {
		fudgedata.which = htonl(FUDGE_FLAGS);
		if (!hextoint(pcmd->argval[2].string, &u_val))
		    err = 1;
		else
		    fudgedata.fudgeval_flags = htonl((u_int32)(u_val & 0xf));
	} else {
		(void) fprintf(stderr, "What fudge is %s?\n",
			       pcmd->argval[1].string);
		return;
	}

	if (err) {
		(void) fprintf(stderr, "Unknown fudge parameter %s\n",
			       pcmd->argval[2].string);
		return;
	}

again:
	res = doquery(impl_ver, REQ_SET_CLKFUDGE, 1, 1,
		      sizeof(struct conf_fudge), (char *)&fudgedata, &items,
		      &itemsize, &dummy, 0, sizeof(dummy));

	if (res == INFO_ERR_IMPL && impl_ver == IMPL_XNTPD) {
		impl_ver = IMPL_XNTPD_OLD;
		goto again;
	}

	if (res == 0)
	    (void) fprintf(fp, "done!\n");
	return;
}

/*
 * clkbug - get and print clock debugging information
 */
static void
clkbug(
	struct parse *pcmd,
	FILE *fp
	)
{
	register int i;
	register int n;
	register u_int32 s;
	struct info_clkbug *cl;
	/* 8 is the maximum number of clocks which will fit in a packet */
	u_long clist[min(MAXARGS, 8)];
	u_int32 ltemp;
	size_t qitemlim;
	size_t qitems;
	size_t items;
	size_t itemsize;
	int res;
	int needsp;
	l_fp ts;

	qitemlim = min(pcmd->nargs, COUNTOF(clist));
	for (qitems = 0; qitems < qitemlim; qitems++)
		clist[qitems] = NSRCADR(&pcmd->argval[qitems].netnum);

again:
	res = doquery(impl_ver, REQ_GET_CLKBUGINFO, 0, qitems,
		      sizeof(u_int32), (char *)clist, &items,
		      &itemsize, (void *)&cl, 0, sizeof(struct info_clkbug));
	
	if (res == INFO_ERR_IMPL && impl_ver == IMPL_XNTPD) {
		impl_ver = IMPL_XNTPD_OLD;
		goto again;
	}

	if (res != 0)
		return;

	if (!checkitems(items, fp))
		return;

	if (!checkitemsize(itemsize, sizeof(struct info_clkbug)))
		return;

	while (items-- > 0) {
		(void) fprintf(fp, "clock address:        %s\n",
			       numtoa(cl->clockadr));
		n = (int)cl->nvalues;
		(void) fprintf(fp, "values: %d", n);
		s = ntohs(cl->svalues);
		if (n > NUMCBUGVALUES)
		    n = NUMCBUGVALUES;
		for (i = 0; i < n; i++) {
			ltemp = ntohl(cl->values[i]);
			ltemp &= 0xffffffff;	/* HMS: This does nothing now */
			if ((i & 0x3) == 0)
			    (void) fprintf(fp, "\n");
			if (s & (1 << i))
			    (void) fprintf(fp, "%12ld", (u_long)ltemp);
			else
			    (void) fprintf(fp, "%12lu", (u_long)ltemp);
		}
		(void) fprintf(fp, "\n");

		n = (int)cl->ntimes;
		(void) fprintf(fp, "times: %d", n);
		s = ntohl(cl->stimes);
		if (n > NUMCBUGTIMES)
		    n = NUMCBUGTIMES;
		needsp = 0;
		for (i = 0; i < n; i++) {
			if ((i & 0x1) == 0) {
			    (void) fprintf(fp, "\n");
			} else {
				for (;needsp > 0; needsp--)
				    putc(' ', fp);
			}
			NTOHL_FP(&cl->times[i], &ts);
			if (s & (1 << i)) {
				(void) fprintf(fp, "%17s",
					       lfptoa(&ts, 6));
				needsp = 22;
			} else {
				(void) fprintf(fp, "%37s",
					       uglydate(&ts));
				needsp = 2;
			}
		}
		(void) fprintf(fp, "\n");
		if (items > 0) {
			cl++;
			(void) fprintf(fp, "\n");
		}
	}
}


/*
 * kerninfo - display the kernel pll/pps variables
 */
static void
kerninfo(
	struct parse *pcmd,
	FILE *fp
	)
{
	struct info_kernel *ik;
	size_t items;
	size_t itemsize;
	int res;
	unsigned status;
	double tscale = 1e-6;

again:
	res = doquery(impl_ver, REQ_GET_KERNEL, 0, 0, 0, (char *)NULL,
		      &items, &itemsize, (void *)&ik, 0, 
		      sizeof(struct info_kernel));

	if (res == INFO_ERR_IMPL && impl_ver == IMPL_XNTPD) {
		impl_ver = IMPL_XNTPD_OLD;
		goto again;
	}

	if (res != 0)
	    return;
	if (!check1item(items, fp))
	    return;
	if (!checkitemsize(itemsize, sizeof(struct info_kernel)))
	    return;

	status = ntohs(ik->status) & 0xffff;
	/*
	 * pll variables. We know more than we should about the NANO bit.
	 */
#ifdef STA_NANO
	if (status & STA_NANO)
		tscale = 1e-9;
#endif
	(void)fprintf(fp, "pll offset:           %g s\n",
	    (int32)ntohl(ik->offset) * tscale);
	(void)fprintf(fp, "pll frequency:        %s ppm\n",
	    fptoa((s_fp)ntohl(ik->freq), 3));
	(void)fprintf(fp, "maximum error:        %g s\n",
	    (u_long)ntohl(ik->maxerror) * tscale);
	(void)fprintf(fp, "estimated error:      %g s\n",
	    (u_long)ntohl(ik->esterror) * tscale);
	(void)fprintf(fp, "status:               %04x ", status);
#ifdef STA_PLL
	if (status & STA_PLL) (void)fprintf(fp, " pll");
#endif
#ifdef STA_PPSFREQ
	if (status & STA_PPSFREQ) (void)fprintf(fp, " ppsfreq");
#endif
#ifdef STA_PPSTIME
	if (status & STA_PPSTIME) (void)fprintf(fp, " ppstime");
#endif
#ifdef STA_FLL
	if (status & STA_FLL) (void)fprintf(fp, " fll");
#endif
#ifdef STA_INS
	if (status & STA_INS) (void)fprintf(fp, " ins");
#endif
#ifdef STA_DEL
	if (status & STA_DEL) (void)fprintf(fp, " del");
#endif
#ifdef STA_UNSYNC
	if (status & STA_UNSYNC) (void)fprintf(fp, " unsync");
#endif
#ifdef STA_FREQHOLD
	if (status & STA_FREQHOLD) (void)fprintf(fp, " freqhold");
#endif
#ifdef STA_PPSSIGNAL
	if (status & STA_PPSSIGNAL) (void)fprintf(fp, " ppssignal");
#endif
#ifdef STA_PPSJITTER
	if (status & STA_PPSJITTER) (void)fprintf(fp, " ppsjitter");
#endif
#ifdef STA_PPSWANDER
	if (status & STA_PPSWANDER) (void)fprintf(fp, " ppswander");
#endif
#ifdef STA_PPSERROR
	if (status & STA_PPSERROR) (void)fprintf(fp, " ppserror");
#endif
#ifdef STA_CLOCKERR
	if (status & STA_CLOCKERR) (void)fprintf(fp, " clockerr");
#endif
#ifdef STA_NANO
	if (status & STA_NANO) (void)fprintf(fp, " nano");
#endif
#ifdef STA_MODE
	if (status & STA_MODE) (void)fprintf(fp, " mode=fll");
#endif
#ifdef STA_CLK
	if (status & STA_CLK) (void)fprintf(fp, " src=B");
#endif
	(void)fprintf(fp, "\n");
	(void)fprintf(fp, "pll time constant:    %ld\n",
	    (u_long)ntohl(ik->constant));
	(void)fprintf(fp, "precision:            %g s\n",
	    (u_long)ntohl(ik->precision) * tscale);
	(void)fprintf(fp, "frequency tolerance:  %s ppm\n",
	    fptoa((s_fp)ntohl(ik->tolerance), 0));

	/*
	 * For backwards compatibility (ugh), we find the pps variables
	 * only if the shift member is nonzero.
	 */
	if (!ik->shift)
	    return;

	/*
	 * pps variables
	 */
	(void)fprintf(fp, "pps frequency:        %s ppm\n",
	    fptoa((s_fp)ntohl(ik->ppsfreq), 3));
	(void)fprintf(fp, "pps stability:        %s ppm\n",
	    fptoa((s_fp)ntohl(ik->stabil), 3));
	(void)fprintf(fp, "pps jitter:           %g s\n",
	    (u_long)ntohl(ik->jitter) * tscale);
	(void)fprintf(fp, "calibration interval: %d s\n",
		      1 << ntohs(ik->shift));
	(void)fprintf(fp, "calibration cycles:   %ld\n",
		      (u_long)ntohl(ik->calcnt));
	(void)fprintf(fp, "jitter exceeded:      %ld\n",
		      (u_long)ntohl(ik->jitcnt));
	(void)fprintf(fp, "stability exceeded:   %ld\n",
		      (u_long)ntohl(ik->stbcnt));
	(void)fprintf(fp, "calibration errors:   %ld\n",
		      (u_long)ntohl(ik->errcnt));
}

#define IF_LIST_FMT     "%2d %c %48s %c %c %12.12s %03lx %3lu %2lu %5lu %5lu %5lu %2lu %3lu %7lu\n"
#define IF_LIST_FMT_STR "%2s %c %48s %c %c %12.12s %3s %3s %2s %5s %5s %5s %2s %3s %7s\n"
#define IF_LIST_AFMT_STR "     %48s %c\n"
#define IF_LIST_LABELS  "#", 'A', "Address/Mask/Broadcast", 'T', 'E', "IF name", "Flg", "TL", "#M", "recv", "sent", "drop", "S", "PC", "uptime"
#define IF_LIST_LINE    "==================================================================================================================\n"

static void
iflist(
	FILE *fp,
	struct info_if_stats *ifs,
	size_t items,
	size_t itemsize,
	int res
	)
{
	static const char *actions = "?.+-";
	sockaddr_u saddr;

	if (res != 0)
	    return;

	if (!checkitems(items, fp))
	    return;

	if (!checkitemsize(itemsize, sizeof(struct info_if_stats)))
	    return;

	fprintf(fp, IF_LIST_FMT_STR, IF_LIST_LABELS);
	fprintf(fp, IF_LIST_LINE);
	
	while (items > 0) {
		SET_ADDR(saddr, ntohl(ifs->v6_flag), 
			 ifs->unaddr.addr.s_addr, ifs->unaddr.addr6);
		fprintf(fp, IF_LIST_FMT,
			ntohl(ifs->ifnum),
			actions[(ifs->action >= 1 && ifs->action < 4) ? ifs->action : 0],
			stoa((&saddr)), 'A',
			ifs->ignore_packets ? 'D' : 'E',
			ifs->name,
			(u_long)ntohl(ifs->flags),
			(u_long)ntohl(ifs->last_ttl),
			(u_long)ntohl(ifs->num_mcast),
			(u_long)ntohl(ifs->received),
			(u_long)ntohl(ifs->sent),
			(u_long)ntohl(ifs->notsent),
			(u_long)ntohl(ifs->scopeid),
			(u_long)ntohl(ifs->peercnt),
			(u_long)ntohl(ifs->uptime));

		SET_ADDR(saddr, ntohl(ifs->v6_flag), 
			 ifs->unmask.addr.s_addr, ifs->unmask.addr6);
		fprintf(fp, IF_LIST_AFMT_STR, stoa(&saddr), 'M');

		if (!ntohl(ifs->v6_flag) && ntohl(ifs->flags) & (INT_BCASTOPEN)) {
			SET_ADDR(saddr, ntohl(ifs->v6_flag), 
				 ifs->unbcast.addr.s_addr, ifs->unbcast.addr6);
			fprintf(fp, IF_LIST_AFMT_STR, stoa(&saddr), 'B');

		}

		ifs++;
		items--;
	}
}

/*ARGSUSED*/
static void
get_if_stats(
	struct parse *pcmd,
	FILE *fp
	)
{
	struct info_if_stats *ifs;
	size_t items;
	size_t itemsize;
	int res;

	res = doquery(impl_ver, REQ_IF_STATS, 1, 0, 0, (char *)NULL, &items,
		      &itemsize, (void *)&ifs, 0, 
		      sizeof(struct info_if_stats));
	iflist(fp, ifs, items, itemsize, res);
}

/*ARGSUSED*/
static void
do_if_reload(
	struct parse *pcmd,
	FILE *fp
	)
{
	struct info_if_stats *ifs;
	size_t items;
	size_t itemsize;
	int res;

	res = doquery(impl_ver, REQ_IF_RELOAD, 1, 0, 0, (char *)NULL, &items,
		      &itemsize, (void *)&ifs, 0, 
		      sizeof(struct info_if_stats));
	iflist(fp, ifs, items, itemsize, res);
}