|
root / base / usr / src / cmd / cmd-inet / usr.sbin / snoop / snoop_slp.c
snoop_slp.c C 1963 lines 46.8 KB
   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
/*
 * CDDL HEADER START
 *
 * The contents of this file are subject to the terms of the
 * Common Development and Distribution License, Version 1.0 only
 * (the "License").  You may not use this file except in compliance
 * with the License.
 *
 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
 * or http://www.opensolaris.org/os/licensing.
 * See the License for the specific language governing permissions
 * and limitations under the License.
 *
 * When distributing Covered Code, include this CDDL HEADER in each
 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
 * If applicable, add the following below this CDDL HEADER, with the
 * fields enclosed by brackets "[]" replaced with your own identifying
 * information: Portions Copyright [yyyy] [name of copyright owner]
 *
 * CDDL HEADER END
 */
/*
 * Copyright (c) 1998,2000 by Sun Microsystems, Inc.
 * All rights reserved.
 */

#include <stdio.h>
#include <arpa/inet.h>
#include <stdlib.h>
#include <string.h>
#include <sys/time.h>
#include <iconv.h>
#include "snoop.h"
#include "slp.h"

#define	MAXSUMLEN 30

/* define VERIFYSLP to enable full message checking in summary mode */
#define	VERIFYSLP

/* Globals -- ugly, yes, but fast and easy in macros */
static int msglength;
static int retlength;
static char *msgend;	/* the end of the summary message buffer */
static char *p;		/* current position in the packet */
static char *msgbuf;	/* message buffer for summary mode */
static boolean_t url_auth	= B_FALSE;
static boolean_t attr_auth	= B_FALSE;
static boolean_t fresh		= B_FALSE;
static boolean_t overflow	= B_FALSE;
static int v1_charset		= 0;	/* character set; only in V1 */

/* Entry points for parsing the protocol */
static int interpret_slp_v1(int, struct slpv1_hdr *, int);
static int interpret_slp_v2(int, struct slpv2_hdr *, int);

/* header parsing */
static int v1_header(int, struct slpv1_hdr *, int);
static int v2_header(int, struct slpv2_hdr *, int *, int);
static int v2_finish(struct slpv2_hdr *, int);

/* V2 auth blocks */
static int slpv2_authblock(int);

/*
 * Functions for parsing each protocol message
 * Each function takes the interpreter's flags argument as its input
 * parameter, and returns 1 on success, or 0 on message corruption.
 * retlength is set as a side-effect in summary mode.
 */
static int v2_srv_rqst(int);
static int v2_srv_rply(int);
static int v2_srv_reg(int);
static int v2_srv_dereg(int);
static int v2_srv_ack(int);
static int v2_attr_rqst(int);
static int v2_attr_rply(int);
static int v2_daadvert(int);
static int v2_srv_type_rqst(int);
static int v2_srv_type_rply(int);
static int v2_saadvert(int);

static int v1_srv_rqst(int);
static int v1_srv_rply(int);
static int v1_srv_reg(int);
static int v1_srv_dereg(int);
static int v1_srv_ack(int);
static int v1_attr_rqst(int);
static int v1_attr_rply(int);
static int v1_daadvert(int);
static int v1_srv_type_rqst(int);
static int v1_srv_type_rply(int);

/*
 * The dispatch tables for handling individual messages, keyed by
 * function number.
 */
typedef int function_handler();

#define	V2_MAX_FUNCTION	11

static function_handler *v2_functions[V2_MAX_FUNCTION + 1] = {
	(function_handler *) NULL,
	(function_handler *) v2_srv_rqst,
	(function_handler *) v2_srv_rply,
	(function_handler *) v2_srv_reg,
	(function_handler *) v2_srv_dereg,
	(function_handler *) v2_srv_ack,
	(function_handler *) v2_attr_rqst,
	(function_handler *) v2_attr_rply,
	(function_handler *) v2_daadvert,
	(function_handler *) v2_srv_type_rqst,
	(function_handler *) v2_srv_type_rply,
	(function_handler *) v2_saadvert };

#define	V1_MAX_FUNCTION	10

static function_handler *v1_functions[V1_MAX_FUNCTION + 1] = {
	(function_handler *) NULL,
	(function_handler *) v1_srv_rqst,
	(function_handler *) v1_srv_rply,
	(function_handler *) v1_srv_reg,
	(function_handler *) v1_srv_dereg,
	(function_handler *) v1_srv_ack,
	(function_handler *) v1_attr_rqst,
	(function_handler *) v1_attr_rply,
	(function_handler *) v1_daadvert,
	(function_handler *) v1_srv_type_rqst,
	(function_handler *) v1_srv_type_rply };

/* TCP continuation handling */
static boolean_t tcp_continuation = B_FALSE;

#define	MAX_TCPCONT	16

static struct tcp_cont {
	int dst_port;
	char *msg;
	int totallen;
	int curr_offset;
} *tcp_cont[MAX_TCPCONT];

static int current_tcp_cont;

static void reg_tcp_cont(char *, int, int, int);
static int add_tcp_cont(struct tcp_cont *, char *, int);
static struct tcp_cont *find_tcp_cont(int);
static void remove_tcp_cont(int);

/* Conversions from numbers to strings */
static char *slpv2_func(int, boolean_t);
static char *slpv2_error(unsigned short);
static char *slpv1_func(int, boolean_t);
static char *slpv1_error(unsigned short);
static char *slpv1_charset(unsigned short);

/*
 * The only external entry point to the SLP interpreter. This function
 * simply dispatches the packet based on the version.
 */
int
interpret_slp(int flags, void *slp, int fraglen)
{
	extern int dst_port, curr_proto;
	struct tcp_cont *tce = NULL;
	char *s;

	msglength = fraglen;
	retlength = 0;
	p = slp;

	/* check if this is a TCP continuation */
	if (flags & F_DTAIL && curr_proto == IPPROTO_TCP) {
		tce = find_tcp_cont(dst_port);
		if (tce) {
			if (add_tcp_cont(tce, slp, fraglen)) {
				slp = tce->msg;
				fraglen = tce->curr_offset;
				tcp_continuation = B_TRUE;
			}
		}
	}
	if (*(char *)slp == 2 || tce)
		interpret_slp_v2(flags, slp, fraglen);
	else
		interpret_slp_v1(flags, slp, fraglen);

	tcp_continuation = B_FALSE;
	return (0);
}

/*
 * Primitives. These are implemented as much as possible as macros for
 * speed.
 */

#define	FIELD_DEFAULT	0
#define	FIELD_PREVRESP	1
#define	FIELD_TYPENA	2

static long long netval = 0;	/* need signed 64 bit quantity */

/* gets two bytes from p and leaves the result in netval */
#define	nbtohs() \
	netval = ((int)(p[0] & 0xff)) << 8; \
	netval += ((int)(p[1] & 0xff))

/* gets four bytes from p and leaves the result in netval */
#define	nbtohl() \
	netval = ((int)(p[0] & 0xff)) << 24; \
	netval += ((int)(p[1] & 0xff)) << 16; \
	netval += ((int)(p[2] & 0xff)) << 8; \
	netval += ((int)(p[3] & 0xff))

#define	get_byte() \
	if (msglength >= 1) { \
		netval = *p; \
		p++; \
		msglength--; \
	} else \
		netval = -1

#define	GETBYTE(x) \
	get_byte(); \
	if ((retlength = netval) < 0) \
		return (0); \
	x = netval

#define	SKIPBYTE \
	get_byte(); \
	if ((retlength = netval) < 0) \
		return (0); \

/*
 * gets two bytes from p, leaves the result in netval, and updates
 * msglength and p.
 */
#define	get_short() \
	if (msglength >= sizeof (unsigned short)) { \
		nbtohs(); \
		p += sizeof (unsigned short); \
		msglength -= sizeof (unsigned short); \
	} else \
		netval = -1

#define	GETSHORT(x) \
	get_short(); \
	if ((retlength = netval) < 0) \
		return (0); \
	x = netval

#define	SKIPSHORT \
	get_short(); \
	if ((retlength = netval) < 0) \
		return (0)

#define	get_int24(pp) \
	netval = ((int)((pp)[0] & 0xff)) << 16; \
	netval += ((int)((pp)[1] & 0xff)) << 8; \
	netval += ((int)((pp)[2] & 0xff))

static void slp_prevresp(char *p) {
	char *p2;

	/* cycle through all entries */
	for (; p != NULL; p = p2) {
	    p2 = strchr(p, ',');
	    if (p2 != NULL)
		*p2++ = '\0';

	    /* print entry at p */
	    sprintf(get_line(0, 0), "  \"%s\"", p);
	}
}

static int skip_field(int type) {
	unsigned short stringlen;

	get_short();
	if (netval < 0) {
	    return (-1);
	}
	stringlen = netval;

	/* special case for NA field in SrvTypeRqst */
	if (type == FIELD_TYPENA && stringlen == 0xffff) {
	    stringlen = 0;
	}

	if (stringlen > msglength) {
	    return (-1);
	}

	msglength -= stringlen;
	p += stringlen;

	return (stringlen);
}

#define	SKIPFIELD(type) \
	if ((retlength = skip_field(type)) < 0) \
		return (0)

#define	GETFIELD \
	get_short(); \
	if ((retlength = netval) < 0) \
		return (0); \
	strncat(msgbuf, p, (retlength > MAXSUMLEN ? MAXSUMLEN : retlength)); \
	p += retlength; \
	msglength -= retlength

/*
 * Determines from the first five bytes of a potential SLP header
 * if the following message is really an SLP message. Returns 1 if
 * it is a real SLP message, 0 if not.
 */
int valid_slp(unsigned char *slphdr, int len) {
	struct slpv1_hdr slp1;
	struct slpv2_hdr slp2;

	len -= (8 /* udp */ + 20 /* IP */ + 14 /* ether */);
	/* a valid version will be 1 or 2 */
	switch (*slphdr) {
	case 1:
	    memcpy(&slp1, slphdr, 5);
	    /* valid function? */
	    if (slp1.function > V1_MAX_FUNCTION) {
		return (0);
	    }
	    /* valid length heuristic */
	    if (slp1.length > len) {
		return (0);
	    }
	    return (1);
	case 2:
	    memcpy(&slp2, slphdr, 5);
	    /* valid function? */
	    if (slp2.function > V2_MAX_FUNCTION) {
		return (0);
	    }
	    /* valid length heuristic */
	    get_int24(&(slp2.l1));
	    if (netval > len) {
		return (0);
	    }
	    return (1);
	default:
	    return (0);
	}
}

/*
 * Converts a V1 char encoding to UTF8. If this fails, returns 0,
 * otherwise, 1. This function is the union of iconv UTF-8
 * modules and character sets registered with IANA.
 */
static int make_utf8(char *outbuf, size_t outlen,
			const char *inbuf, size_t inlen) {
	iconv_t cd;
	size_t converted;

	switch (v1_charset) {
	case 4:
	case 1004:
	    cd = iconv_open("UTF-8", "8859-1");
	    break;
	case 5:
	    cd = iconv_open("UTF-8", "8859-2");
	    break;
	case 6:
	    cd = iconv_open("UTF-8", "8859-3");
	    break;
	case 7:
	    cd = iconv_open("UTF-8", "8859-4");
	    break;
	case 8:
	    cd = iconv_open("UTF-8", "8859-5");
	    break;
	case 9:
	    cd = iconv_open("UTF-8", "8859-6");
	    break;
	case 10:
	    cd = iconv_open("UTF-8", "8859-7");
	    break;
	case 11:
	    cd = iconv_open("UTF-8", "8859-8");
	    break;
	case 12:
	    cd = iconv_open("UTF-8", "8859-9");
	    break;
	case 13:
	    cd = iconv_open("UTF-8", "8859-10");
	    break;
	case 37:
	    cd = iconv_open("UTF-8", "ko_KR-iso2022-7");
	    break;
	case 104:
	    cd = iconv_open("UTF-8", "iso2022");
	    break;
	case 1000:
	    cd = iconv_open("UTF-8", "UCS-2");
	    break;
	case 1001:
	    cd = iconv_open("UTF-8", "UCS-4");
	    break;
	default:
		/*
		 * charset not set, or reserved, or not supported, so
		 * just copy it and hope for the best.
		 */
	    converted = outlen < inlen ? outlen : inlen;
	    memcpy(outbuf, inbuf, converted);
	    outbuf[converted] = 0;
	    return (1);
	}

	if (cd == (iconv_t)-1) {
	    return (0);
	}

	if ((converted = iconv(cd, &inbuf, &inlen, &outbuf, &outlen))
	    == (size_t)-1) {
	    return (0);
	}

	outbuf[converted] = 0;
	iconv_close(cd);

	return (1);
}

static int slp_field(char *tag, int type) {
	int length;

	get_short();
	if (netval < 0) {
	    return (-1);
	}
	length = netval;

	/* special case for NA field in SrvTypeRqst */
	if (type == FIELD_TYPENA && length == 0xffff) {
	    sprintf(get_line(0, 0), "%s: length = -1: Use all NAs", tag);
	    return (0);
	}

	sprintf(get_line(0, 0), "%s: length = %d", tag, length);
	if (length > msglength) {
	    /* framing error: message is not long enough to contain data */
	    sprintf(get_line(0, 0),
		    "  [Framing error: remaining pkt length = %u]",
		    msglength);
	    return (-1);
	}

	if (length > 0) {
	    char *buf = malloc(length + 1);
	    if (buf != NULL) {
		if (v1_charset) {
		    if (!make_utf8(buf, length, p, length)) {
			strcpy(buf, "[Invalid Character Encoding]");
		    }
		} else {
		    memcpy(buf, p, length);
		    buf[length] = '\0';		/* ensure null-terminated */
		}

		switch (type) {
		    case FIELD_PREVRESP:
			slp_prevresp(buf);
			break;

		    default:
			sprintf(get_line(0, 0), "  \"%s\"", buf);
			break;
		}
		free(buf);
	    }

	    p += length;
	    msglength -= length;
	}

	/* return ok */
	return (0);
}

static int slpv2_url(int cnt) {
	time_t exp;
	int lifetime, length, n;

	/* reserved */
	get_byte();
	if (netval < 0)
	    return (-1);

	/* lifetime */
	get_short();
	if ((lifetime = netval) < 0)
	    return (-1);

	/* length */
	get_short();
	if ((length = netval) < 0)
	    return (-1);

	/* time */
	exp = time(0) + lifetime;
	if (cnt == -1)
	    sprintf(get_line(0, 0),
		    "URL: length = %u, lifetime = %d (%24.24s)",
		    length, lifetime, ctime(&exp));
	else
	    /* number the URLs to make it easier to parse them */
	    sprintf(get_line(0, 0),
		    "URL %d: length = %u, lifetime = %d (%24.24s)",
		    cnt, length, lifetime, ctime(&exp));

	if (length > msglength) {
	    if (!tcp_continuation)
		/* framing error: message is not long enough to contain data */
		sprintf(get_line(0, 0),
			"  [Framing error: remaining pkt length = %u]",
			msglength);
	    return (-1);
	}

	if (length > 0) {
	    char *buf = malloc(length + 1);
	    if (buf != NULL) {
		memcpy(buf, p, length);
		buf[length] = '\0';		/* ensure null-terminated */
		sprintf(get_line(0, 0), "  \"%s\"", buf);
		free(buf);
	    }
	}
	msglength -= length;
	p += length;

	get_byte();
	if ((n = netval) < 0)
	    return (-1);

	if (n > 0) {
	    int i;
	    sprintf(get_line(0, 0), "%d Authentication Blocks", n);
	    for (i = 0; i < n; i++)
		if ((length = slpv2_authblock(i)) < 0)
		    return (-1);
	}
	return (0);
}

#define	DOFIELD(tag, type) \
	if (slp_field(tag, type) < 0) \
		return (0)

#define	V2_DOURL(x) \
	if (slpv2_url(x) < 0) \
		return (0)

#define	V2_DOERRCODE \
	if (msglength < sizeof (unsigned short)) \
		return (0); \
	nbtohs(); \
	errcode = netval; \
	sprintf(get_line(0, 0), "Error code = %d, %s", \
				errcode, slpv2_error(errcode)); \
	p += sizeof (unsigned short); \
	msglength -= sizeof (unsigned short); \
	if (errcode != OK) \
		msglength = 0;	/* skip rest of message */ \
	if (errcode != OK) \
		return (0)

#define	V2_DOAUTH(cnt) \
	if (slpv2_authblock(cnt) < 0) \
		return (0)

#define	V2_DOTIMESTAMP \
	if (msglength < 4) \
		return (0); \
	nbtohl(); \
	timestamp = netval; \
	sprintf(get_line(0, 0), "Timestamp = %u, %s", \
		timestamp, (timestamp ? convert_ts(timestamp) : "0")); \
	p += 4; \
	msglength -= 4

/* some V1 macros */
#define	SKIPAUTH(auth) \
	if (auth && ((retlength = skip_v1authblock()) < 0)) \
		return (0)

#define	DOERRCODE \
	if (msglength < sizeof (unsigned short)) \
		return (0); \
	nbtohs(); \
	errcode = netval; \
	sprintf(get_line(0, 0), "Error code = %d, %s", errcode, \
				slpv1_error(errcode)); \
	p += sizeof (unsigned short); \
	msglength -= sizeof (unsigned short); \
	if (errcode != OK) \
		return (0)

#define	DOURL \
	if (slpv1_url(url_auth) < 0) \
		return (0)

#define	DOAUTH(auth) \
	if (auth && slpv1_authblock() < 0) \
		return (0)

/*
 * TCP Continuation handling
 * We keep track of continuations in a fixed size cache, so as to prevent
 * memory leaks if some continuations are never finished. The continuations
 * are indexed by their destination ports.
 */
static void reg_tcp_cont(char *msg, int totallen,
			    int fraglen, int dst_port) {
	struct tcp_cont *tce = malloc(sizeof (*tce));

	/* always overwrite the entry at current_tcp_cont */
	if (tcp_cont[current_tcp_cont]) {
	    free(tcp_cont[current_tcp_cont]->msg);
	    free(tcp_cont[current_tcp_cont]);
	}

	tce->dst_port = dst_port;
	tce->msg = malloc(totallen);
	memcpy(tce->msg, msg, fraglen);
	tce->totallen = totallen;
	tce->curr_offset = fraglen;

	tcp_cont[current_tcp_cont++] = tce;
	if (current_tcp_cont == MAX_TCPCONT)
	    current_tcp_cont = 0;
}

/* returns 0 if there is a mismatch error, 1 on success */
static int add_tcp_cont(struct tcp_cont *tce, char *msg, int fraglen) {
	if ((fraglen + tce->curr_offset) > tce->totallen)
	    return (0);

	memcpy(tce->msg + tce->curr_offset, msg, fraglen);
	tce->curr_offset += fraglen;
	return (1);
}

static struct tcp_cont *find_tcp_cont(int dst_port) {
	int i;
	for (i = current_tcp_cont; i >= 0; i--)
	    if (tcp_cont[i] && tcp_cont[i]->dst_port == dst_port)
		return (tcp_cont[i]);

	for (i = MAX_TCPCONT -1; i > current_tcp_cont; i--)
	    if (tcp_cont[i] && tcp_cont[i]->dst_port == dst_port)
		return (tcp_cont[i]);

	return (NULL);
}

static void remove_tcp_cont(int dst_port) {
	int i;
	for (i = current_tcp_cont; i >= 0; i--)
	    if (tcp_cont[i] && tcp_cont[i]->dst_port == dst_port) {
		free(tcp_cont[i]->msg);
		free(tcp_cont[i]);
		tcp_cont[i] = NULL;
		return;
	    }

	for (i = MAX_TCPCONT -1; i > current_tcp_cont; i--)
	    if (tcp_cont[i] && tcp_cont[i]->dst_port == dst_port) {
		free(tcp_cont[i]->msg);
		free(tcp_cont[i]);
		tcp_cont[i] = NULL;
		return;
	    }
}

/*
 * V2 interpreter
 */

static int interpret_slp_v2(int flags, struct slpv2_hdr *slp, int fraglen) {
	extern int src_port, dst_port, curr_proto;
	char msgbuf_real[256];
	int totallen = 0;

	msgbuf = msgbuf_real;

	/*
	 * Somewhat of a hack to decode traffic from a server that does
	 * not send udp replies from its SLP src port.
	 */

	if (curr_proto == IPPROTO_UDP &&
	    dst_port == 427 &&
	    src_port != 427) {
	    add_transient(src_port, interpret_slp);
	}

	/* parse the header */
	if (v2_header(flags, slp, &totallen, fraglen)) {

	    if (slp->function <= V2_MAX_FUNCTION && slp->function > 0) {

		/* Parse the message body */
		if ((v2_functions[slp->function])(flags)) {

		    /* finish any remaining tasks */
		    v2_finish(slp, flags);

		}

	    }

	}

	/* summary error check */
	if (flags & F_SUM) {
	    if (retlength < 0) {
		if (curr_proto == IPPROTO_TCP)
		    sprintf(get_sum_line(),
			    "%s [partial TCP message]", msgbuf);
		else if (overflow)
		    sprintf(get_sum_line(), "%s [OVERFLOW]", msgbuf);
		else
		    sprintf(get_sum_line(), "%s [CORRUPTED MESSAGE]", msgbuf);
	    }
#ifdef VERIFYSLP
	    else if (msglength > 0)
		sprintf(get_sum_line(), "%s +%d", msgbuf, msglength);
#endif
	    else
		sprintf(get_sum_line(), "%s", msgbuf);
	} else if (flags & F_DTAIL) {
	    /* detailed error check */
	    if (msglength > 0) {
		if (tcp_continuation) {
		    sprintf(get_line(0, 0),
			    "[TCP Continuation, %d bytes remaining]",
			    totallen - fraglen);
		} else
		    sprintf(get_line(0, 0),
			"[%d extra bytes at end of SLP message]", msglength);
	    }

	    show_trailer();

	    if (tcp_continuation && msglength == 0)
		remove_tcp_cont(dst_port);
	}

	return (0);
}

static int v2_header(int flags,
			struct slpv2_hdr *slp,
			int *totallen,
			int fraglen) {
	extern int curr_proto, dst_port;
	char *prototag = (curr_proto == IPPROTO_TCP ? "/tcp" : "");

	if ((slp->flags & V2_OVERFLOW) == V2_OVERFLOW)
	    overflow = B_TRUE;

	/* summary mode header parsing */
	if (flags & F_SUM) {

	    /* make sure we have at least a header */
	    if (msglength < sizeof (*slp)) {
		sprintf(get_sum_line(), "SLP V2 [Incomplete Header]");
		return (0);
	    }

	    sprintf(msgbuf, "SLP V2 %s [%d%s] ",
		    slpv2_func(slp->function, B_TRUE),
		    ntohs(slp->xid), prototag);

	    /* skip to end of header */
	    msgend = msgbuf + strlen(msgbuf);
	    msglength -= sizeof (*slp);
	    p += sizeof (*slp);

	    /* skip language tag */
	    SKIPFIELD(FIELD_DEFAULT);
	} else if (flags & F_DTAIL) {
	    char *lang;
	    int len;

	    /* detailed mode header parsing */
	    show_header("SLP:  ", "Service Location Protocol (v2)", fraglen);
	    show_space();

	    if (msglength < sizeof (*slp)) {
		sprintf(get_line(0, 0), "==> Incomplete SLP header");
		return (0);
	    }

	    sprintf(get_line(0, 0), "Version = %d", slp->vers);
	    sprintf(get_line(0, 0), "Function = %d, %s",
		    slp->function, slpv2_func(slp->function, B_FALSE));
	    get_int24(&(slp->l1));
	    *totallen = netval;
	    sprintf(get_line(0, 0), "Message length = %u", *totallen);
	    /* check for TCP continuation */
	    if (curr_proto == IPPROTO_TCP &&
		*totallen > msglength &&
		!tcp_continuation) {
		tcp_continuation = B_TRUE;
		reg_tcp_cont((char *)slp, *totallen, msglength, dst_port);
	    }

	    if (!tcp_continuation && *totallen != msglength) {
		sprintf(get_line(0, 0),
			"  (Stated and on-the-wire lengths differ)");
	    }
	    /* flags */
	    sprintf(get_line(0, 0), "Flags = 0x%02x", slp->flags);
	    sprintf(get_line(0, 0), "      %s",
		    getflag(slp->flags, V2_OVERFLOW,
			    "overflow", "no overflow"));
	    sprintf(get_line(0, 0), "      %s",
		    getflag(slp->flags, V2_FRESH,
			    "fresh registration", "no fresh registration"));
	    sprintf(get_line(0, 0), "      %s",
		    getflag(slp->flags, V2_MCAST,
			    "request multicast / broadcast", "unicast"));
	    /* check reserved flags that must be zero */
	    if ((slp->flags & 7) != 0) {
		sprintf(get_line(0, 0),
			"      .... .xxx = %d (reserved flags nonzero)",
			slp->flags & 7);
	    }
	    /* end of flags */

	    /* language tag */
	    p = (char *)slp + sizeof (*slp);
	    msglength -= sizeof (*slp);
	    GETSHORT(len);
	    if (len > msglength) {
		sprintf(get_line(0, 0),
			"Language Tag Length = %u [CORRUPT MESSAGE]",
			len);
		return (0);
	    }

	    lang = get_line(0, 0);
	    strcpy(lang, "Language Tag = ");
	    strncat(lang,  p, len);
	    sprintf(get_line(0, 0), "XID = %u", ntohs(slp->xid));

	    /* set msglength to remaining length of SLP message */
	    p += len;
	    msglength -= len;
	}

	return (1);
}

static int v2_finish(struct slpv2_hdr *slp, int flags) {
	unsigned int firstop;

	if (!(flags & F_DTAIL))
	    return (1);

	/* check for options */
	get_int24(&(slp->o1));
	firstop = netval;

	if (firstop) {
	    unsigned short op_id;
	    unsigned short nextop;
	    char *op_class;

	    for (;;) {
		unsigned short real_oplen;

		if (msglength < 4) {
		    sprintf(get_line(0, 0),
			    "Option expected but not present");
		    return (0);
		}

		nbtohs();
		op_id = netval;
		p += sizeof (unsigned short);
		msglength -= sizeof (unsigned short);
		nbtohs();
		nextop = netval;
		p += sizeof (unsigned short);
		msglength -= sizeof (unsigned short);

		real_oplen = nextop ? nextop : msglength;

		/* known options */
		switch (op_id) {
		case 1:
		    sprintf(get_line(0, 0),
			    "Option: Required Attribute Missing");
		    DOFIELD("Template IDVer", FIELD_DEFAULT);
		    DOFIELD("Required Attrs", FIELD_DEFAULT);
		    break;
		default:
		    sprintf(get_line(0, 0), "Option: Unknown");
		    p += (real_oplen - 4);
		    msglength -= (real_oplen - 4);
		    break;
		}

		if (op_id < 0x3fff)
		    op_class = "Standardized, optional";
		else if (op_id < 0x7fff)
		    op_class = "Standardized, mandatory";
		else if (op_id < 0x8fff)
		    op_class = "Not standardized, private";
		else if (op_id < 0xffff)
		    op_class = "Reserved";
		sprintf(get_line(0, 0), "Option ID = 0x%04x, %s",
			op_id, op_class);
		if (nextop &&
		    ((nextop - 4) > msglength) &&
		    !tcp_continuation) {
		    sprintf(get_line(0, 0),
			    "[Framing error: remaining pkt length = %u]",
			    msglength);
		    return (0);
		}

		sprintf(get_line(0, 0), "Option Length = %u", real_oplen);

		if (!nextop)
		    break;
	    }
	}

	return (1);
}

#ifdef VERIFYSLP
static int skip_v2authblock() {
	unsigned short length, slen;

	/* auth header */
	if (msglength < 10)
	    return (-1);

	/* block descriptor: 2 bytes */
	p += sizeof (unsigned short);
	/* length */
	nbtohs();
	length = netval;
	p += sizeof (unsigned short);
	/* timestamp */
	p += 4;
	/* SPI String length */
	nbtohs();
	slen = netval;
	p += sizeof (unsigned short);

	msglength -= 10;
	if (slen > msglength || length > (msglength + 10))
	    return (-1);

	p += slen;
	msglength -= slen;

	/* structured auth block */
	p += (length - 10 - slen);
	msglength -= (length - 10 - slen);
	return (0);
}
#endif

static char *display_bsd(unsigned short bsd) {
	switch (bsd) {
	case 1: return ("MD5 with RSA");
	case 2: return ("DSA with SHA-1");
	case 3: return ("Keyed HMAC with MD5");
	default: return ("Unknown BSD");
	}
}

static char *slpv2_func(int t, boolean_t s) {
	static char buf[128];

	switch (t) {
	case V2_SRVRQST:	return s? "SrvRqst"  : "Service Request";
	case V2_SRVRPLY:	return s? "SrvRply"  : "Service Reply";
	case V2_SRVREG:		return s? "SrvReg"   : "Service Registration";
	case V2_SRVDEREG:
	    return (s ? "SrvDereg" : "Service Deregistration");
	case V2_SRVACK:		return s? "SrvAck"   : "Service Acknowledge";
	case V2_ATTRRQST:	return s? "AttrRqst" : "Attribute Request";
	case V2_ATTRRPLY:	return s? "AttrRply" : "Attribute Reply";
	case V2_DAADVERT:	return s? "DAAdvert" : "DA advertisement";
	case V2_SRVTYPERQST:
	    return (s ? "SrvTypeRqst" : "Service Type Request");
	case V2_SRVTYPERPLY:
	    return (s ? "SrvTypeRply" : "Service Type Reply");
	case V2_SAADVERT:	return s? "SAAdvert" : "SA advertisement";
	}
	sprintf(buf, "(func %d)", t);
	return (s ? buf : "unknown function");
}

static char *slpv2_error(unsigned short code) {
	static char buf[128];

	switch (code) {
	case OK:			return "ok";
	case LANG_NOT_SUPPORTED:	return "language not supported";
	case PROTOCOL_PARSE_ERR:	return "protocol parse error";
	case INVALID_REGISTRATION:	return "invalid registration";
	case SCOPE_NOT_SUPPORTED:	return "scope not supported";
	case AUTHENTICATION_UNKNOWN:	return "authentication unknown";
	case V2_AUTHENTICATION_ABSENT:	return "authentication absent";
	case V2_AUTHENTICATION_FAILED:	return "authentication failed";
	case V2_VER_NOT_SUPPORTED:	return "version not supported";
	case V2_INTERNAL_ERROR:		return "internal error";
	case V2_DA_BUSY_NOW:		return "DA busy";
	case V2_OPTION_NOT_UNDERSTOOD:	return "option not understood";
	case V2_INVALID_UPDATE:		return "invalid update";
	case V2_RQST_NOT_SUPPORTED:	return "request not supported";
	case INVALID_LIFETIME:		return "invalid lifetime";
	}
	sprintf(buf, "error %d", code);
	return (buf);
}

static char *convert_ts(unsigned int timestamp) {
	/* timestamp is in UNIX time */
	static char buff[128];

	strcpy(buff, ctime((time_t *)&timestamp));
	buff[strlen(buff) - 1] = '\0';
	return (buff);
}

static int slpv2_authblock(int cnt) {
	unsigned short bsd, length, slen;
	char *pp, *scopes;
	unsigned int timestamp;

	if (msglength < 10) {
	    sprintf(get_line(0, 0),
		"  [no room for auth block header: remaining msg length = %u]",
		    msglength);
	    return (-1);
	}

	/* bsd */
	nbtohs();
	bsd = netval;
	p += sizeof (unsigned short);

	/* length */
	nbtohs();
	length = netval;
	p += sizeof (unsigned short);

	/* timestamp */
	nbtohl();
	timestamp = netval;
	p += 4;

	/* SPI String length */
	nbtohs();
	slen = netval;
	p += sizeof (unsigned short);

	msglength -= 10;
	if (slen > msglength) {
	    sprintf(get_line(0, 0),
		"  [no room for auth block scopes: remaining msg length = %u]",
		    msglength);
	    return (-1);
	}

	if (length > (msglength + 10)) {
	    if (!tcp_continuation)
		/* framing error: message is not long enough to contain data */
		sprintf(get_line(0, 0),
			"  [Framing error: remaining pkt length = %u]",
			msglength);
	    return (-1);
	}

	scopes = p;
	p += slen;
	msglength -= slen;

	sprintf(get_line(0, 0),
	    "Auth block %d: timestamp = %s", cnt,
	    (timestamp) ? convert_ts(timestamp) : "0");

	pp = get_line(0, 0);
	strcpy(pp, "              SPI = ");
	strncat(pp, scopes, slen);

	sprintf(get_line(0, 0),
	    "              block desc = 0x%04x: %s", bsd, display_bsd(bsd));

	sprintf(get_line(0, 0), "              length = %u", length);

	p += (length - 10 - slen);
	msglength -= (length - 10 - slen);
	return (0);
}

static int v2_srv_rqst(int flags) {
	if (flags & F_SUM) {
		SKIPFIELD(FIELD_DEFAULT);	/* PR list */
		GETFIELD;			/* service type */
		SKIPFIELD(FIELD_DEFAULT);	/* scopes */
		strcat(msgend, " [");
		GETFIELD;			/* predicate */
		strcat(msgend, "]");
		SKIPFIELD(FIELD_DEFAULT);	/* SPI */
	} else if (flags & F_DTAIL) {
		DOFIELD("Previous responders", FIELD_DEFAULT);
		DOFIELD("Service type",  FIELD_DEFAULT);
		DOFIELD("Scopes",  FIELD_DEFAULT);
		DOFIELD("Predicate string",  FIELD_DEFAULT);
		DOFIELD("Requested SPI", FIELD_DEFAULT);
	}

	return (1);
}

static int v2_srv_rply(int flags) {
	unsigned short itemcnt, errcode;
	int n;

	if (flags & F_SUM) {
	    int i, auth_cnt;

	    GETSHORT(errcode);
	    if (errcode != OK) {
		strcat(msgbuf, slpv2_error(errcode));
		msglength = 0;	/* skip rest of message */
		return (0);
	    } else {
		GETSHORT(itemcnt);
		sprintf(msgend, "%d URL entries", itemcnt);
#ifdef VERIFYSLP
		for (n = 0; n < itemcnt; n++) {
		    SKIPBYTE;			/* reserved */
		    SKIPSHORT;			/* lifetime */
		    SKIPFIELD(FIELD_DEFAULT);	/* URL */
		    GETBYTE(auth_cnt);
		    for (i = 0; i < auth_cnt; auth_cnt++)
			if (skip_v2authblock() < 0)
			    return (0);
		}
#endif
	    }
	} else if (flags & F_DTAIL) {
	    V2_DOERRCODE;
	    GETSHORT(itemcnt);
	    sprintf(get_line(0, 0), "URL entry count = %d", itemcnt);
	    for (n = 0; n < itemcnt; n++) {
		V2_DOURL(n);
	    }
	}

	return (1);
}

static int v2_srv_reg(int flags) {
	int i, auth_cnt;

	if (flags & F_SUM) {
	    SKIPBYTE;			/* reserved */
	    SKIPSHORT;			/* lifetime */
	    GETFIELD;			/* URL */
#ifdef VERIFYSLP
	    GETBYTE(auth_cnt);
	    for (i = 0; i < auth_cnt; i++)
		if (skip_v2authblock() < 0)
		    return (0);
	    SKIPFIELD(FIELD_DEFAULT);	/* type */
	    SKIPFIELD(FIELD_DEFAULT);	/* scopes */
	    SKIPFIELD(FIELD_DEFAULT);	/* attrs */
	    GETBYTE(auth_cnt);
	    for (i = 0; i < auth_cnt; i++)
		if (skip_v2authblock() < 0)
		    return (0);
#endif
	} if (flags & F_DTAIL) {
	    V2_DOURL(-1);
	    DOFIELD("Service type", FIELD_DEFAULT);
	    DOFIELD("Scopes", FIELD_DEFAULT);
	    DOFIELD("Attribute list", FIELD_DEFAULT);
	    /* auth */
	    GETBYTE(auth_cnt);
	    for (i = 0; i < auth_cnt; i++)
		V2_DOAUTH(i);
	}

	return (1);
}

static int v2_srv_dereg(int flags) {
	if (flags & F_SUM) {
	    int i, auth_cnt;

	    SKIPFIELD(FIELD_DEFAULT);	/* scopes */
	    SKIPBYTE;			/* reserved */
	    SKIPSHORT;			/* lifetime */
	    GETFIELD;			/* URL */

#ifdef VERIFYSLP
	    GETBYTE(auth_cnt);
	    for (i = 0; i < auth_cnt; i++)
		if (skip_v2authblock() < 0)
		    return (0);
	    SKIPFIELD(FIELD_DEFAULT);	/* attrs */
#endif
	} else if (flags & F_DTAIL) {
	    DOFIELD("Scopes", FIELD_DEFAULT);
	    V2_DOURL(-1);
	    DOFIELD("Tag list",  FIELD_DEFAULT);
	}

	return (1);
}

static int v2_srv_ack(int flags) {
	unsigned short errcode;
	if (flags & F_SUM) {
	    GETSHORT(errcode);
	    strcat(msgbuf, slpv2_error(errcode));
	} else if (flags & F_DTAIL) {
	    V2_DOERRCODE;
	}

	return (1);
}

static int v2_attr_rqst(int flags) {
	if (flags  & F_SUM) {
	    SKIPFIELD(FIELD_DEFAULT);	/* PR list */
	    GETFIELD;			/* URL */
	    SKIPFIELD(FIELD_DEFAULT);	/* scopes */
	    strcat(msgend, " [");
	    GETFIELD;			/* attrs */
	    strcat(msgend, "]");

#ifdef VERIFYSLP
	    SKIPFIELD(FIELD_DEFAULT);	/* SPI */
#endif
	} else if (flags & F_DTAIL) {
	    DOFIELD("Previous responders", FIELD_DEFAULT);
	    DOFIELD("URL",  FIELD_DEFAULT);
	    DOFIELD("Scopes",  FIELD_DEFAULT);
	    DOFIELD("Tag list",  FIELD_DEFAULT);
	    DOFIELD("Requested SPI", FIELD_DEFAULT);
	}

	return (1);
}

static int v2_attr_rply(int flags) {
	int auth_cnt, i;
	unsigned short errcode;

	if (flags & F_SUM) {
	    GETSHORT(errcode);
	    if (errcode != OK) {
		strcat(msgbuf, slpv2_error(errcode));
		msglength = 0;	/* skip rest of message */
		return (0);
	    } else {
		GETFIELD;			/* attr list */

#ifdef VERIFYSLP
		GETBYTE(auth_cnt);
		for (i = 0; i < auth_cnt; i++)
		    if (skip_v2authblock() < 0)
			return (0);
#endif
	    }
	} else if (flags & F_DTAIL) {
	    V2_DOERRCODE;
	    DOFIELD("Attribute list", FIELD_DEFAULT);
	    /* auth */
	    GETBYTE(auth_cnt);
	    for (i = 0; i < auth_cnt; i++)
		V2_DOAUTH(i);
	}

	return (1);
}

static int v2_daadvert(int flags) {
	int auth_cnt, i;
	unsigned short errcode;
	unsigned int timestamp;

	if (flags & F_SUM) {
	    SKIPSHORT;			/* error code */
	    SKIPSHORT; SKIPSHORT;	/* timestamp */
	    GETFIELD;			/* URL */

#ifdef VERIFYSLP
	    SKIPFIELD(FIELD_DEFAULT);	/* scopes */
	    SKIPFIELD(FIELD_DEFAULT);	/* attrs */
	    SKIPFIELD(FIELD_DEFAULT);	/* SPIs */

	    GETBYTE(auth_cnt);
	    for (i = 0; i < auth_cnt; i++)
		if (skip_v2authblock() < 0)
		    return (0);
#endif
	} else if (flags & F_DTAIL) {
	    V2_DOERRCODE;
	    V2_DOTIMESTAMP;
	    DOFIELD("URL", FIELD_DEFAULT);
	    DOFIELD("Scope list", FIELD_DEFAULT);
	    DOFIELD("Attribute list", FIELD_DEFAULT);
	    DOFIELD("Configured SPIs", FIELD_DEFAULT);
	    /* auth */
	    GETBYTE(auth_cnt);
	    for (i = 0; i < auth_cnt; i++)
		V2_DOAUTH(i);
	}

	return (1);
}

static int v2_srv_type_rqst(int flags) {
	if (flags & F_SUM) {
	    SKIPFIELD(FIELD_DEFAULT);	/* prev responders */
	    SKIPFIELD(FIELD_TYPENA);	/* naming authority */
	    GETFIELD;			/* scope */
	} else if (flags & F_DTAIL) {
	    DOFIELD("Previous responders", FIELD_DEFAULT);
	    DOFIELD("Naming authority", FIELD_TYPENA);
	    DOFIELD("Scopes",  FIELD_DEFAULT);
	}

	return (1);
}

static int v2_srv_type_rply(int flags) {
	unsigned short errcode;

	if (flags & F_SUM) {
	    GETSHORT(errcode);
	    if (errcode != OK)
		strcat(msgbuf, slpv2_error(errcode));
	    else
		GETFIELD;
	} else if (flags & F_DTAIL) {
		V2_DOERRCODE;
		DOFIELD("Service types", FIELD_DEFAULT);
	}

	return (1);
}

static int v2_saadvert(int flags) {
	int auth_cnt, i;

	if (flags & F_SUM) {
	    GETFIELD;			/* URL */

#ifdef VERIFYSLP
	    SKIPFIELD(FIELD_DEFAULT);	/* scopes */
	    SKIPFIELD(FIELD_DEFAULT);	/* attrs */

	    GETBYTE(auth_cnt);
	    for (i = 0; i < auth_cnt; i++)
		if (skip_v2authblock() < 0)
		    return (0);
#endif
	} else if (flags & F_DTAIL) {
	    DOFIELD("URL", FIELD_DEFAULT);
	    DOFIELD("Scopes",  FIELD_DEFAULT);
	    DOFIELD("Attribute list", FIELD_DEFAULT);
	    /* auth */
	    GETBYTE(auth_cnt);
	    for (i = 0; i < auth_cnt; i++)
		V2_DOAUTH(i);
	}

	return (1);
}

/*
 * V1 Interpreter
 */

static int interpret_slp_v1(int flags, struct slpv1_hdr *slp, int fraglen) {
	char msgbuf_real[256];
	extern int src_port, dst_port, curr_proto;
	boolean_t overflow	= B_FALSE;

	msgbuf = msgbuf_real;

	if (msglength >= sizeof (*slp)) {
	    if ((slp->flags & V1_URL_AUTH) == V1_URL_AUTH)
		url_auth = B_TRUE;
	    if ((slp->flags & V1_ATTR_AUTH) == V1_ATTR_AUTH)
		attr_auth = B_TRUE;
	    if ((slp->flags & V1_FRESH_REG) == V1_FRESH_REG)
		fresh = B_TRUE;
	    if ((slp->flags & V1_OVERFLOW) == V1_OVERFLOW)
		overflow = B_TRUE;
	}

	/*
	 * Somewhat of a hack to decode traffic from a server that does
	 * not send udp replies from its SLP src port.
	 */
	if (curr_proto == IPPROTO_UDP &&
	    dst_port == 427 &&
	    src_port != 427)
		add_transient(src_port, interpret_slp);

	/* parse the header */
	if (v1_header(flags, slp, fraglen)) {

	    if (slp->function <= V1_MAX_FUNCTION && slp->function > 0) {

		/* Parse the message body */
		(v1_functions[slp->function])(flags);

	    }

	}

	/* summary error check */
	if (flags & F_SUM) {
	    if (retlength < 0) {
		if (curr_proto == IPPROTO_TCP)
		    sprintf(get_sum_line(),
			    "%s [partial TCP message]",
			    msgbuf);
		else if (overflow)
		    sprintf(get_sum_line(), "%s [OVERFLOW]", msgbuf);
		else
		    sprintf(get_sum_line(), "%s [CORRUPTED MESSAGE]", msgbuf);
	    }
#ifdef VERIFYSLP
	    else if (msglength > 0)
		sprintf(get_sum_line(), "%s +%d", msgbuf, msglength);
#endif
	    else
		sprintf(get_sum_line(), "%s", msgbuf);
	} else if (flags & F_DTAIL) {
	    /* detail error check */
	    if (msglength > 0) {
		sprintf(get_line(0, 0),
			"[%d extra bytes at end of SLP message]", msglength);
	    }

	    show_trailer();

	}

	v1_charset = 0;

	return (0);
}

static int v1_header(int flags,
			struct slpv1_hdr *slp,
			int fraglen) {
	extern int src_port, dst_port, curr_proto;
	char *prototag = (curr_proto == IPPROTO_TCP? "/tcp" : "");

	if (flags & F_SUM) {
	    char portflag = ' ';

	    if (msglength < sizeof (*slp)) {
		sprintf(msgbuf, "SLP V1 [incomplete header]");
		return (0);
	    }

	    if (slp->vers != 1) {
		if (curr_proto == IPPROTO_TCP)
		    sprintf(msgbuf, "SLP [TCP Continuation]");
		else
		    sprintf(msgbuf, "SLP [unknown version %d]", slp->vers);
		return (0);
	    }

	    if (src_port != 427 && dst_port != 427)
		portflag = '-';

	    sprintf(msgbuf, "SLP V1%c%s [%d%s] ", portflag,
		    slpv1_func(slp->function, B_TRUE),
		    ntohs(slp->xid), prototag);
	    msgend = msgbuf + strlen(msgbuf);
	    msglength -= sizeof (*slp);
	    p += sizeof (*slp);
	} else if (flags & F_DTAIL) {
	    show_header("SLP:  ", "Service Location Protocol (v1)", fraglen);
	    show_space();

	    if (msglength < sizeof (*slp)) {
		sprintf(get_line(0, 0), "==> Incomplete SLP header");
		return (0);
	    }

	    sprintf(get_line(0, 0), "Version = %d", slp->vers);
	    if (slp->vers != 1) {
		if (curr_proto == IPPROTO_TCP)
		    sprintf(get_line(0, 0), "==> TCP continuation");
		else
		    sprintf(get_line(0, 0), "==> Unexpected version number");
		return (0);
	    }
	    sprintf(get_line(0, 0), "Function = %d, %s",
		slp->function, slpv1_func(slp->function, B_FALSE));
	    sprintf(get_line(0, 0), "Message length = %u", ntohs(slp->length));

	    /* flags */
	    sprintf(get_line(0, 0), "Flags = 0x%02x", slp->flags);
	    sprintf(get_line(0, 0), "      %s",
		    getflag(slp->flags, V1_OVERFLOW,
			    "overflow", "no overflow"));
	    sprintf(get_line(0, 0), "      %s",
		    getflag(slp->flags, V1_MONOLINGUAL,
			    "monolingual", "not monolingual"));
	    sprintf(get_line(0, 0), "      %s",
		    getflag(slp->flags, V1_URL_AUTH,
			    "url authentication", "no url authentication"));
	    sprintf(get_line(0, 0), "      %s",
		    getflag(slp->flags, V1_ATTR_AUTH,
		"attribute authentication", "no attribute authentication"));
	    sprintf(get_line(0, 0), "      %s",
		    getflag(slp->flags, V1_FRESH_REG,
			    "fresh registration", "no fresh registration"));
	    /* check reserved flags that must be zero */
	    if ((slp->flags & 7) != 0) {
		sprintf(get_line(0, 0),
			"      .... .xxx = %d (reserved flags nonzero)",
			slp->flags & 7);
	    }
	    /* end of flags */

	    sprintf(get_line(0, 0), "Dialect = %u", slp->dialect);
	    sprintf(get_line(0, 0), "Language = 0x%02x%02x, %c%c",
		    slp->language[0], slp->language[1],
		    slp->language[0], slp->language[1]);
	    v1_charset = ntohs(slp->charset);
	    sprintf(get_line(0, 0), "Character encoding = %u, %s",
		    v1_charset,
		    slpv1_charset(v1_charset));
	    sprintf(get_line(0, 0), "XID = %u", ntohs(slp->xid));

	    /* set msglength to remaining length of SLP message */
	    msglength -= sizeof (*slp);
	    p += sizeof (*slp);
	}

	return (1);
}

static char *slpv1_func(int t, boolean_t s) {
	static char buf[128];
	switch (t) {
	case V1_SRVREQ:	return s? "SrvRqst"  : "Service Request";
	case V1_SRVRPLY:	return s? "SrvRply"  : "Service Reply";
	case V1_SRVREG:	return s? "SrvReg"   : "Service Registration";
	case V1_SRVDEREG:	return s?
					"SrvDereg" : "Service Deregistration";
	case V1_SRVACK:	return s? "SrvAck"   : "Service Acknowledge";
	case V1_ATTRRQST:	return s? "AttrRqst" : "Attribute Request";
	case V1_ATTRRPLY:	return s? "AttrRply" : "Attribute Reply";
	case V1_DAADVERT:	return s? "DAAdvert" : "DA advertisement";
	case V1_SRVTYPERQST:return s? "SrvTypeRqst" : "Service Type Request";
	case V1_SRVTYPERPLY:return s? "SrvTypeRply" : "Service Type Reply";
	}
	sprintf(buf, "(func %d)", t);
	return (s ? buf : "unknown function");
}

static char *slpv1_error(unsigned short code) {
	static char buf[128];

	switch (code) {
	    case OK:			return "ok";
	    case LANG_NOT_SUPPORTED:	return "language not supported";
	    case PROTOCOL_PARSE_ERR:	return "protocol parse error";
	    case INVALID_REGISTRATION:	return "invalid registration";
	    case SCOPE_NOT_SUPPORTED:	return "scope not supported";
	    case CHARSET_NOT_UNDERSTOOD:return "character set not understood";
	    case AUTHENTICATION_INVALID:return "invalid authentication";
	    case NOT_SUPPORTED_YET:	return "not yet supported";
	    case REQUEST_TIMED_OUT:	return "request timed out";
	    case COULD_NOT_INIT_NET_RESOURCES:
				return ("could not initialize net resources");
	    case COULD_NOT_ALLOCATE_MEMORY:
					return ("could not allocate memory");
	    case PARAMETER_BAD:		return "bad parameter";
	    case INTERNAL_NET_ERROR:	return "internal network error";
	    case INTERNAL_SYSTEM_ERROR:	return "internal system error";
	}
	sprintf(buf, "error %d", code);
	return (buf);
}

/*
 *  Character set info from
 *    www.isi.edu/in-notes/iana/assignments/character-sets
 *
 *	Assigned MIB enum Numbers
 *	-------------------------
 *	0               Reserved
 *	1               Reserved
 *	3-106           Set By Standards Organizations
 *	1000-1010       Unicode / 10646
 *	2000-2087       Vendor
 *	2250-2258       Vendor
 *
 *	MIBenum: 3
 *	Alias: US-ASCII (preferred MIME name)
 *	Source: ECMA registry [RFC1345]
 *
 *	MIBenum: 106
 *	Name: UTF-8
 *	Source: RFC 2044
 */

static char *slpv1_charset(unsigned short code) {
	if (code <= 1)
	    return ("Reserved");
	if (code == 3)
	    return ("US-ASCII");
	if (code == 4)
	    return ("latin1");
	if (code == 106)
	    return ("UTF-8");
	if (code >= 3 && code <= 106)
	    return ("set by standards organization");
	if (code >= 1000 && code <= 1010)
	    return ("Unicode variant");
	if ((code >= 2000 && code <= 2087) ||
	    (code >= 2250 && code <= 2258))
	    return ("Vendor assigned");

	return ("unknown");
}

#ifdef VERIFYSLP
static int skip_v1authblock() {
	unsigned short length;

	/* auth header: 12 bytes total */
	if (msglength < 12)
	    return (-1);

	/* timestamp: 8 bytes */
	p += 8;			/* timestamp: 8 bytes */
	p += sizeof (short);		/* block descriptor: 2 bytes */
	nbtohs();
	length = netval;
	p += sizeof (short);
	msglength -= 12;

	if (length > msglength) {
	    /* framing error: message is not long enough to contain data */
	    return (-1);
	}

	p += length;
	msglength -= length;
	return (0);
}
#endif

static int slpv1_authblock() {
	unsigned short bsd, length;
	char msgbuf[128];
	int n;

	if (msglength < 12) {
	    sprintf(get_line(0, 0),
		    "  [no room for auth block: remaining msg length = %u]",
		    msglength);
	    return (-1);
	}

	/* timestamp: 8 bytes */
	*msgbuf = '\0';
	for (n = 0; n < 8; n++, p += 1) {
	    char tmp[16];
	    sprintf(tmp, "%02x", (unsigned char)(*p));
	    strcat(msgbuf, tmp);
	}

	nbtohs();
	bsd = netval;
	p += sizeof (short);
	nbtohs();
	length = netval;
	p += sizeof (short);
	msglength -= 12;

	sprintf(get_line(0, 0),
		"  Auth block: timestamp = %s",
		msgbuf);
	sprintf(get_line(0, 0),
		"              block desc = 0x%04x, length = %u",
		bsd, length);
	if (length > msglength) {
	    /* framing error: message is not long enough to contain data */
	    sprintf(get_line(0, 0),
		"  [Framing error: remaining pkt length = %u]",  msglength);
	    return (-1);
	}

	p += length;
	msglength -= length;
	return (0);
}

static int slpv1_url(boolean_t auth_present) {
	time_t exp;
	int lifetime, length;

	get_short();
	if ((lifetime = netval) < 0)
	    return (-1);
	get_short();
	if ((length = netval) < 0)
	    return (-1);

	exp = time(0) + lifetime;
	sprintf(get_line(0, 0), "URL: length = %u, lifetime = %d (%24.24s)",
		length, lifetime, ctime(&exp));
	if (length > msglength) {
	    /* framing error: message is not long enough to contain data */
	    sprintf(get_line(0, 0),
		"  [Framing error: remaining pkt length = %u]",  msglength);
	    return (-1);
	}

	if (length > 0) {
	    char *buf = malloc(length + 1);
	    if (buf != NULL) {
		if (!make_utf8(buf, length, p, length)) {
			strcpy(buf, "[Invalid Character Encoding]");
		}
		sprintf(get_line(0, 0), "  \"%s\"", buf);
		free(buf);
	    }
	}
	msglength -= length;
	p += length;

	if (auth_present)
	    return (slpv1_authblock());

	return (0);
}

static int v1_srv_rqst(int flags) {
	if (flags & F_SUM) {
	    SKIPFIELD(FIELD_PREVRESP);	/* prev responders */
	    GETFIELD;			/* predicate */
	} else if (flags & F_DTAIL) {
	    DOFIELD("Previous responders", FIELD_PREVRESP);
	    DOFIELD("predicate string", FIELD_DEFAULT);
	}

	return (1);
}

static int v1_srv_rply(int flags) {
	unsigned short errcode, itemcnt;
	int n;

	if (flags & F_SUM) {
	    GETSHORT(errcode);
	    if (errcode != OK) {
		strcat(msgbuf, slpv1_error(errcode));
	    } else {
		GETSHORT(itemcnt);
		sprintf(msgend, "%d URL entries", itemcnt);
#ifdef VERIFYSLP
		for (n = 0; n < itemcnt; n++) {
		    SKIPSHORT;		/* lifetime */
		    SKIPFIELD(FIELD_DEFAULT);	/* URL */
		    SKIPAUTH(url_auth);		/* URL auth */
		}
#endif
	    }
	} else if (flags & F_DTAIL) {
	    DOERRCODE;
	    GETSHORT(itemcnt);
	    sprintf(get_line(0, 0), "URL entry count = %d", itemcnt);
	    for (n = 0; n < itemcnt; n++) {
		DOURL;
	    }
	}

	return (1);
}

static int v1_srv_reg(int flags) {
	if (flags & F_SUM) {
	    SKIPSHORT;			/* lifetime */
	    GETFIELD;			/* URL */
#ifdef VERIFYSLP
	    SKIPAUTH(url_auth);		/* URL auth */
	    SKIPFIELD(FIELD_DEFAULT);	/* attribute list */
	    SKIPAUTH(attr_auth);		/* attr auth */
#endif
	} else if (flags & F_DTAIL) {
	    DOURL;
	    DOFIELD("Attribute list", FIELD_DEFAULT);
	    DOAUTH(attr_auth);
	}

	return (1);
}

static int v1_srv_ack(int flags) {
	unsigned short errcode;

	if (flags & F_SUM) {
	    GETSHORT(errcode);
	    strcat(msgbuf, slpv1_error(errcode));
	    if (errcode == OK && fresh) {
		strcat(msgbuf, " [Fresh]");
	    }
	} else if (flags & F_DTAIL) {
	    DOERRCODE;
	}

	return (1);
}

static int v1_srv_dereg(int flags) {
	if (flags & F_SUM) {
	    GETFIELD;			/* URL */
#ifdef VERIFYSLP
	    SKIPAUTH(url_auth);
	    SKIPFIELD(FIELD_DEFAULT);	/* tag spec */
#endif
	} else if (flags & F_DTAIL) {
	    DOFIELD("URL", FIELD_DEFAULT);
	    DOAUTH(url_auth);
	    DOFIELD("Tag spec", FIELD_DEFAULT);
	}

	return (1);
}

static int v1_attr_rqst(int flags) {
	if (flags & F_SUM) {
	    SKIPFIELD(FIELD_PREVRESP);	/* prev responders */
	    GETFIELD;			/* URL */
#ifdef VERIFYSLP
	    SKIPFIELD(FIELD_DEFAULT);	/* scope */
	    SKIPFIELD(FIELD_DEFAULT);	/* select list */
#endif
	} else if (flags & F_DTAIL) {
	    DOFIELD("Previous responders", FIELD_PREVRESP);
	    DOFIELD("URL", FIELD_DEFAULT);
	    DOFIELD("Scope", FIELD_DEFAULT);
	    DOFIELD("Select list", FIELD_DEFAULT);
	}

	return (1);
}

static int v1_attr_rply(int flags) {
	unsigned short errcode;

	if (flags & F_SUM) {
	    GETSHORT(errcode);
	    if (errcode != OK) {
		strcat(msgbuf, slpv1_error(errcode));
	    } else {
		GETFIELD;			/* attr list */
#ifdef VERIFYSLP
		SKIPAUTH(attr_auth);
#endif
	    }
	} else if (flags & F_DTAIL) {
	    DOERRCODE;
	    DOFIELD("Attribute list", FIELD_DEFAULT);
	    DOAUTH(attr_auth);
	}

	return (1);
}

static int v1_daadvert(int flags) {
	unsigned short errcode;

	if (flags & F_SUM) {
	    GETSHORT(errcode);
	    if (errcode != OK) {
		strcat(msgbuf, slpv1_error(errcode));
	    } else {
		    GETFIELD;			/* URL */
#ifdef VERIFYSLP
		    SKIPFIELD(FIELD_DEFAULT);	/* scope list */
#endif
	    }
	} else if (flags & F_DTAIL) {
	    DOERRCODE;
	    DOFIELD("URL", FIELD_DEFAULT);
	    DOFIELD("Scope list", FIELD_DEFAULT);
	}

	return (1);
}

static int v1_srv_type_rqst(int flags) {
	if (flags & F_SUM) {
	    SKIPFIELD(FIELD_PREVRESP);	/* prev responders */
	    SKIPFIELD(FIELD_TYPENA);	/* naming authority */
	    GETFIELD;			/* scope */
	} else if (flags & F_DTAIL) {
	    DOFIELD("Previous responders", FIELD_PREVRESP);
	    DOFIELD("Naming authority", FIELD_TYPENA);
	    DOFIELD("Scope string", FIELD_DEFAULT);
	}

	return (1);
}

static int v1_srv_type_rply(int flags) {
	unsigned short errcode, itemcnt;
	int n;

	if (flags & F_SUM) {
	    GETSHORT(errcode);
	    if (errcode != OK) {
		strcat(msgbuf, slpv1_error(errcode));
	    } else {
		GETSHORT(itemcnt);
		sprintf(msgend, "%d type entries", itemcnt);
#ifdef VERIFYSLP
		for (n = 0; n < itemcnt; n++) {
		    SKIPFIELD(FIELD_DEFAULT);  /* Service type item */
		}
#endif
	    }
	} else if (flags & F_DTAIL) {
	    DOERRCODE;
	    GETSHORT(itemcnt);
	    sprintf(get_line(0, 0), "Service type count = %d", itemcnt);
	    for (n = 0; n < itemcnt; n++) {
		DOFIELD("  Service type item", FIELD_DEFAULT);
	    }
	}

	return (1);
}