17c478bdstevel@tonic-gate/*
27c478bdstevel@tonic-gate * CDDL HEADER START
37c478bdstevel@tonic-gate *
47c478bdstevel@tonic-gate * The contents of this file are subject to the terms of the
57c478bdstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only
67c478bdstevel@tonic-gate * (the "License").  You may not use this file except in compliance
77c478bdstevel@tonic-gate * with the License.
87c478bdstevel@tonic-gate *
97c478bdstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
107c478bdstevel@tonic-gate * or http://www.opensolaris.org/os/licensing.
117c478bdstevel@tonic-gate * See the License for the specific language governing permissions
127c478bdstevel@tonic-gate * and limitations under the License.
137c478bdstevel@tonic-gate *
147c478bdstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each
157c478bdstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
167c478bdstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the
177c478bdstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying
187c478bdstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner]
197c478bdstevel@tonic-gate *
207c478bdstevel@tonic-gate * CDDL HEADER END
217c478bdstevel@tonic-gate */
227c478bdstevel@tonic-gate/*
237c478bdstevel@tonic-gate * Copyright (c) 1998,2000 by Sun Microsystems, Inc.
247c478bdstevel@tonic-gate * All rights reserved.
257c478bdstevel@tonic-gate */
267c478bdstevel@tonic-gate
277c478bdstevel@tonic-gate#include <stdio.h>
287c478bdstevel@tonic-gate#include <arpa/inet.h>
297c478bdstevel@tonic-gate#include <stdlib.h>
307c478bdstevel@tonic-gate#include <string.h>
317c478bdstevel@tonic-gate#include <sys/time.h>
327c478bdstevel@tonic-gate#include <iconv.h>
337c478bdstevel@tonic-gate#include "snoop.h"
347c478bdstevel@tonic-gate#include "slp.h"
357c478bdstevel@tonic-gate
367c478bdstevel@tonic-gate#define	MAXSUMLEN 30
377c478bdstevel@tonic-gate
387c478bdstevel@tonic-gate/* define VERIFYSLP to enable full message checking in summary mode */
397c478bdstevel@tonic-gate#define	VERIFYSLP
407c478bdstevel@tonic-gate
417c478bdstevel@tonic-gate/* Globals -- ugly, yes, but fast and easy in macros */
427c478bdstevel@tonic-gatestatic int msglength;
437c478bdstevel@tonic-gatestatic int retlength;
447c478bdstevel@tonic-gatestatic char *msgend;	/* the end of the summary message buffer */
457c478bdstevel@tonic-gatestatic char *p;		/* current position in the packet */
467c478bdstevel@tonic-gatestatic char *msgbuf;	/* message buffer for summary mode */
477c478bdstevel@tonic-gatestatic boolean_t url_auth	= B_FALSE;
487c478bdstevel@tonic-gatestatic boolean_t attr_auth	= B_FALSE;
497c478bdstevel@tonic-gatestatic boolean_t fresh		= B_FALSE;
507c478bdstevel@tonic-gatestatic boolean_t overflow	= B_FALSE;
517c478bdstevel@tonic-gatestatic int v1_charset		= 0;	/* character set; only in V1 */
527c478bdstevel@tonic-gate
537c478bdstevel@tonic-gate/* Entry points for parsing the protocol */
547c478bdstevel@tonic-gatestatic int interpret_slp_v1(int, struct slpv1_hdr *, int);
557c478bdstevel@tonic-gatestatic int interpret_slp_v2(int, struct slpv2_hdr *, int);
567c478bdstevel@tonic-gate
577c478bdstevel@tonic-gate/* header parsing */
587c478bdstevel@tonic-gatestatic int v1_header(int, struct slpv1_hdr *, int);
597c478bdstevel@tonic-gatestatic int v2_header(int, struct slpv2_hdr *, int *, int);
607c478bdstevel@tonic-gatestatic int v2_finish(struct slpv2_hdr *, int);
617c478bdstevel@tonic-gate
627c478bdstevel@tonic-gate/* V2 auth blocks */
637c478bdstevel@tonic-gatestatic int slpv2_authblock(int);
647c478bdstevel@tonic-gate
657c478bdstevel@tonic-gate/*
667c478bdstevel@tonic-gate * Functions for parsing each protocol message
677c478bdstevel@tonic-gate * Each function takes the interpreter's flags argument as its input
687c478bdstevel@tonic-gate * parameter, and returns 1 on success, or 0 on message corruption.
697c478bdstevel@tonic-gate * retlength is set as a side-effect in summary mode.
707c478bdstevel@tonic-gate */
717c478bdstevel@tonic-gatestatic int v2_srv_rqst(int);
727c478bdstevel@tonic-gatestatic int v2_srv_rply(int);
737c478bdstevel@tonic-gatestatic int v2_srv_reg(int);
747c478bdstevel@tonic-gatestatic int v2_srv_dereg(int);
757c478bdstevel@tonic-gatestatic int v2_srv_ack(int);
767c478bdstevel@tonic-gatestatic int v2_attr_rqst(int);
777c478bdstevel@tonic-gatestatic int v2_attr_rply(int);
787c478bdstevel@tonic-gatestatic int v2_daadvert(int);
797c478bdstevel@tonic-gatestatic int v2_srv_type_rqst(int);
807c478bdstevel@tonic-gatestatic int v2_srv_type_rply(int);
817c478bdstevel@tonic-gatestatic int v2_saadvert(int);
827c478bdstevel@tonic-gate
837c478bdstevel@tonic-gatestatic int v1_srv_rqst(int);
847c478bdstevel@tonic-gatestatic int v1_srv_rply(int);
857c478bdstevel@tonic-gatestatic int v1_srv_reg(int);
867c478bdstevel@tonic-gatestatic int v1_srv_dereg(int);
877c478bdstevel@tonic-gatestatic int v1_srv_ack(int);
887c478bdstevel@tonic-gatestatic int v1_attr_rqst(int);
897c478bdstevel@tonic-gatestatic int v1_attr_rply(int);
907c478bdstevel@tonic-gatestatic int v1_daadvert(int);
917c478bdstevel@tonic-gatestatic int v1_srv_type_rqst(int);
927c478bdstevel@tonic-gatestatic int v1_srv_type_rply(int);
937c478bdstevel@tonic-gate
947c478bdstevel@tonic-gate/*
957c478bdstevel@tonic-gate * The dispatch tables for handling individual messages, keyed by
967c478bdstevel@tonic-gate * function number.
977c478bdstevel@tonic-gate */
987c478bdstevel@tonic-gatetypedef int function_handler();
997c478bdstevel@tonic-gate
1007c478bdstevel@tonic-gate#define	V2_MAX_FUNCTION	11
1017c478bdstevel@tonic-gate
1027c478bdstevel@tonic-gatestatic function_handler *v2_functions[V2_MAX_FUNCTION + 1] = {
1037c478bdstevel@tonic-gate	(function_handler *) NULL,
1047c478bdstevel@tonic-gate	(function_handler *) v2_srv_rqst,
1057c478bdstevel@tonic-gate	(function_handler *) v2_srv_rply,
1067c478bdstevel@tonic-gate	(function_handler *) v2_srv_reg,
1077c478bdstevel@tonic-gate	(function_handler *) v2_srv_dereg,
1087c478bdstevel@tonic-gate	(function_handler *) v2_srv_ack,
1097c478bdstevel@tonic-gate	(function_handler *) v2_attr_rqst,
1107c478bdstevel@tonic-gate	(function_handler *) v2_attr_rply,
1117c478bdstevel@tonic-gate	(function_handler *) v2_daadvert,
1127c478bdstevel@tonic-gate	(function_handler *) v2_srv_type_rqst,
1137c478bdstevel@tonic-gate	(function_handler *) v2_srv_type_rply,
1147c478bdstevel@tonic-gate	(function_handler *) v2_saadvert };
1157c478bdstevel@tonic-gate
1167c478bdstevel@tonic-gate#define	V1_MAX_FUNCTION	10
1177c478bdstevel@tonic-gate
1187c478bdstevel@tonic-gatestatic function_handler *v1_functions[V1_MAX_FUNCTION + 1] = {
1197c478bdstevel@tonic-gate	(function_handler *) NULL,
1207c478bdstevel@tonic-gate	(function_handler *) v1_srv_rqst,
1217c478bdstevel@tonic-gate	(function_handler *) v1_srv_rply,
1227c478bdstevel@tonic-gate	(function_handler *) v1_srv_reg,
1237c478bdstevel@tonic-gate	(function_handler *) v1_srv_dereg,
1247c478bdstevel@tonic-gate	(function_handler *) v1_srv_ack,
1257c478bdstevel@tonic-gate	(function_handler *) v1_attr_rqst,
1267c478bdstevel@tonic-gate	(function_handler *) v1_attr_rply,
1277c478bdstevel@tonic-gate	(function_handler *) v1_daadvert,
1287c478bdstevel@tonic-gate	(function_handler *) v1_srv_type_rqst,
1297c478bdstevel@tonic-gate	(function_handler *) v1_srv_type_rply };
1307c478bdstevel@tonic-gate
1317c478bdstevel@tonic-gate/* TCP continuation handling */
1327c478bdstevel@tonic-gatestatic boolean_t tcp_continuation = B_FALSE;
1337c478bdstevel@tonic-gate
1347c478bdstevel@tonic-gate#define	MAX_TCPCONT	16
1357c478bdstevel@tonic-gate
1367c478bdstevel@tonic-gatestatic struct tcp_cont {
1377c478bdstevel@tonic-gate	int dst_port;
1387c478bdstevel@tonic-gate	char *msg;
1397c478bdstevel@tonic-gate	int totallen;
1407c478bdstevel@tonic-gate	int curr_offset;
1417c478bdstevel@tonic-gate} *tcp_cont[MAX_TCPCONT];
1427c478bdstevel@tonic-gate
1437c478bdstevel@tonic-gatestatic int current_tcp_cont;
1447c478bdstevel@tonic-gate
1457c478bdstevel@tonic-gatestatic void reg_tcp_cont(char *, int, int, int);
1467c478bdstevel@tonic-gatestatic int add_tcp_cont(struct tcp_cont *, char *, int);
1477c478bdstevel@tonic-gatestatic struct tcp_cont *find_tcp_cont(int);
1487c478bdstevel@tonic-gatestatic void remove_tcp_cont(int);
1497c478bdstevel@tonic-gate
1507c478bdstevel@tonic-gate/* Conversions from numbers to strings */
1517c478bdstevel@tonic-gatestatic char *slpv2_func(int, boolean_t);
1527c478bdstevel@tonic-gatestatic char *slpv2_error(unsigned short);
1537c478bdstevel@tonic-gatestatic char *slpv1_func(int, boolean_t);
1547c478bdstevel@tonic-gatestatic char *slpv1_error(unsigned short);
1557c478bdstevel@tonic-gatestatic char *slpv1_charset(unsigned short);
1567c478bdstevel@tonic-gate
1577c478bdstevel@tonic-gate/*
1587c478bdstevel@tonic-gate * The only external entry point to the SLP interpreter. This function
1597c478bdstevel@tonic-gate * simply dispatches the packet based on the version.
1607c478bdstevel@tonic-gate */
161d6913e0Toomas Soomeint
162d6913e0Toomas Soomeinterpret_slp(int flags, void *slp, int fraglen)
163d6913e0Toomas Soome{
1647c478bdstevel@tonic-gate	extern int dst_port, curr_proto;
1657c478bdstevel@tonic-gate	struct tcp_cont *tce = NULL;
1665b8f338Toomas Soome	char *s;
1677c478bdstevel@tonic-gate
1687c478bdstevel@tonic-gate	msglength = fraglen;
1697c478bdstevel@tonic-gate	retlength = 0;
1707c478bdstevel@tonic-gate	p = slp;
1717c478bdstevel@tonic-gate
1727c478bdstevel@tonic-gate	/* check if this is a TCP continuation */
1737c478bdstevel@tonic-gate	if (flags & F_DTAIL && curr_proto == IPPROTO_TCP) {
174d6913e0Toomas Soome		tce = find_tcp_cont(dst_port);
175d6913e0Toomas Soome		if (tce) {
176d6913e0Toomas Soome			if (add_tcp_cont(tce, slp, fraglen)) {
177d6913e0Toomas Soome				slp = tce->msg;
178d6913e0Toomas Soome				fraglen = tce->curr_offset;
179d6913e0Toomas Soome				tcp_continuation = B_TRUE;
180d6913e0Toomas Soome			}
1817c478bdstevel@tonic-gate		}
1827c478bdstevel@tonic-gate	}
1835b8f338Toomas Soome	if (*(char *)slp == 2 || tce)
184d6913e0Toomas Soome		interpret_slp_v2(flags, slp, fraglen);
1857c478bdstevel@tonic-gate	else
186d6913e0Toomas Soome		interpret_slp_v1(flags, slp, fraglen);
1877c478bdstevel@tonic-gate
1887c478bdstevel@tonic-gate	tcp_continuation = B_FALSE;
189d6913e0Toomas Soome	return (0);
1907c478bdstevel@tonic-gate}
1917c478bdstevel@tonic-gate
1927c478bdstevel@tonic-gate/*
1937c478bdstevel@tonic-gate * Primitives. These are implemented as much as possible as macros for
1947c478bdstevel@tonic-gate * speed.
1957c478bdstevel@tonic-gate */
1967c478bdstevel@tonic-gate
1977c478bdstevel@tonic-gate#define	FIELD_DEFAULT	0
1987c478bdstevel@tonic-gate#define	FIELD_PREVRESP	1
1997c478bdstevel@tonic-gate#define	FIELD_TYPENA	2
2007c478bdstevel@tonic-gate
2017c478bdstevel@tonic-gatestatic long long netval = 0;	/* need signed 64 bit quantity */
2027c478bdstevel@tonic-gate
2037c478bdstevel@tonic-gate/* gets two bytes from p and leaves the result in netval */
2047c478bdstevel@tonic-gate#define	nbtohs() \
2057c478bdstevel@tonic-gate	netval = ((int)(p[0] & 0xff)) << 8; \
2067c478bdstevel@tonic-gate	netval += ((int)(p[1] & 0xff))
2077c478bdstevel@tonic-gate
2087c478bdstevel@tonic-gate/* gets four bytes from p and leaves the result in netval */
2097c478bdstevel@tonic-gate#define	nbtohl() \
2107c478bdstevel@tonic-gate	netval = ((int)(p[0] & 0xff)) << 24; \
2117c478bdstevel@tonic-gate	netval += ((int)(p[1] & 0xff)) << 16; \
2127c478bdstevel@tonic-gate	netval += ((int)(p[2] & 0xff)) << 8; \
2137c478bdstevel@tonic-gate	netval += ((int)(p[3] & 0xff))
2147c478bdstevel@tonic-gate
2157c478bdstevel@tonic-gate#define	get_byte() \
2167c478bdstevel@tonic-gate	if (msglength >= 1) { \
2177c478bdstevel@tonic-gate		netval = *p; \
2187c478bdstevel@tonic-gate		p++; \
2197c478bdstevel@tonic-gate		msglength--; \
2207c478bdstevel@tonic-gate	} else \
2217c478bdstevel@tonic-gate		netval = -1
2227c478bdstevel@tonic-gate
2237c478bdstevel@tonic-gate#define	GETBYTE(x) \
2247c478bdstevel@tonic-gate	get_byte(); \
2257c478bdstevel@tonic-gate	if ((retlength = netval) < 0) \
2267c478bdstevel@tonic-gate		return (0); \
2277c478bdstevel@tonic-gate	x = netval
2287c478bdstevel@tonic-gate
2297c478bdstevel@tonic-gate#define	SKIPBYTE \
2307c478bdstevel@tonic-gate	get_byte(); \
2317c478bdstevel@tonic-gate	if ((retlength = netval) < 0) \
2327c478bdstevel@tonic-gate		return (0); \
2337c478bdstevel@tonic-gate
2347c478bdstevel@tonic-gate/*
2357c478bdstevel@tonic-gate * gets two bytes from p, leaves the result in netval, and updates
2367c478bdstevel@tonic-gate * msglength and p.
2377c478bdstevel@tonic-gate */
2387c478bdstevel@tonic-gate#define	get_short() \
2397c478bdstevel@tonic-gate	if (msglength >= sizeof (unsigned short)) { \
2407c478bdstevel@tonic-gate		nbtohs(); \
2417c478bdstevel@tonic-gate		p += sizeof (unsigned short); \
2427c478bdstevel@tonic-gate		msglength -= sizeof (unsigned short); \
2437c478bdstevel@tonic-gate	} else \
2447c478bdstevel@tonic-gate		netval = -1
2457c478bdstevel@tonic-gate
2467c478bdstevel@tonic-gate#define	GETSHORT(x) \
2477c478bdstevel@tonic-gate	get_short(); \
2487c478bdstevel@tonic-gate	if ((retlength = netval) < 0) \
2497c478bdstevel@tonic-gate		return (0); \
2507c478bdstevel@tonic-gate	x = netval
2517c478bdstevel@tonic-gate
2527c478bdstevel@tonic-gate#define	SKIPSHORT \
2537c478bdstevel@tonic-gate	get_short(); \
2547c478bdstevel@tonic-gate	if ((retlength = netval) < 0) \
2557c478bdstevel@tonic-gate		return (0)
2567c478bdstevel@tonic-gate
2577c478bdstevel@tonic-gate#define	get_int24(pp) \
2587c478bdstevel@tonic-gate	netval = ((int)((pp)[0] & 0xff)) << 16; \
2597c478bdstevel@tonic-gate	netval += ((int)((pp)[1] & 0xff)) << 8; \
2607c478bdstevel@tonic-gate	netval += ((int)((pp)[2] & 0xff))
2617c478bdstevel@tonic-gate
2627c478bdstevel@tonic-gatestatic void slp_prevresp(char *p) {
2637c478bdstevel@tonic-gate	char *p2;
2647c478bdstevel@tonic-gate
2657c478bdstevel@tonic-gate	/* cycle through all entries */
2667c478bdstevel@tonic-gate	for (; p != NULL; p = p2) {
2677c478bdstevel@tonic-gate	    p2 = strchr(p, ',');
2687c478bdstevel@tonic-gate	    if (p2 != NULL)
2697c478bdstevel@tonic-gate		*p2++ = '\0';
2707c478bdstevel@tonic-gate
2717c478bdstevel@tonic-gate	    /* print entry at p */
2727c478bdstevel@tonic-gate	    sprintf(get_line(0, 0), "  \"%s\"", p);
2737c478bdstevel@tonic-gate	}
2747c478bdstevel@tonic-gate}
2757c478bdstevel@tonic-gate
2767c478bdstevel@tonic-gatestatic int skip_field(int type) {
2777c478bdstevel@tonic-gate	unsigned short stringlen;
2787c478bdstevel@tonic-gate
2797c478bdstevel@tonic-gate	get_short();
2807c478bdstevel@tonic-gate	if (netval < 0) {
2817c478bdstevel@tonic-gate	    return (-1);
2827c478bdstevel@tonic-gate	}
2837c478bdstevel@tonic-gate	stringlen = netval;
2847c478bdstevel@tonic-gate
2857c478bdstevel@tonic-gate	/* special case for NA field in SrvTypeRqst */
2867c478bdstevel@tonic-gate	if (type == FIELD_TYPENA && stringlen == 0xffff) {
2877c478bdstevel@tonic-gate	    stringlen = 0;
2887c478bdstevel@tonic-gate	}
2897c478bdstevel@tonic-gate
2907c478bdstevel@tonic-gate	if (stringlen > msglength) {
2917c478bdstevel@tonic-gate	    return (-1);
2927c478bdstevel@tonic-gate	}
2937c478bdstevel@tonic-gate
2947c478bdstevel@tonic-gate	msglength -= stringlen;
2957c478bdstevel@tonic-gate	p += stringlen;
2967c478bdstevel@tonic-gate
2977c478bdstevel@tonic-gate	return (stringlen);
2987c478bdstevel@tonic-gate}
2997c478bdstevel@tonic-gate
3007c478bdstevel@tonic-gate#define	SKIPFIELD(type) \
3017c478bdstevel@tonic-gate	if ((retlength = skip_field(type)) < 0) \
3027c478bdstevel@tonic-gate		return (0)
3037c478bdstevel@tonic-gate
3047c478bdstevel@tonic-gate#define	GETFIELD \
3057c478bdstevel@tonic-gate	get_short(); \
3067c478bdstevel@tonic-gate	if ((retlength = netval) < 0) \
3077c478bdstevel@tonic-gate		return (0); \
3087c478bdstevel@tonic-gate	strncat(msgbuf, p, (retlength > MAXSUMLEN ? MAXSUMLEN : retlength)); \
3097c478bdstevel@tonic-gate	p += retlength; \
3107c478bdstevel@tonic-gate	msglength -= retlength
3117c478bdstevel@tonic-gate
3127c478bdstevel@tonic-gate/*
3137c478bdstevel@tonic-gate * Determines from the first five bytes of a potential SLP header
3147c478bdstevel@tonic-gate * if the following message is really an SLP message. Returns 1 if
3157c478bdstevel@tonic-gate * it is a real SLP message, 0 if not.
3167c478bdstevel@tonic-gate */
3177c478bdstevel@tonic-gateint valid_slp(unsigned char *slphdr, int len) {
3187c478bdstevel@tonic-gate	struct slpv1_hdr slp1;
3197c478bdstevel@tonic-gate	struct slpv2_hdr slp2;
3207c478bdstevel@tonic-gate
3217c478bdstevel@tonic-gate	len -= (8 /* udp */ + 20 /* IP */ + 14 /* ether */);
3227c478bdstevel@tonic-gate	/* a valid version will be 1 or 2 */
3237c478bdstevel@tonic-gate	switch (*slphdr) {
3247c478bdstevel@tonic-gate	case 1:
3257c478bdstevel@tonic-gate	    memcpy(&slp1, slphdr, 5);
3267c478bdstevel@tonic-gate	    /* valid function? */
3277c478bdstevel@tonic-gate	    if (slp1.function > V1_MAX_FUNCTION) {
3287c478bdstevel@tonic-gate		return (0);
3297c478bdstevel@tonic-gate	    }
3307c478bdstevel@tonic-gate	    /* valid length heuristic */
3317c478bdstevel@tonic-gate	    if (slp1.length > len) {
3327c478bdstevel@tonic-gate		return (0);
3337c478bdstevel@tonic-gate	    }
3347c478bdstevel@tonic-gate	    return (1);
3357c478bdstevel@tonic-gate	case 2:
3367c478bdstevel@tonic-gate	    memcpy(&slp2, slphdr, 5);
3377c478bdstevel@tonic-gate	    /* valid function? */
3387c478bdstevel@tonic-gate	    if (slp2.function > V2_MAX_FUNCTION) {
3397c478bdstevel@tonic-gate		return (0);
3407c478bdstevel@tonic-gate	    }
3417c478bdstevel@tonic-gate	    /* valid length heuristic */
3427c478bdstevel@tonic-gate	    get_int24(&(slp2.l1));
3437c478bdstevel@tonic-gate	    if (netval > len) {
3447c478bdstevel@tonic-gate		return (0);
3457c478bdstevel@tonic-gate	    }
3467c478bdstevel@tonic-gate	    return (1);
3477c478bdstevel@tonic-gate	default:
3487c478bdstevel@tonic-gate	    return (0);
3497c478bdstevel@tonic-gate	}
3507c478bdstevel@tonic-gate}
3517c478bdstevel@tonic-gate
3527c478bdstevel@tonic-gate/*
3537c478bdstevel@tonic-gate * Converts a V1 char encoding to UTF8. If this fails, returns 0,
3547c478bdstevel@tonic-gate * otherwise, 1. This function is the union of iconv UTF-8
3557c478bdstevel@tonic-gate * modules and character sets registered with IANA.
3567c478bdstevel@tonic-gate */
3577c478bdstevel@tonic-gatestatic int make_utf8(char *outbuf, size_t outlen,
3587c478bdstevel@tonic-gate			const char *inbuf, size_t inlen) {
3597c478bdstevel@tonic-gate	iconv_t cd;
3607c478bdstevel@tonic-gate	size_t converted;
3617c478bdstevel@tonic-gate
3627c478bdstevel@tonic-gate	switch (v1_charset) {
3637c478bdstevel@tonic-gate	case 4:
3647c478bdstevel@tonic-gate	case 1004:
3657c478bdstevel@tonic-gate	    cd = iconv_open("UTF-8", "8859-1");
3667c478bdstevel@tonic-gate	    break;
3677c478bdstevel@tonic-gate	case 5:
3687c478bdstevel@tonic-gate	    cd = iconv_open("UTF-8", "8859-2");
3697c478bdstevel@tonic-gate	    break;
3707c478bdstevel@tonic-gate	case 6:
3717c478bdstevel@tonic-gate	    cd = iconv_open("UTF-8", "8859-3");
3727c478bdstevel@tonic-gate	    break;
3737c478bdstevel@tonic-gate	case 7:
3747c478bdstevel@tonic-gate	    cd = iconv_open("UTF-8", "8859-4");
3757c478bdstevel@tonic-gate	    break;
3767c478bdstevel@tonic-gate	case 8:
3777c478bdstevel@tonic-gate	    cd = iconv_open("UTF-8", "8859-5");
3787c478bdstevel@tonic-gate	    break;
3797c478bdstevel@tonic-gate	case 9:
3807c478bdstevel@tonic-gate	    cd = iconv_open("UTF-8", "8859-6");
3817c478bdstevel@tonic-gate	    break;
3827c478bdstevel@tonic-gate	case 10:
3837c478bdstevel@tonic-gate	    cd = iconv_open("UTF-8", "8859-7");
3847c478bdstevel@tonic-gate	    break;
3857c478bdstevel@tonic-gate	case 11:
3867c478bdstevel@tonic-gate	    cd = iconv_open("UTF-8", "8859-8");
3877c478bdstevel@tonic-gate	    break;
3887c478bdstevel@tonic-gate	case 12:
3897c478bdstevel@tonic-gate	    cd = iconv_open("UTF-8", "8859-9");
3907c478bdstevel@tonic-gate	    break;
3917c478bdstevel@tonic-gate	case 13:
3927c478bdstevel@tonic-gate	    cd = iconv_open("UTF-8", "8859-10");
3937c478bdstevel@tonic-gate	    break;
3947c478bdstevel@tonic-gate	case 37:
3957c478bdstevel@tonic-gate	    cd = iconv_open("UTF-8", "ko_KR-iso2022-7");
3967c478bdstevel@tonic-gate	    break;
3977c478bdstevel@tonic-gate	case 104:
3987c478bdstevel@tonic-gate	    cd = iconv_open("UTF-8", "iso2022");
3997c478bdstevel@tonic-gate	    break;
4007c478bdstevel@tonic-gate	case 1000:
4017c478bdstevel@tonic-gate	    cd = iconv_open("UTF-8", "UCS-2");
4027c478bdstevel@tonic-gate	    break;
4037c478bdstevel@tonic-gate	case 1001:
4047c478bdstevel@tonic-gate	    cd = iconv_open("UTF-8", "UCS-4");
4057c478bdstevel@tonic-gate	    break;
4067c478bdstevel@tonic-gate	default:
4077c478bdstevel@tonic-gate		/*
4087c478bdstevel@tonic-gate		 * charset not set, or reserved, or not supported, so
4097c478bdstevel@tonic-gate		 * just copy it and hope for the best.
4107c478bdstevel@tonic-gate		 */
4117c478bdstevel@tonic-gate	    converted = outlen < inlen ? outlen : inlen;
4127c478bdstevel@tonic-gate	    memcpy(outbuf, inbuf, converted);
4137c478bdstevel@tonic-gate	    outbuf[converted] = 0;
4147c478bdstevel@tonic-gate	    return (1);
4157c478bdstevel@tonic-gate	}
4167c478bdstevel@tonic-gate
4177c478bdstevel@tonic-gate	if (cd == (iconv_t)-1) {
4187c478bdstevel@tonic-gate	    return (0);
4197c478bdstevel@tonic-gate	}
4207c478bdstevel@tonic-gate
4217c478bdstevel@tonic-gate	if ((converted = iconv(cd, &inbuf, &inlen, &outbuf, &outlen))
4227c478bdstevel@tonic-gate	    == (size_t)-1) {
4237c478bdstevel@tonic-gate	    return (0);
4247c478bdstevel@tonic-gate	}
4257c478bdstevel@tonic-gate
4267c478bdstevel@tonic-gate	outbuf[converted] = 0;
4277c478bdstevel@tonic-gate	iconv_close(cd);
4287c478bdstevel@tonic-gate
4297c478bdstevel@tonic-gate	return (1);
4307c478bdstevel@tonic-gate}
4317c478bdstevel@tonic-gate
4327c478bdstevel@tonic-gatestatic int slp_field(char *tag, int type) {
4337c478bdstevel@tonic-gate	int length;
4347c478bdstevel@tonic-gate
4357c478bdstevel@tonic-gate	get_short();
4367c478bdstevel@tonic-gate	if (netval < 0) {
4377c478bdstevel@tonic-gate	    return (-1);
4387c478bdstevel@tonic-gate	}
4397c478bdstevel@tonic-gate	length = netval;
4407c478bdstevel@tonic-gate
4417c478bdstevel@tonic-gate	/* special case for NA field in SrvTypeRqst */
4427c478bdstevel@tonic-gate	if (type == FIELD_TYPENA && length == 0xffff) {
4437c478bdstevel@tonic-gate	    sprintf(get_line(0, 0), "%s: length = -1: Use all NAs", tag);
4447c478bdstevel@tonic-gate	    return (0);
4457c478bdstevel@tonic-gate	}
4467c478bdstevel@tonic-gate
4477c478bdstevel@tonic-gate	sprintf(get_line(0, 0), "%s: length = %d", tag, length);
4487c478bdstevel@tonic-gate	if (length > msglength) {
4497c478bdstevel@tonic-gate	    /* framing error: message is not long enough to contain data */
4507c478bdstevel@tonic-gate	    sprintf(get_line(0, 0),
4517c478bdstevel@tonic-gate		    "  [Framing error: remaining pkt length = %u]",
4527c478bdstevel@tonic-gate		    msglength);
4537c478bdstevel@tonic-gate	    return (-1);
4547c478bdstevel@tonic-gate	}
4557c478bdstevel@tonic-gate
4567c478bdstevel@tonic-gate	if (length > 0) {
4577c478bdstevel@tonic-gate	    char *buf = malloc(length + 1);
4587c478bdstevel@tonic-gate	    if (buf != NULL) {
4597c478bdstevel@tonic-gate		if (v1_charset) {
4607c478bdstevel@tonic-gate		    if (!make_utf8(buf, length, p, length)) {
4617c478bdstevel@tonic-gate			strcpy(buf, "[Invalid Character Encoding]");
4627c478bdstevel@tonic-gate		    }
4637c478bdstevel@tonic-gate		} else {
4647c478bdstevel@tonic-gate		    memcpy(buf, p, length);
4657c478bdstevel@tonic-gate		    buf[length] = '\0';		/* ensure null-terminated */
4667c478bdstevel@tonic-gate		}
4677c478bdstevel@tonic-gate
4687c478bdstevel@tonic-gate		switch (type) {
4697c478bdstevel@tonic-gate		    case FIELD_PREVRESP:
4707c478bdstevel@tonic-gate			slp_prevresp(buf);
4717c478bdstevel@tonic-gate			break;
4727c478bdstevel@tonic-gate
4737c478bdstevel@tonic-gate		    default:
4747c478bdstevel@tonic-gate			sprintf(get_line(0, 0), "  \"%s\"", buf);
4757c478bdstevel@tonic-gate			break;
4767c478bdstevel@tonic-gate		}
4777c478bdstevel@tonic-gate		free(buf);
4787c478bdstevel@tonic-gate	    }
4797c478bdstevel@tonic-gate
4807c478bdstevel@tonic-gate	    p += length;
4817c478bdstevel@tonic-gate	    msglength -= length;
4827c478bdstevel@tonic-gate	}
4837c478bdstevel@tonic-gate
4847c478bdstevel@tonic-gate	/* return ok */
4857c478bdstevel@tonic-gate	return (0);
4867c478bdstevel@tonic-gate}
4877c478bdstevel@tonic-gate
4887c478bdstevel@tonic-gatestatic int slpv2_url(int cnt) {
4897c478bdstevel@tonic-gate	time_t exp;
4907c478bdstevel@tonic-gate	int lifetime, length, n;
4917c478bdstevel@tonic-gate
4927c478bdstevel@tonic-gate	/* reserved */
4937c478bdstevel@tonic-gate	get_byte();
4947c478bdstevel@tonic-gate	if (netval < 0)
4957c478bdstevel@tonic-gate	    return (-1);
4967c478bdstevel@tonic-gate
4977c478bdstevel@tonic-gate	/* lifetime */
4987c478bdstevel@tonic-gate	get_short();
4997c478bdstevel@tonic-gate	if ((lifetime = netval) < 0)
5007c478bdstevel@tonic-gate	    return (-1);
5017c478bdstevel@tonic-gate
5027c478bdstevel@tonic-gate	/* length */
5037c478bdstevel@tonic-gate	get_short();
5047c478bdstevel@tonic-gate	if ((length = netval) < 0)
5057c478bdstevel@tonic-gate	    return (-1);
5067c478bdstevel@tonic-gate
5077c478bdstevel@tonic-gate	/* time */
5087c478bdstevel@tonic-gate	exp = time(0) + lifetime;
5097c478bdstevel@tonic-gate	if (cnt == -1)
5107c478bdstevel@tonic-gate	    sprintf(get_line(0, 0),
5117c478bdstevel@tonic-gate		    "URL: length = %u, lifetime = %d (%24.24s)",
5127c478bdstevel@tonic-gate		    length, lifetime, ctime(&exp));
5137c478bdstevel@tonic-gate	else
5147c478bdstevel@tonic-gate	    /* number the URLs to make it easier to parse them */
5157c478bdstevel@tonic-gate	    sprintf(get_line(0, 0),
5167c478bdstevel@tonic-gate		    "URL %d: length = %u, lifetime = %d (%24.24s)",
5177c478bdstevel@tonic-gate		    cnt, length, lifetime, ctime(&exp));
5187c478bdstevel@tonic-gate
5197c478bdstevel@tonic-gate	if (length > msglength) {
5207c478bdstevel@tonic-gate	    if (!tcp_continuation)
5217c478bdstevel@tonic-gate		/* framing error: message is not long enough to contain data */
5227c478bdstevel@tonic-gate		sprintf(get_line(0, 0),
5237c478bdstevel@tonic-gate			"  [Framing error: remaining pkt length = %u]",
5247c478bdstevel@tonic-gate			msglength);
5257c478bdstevel@tonic-gate	    return (-1);
5267c478bdstevel@tonic-gate	}
5277c478bdstevel@tonic-gate
5287c478bdstevel@tonic-gate	if (length > 0) {
5297c478bdstevel@tonic-gate	    char *buf = malloc(length + 1);
5307c478bdstevel@tonic-gate	    if (buf != NULL) {
5317c478bdstevel@tonic-gate		memcpy(buf, p, length);
5327c478bdstevel@tonic-gate		buf[length] = '\0';		/* ensure null-terminated */
5337c478bdstevel@tonic-gate		sprintf(get_line(0, 0), "  \"%s\"", buf);
5347c478bdstevel@tonic-gate		free(buf);
5357c478bdstevel@tonic-gate	    }
5367c478bdstevel@tonic-gate	}
5377c478bdstevel@tonic-gate	msglength -= length;
5387c478bdstevel@tonic-gate	p += length;
5397c478bdstevel@tonic-gate
5407c478bdstevel@tonic-gate	get_byte();
5417c478bdstevel@tonic-gate	if ((n = netval) < 0)
5427c478bdstevel@tonic-gate	    return (-1);
5437c478bdstevel@tonic-gate
5447c478bdstevel@tonic-gate	if (n > 0) {
5457c478bdstevel@tonic-gate	    int i;
5467c478bdstevel@tonic-gate	    sprintf(get_line(0, 0), "%d Authentication Blocks", n);
5477c478bdstevel@tonic-gate	    for (i = 0; i < n; i++)
5487c478bdstevel@tonic-gate		if ((length = slpv2_authblock(i)) < 0)
5497c478bdstevel@tonic-gate		    return (-1);
5507c478bdstevel@tonic-gate	}
5517c478bdstevel@tonic-gate	return (0);
5527c478bdstevel@tonic-gate}
5537c478bdstevel@tonic-gate
5547c478bdstevel@tonic-gate#define	DOFIELD(tag, type) \
5557c478bdstevel@tonic-gate	if (slp_field(tag, type) < 0) \
5567c478bdstevel@tonic-gate		return (0)
5577c478bdstevel@tonic-gate
5587c478bdstevel@tonic-gate#define	V2_DOURL(x) \
5597c478bdstevel@tonic-gate	if (slpv2_url(x) < 0) \
5607c478bdstevel@tonic-gate		return (0)
5617c478bdstevel@tonic-gate
5627c478bdstevel@tonic-gate#define	V2_DOERRCODE \
5637c478bdstevel@tonic-gate	if (msglength < sizeof (unsigned short)) \
5647c478bdstevel@tonic-gate		return (0); \
5657c478bdstevel@tonic-gate	nbtohs(); \
5667c478bdstevel@tonic-gate	errcode = netval; \
5677c478bdstevel@tonic-gate	sprintf(get_line(0, 0), "Error code = %d, %s", \
5687c478bdstevel@tonic-gate				errcode, slpv2_error(errcode)); \
5697c478bdstevel@tonic-gate	p += sizeof (unsigned short); \
5707c478bdstevel@tonic-gate	msglength -= sizeof (unsigned short); \
5717c478bdstevel@tonic-gate	if (errcode != OK) \
5727c478bdstevel@tonic-gate		msglength = 0;	/* skip rest of message */ \
5737c478bdstevel@tonic-gate	if (errcode != OK) \
5747c478bdstevel@tonic-gate		return (0)
5757c478bdstevel@tonic-gate
5767c478bdstevel@tonic-gate#define	V2_DOAUTH(cnt) \
5777c478bdstevel@tonic-gate	if (slpv2_authblock(cnt) < 0) \
5787c478bdstevel@tonic-gate		return (0)
5797c478bdstevel@tonic-gate
5807c478bdstevel@tonic-gate#define	V2_DOTIMESTAMP \
5817c478bdstevel@tonic-gate	if (msglength < 4) \
5827c478bdstevel@tonic-gate		return (0); \
5837c478bdstevel@tonic-gate	nbtohl(); \
5847c478bdstevel@tonic-gate	timestamp = netval; \
5857c478bdstevel@tonic-gate	sprintf(get_line(0, 0), "Timestamp = %u, %s", \
5867c478bdstevel@tonic-gate		timestamp, (timestamp ? convert_ts(timestamp) : "0")); \
5877c478bdstevel@tonic-gate	p += 4; \
5887c478bdstevel@tonic-gate	msglength -= 4
5897c478bdstevel@tonic-gate
5907c478bdstevel@tonic-gate/* some V1 macros */
5917c478bdstevel@tonic-gate#define	SKIPAUTH(auth) \
5927c478bdstevel@tonic-gate	if (auth && ((retlength = skip_v1authblock()) < 0)) \
5937c478bdstevel@tonic-gate		return (0)
5947c478bdstevel@tonic-gate
5957c478bdstevel@tonic-gate#define	DOERRCODE \
5967c478bdstevel@tonic-gate	if (msglength < sizeof (unsigned short)) \
5977c478bdstevel@tonic-gate		return (0); \
5987c478bdstevel@tonic-gate	nbtohs(); \
5997c478bdstevel@tonic-gate	errcode = netval; \
6007c478bdstevel@tonic-gate	sprintf(get_line(0, 0), "Error code = %d, %s", errcode, \
6017c478bdstevel@tonic-gate				slpv1_error(errcode)); \
6027c478bdstevel@tonic-gate	p += sizeof (unsigned short); \
6037c478bdstevel@tonic-gate	msglength -= sizeof (unsigned short); \
6047c478bdstevel@tonic-gate	if (errcode != OK) \
6057c478bdstevel@tonic-gate		return (0)
6067c478bdstevel@tonic-gate
6077c478bdstevel@tonic-gate#define	DOURL \
6087c478bdstevel@tonic-gate	if (slpv1_url(url_auth) < 0) \
6097c478bdstevel@tonic-gate		return (0)
6107c478bdstevel@tonic-gate
6117c478bdstevel@tonic-gate#define	DOAUTH(auth) \
6127c478bdstevel@tonic-gate	if (auth && slpv1_authblock() < 0) \
6137c478bdstevel@tonic-gate		return (0)
6147c478bdstevel@tonic-gate
6157c478bdstevel@tonic-gate/*
6167c478bdstevel@tonic-gate * TCP Continuation handling
6177c478bdstevel@tonic-gate * We keep track of continuations in a fixed size cache, so as to prevent
6187c478bdstevel@tonic-gate * memory leaks if some continuations are never finished. The continuations
6197c478bdstevel@tonic-gate * are indexed by their destination ports.
6207c478bdstevel@tonic-gate */
6217c478bdstevel@tonic-gatestatic void reg_tcp_cont(char *msg, int totallen,
6227c478bdstevel@tonic-gate			    int fraglen, int dst_port) {
6237c478bdstevel@tonic-gate	struct tcp_cont *tce = malloc(sizeof (*tce));
6247c478bdstevel@tonic-gate
6257c478bdstevel@tonic-gate	/* always overwrite the entry at current_tcp_cont */
6267c478bdstevel@tonic-gate	if (tcp_cont[current_tcp_cont]) {
6277c478bdstevel@tonic-gate	    free(tcp_cont[current_tcp_cont]->msg);
6287c478bdstevel@tonic-gate	    free(tcp_cont[current_tcp_cont]);
6297c478bdstevel@tonic-gate	}
6307c478bdstevel@tonic-gate
6317c478bdstevel@tonic-gate	tce->dst_port = dst_port;
6327c478bdstevel@tonic-gate	tce->msg = malloc(totallen);
6337c478bdstevel@tonic-gate	memcpy(tce->msg, msg, fraglen);
6347c478bdstevel@tonic-gate	tce->totallen = totallen;
6357c478bdstevel@tonic-gate	tce->curr_offset = fraglen;
6367c478bdstevel@tonic-gate
6377c478bdstevel@tonic-gate	tcp_cont[current_tcp_cont++] = tce;
6387c478bdstevel@tonic-gate	if (current_tcp_cont == MAX_TCPCONT)
6397c478bdstevel@tonic-gate	    current_tcp_cont = 0;
6407c478bdstevel@tonic-gate}
6417c478bdstevel@tonic-gate
6427c478bdstevel@tonic-gate/* returns 0 if there is a mismatch error, 1 on success */
6437c478bdstevel@tonic-gatestatic int add_tcp_cont(struct tcp_cont *tce, char *msg, int fraglen) {
6447c478bdstevel@tonic-gate	if ((fraglen + tce->curr_offset) > tce->totallen)
6457c478bdstevel@tonic-gate	    return (0);
6467c478bdstevel@tonic-gate
6477c478bdstevel@tonic-gate	memcpy(tce->msg + tce->curr_offset, msg, fraglen);
6487c478bdstevel@tonic-gate	tce->curr_offset += fraglen;
6497c478bdstevel@tonic-gate	return (1);
6507c478bdstevel@tonic-gate}
6517c478bdstevel@tonic-gate
6527c478bdstevel@tonic-gatestatic struct tcp_cont *find_tcp_cont(int dst_port) {
6537c478bdstevel@tonic-gate	int i;
6547c478bdstevel@tonic-gate	for (i = current_tcp_cont; i >= 0; i--)
6557c478bdstevel@tonic-gate	    if (tcp_cont[i] && tcp_cont[i]->dst_port == dst_port)
6567c478bdstevel@tonic-gate		return (tcp_cont[i]);
6577c478bdstevel@tonic-gate
6587c478bdstevel@tonic-gate	for (i = MAX_TCPCONT -1; i > current_tcp_cont; i--)
6597c478bdstevel@tonic-gate	    if (tcp_cont[i] && tcp_cont[i]->dst_port == dst_port)
6607c478bdstevel@tonic-gate		return (tcp_cont[i]);
6617c478bdstevel@tonic-gate
6627c478bdstevel@tonic-gate	return (NULL);
6637c478bdstevel@tonic-gate}
6647c478bdstevel@tonic-gate
6657c478bdstevel@tonic-gatestatic void remove_tcp_cont(int dst_port) {
6667c478bdstevel@tonic-gate	int i;
6677c478bdstevel@tonic-gate	for (i = current_tcp_cont; i >= 0; i--)
6687c478bdstevel@tonic-gate	    if (tcp_cont[i] && tcp_cont[i]->dst_port == dst_port) {
6697c478bdstevel@tonic-gate		free(tcp_cont[i]->msg);
6707c478bdstevel@tonic-gate		free(tcp_cont[i]);
6717c478bdstevel@tonic-gate		tcp_cont[i] = NULL;
6727c478bdstevel@tonic-gate		return;
6737c478bdstevel@tonic-gate	    }
6747c478bdstevel@tonic-gate
6757c478bdstevel@tonic-gate	for (i = MAX_TCPCONT -1; i > current_tcp_cont; i--)
6767c478bdstevel@tonic-gate	    if (tcp_cont[i] && tcp_cont[i]->dst_port == dst_port) {
6777c478bdstevel@tonic-gate		free(tcp_cont[i]->msg);
6787c478bdstevel@tonic-gate		free(tcp_cont[i]);
6797c478bdstevel@tonic-gate		tcp_cont[i] = NULL;
6807c478bdstevel@tonic-gate		return;
6817c478bdstevel@tonic-gate	    }
6827c478bdstevel@tonic-gate}
6837c478bdstevel@tonic-gate
6847c478bdstevel@tonic-gate/*
6857c478bdstevel@tonic-gate * V2 interpreter
6867c478bdstevel@tonic-gate */
6877c478bdstevel@tonic-gate
6887c478bdstevel@tonic-gatestatic int interpret_slp_v2(int flags, struct slpv2_hdr *slp, int fraglen) {
6897c478bdstevel@tonic-gate	extern int src_port, dst_port, curr_proto;
6907c478bdstevel@tonic-gate	char msgbuf_real[256];
6917c478bdstevel@tonic-gate	int totallen = 0;
6927c478bdstevel@tonic-gate
6937c478bdstevel@tonic-gate	msgbuf = msgbuf_real;
6947c478bdstevel@tonic-gate
6957c478bdstevel@tonic-gate	/*
6967c478bdstevel@tonic-gate	 * Somewhat of a hack to decode traffic from a server that does
6977c478bdstevel@tonic-gate	 * not send udp replies from its SLP src port.
6987c478bdstevel@tonic-gate	 */
6997c478bdstevel@tonic-gate
7007c478bdstevel@tonic-gate	if (curr_proto == IPPROTO_UDP &&
7017c478bdstevel@tonic-gate	    dst_port == 427 &&
7027c478bdstevel@tonic-gate	    src_port != 427) {
703d6913e0Toomas Soome	    add_transient(src_port, interpret_slp);
7047c478bdstevel@tonic-gate	}
7057c478bdstevel@tonic-gate
7067c478bdstevel@tonic-gate	/* parse the header */
7077c478bdstevel@tonic-gate	if (v2_header(flags, slp, &totallen, fraglen)) {
7087c478bdstevel@tonic-gate
7097c478bdstevel@tonic-gate	    if (slp->function <= V2_MAX_FUNCTION && slp->function > 0) {
7107c478bdstevel@tonic-gate
7117c478bdstevel@tonic-gate		/* Parse the message body */
7127c478bdstevel@tonic-gate		if ((v2_functions[slp->function])(flags)) {
7137c478bdstevel@tonic-gate
7147c478bdstevel@tonic-gate		    /* finish any remaining tasks */
7157c478bdstevel@tonic-gate		    v2_finish(slp, flags);
7167c478bdstevel@tonic-gate
7177c478bdstevel@tonic-gate		}
7187c478bdstevel@tonic-gate
7197c478bdstevel@tonic-gate	    }
7207c478bdstevel@tonic-gate
7217c478bdstevel@tonic-gate	}
7227c478bdstevel@tonic-gate
7237c478bdstevel@tonic-gate	/* summary error check */
7247c478bdstevel@tonic-gate	if (flags & F_SUM) {
7257c478bdstevel@tonic-gate	    if (retlength < 0) {
7267c478bdstevel@tonic-gate		if (curr_proto == IPPROTO_TCP)
7277c478bdstevel@tonic-gate		    sprintf(get_sum_line(),
7287c478bdstevel@tonic-gate			    "%s [partial TCP message]", msgbuf);
7297c478bdstevel@tonic-gate		else if (overflow)
7307c478bdstevel@tonic-gate		    sprintf(get_sum_line(), "%s [OVERFLOW]", msgbuf);
7317c478bdstevel@tonic-gate		else
7327c478bdstevel@tonic-gate		    sprintf(get_sum_line(), "%s [CORRUPTED MESSAGE]", msgbuf);
7337c478bdstevel@tonic-gate	    }
7347c478bdstevel@tonic-gate#ifdef VERIFYSLP
7357c478bdstevel@tonic-gate	    else if (msglength > 0)
7367c478bdstevel@tonic-gate		sprintf(get_sum_line(), "%s +%d", msgbuf, msglength);
7377c478bdstevel@tonic-gate#endif
7387c478bdstevel@tonic-gate	    else
7397c478bdstevel@tonic-gate		sprintf(get_sum_line(), "%s", msgbuf);
7407c478bdstevel@tonic-gate	} else if (flags & F_DTAIL) {
7417c478bdstevel@tonic-gate	    /* detailed error check */
7427c478bdstevel@tonic-gate	    if (msglength > 0) {
7437c478bdstevel@tonic-gate		if (tcp_continuation) {
7447c478bdstevel@tonic-gate		    sprintf(get_line(0, 0),
7457c478bdstevel@tonic-gate			    "[TCP Continuation, %d bytes remaining]",
7467c478bdstevel@tonic-gate			    totallen - fraglen);
7477c478bdstevel@tonic-gate		} else
7487c478bdstevel@tonic-gate		    sprintf(get_line(0, 0),
7497c478bdstevel@tonic-gate			"[%d extra bytes at end of SLP message]", msglength);
7507c478bdstevel@tonic-gate	    }
7517c478bdstevel@tonic-gate
7527c478bdstevel@tonic-gate	    show_trailer();
7537c478bdstevel@tonic-gate
7547c478bdstevel@tonic-gate	    if (tcp_continuation && msglength == 0)
7557c478bdstevel@tonic-gate		remove_tcp_cont(dst_port);
7567c478bdstevel@tonic-gate	}
7577c478bdstevel@tonic-gate
7587c478bdstevel@tonic-gate	return (0);
7597c478bdstevel@tonic-gate}
7607c478bdstevel@tonic-gate
7617c478bdstevel@tonic-gatestatic int v2_header(int flags,
7627c478bdstevel@tonic-gate			struct slpv2_hdr *slp,
7637c478bdstevel@tonic-gate			int *totallen,
7647c478bdstevel@tonic-gate			int fraglen) {
7657c478bdstevel@tonic-gate	extern int curr_proto, dst_port;
7667c478bdstevel@tonic-gate	char *prototag = (curr_proto == IPPROTO_TCP ? "/tcp" : "");
7677c478bdstevel@tonic-gate
7687c478bdstevel@tonic-gate	if ((slp->flags & V2_OVERFLOW) == V2_OVERFLOW)
7697c478bdstevel@tonic-gate	    overflow = B_TRUE;
7707c478bdstevel@tonic-gate
7717c478bdstevel@tonic-gate	/* summary mode header parsing */
7727c478bdstevel@tonic-gate	if (flags & F_SUM) {
7737c478bdstevel@tonic-gate
7747c478bdstevel@tonic-gate	    /* make sure we have at least a header */
7757c478bdstevel@tonic-gate	    if (msglength < sizeof (*slp)) {
7767c478bdstevel@tonic-gate		sprintf(get_sum_line(), "SLP V2 [Incomplete Header]");
7777c478bdstevel@tonic-gate		return (0);
7787c478bdstevel@tonic-gate	    }
7797c478bdstevel@tonic-gate
7807c478bdstevel@tonic-gate	    sprintf(msgbuf, "SLP V2 %s [%d%s] ",
7817c478bdstevel@tonic-gate		    slpv2_func(slp->function, B_TRUE),
7827c478bdstevel@tonic-gate		    ntohs(slp->xid), prototag);
7837c478bdstevel@tonic-gate
7847c478bdstevel@tonic-gate	    /* skip to end of header */
7857c478bdstevel@tonic-gate	    msgend = msgbuf + strlen(msgbuf);
7867c478bdstevel@tonic-gate	    msglength -= sizeof (*slp);
7877c478bdstevel@tonic-gate	    p += sizeof (*slp);
7887c478bdstevel@tonic-gate
7897c478bdstevel@tonic-gate	    /* skip language tag */
7907c478bdstevel@tonic-gate	    SKIPFIELD(FIELD_DEFAULT);
7917c478bdstevel@tonic-gate	} else if (flags & F_DTAIL) {
7927c478bdstevel@tonic-gate	    char *lang;
7937c478bdstevel@tonic-gate	    int len;
7947c478bdstevel@tonic-gate
7957c478bdstevel@tonic-gate	    /* detailed mode header parsing */
7967c478bdstevel@tonic-gate	    show_header("SLP:  ", "Service Location Protocol (v2)", fraglen);
7977c478bdstevel@tonic-gate	    show_space();
7987c478bdstevel@tonic-gate
7997c478bdstevel@tonic-gate	    if (msglength < sizeof (*slp)) {
8007c478bdstevel@tonic-gate		sprintf(get_line(0, 0), "==> Incomplete SLP header");
8017c478bdstevel@tonic-gate		return (0);
8027c478bdstevel@tonic-gate	    }
8037c478bdstevel@tonic-gate
8047c478bdstevel@tonic-gate	    sprintf(get_line(0, 0), "Version = %d", slp->vers);
8057c478bdstevel@tonic-gate	    sprintf(get_line(0, 0), "Function = %d, %s",
8067c478bdstevel@tonic-gate		    slp->function, slpv2_func(slp->function, B_FALSE));
8077c478bdstevel@tonic-gate	    get_int24(&(slp->l1));
8087c478bdstevel@tonic-gate	    *totallen = netval;
8097c478bdstevel@tonic-gate	    sprintf(get_line(0, 0), "Message length = %u", *totallen);
8107c478bdstevel@tonic-gate	    /* check for TCP continuation */
8117c478bdstevel@tonic-gate	    if (curr_proto == IPPROTO_TCP &&
8127c478bdstevel@tonic-gate		*totallen > msglength &&
8137c478bdstevel@tonic-gate		!tcp_continuation) {
8147c478bdstevel@tonic-gate		tcp_continuation = B_TRUE;
8157c478bdstevel@tonic-gate		reg_tcp_cont((char *)slp, *totallen, msglength, dst_port);
8167c478bdstevel@tonic-gate	    }
8177c478bdstevel@tonic-gate
8187c478bdstevel@tonic-gate	    if (!tcp_continuation && *totallen != msglength) {
8197c478bdstevel@tonic-gate		sprintf(get_line(0, 0),
8207c478bdstevel@tonic-gate			"  (Stated and on-the-wire lengths differ)");
8217c478bdstevel@tonic-gate	    }
8227c478bdstevel@tonic-gate	    /* flags */
8237c478bdstevel@tonic-gate	    sprintf(get_line(0, 0), "Flags = 0x%02x", slp->flags);
8247c478bdstevel@tonic-gate	    sprintf(get_line(0, 0), "      %s",
8257c478bdstevel@tonic-gate		    getflag(slp->flags, V2_OVERFLOW,
8267c478bdstevel@tonic-gate			    "overflow", "no overflow"));
8277c478bdstevel@tonic-gate	    sprintf(get_line(0, 0), "      %s",
8287c478bdstevel@tonic-gate		    getflag(slp->flags, V2_FRESH,
8297c478bdstevel@tonic-gate			    "fresh registration", "no fresh registration"));
8307c478bdstevel@tonic-gate	    sprintf(get_line(0, 0), "      %s",
8317c478bdstevel@tonic-gate		    getflag(slp->flags, V2_MCAST,
8327c478bdstevel@tonic-gate			    "request multicast / broadcast", "unicast"));
8337c478bdstevel@tonic-gate	    /* check reserved flags that must be zero */
8347c478bdstevel@tonic-gate	    if ((slp->flags & 7) != 0) {
8357c478bdstevel@tonic-gate		sprintf(get_line(0, 0),
8367c478bdstevel@tonic-gate			"      .... .xxx = %d (reserved flags nonzero)",
8377c478bdstevel@tonic-gate			slp->flags & 7);
8387c478bdstevel@tonic-gate	    }
8397c478bdstevel@tonic-gate	    /* end of flags */
8407c478bdstevel@tonic-gate
8417c478bdstevel@tonic-gate	    /* language tag */
8427c478bdstevel@tonic-gate	    p = (char *)slp + sizeof (*slp);
8437c478bdstevel@tonic-gate	    msglength -= sizeof (*slp);
8447c478bdstevel@tonic-gate	    GETSHORT(len);
8457c478bdstevel@tonic-gate	    if (len > msglength) {
8467c478bdstevel@tonic-gate		sprintf(get_line(0, 0),
8477c478bdstevel@tonic-gate			"Language Tag Length = %u [CORRUPT MESSAGE]",
8487c478bdstevel@tonic-gate			len);
8497c478bdstevel@tonic-gate		return (0);
8507c478bdstevel@tonic-gate	    }
8517c478bdstevel@tonic-gate
8527c478bdstevel@tonic-gate	    lang = get_line(0, 0);
8537c478bdstevel@tonic-gate	    strcpy(lang, "Language Tag = ");
8547c478bdstevel@tonic-gate	    strncat(lang,  p, len);
8557c478bdstevel@tonic-gate	    sprintf(get_line(0, 0), "XID = %u", ntohs(slp->xid));
8567c478bdstevel@tonic-gate
8577c478bdstevel@tonic-gate	    /* set msglength to remaining length of SLP message */
8587c478bdstevel@tonic-gate	    p += len;
8597c478bdstevel@tonic-gate	    msglength -= len;
8607c478bdstevel@tonic-gate	}
8617c478bdstevel@tonic-gate
8627c478bdstevel@tonic-gate	return (1);
8637c478bdstevel@tonic-gate}
8647c478bdstevel@tonic-gate
8657c478bdstevel@tonic-gatestatic int v2_finish(struct slpv2_hdr *slp, int flags) {
8667c478bdstevel@tonic-gate	unsigned int firstop;
8677c478bdstevel@tonic-gate
8687c478bdstevel@tonic-gate	if (!(flags & F_DTAIL))
8697c478bdstevel@tonic-gate	    return (1);
8707c478bdstevel@tonic-gate
8717c478bdstevel@tonic-gate	/* check for options */
8727c478bdstevel@tonic-gate	get_int24(&(slp->o1));
8737c478bdstevel@tonic-gate	firstop = netval;
8747c478bdstevel@tonic-gate
8757c478bdstevel@tonic-gate	if (firstop) {
8767c478bdstevel@tonic-gate	    unsigned short op_id;
8777c478bdstevel@tonic-gate	    unsigned short nextop;
8787c478bdstevel@tonic-gate	    char *op_class;
8797c478bdstevel@tonic-gate
8807c478bdstevel@tonic-gate	    for (;;) {
8817c478bdstevel@tonic-gate		unsigned short real_oplen;
8827c478bdstevel@tonic-gate
8837c478bdstevel@tonic-gate		if (msglength < 4) {
8847c478bdstevel@tonic-gate		    sprintf(get_line(0, 0),
8857c478bdstevel@tonic-gate			    "Option expected but not present");
8867c478bdstevel@tonic-gate		    return (0);
8877c478bdstevel@tonic-gate		}
8887c478bdstevel@tonic-gate
8897c478bdstevel@tonic-gate		nbtohs();
8907c478bdstevel@tonic-gate		op_id = netval;
8917c478bdstevel@tonic-gate		p += sizeof (unsigned short);
8927c478bdstevel@tonic-gate		msglength -= sizeof (unsigned short);
8937c478bdstevel@tonic-gate		nbtohs();
8947c478bdstevel@tonic-gate		nextop = netval;
8957c478bdstevel@tonic-gate		p += sizeof (unsigned short);
8967c478bdstevel@tonic-gate		msglength -= sizeof (unsigned short);
8977c478bdstevel@tonic-gate
8987c478bdstevel@tonic-gate		real_oplen = nextop ? nextop : msglength;
8997c478bdstevel@tonic-gate
9007c478bdstevel@tonic-gate		/* known options */
9017c478bdstevel@tonic-gate		switch (op_id) {
9027c478bdstevel@tonic-gate		case 1:
9037c478bdstevel@tonic-gate		    sprintf(get_line(0, 0),
9047c478bdstevel@tonic-gate			    "Option: Required Attribute Missing");
9057c478bdstevel@tonic-gate		    DOFIELD("Template IDVer", FIELD_DEFAULT);
9067c478bdstevel@tonic-gate		    DOFIELD("Required Attrs", FIELD_DEFAULT);
9077c478bdstevel@tonic-gate		    break;
9087c478bdstevel@tonic-gate		default:
9097c478bdstevel@tonic-gate		    sprintf(get_line(0, 0), "Option: Unknown");
9107c478bdstevel@tonic-gate		    p += (real_oplen - 4);
9117c478bdstevel@tonic-gate		    msglength -= (real_oplen - 4);
9127c478bdstevel@tonic-gate		    break;
9137c478bdstevel@tonic-gate		}
9147c478bdstevel@tonic-gate
9157c478bdstevel@tonic-gate		if (op_id < 0x3fff)
9167c478bdstevel@tonic-gate		    op_class = "Standardized, optional";
9177c478bdstevel@tonic-gate		else if (op_id < 0x7fff)
9187c478bdstevel@tonic-gate		    op_class = "Standardized, mandatory";
9197c478bdstevel@tonic-gate		else if (op_id < 0x8fff)
9207c478bdstevel@tonic-gate		    op_class = "Not standardized, private";
9217c478bdstevel@tonic-gate		else if (op_id < 0xffff)
9227c478bdstevel@tonic-gate		    op_class = "Reserved";
9237c478bdstevel@tonic-gate		sprintf(get_line(0, 0), "Option ID = 0x%04x, %s",
9247c478bdstevel@tonic-gate			op_id, op_class);
9257c478bdstevel@tonic-gate		if (nextop &&
9267c478bdstevel@tonic-gate		    ((nextop - 4) > msglength) &&
9277c478bdstevel@tonic-gate		    !tcp_continuation) {
9287c478bdstevel@tonic-gate		    sprintf(get_line(0, 0),
9297c478bdstevel@tonic-gate			    "[Framing error: remaining pkt length = %u]",
9307c478bdstevel@tonic-gate			    msglength);
9317c478bdstevel@tonic-gate		    return (0);
9327c478bdstevel@tonic-gate		}
9337c478bdstevel@tonic-gate
9347c478bdstevel@tonic-gate		sprintf(get_line(0, 0), "Option Length = %u", real_oplen);
9357c478bdstevel@tonic-gate
9367c478bdstevel@tonic-gate		if (!nextop)
9377c478bdstevel@tonic-gate		    break;
9387c478bdstevel@tonic-gate	    }
9397c478bdstevel@tonic-gate	}
9407c478bdstevel@tonic-gate
9417c478bdstevel@tonic-gate	return (1);
9427c478bdstevel@tonic-gate}
9437c478bdstevel@tonic-gate
9447c478bdstevel@tonic-gate#ifdef VERIFYSLP
9457c478bdstevel@tonic-gatestatic int skip_v2authblock() {
9467c478bdstevel@tonic-gate	unsigned short length, slen;
9477c478bdstevel@tonic-gate
9487c478bdstevel@tonic-gate	/* auth header */
9497c478bdstevel@tonic-gate	if (msglength < 10)
9507c478bdstevel@tonic-gate	    return (-1);
9517c478bdstevel@tonic-gate
9527c478bdstevel@tonic-gate	/* block descriptor: 2 bytes */
9537c478bdstevel@tonic-gate	p += sizeof (unsigned short);
9547c478bdstevel@tonic-gate	/* length */
9557c478bdstevel@tonic-gate	nbtohs();
9567c478bdstevel@tonic-gate	length = netval;
9577c478bdstevel@tonic-gate	p += sizeof (unsigned short);
9587c478bdstevel@tonic-gate	/* timestamp */
9597c478bdstevel@tonic-gate	p += 4;
9607c478bdstevel@tonic-gate	/* SPI String length */
9617c478bdstevel@tonic-gate	nbtohs();
9627c478bdstevel@tonic-gate	slen = netval;
9637c478bdstevel@tonic-gate	p += sizeof (unsigned short);
9647c478bdstevel@tonic-gate
9657c478bdstevel@tonic-gate	msglength -= 10;
9667c478bdstevel@tonic-gate	if (slen > msglength || length > (msglength + 10))
9677c478bdstevel@tonic-gate	    return (-1);
9687c478bdstevel@tonic-gate
9697c478bdstevel@tonic-gate	p += slen;
9707c478bdstevel@tonic-gate	msglength -= slen;
9717c478bdstevel@tonic-gate
9727c478bdstevel@tonic-gate	/* structured auth block */
9737c478bdstevel@tonic-gate	p += (length - 10 - slen);
9747c478bdstevel@tonic-gate	msglength -= (length - 10 - slen);
9757c478bdstevel@tonic-gate	return (0);
9767c478bdstevel@tonic-gate}
9777c478bdstevel@tonic-gate#endif
9787c478bdstevel@tonic-gate
9797c478bdstevel@tonic-gatestatic char *display_bsd(unsigned short bsd) {
9807c478bdstevel@tonic-gate	switch (bsd) {
9817c478bdstevel@tonic-gate	case 1: return ("MD5 with RSA");
9827c478bdstevel@tonic-gate	case 2: return ("DSA with SHA-1");
9837c478bdstevel@tonic-gate	case 3: return ("Keyed HMAC with MD5");
9847c478bdstevel@tonic-gate	default: return ("Unknown BSD");
9857c478bdstevel@tonic-gate	}
9867c478bdstevel@tonic-gate}
9877c478bdstevel@tonic-gate
9887c478bdstevel@tonic-gatestatic char *slpv2_func(int t, boolean_t s) {
9897c478bdstevel@tonic-gate	static char buf[128];
9907c478bdstevel@tonic-gate
9917c478bdstevel@tonic-gate	switch (t) {
9927c478bdstevel@tonic-gate	case V2_SRVRQST:	return s? "SrvRqst"  : "Service Request";
9937c478bdstevel@tonic-gate	case V2_SRVRPLY:	return s? "SrvRply"  : "Service Reply";
9947c478bdstevel@tonic-gate	case V2_SRVREG:		return s? "SrvReg"   : "Service Registration";
9957c478bdstevel@tonic-gate	case V2_SRVDEREG:
9967c478bdstevel@tonic-gate	    return (s ? "SrvDereg" : "Service Deregistration");
9977c478bdstevel@tonic-gate	case V2_SRVACK:		return s? "SrvAck"   : "Service Acknowledge";
9987c478bdstevel@tonic-gate	case V2_ATTRRQST:	return s? "AttrRqst" : "Attribute Request";
9997c478bdstevel@tonic-gate	case V2_ATTRRPLY:	return s? "AttrRply" : "Attribute Reply";
10007c478bdstevel@tonic-gate	case V2_DAADVERT:	return s? "DAAdvert" : "DA advertisement";
10017c478bdstevel@tonic-gate	case V2_SRVTYPERQST:
10027c478bdstevel@tonic-gate	    return (s ? "SrvTypeRqst" : "Service Type Request");
10037c478bdstevel@tonic-gate	case V2_SRVTYPERPLY:
10047c478bdstevel@tonic-gate	    return (s ? "SrvTypeRply" : "Service Type Reply");
10057c478bdstevel@tonic-gate	case V2_SAADVERT:	return s? "SAAdvert" : "SA advertisement";
10067c478bdstevel@tonic-gate	}
10077c478bdstevel@tonic-gate	sprintf(buf, "(func %d)", t);
10087c478bdstevel@tonic-gate	return (s ? buf : "unknown function");
10097c478bdstevel@tonic-gate}
10107c478bdstevel@tonic-gate
10117c478bdstevel@tonic-gatestatic char *slpv2_error(unsigned short code) {
10127c478bdstevel@tonic-gate	static char buf[128];
10137c478bdstevel@tonic-gate
10147c478bdstevel@tonic-gate	switch (code) {
10157c478bdstevel@tonic-gate	case OK:			return "ok";
10167c478bdstevel@tonic-gate	case LANG_NOT_SUPPORTED:	return "language not supported";
10177c478bdstevel@tonic-gate	case PROTOCOL_PARSE_ERR:	return "protocol parse error";
10187c478bdstevel@tonic-gate	case INVALID_REGISTRATION:	return "invalid registration";
10197c478bdstevel@tonic-gate	case SCOPE_NOT_SUPPORTED:	return "scope not supported";
10207c478bdstevel@tonic-gate	case AUTHENTICATION_UNKNOWN:	return "authentication unknown";
10217c478bdstevel@tonic-gate	case V2_AUTHENTICATION_ABSENT:	return "authentication absent";
10227c478bdstevel@tonic-gate	case V2_AUTHENTICATION_FAILED:	return "authentication failed";
10237c478bdstevel@tonic-gate	case V2_VER_NOT_SUPPORTED:	return "version not supported";
10247c478bdstevel@tonic-gate	case V2_INTERNAL_ERROR:		return "internal error";
10257c478bdstevel@tonic-gate	case V2_DA_BUSY_NOW:		return "DA busy";
10267c478bdstevel@tonic-gate	case V2_OPTION_NOT_UNDERSTOOD:	return "option not understood";
10277c478bdstevel@tonic-gate	case V2_INVALID_UPDATE:		return "invalid update";
10287c478bdstevel@tonic-gate	case V2_RQST_NOT_SUPPORTED:	return "request not supported";
10297c478bdstevel@tonic-gate	case INVALID_LIFETIME:		return "invalid lifetime";
10307c478bdstevel@tonic-gate	}
10317c478bdstevel@tonic-gate	sprintf(buf, "error %d", code);
10327c478bdstevel@tonic-gate	return (buf);
10337c478bdstevel@tonic-gate}
10347c478bdstevel@tonic-gate
10357c478bdstevel@tonic-gatestatic char *convert_ts(unsigned int timestamp) {
10367c478bdstevel@tonic-gate	/* timestamp is in UNIX time */
10377c478bdstevel@tonic-gate	static char buff[128];
10387c478bdstevel@tonic-gate
10397c478bdstevel@tonic-gate	strcpy(buff, ctime((time_t *)&timestamp));
10407c478bdstevel@tonic-gate	buff[strlen(buff) - 1] = '\0';
10417c478bdstevel@tonic-gate	return (buff);
10427c478bdstevel@tonic-gate}
10437c478bdstevel@tonic-gate
10447c478bdstevel@tonic-gatestatic int slpv2_authblock(int cnt) {
10457c478bdstevel@tonic-gate	unsigned short bsd, length, slen;
10467c478bdstevel@tonic-gate	char *pp, *scopes;
10477c478bdstevel@tonic-gate	unsigned int timestamp;
10487c478bdstevel@tonic-gate
10497c478bdstevel@tonic-gate	if (msglength < 10) {
10507c478bdstevel@tonic-gate	    sprintf(get_line(0, 0),
10517c478bdstevel@tonic-gate		"  [no room for auth block header: remaining msg length = %u]",
10527c478bdstevel@tonic-gate		    msglength);
10537c478bdstevel@tonic-gate	    return (-1);
10547c478bdstevel@tonic-gate	}
10557c478bdstevel@tonic-gate
10567c478bdstevel@tonic-gate	/* bsd */
10577c478bdstevel@tonic-gate	nbtohs();
10587c478bdstevel@tonic-gate	bsd = netval;
10597c478bdstevel@tonic-gate	p += sizeof (unsigned short);
10607c478bdstevel@tonic-gate
10617c478bdstevel@tonic-gate	/* length */
10627c478bdstevel@tonic-gate	nbtohs();
10637c478bdstevel@tonic-gate	length = netval;
10647c478bdstevel@tonic-gate	p += sizeof (unsigned short);
10657c478bdstevel@tonic-gate
10667c478bdstevel@tonic-gate	/* timestamp */
10677c478bdstevel@tonic-gate	nbtohl();
10687c478bdstevel@tonic-gate	timestamp = netval;
10697c478bdstevel@tonic-gate	p += 4;
10707c478bdstevel@tonic-gate
10717c478bdstevel@tonic-gate	/* SPI String length */
10727c478bdstevel@tonic-gate	nbtohs();
10737c478bdstevel@tonic-gate	slen = netval;
10747c478bdstevel@tonic-gate	p += sizeof (unsigned short);
10757c478bdstevel@tonic-gate
10767c478bdstevel@tonic-gate	msglength -= 10;
10777c478bdstevel@tonic-gate	if (slen > msglength) {
10787c478bdstevel@tonic-gate	    sprintf(get_line(0, 0),
10797c478bdstevel@tonic-gate		"  [no room for auth block scopes: remaining msg length = %u]",
10807c478bdstevel@tonic-gate		    msglength);
10817c478bdstevel@tonic-gate	    return (-1);
10827c478bdstevel@tonic-gate	}
10837c478bdstevel@tonic-gate
10847c478bdstevel@tonic-gate	if (length > (msglength + 10)) {
10857c478bdstevel@tonic-gate	    if (!tcp_continuation)
10867c478bdstevel@tonic-gate		/* framing error: message is not long enough to contain data */
10877c478bdstevel@tonic-gate		sprintf(get_line(0, 0),
10887c478bdstevel@tonic-gate			"  [Framing error: remaining pkt length = %u]",
10897c478bdstevel@tonic-gate			msglength);
10907c478bdstevel@tonic-gate	    return (-1);
10917c478bdstevel@tonic-gate	}
10927c478bdstevel@tonic-gate
10937c478bdstevel@tonic-gate	scopes = p;
10947c478bdstevel@tonic-gate	p += slen;
10957c478bdstevel@tonic-gate	msglength -= slen;
10967c478bdstevel@tonic-gate
10977c478bdstevel@tonic-gate	sprintf(get_line(0, 0),
10987c478bdstevel@tonic-gate	    "Auth block %d: timestamp = %s", cnt,
10997c478bdstevel@tonic-gate	    (timestamp) ? convert_ts(timestamp) : "0");
11007c478bdstevel@tonic-gate
11017c478bdstevel@tonic-gate	pp = get_line(0, 0);
11027c478bdstevel@tonic-gate	strcpy(pp, "              SPI = ");
11037c478bdstevel@tonic-gate	strncat(pp, scopes, slen);
11047c478bdstevel@tonic-gate
11057c478bdstevel@tonic-gate	sprintf(get_line(0, 0),
11067c478bdstevel@tonic-gate	    "              block desc = 0x%04x: %s", bsd, display_bsd(bsd));
11077c478bdstevel@tonic-gate
11087c478bdstevel@tonic-gate	sprintf(get_line(0, 0), "              length = %u", length);
11097c478bdstevel@tonic-gate
11107c478bdstevel@tonic-gate	p += (length - 10 - slen);
11117c478bdstevel@tonic-gate	msglength -= (length - 10 - slen);
11127c478bdstevel@tonic-gate	return (0);
11137c478bdstevel@tonic-gate}
11147c478bdstevel@tonic-gate
11157c478bdstevel@tonic-gatestatic int v2_srv_rqst(int flags) {
11167c478bdstevel@tonic-gate	if (flags & F_SUM) {
11177c478bdstevel@tonic-gate		SKIPFIELD(FIELD_DEFAULT);	/* PR list */
11187c478bdstevel@tonic-gate		GETFIELD;			/* service type */
11197c478bdstevel@tonic-gate		SKIPFIELD(FIELD_DEFAULT);	/* scopes */
11207c478bdstevel@tonic-gate		strcat(msgend, " [");
11217c478bdstevel@tonic-gate		GETFIELD;			/* predicate */
11227c478bdstevel@tonic-gate		strcat(msgend, "]");
11237c478bdstevel@tonic-gate		SKIPFIELD(FIELD_DEFAULT);	/* SPI */
11247c478bdstevel@tonic-gate	} else if (flags & F_DTAIL) {
11257c478bdstevel@tonic-gate		DOFIELD("Previous responders", FIELD_DEFAULT);
11267c478bdstevel@tonic-gate		DOFIELD("Service type",  FIELD_DEFAULT);
11277c478bdstevel@tonic-gate		DOFIELD("Scopes",  FIELD_DEFAULT);
11287c478bdstevel@tonic-gate		DOFIELD("Predicate string",  FIELD_DEFAULT);
11297c478bdstevel@tonic-gate		DOFIELD("Requested SPI", FIELD_DEFAULT);
11307c478bdstevel@tonic-gate	}
11317c478bdstevel@tonic-gate
11327c478bdstevel@tonic-gate	return (1);
11337c478bdstevel@tonic-gate}
11347c478bdstevel@tonic-gate
11357c478bdstevel@tonic-gatestatic int v2_srv_rply(int flags) {
11367c478bdstevel@tonic-gate	unsigned short itemcnt, errcode;
11377c478bdstevel@tonic-gate	int n;
11387c478bdstevel@tonic-gate
11397c478bdstevel@tonic-gate	if (flags & F_SUM) {
11407c478bdstevel@tonic-gate	    int i, auth_cnt;
11417c478bdstevel@tonic-gate
11427c478bdstevel@tonic-gate	    GETSHORT(errcode);
11437c478bdstevel@tonic-gate	    if (errcode != OK) {
11447c478bdstevel@tonic-gate		strcat(msgbuf, slpv2_error(errcode));
11457c478bdstevel@tonic-gate		msglength = 0;	/* skip rest of message */
11467c478bdstevel@tonic-gate		return (0);
11477c478bdstevel@tonic-gate	    } else {
11487c478bdstevel@tonic-gate		GETSHORT(itemcnt);
11497c478bdstevel@tonic-gate		sprintf(msgend, "%d URL entries", itemcnt);
11507c478bdstevel@tonic-gate#ifdef VERIFYSLP
11517c478bdstevel@tonic-gate		for (n = 0; n < itemcnt; n++) {
11527c478bdstevel@tonic-gate		    SKIPBYTE;			/* reserved */
11537c478bdstevel@tonic-gate		    SKIPSHORT;			/* lifetime */
11547c478bdstevel@tonic-gate		    SKIPFIELD(FIELD_DEFAULT);	/* URL */
11557c478bdstevel@tonic-gate		    GETBYTE(auth_cnt);
11567c478bdstevel@tonic-gate		    for (i = 0; i < auth_cnt; auth_cnt++)
11577c478bdstevel@tonic-gate			if (skip_v2authblock() < 0)
11587c478bdstevel@tonic-gate			    return (0);
11597c478bdstevel@tonic-gate		}
11607c478bdstevel@tonic-gate#endif
11617c478bdstevel@tonic-gate	    }
11627c478bdstevel@tonic-gate	} else if (flags & F_DTAIL) {
11637c478bdstevel@tonic-gate	    V2_DOERRCODE;
11647c478bdstevel@tonic-gate	    GETSHORT(itemcnt);
11657c478bdstevel@tonic-gate	    sprintf(get_line(0, 0), "URL entry count = %d", itemcnt);
11667c478bdstevel@tonic-gate	    for (n = 0; n < itemcnt; n++) {
11677c478bdstevel@tonic-gate		V2_DOURL(n);
11687c478bdstevel@tonic-gate	    }
11697c478bdstevel@tonic-gate	}
11707c478bdstevel@tonic-gate
11717c478bdstevel@tonic-gate	return (1);
11727c478bdstevel@tonic-gate}
11737c478bdstevel@tonic-gate
11747c478bdstevel@tonic-gatestatic int v2_srv_reg(int flags) {
11757c478bdstevel@tonic-gate	int i, auth_cnt;
11767c478bdstevel@tonic-gate
11777c478bdstevel@tonic-gate	if (flags & F_SUM) {
11787c478bdstevel@tonic-gate	    SKIPBYTE;			/* reserved */
11797c478bdstevel@tonic-gate	    SKIPSHORT;			/* lifetime */
11807c478bdstevel@tonic-gate	    GETFIELD;			/* URL */
11817c478bdstevel@tonic-gate#ifdef VERIFYSLP
11827c478bdstevel@tonic-gate	    GETBYTE(auth_cnt);
11837c478bdstevel@tonic-gate	    for (i = 0; i < auth_cnt; i++)
11847c478bdstevel@tonic-gate		if (skip_v2authblock() < 0)
11857c478bdstevel@tonic-gate		    return (0);
11867c478bdstevel@tonic-gate	    SKIPFIELD(FIELD_DEFAULT);	/* type */
11877c478bdstevel@tonic-gate	    SKIPFIELD(FIELD_DEFAULT);	/* scopes */
11887c478bdstevel@tonic-gate	    SKIPFIELD(FIELD_DEFAULT);	/* attrs */
11897c478bdstevel@tonic-gate	    GETBYTE(auth_cnt);
11907c478bdstevel@tonic-gate	    for (i = 0; i < auth_cnt; i++)
11917c478bdstevel@tonic-gate		if (skip_v2authblock() < 0)
11927c478bdstevel@tonic-gate		    return (0);
11937c478bdstevel@tonic-gate#endif
11947c478bdstevel@tonic-gate	} if (flags & F_DTAIL) {
11957c478bdstevel@tonic-gate	    V2_DOURL(-1);
11967c478bdstevel@tonic-gate	    DOFIELD("Service type", FIELD_DEFAULT);
11977c478bdstevel@tonic-gate	    DOFIELD("Scopes", FIELD_DEFAULT);
11987c478bdstevel@tonic-gate	    DOFIELD("Attribute list", FIELD_DEFAULT);
11997c478bdstevel@tonic-gate	    /* auth */
12007c478bdstevel@tonic-gate	    GETBYTE(auth_cnt);
12017c478bdstevel@tonic-gate	    for (i = 0; i < auth_cnt; i++)
12027c478bdstevel@tonic-gate		V2_DOAUTH(i);
12037c478bdstevel@tonic-gate	}
12047c478bdstevel@tonic-gate
12057c478bdstevel@tonic-gate	return (1);
12067c478bdstevel@tonic-gate}
12077c478bdstevel@tonic-gate
12087c478bdstevel@tonic-gatestatic int v2_srv_dereg(int flags) {
12097c478bdstevel@tonic-gate	if (flags & F_SUM) {
12107c478bdstevel@tonic-gate	    int i, auth_cnt;
12117c478bdstevel@tonic-gate
12127c478bdstevel@tonic-gate	    SKIPFIELD(FIELD_DEFAULT);	/* scopes */
12137c478bdstevel@tonic-gate	    SKIPBYTE;			/* reserved */
12147c478bdstevel@tonic-gate	    SKIPSHORT;			/* lifetime */
12157c478bdstevel@tonic-gate	    GETFIELD;			/* URL */
12167c478bdstevel@tonic-gate
12177c478bdstevel@tonic-gate#ifdef VERIFYSLP
12187c478bdstevel@tonic-gate	    GETBYTE(auth_cnt);
12197c478bdstevel@tonic-gate	    for (i = 0; i < auth_cnt; i++)
12207c478bdstevel@tonic-gate		if (skip_v2authblock() < 0)
12217c478bdstevel@tonic-gate		    return (0);
12227c478bdstevel@tonic-gate	    SKIPFIELD(FIELD_DEFAULT);	/* attrs */
12237c478bdstevel@tonic-gate#endif
12247c478bdstevel@tonic-gate	} else if (flags & F_DTAIL) {
12257c478bdstevel@tonic-gate	    DOFIELD("Scopes", FIELD_DEFAULT);
12267c478bdstevel@tonic-gate	    V2_DOURL(-1);
12277c478bdstevel@tonic-gate	    DOFIELD("Tag list",  FIELD_DEFAULT);
12287c478bdstevel@tonic-gate	}
12297c478bdstevel@tonic-gate
12307c478bdstevel@tonic-gate	return (1);
12317c478bdstevel@tonic-gate}
12327c478bdstevel@tonic-gate
12337c478bdstevel@tonic-gatestatic int v2_srv_ack(int flags) {
12347c478bdstevel@tonic-gate	unsigned short errcode;
12357c478bdstevel@tonic-gate	if (flags & F_SUM) {
12367c478bdstevel@tonic-gate	    GETSHORT(errcode);
12377c478bdstevel@tonic-gate	    strcat(msgbuf, slpv2_error(errcode));
12387c478bdstevel@tonic-gate	} else if (flags & F_DTAIL) {
12397c478bdstevel@tonic-gate	    V2_DOERRCODE;
12407c478bdstevel@tonic-gate	}
12417c478bdstevel@tonic-gate
12427c478bdstevel@tonic-gate	return (1);
12437c478bdstevel@tonic-gate}
12447c478bdstevel@tonic-gate
12457c478bdstevel@tonic-gatestatic int v2_attr_rqst(int flags) {
12467c478bdstevel@tonic-gate	if (flags  & F_SUM) {
12477c478bdstevel@tonic-gate	    SKIPFIELD(FIELD_DEFAULT);	/* PR list */
12487c478bdstevel@tonic-gate	    GETFIELD;			/* URL */
12497c478bdstevel@tonic-gate	    SKIPFIELD(FIELD_DEFAULT);	/* scopes */
12507c478bdstevel@tonic-gate	    strcat(msgend, " [");
12517c478bdstevel@tonic-gate	    GETFIELD;			/* attrs */
12527c478bdstevel@tonic-gate	    strcat(msgend, "]");
12537c478bdstevel@tonic-gate
12547c478bdstevel@tonic-gate#ifdef VERIFYSLP
12557c478bdstevel@tonic-gate	    SKIPFIELD(FIELD_DEFAULT);	/* SPI */
12567c478bdstevel@tonic-gate#endif
12577c478bdstevel@tonic-gate	} else if (flags & F_DTAIL) {
12587c478bdstevel@tonic-gate	    DOFIELD("Previous responders", FIELD_DEFAULT);
12597c478bdstevel@tonic-gate	    DOFIELD("URL",  FIELD_DEFAULT);
12607c478bdstevel@tonic-gate	    DOFIELD("Scopes",  FIELD_DEFAULT);
12617c478bdstevel@tonic-gate	    DOFIELD("Tag list",  FIELD_DEFAULT);
12627c478bdstevel@tonic-gate	    DOFIELD("Requested SPI", FIELD_DEFAULT);
12637c478bdstevel@tonic-gate	}
12647c478bdstevel@tonic-gate
12657c478bdstevel@tonic-gate	return (1);
12667c478bdstevel@tonic-gate}
12677c478bdstevel@tonic-gate
12687c478bdstevel@tonic-gatestatic int v2_attr_rply(int flags) {
12697c478bdstevel@tonic-gate	int auth_cnt, i;
12707c478bdstevel@tonic-gate	unsigned short errcode;
12717c478bdstevel@tonic-gate
12727c478bdstevel@tonic-gate	if (flags & F_SUM) {
12737c478bdstevel@tonic-gate	    GETSHORT(errcode);
12747c478bdstevel@tonic-gate	    if (errcode != OK) {
12757c478bdstevel@tonic-gate		strcat(msgbuf, slpv2_error(errcode));
12767c478bdstevel@tonic-gate		msglength = 0;	/* skip rest of message */
12777c478bdstevel@tonic-gate		return (0);
12787c478bdstevel@tonic-gate	    } else {
12797c478bdstevel@tonic-gate		GETFIELD;			/* attr list */
12807c478bdstevel@tonic-gate
12817c478bdstevel@tonic-gate#ifdef VERIFYSLP
12827c478bdstevel@tonic-gate		GETBYTE(auth_cnt);
12837c478bdstevel@tonic-gate		for (i = 0; i < auth_cnt; i++)
12847c478bdstevel@tonic-gate		    if (skip_v2authblock() < 0)
12857c478bdstevel@tonic-gate			return (0);
12867c478bdstevel@tonic-gate#endif
12877c478bdstevel@tonic-gate	    }
12887c478bdstevel@tonic-gate	} else if (flags & F_DTAIL) {
12897c478bdstevel@tonic-gate	    V2_DOERRCODE;
12907c478bdstevel@tonic-gate	    DOFIELD("Attribute list", FIELD_DEFAULT);
12917c478bdstevel@tonic-gate	    /* auth */
12927c478bdstevel@tonic-gate	    GETBYTE(auth_cnt);
12937c478bdstevel@tonic-gate	    for (i = 0; i < auth_cnt; i++)
12947c478bdstevel@tonic-gate		V2_DOAUTH(i);
12957c478bdstevel@tonic-gate	}
12967c478bdstevel@tonic-gate
12977c478bdstevel@tonic-gate	return (1);
12987c478bdstevel@tonic-gate}
12997c478bdstevel@tonic-gate
13007c478bdstevel@tonic-gatestatic int v2_daadvert(int flags) {
13017c478bdstevel@tonic-gate	int auth_cnt, i;
13027c478bdstevel@tonic-gate	unsigned short errcode;
13037c478bdstevel@tonic-gate	unsigned int timestamp;
13047c478bdstevel@tonic-gate
13057c478bdstevel@tonic-gate	if (flags & F_SUM) {
13067c478bdstevel@tonic-gate	    SKIPSHORT;			/* error code */
13077c478bdstevel@tonic-gate	    SKIPSHORT; SKIPSHORT;	/* timestamp */
13087c478bdstevel@tonic-gate	    GETFIELD;			/* URL */
13097c478bdstevel@tonic-gate
13107c478bdstevel@tonic-gate#ifdef VERIFYSLP
13117c478bdstevel@tonic-gate	    SKIPFIELD(FIELD_DEFAULT);	/* scopes */
13127c478bdstevel@tonic-gate	    SKIPFIELD(FIELD_DEFAULT);	/* attrs */
13137c478bdstevel@tonic-gate	    SKIPFIELD(FIELD_DEFAULT);	/* SPIs */
13147c478bdstevel@tonic-gate
13157c478bdstevel@tonic-gate	    GETBYTE(auth_cnt);
13167c478bdstevel@tonic-gate	    for (i = 0; i < auth_cnt; i++)
13177c478bdstevel@tonic-gate		if (skip_v2authblock() < 0)
13187c478bdstevel@tonic-gate		    return (0);
13197c478bdstevel@tonic-gate#endif
13207c478bdstevel@tonic-gate	} else if (flags & F_DTAIL) {
13217c478bdstevel@tonic-gate	    V2_DOERRCODE;
13227c478bdstevel@tonic-gate	    V2_DOTIMESTAMP;
13237c478bdstevel@tonic-gate	    DOFIELD("URL", FIELD_DEFAULT);
13247c478bdstevel@tonic-gate	    DOFIELD("Scope list", FIELD_DEFAULT);
13257c478bdstevel@tonic-gate	    DOFIELD("Attribute list", FIELD_DEFAULT);
13267c478bdstevel@tonic-gate	    DOFIELD("Configured SPIs", FIELD_DEFAULT);
13277c478bdstevel@tonic-gate	    /* auth */
13287c478bdstevel@tonic-gate	    GETBYTE(auth_cnt);
13297c478bdstevel@tonic-gate	    for (i = 0; i < auth_cnt; i++)
13307c478bdstevel@tonic-gate		V2_DOAUTH(i);
13317c478bdstevel@tonic-gate	}
13327c478bdstevel@tonic-gate
13337c478bdstevel@tonic-gate	return (1);
13347c478bdstevel@tonic-gate}
13357c478bdstevel@tonic-gate
13367c478bdstevel@tonic-gatestatic int v2_srv_type_rqst(int flags) {
13377c478bdstevel@tonic-gate	if (flags & F_SUM) {
13387c478bdstevel@tonic-gate	    SKIPFIELD(FIELD_DEFAULT);	/* prev responders */
13397c478bdstevel@tonic-gate	    SKIPFIELD(FIELD_TYPENA);	/* naming authority */
13407c478bdstevel@tonic-gate	    GETFIELD;			/* scope */
13417c478bdstevel@tonic-gate	} else if (flags & F_DTAIL) {
13427c478bdstevel@tonic-gate	    DOFIELD("Previous responders", FIELD_DEFAULT);
13437c478bdstevel@tonic-gate	    DOFIELD("Naming authority", FIELD_TYPENA);
13447c478bdstevel@tonic-gate	    DOFIELD("Scopes",  FIELD_DEFAULT);
13457c478bdstevel@tonic-gate	}
13467c478bdstevel@tonic-gate
13477c478bdstevel@tonic-gate	return (1);
13487c478bdstevel@tonic-gate}
13497c478bdstevel@tonic-gate
13507c478bdstevel@tonic-gatestatic int v2_srv_type_rply(int flags) {
13517c478bdstevel@tonic-gate	unsigned short errcode;
13527c478bdstevel@tonic-gate
13537c478bdstevel@tonic-gate	if (flags & F_SUM) {
13547c478bdstevel@tonic-gate	    GETSHORT(errcode);
13557c478bdstevel@tonic-gate	    if (errcode != OK)
13567c478bdstevel@tonic-gate		strcat(msgbuf, slpv2_error(errcode));
13577c478bdstevel@tonic-gate	    else
13587c478bdstevel@tonic-gate		GETFIELD;
13597c478bdstevel@tonic-gate	} else if (flags & F_DTAIL) {
13607c478bdstevel@tonic-gate		V2_DOERRCODE;
13617c478bdstevel@tonic-gate		DOFIELD("Service types", FIELD_DEFAULT);
13627c478bdstevel@tonic-gate	}
13637c478bdstevel@tonic-gate
13647c478bdstevel@tonic-gate	return (1);
13657c478bdstevel@tonic-gate}
13667c478bdstevel@tonic-gate
13677c478bdstevel@tonic-gatestatic int v2_saadvert(int flags) {
13687c478bdstevel@tonic-gate	int auth_cnt, i;
13697c478bdstevel@tonic-gate
13707c478bdstevel@tonic-gate	if (flags & F_SUM) {
13717c478bdstevel@tonic-gate	    GETFIELD;			/* URL */
13727c478bdstevel@tonic-gate
13737c478bdstevel@tonic-gate#ifdef VERIFYSLP
13747c478bdstevel@tonic-gate	    SKIPFIELD(FIELD_DEFAULT);	/* scopes */
13757c478bdstevel@tonic-gate	    SKIPFIELD(FIELD_DEFAULT);	/* attrs */
13767c478bdstevel@tonic-gate
13777c478bdstevel@tonic-gate	    GETBYTE(auth_cnt);
13787c478bdstevel@tonic-gate	    for (i = 0; i < auth_cnt; i++)
13797c478bdstevel@tonic-gate		if (skip_v2authblock() < 0)
13807c478bdstevel@tonic-gate		    return (0);
13817c478bdstevel@tonic-gate#endif
13827c478bdstevel@tonic-gate	} else if (flags & F_DTAIL) {
13837c478bdstevel@tonic-gate	    DOFIELD("URL", FIELD_DEFAULT);
13847c478bdstevel@tonic-gate	    DOFIELD("Scopes",  FIELD_DEFAULT);
13857c478bdstevel@tonic-gate	    DOFIELD("Attribute list", FIELD_DEFAULT);
13867c478bdstevel@tonic-gate	    /* auth */
13877c478bdstevel@tonic-gate	    GETBYTE(auth_cnt);
13887c478bdstevel@tonic-gate	    for (i = 0; i < auth_cnt; i++)
13897c478bdstevel@tonic-gate		V2_DOAUTH(i);
13907c478bdstevel@tonic-gate	}
13917c478bdstevel@tonic-gate
13927c478bdstevel@tonic-gate	return (1);
13937c478bdstevel@tonic-gate}
13947c478bdstevel@tonic-gate
13957c478bdstevel@tonic-gate/*
13967c478bdstevel@tonic-gate * V1 Interpreter
13977c478bdstevel@tonic-gate */
13987c478bdstevel@tonic-gate
13997c478bdstevel@tonic-gatestatic int interpret_slp_v1(int flags, struct slpv1_hdr *slp, int fraglen) {
14007c478bdstevel@tonic-gate	char msgbuf_real[256];
14017c478bdstevel@tonic-gate	extern int src_port, dst_port, curr_proto;
14027c478bdstevel@tonic-gate	boolean_t overflow	= B_FALSE;
14037c478bdstevel@tonic-gate
14047c478bdstevel@tonic-gate	msgbuf = msgbuf_real;
14057c478bdstevel@tonic-gate
14067c478bdstevel@tonic-gate	if (msglength >= sizeof (*slp)) {
14077c478bdstevel@tonic-gate	    if ((slp->flags & V1_URL_AUTH) == V1_URL_AUTH)
14087c478bdstevel@tonic-gate		url_auth = B_TRUE;
14097c478bdstevel@tonic-gate	    if ((slp->flags & V1_ATTR_AUTH) == V1_ATTR_AUTH)
14107c478bdstevel@tonic-gate		attr_auth = B_TRUE;
14117c478bdstevel@tonic-gate	    if ((slp->flags & V1_FRESH_REG) == V1_FRESH_REG)
14127c478bdstevel@tonic-gate		fresh = B_TRUE;
14137c478bdstevel@tonic-gate	    if ((slp->flags & V1_OVERFLOW) == V1_OVERFLOW)
14147c478bdstevel@tonic-gate		overflow = B_TRUE;
14157c478bdstevel@tonic-gate	}
14167c478bdstevel@tonic-gate
14177c478bdstevel@tonic-gate	/*
14187c478bdstevel@tonic-gate	 * Somewhat of a hack to decode traffic from a server that does
14197c478bdstevel@tonic-gate	 * not send udp replies from its SLP src port.
14207c478bdstevel@tonic-gate	 */
14217c478bdstevel@tonic-gate	if (curr_proto == IPPROTO_UDP &&
14227c478bdstevel@tonic-gate	    dst_port == 427 &&
14237c478bdstevel@tonic-gate	    src_port != 427)
1424d6913e0Toomas Soome		add_transient(src_port, interpret_slp);
14257c478bdstevel@tonic-gate
14267c478bdstevel@tonic-gate	/* parse the header */
14277c478bdstevel@tonic-gate	if (v1_header(flags, slp, fraglen)) {
14287c478bdstevel@tonic-gate
14297c478bdstevel@tonic-gate	    if (slp->function <= V1_MAX_FUNCTION && slp->function > 0) {
14307c478bdstevel@tonic-gate
14317c478bdstevel@tonic-gate		/* Parse the message body */
14327c478bdstevel@tonic-gate		(v1_functions[slp->function])(flags);
14337c478bdstevel@tonic-gate
14347c478bdstevel@tonic-gate	    }
14357c478bdstevel@tonic-gate
14367c478bdstevel@tonic-gate	}
14377c478bdstevel@tonic-gate
14387c478bdstevel@tonic-gate	/* summary error check */
14397c478bdstevel@tonic-gate	if (flags & F_SUM) {
14407c478bdstevel@tonic-gate	    if (retlength < 0) {
14417c478bdstevel@tonic-gate		if (curr_proto == IPPROTO_TCP)
14427c478bdstevel@tonic-gate		    sprintf(get_sum_line(),
14437c478bdstevel@tonic-gate			    "%s [partial TCP message]",
14447c478bdstevel@tonic-gate			    msgbuf);
14457c478bdstevel@tonic-gate		else if (overflow)
14467c478bdstevel@tonic-gate		    sprintf(get_sum_line(), "%s [OVERFLOW]", msgbuf);
14477c478bdstevel@tonic-gate		else
14487c478bdstevel@tonic-gate		    sprintf(get_sum_line(), "%s [CORRUPTED MESSAGE]", msgbuf);
14497c478bdstevel@tonic-gate	    }
14507c478bdstevel@tonic-gate#ifdef VERIFYSLP
14517c478bdstevel@tonic-gate	    else if (msglength > 0)
14527c478bdstevel@tonic-gate		sprintf(get_sum_line(), "%s +%d", msgbuf, msglength);
14537c478bdstevel@tonic-gate#endif
14547c478bdstevel@tonic-gate	    else
14557c478bdstevel@tonic-gate		sprintf(get_sum_line(), "%s", msgbuf);
14567c478bdstevel@tonic-gate	} else if (flags & F_DTAIL) {
14577c478bdstevel@tonic-gate	    /* detail error check */
14587c478bdstevel@tonic-gate	    if (msglength > 0) {
14597c478bdstevel@tonic-gate		sprintf(get_line(0, 0),
14607c478bdstevel@tonic-gate			"[%d extra bytes at end of SLP message]", msglength);
14617c478bdstevel@tonic-gate	    }
14627c478bdstevel@tonic-gate
14637c478bdstevel@tonic-gate	    show_trailer();
14647c478bdstevel@tonic-gate
14657c478bdstevel@tonic-gate	}
14667c478bdstevel@tonic-gate
14677c478bdstevel@tonic-gate	v1_charset = 0;
14687c478bdstevel@tonic-gate
14697c478bdstevel@tonic-gate	return (0);
14707c478bdstevel@tonic-gate}
14717c478bdstevel@tonic-gate
14727c478bdstevel@tonic-gatestatic int v1_header(int flags,
14737c478bdstevel@tonic-gate			struct slpv1_hdr *slp,
14747c478bdstevel@tonic-gate			int fraglen) {
14757c478bdstevel@tonic-gate	extern int src_port, dst_port, curr_proto;
14767c478bdstevel@tonic-gate	char *prototag = (curr_proto == IPPROTO_TCP? "/tcp" : "");
14777c478bdstevel@tonic-gate
14787c478bdstevel@tonic-gate	if (flags & F_SUM) {
14797c478bdstevel@tonic-gate	    char portflag = ' ';
14807c478bdstevel@tonic-gate
14817c478bdstevel@tonic-gate	    if (msglength < sizeof (*slp)) {
14827c478bdstevel@tonic-gate		sprintf(msgbuf, "SLP V1 [incomplete header]");
14837c478bdstevel@tonic-gate		return (0);
14847c478bdstevel@tonic-gate	    }
14857c478bdstevel@tonic-gate
14867c478bdstevel@tonic-gate	    if (slp->vers != 1) {
14877c478bdstevel@tonic-gate		if (curr_proto == IPPROTO_TCP)
14887c478bdstevel@tonic-gate		    sprintf(msgbuf, "SLP [TCP Continuation]");
14897c478bdstevel@tonic-gate		else
14907c478bdstevel@tonic-gate		    sprintf(msgbuf, "SLP [unknown version %d]", slp->vers);
14917c478bdstevel@tonic-gate		return (0);
14927c478bdstevel@tonic-gate	    }
14937c478bdstevel@tonic-gate
14947c478bdstevel@tonic-gate	    if (src_port != 427 && dst_port != 427)
14957c478bdstevel@tonic-gate		portflag = '-';
14967c478bdstevel@tonic-gate
14977c478bdstevel@tonic-gate	    sprintf(msgbuf, "SLP V1%c%s [%d%s] ", portflag,
14987c478bdstevel@tonic-gate		    slpv1_func(slp->function, B_TRUE),
14997c478bdstevel@tonic-gate		    ntohs(slp->xid), prototag);
15007c478bdstevel@tonic-gate	    msgend = msgbuf + strlen(msgbuf);
15017c478bdstevel@tonic-gate	    msglength -= sizeof (*slp);
15027c478bdstevel@tonic-gate	    p += sizeof (*slp);
15037c478bdstevel@tonic-gate	} else if (flags & F_DTAIL) {
15047c478bdstevel@tonic-gate	    show_header("SLP:  ", "Service Location Protocol (v1)", fraglen);
15057c478bdstevel@tonic-gate	    show_space();
15067c478bdstevel@tonic-gate
15077c478bdstevel@tonic-gate	    if (msglength < sizeof (*slp)) {
15087c478bdstevel@tonic-gate		sprintf(get_line(0, 0), "==> Incomplete SLP header");
15097c478bdstevel@tonic-gate		return (0);
15107c478bdstevel@tonic-gate	    }
15117c478bdstevel@tonic-gate
15127c478bdstevel@tonic-gate	    sprintf(get_line(0, 0), "Version = %d", slp->vers);
15137c478bdstevel@tonic-gate	    if (slp->vers != 1) {
15147c478bdstevel@tonic-gate		if (curr_proto == IPPROTO_TCP)
15157c478bdstevel@tonic-gate		    sprintf(get_line(0, 0), "==> TCP continuation");
15167c478bdstevel@tonic-gate		else
15177c478bdstevel@tonic-gate		    sprintf(get_line(0, 0), "==> Unexpected version number");
15187c478bdstevel@tonic-gate		return (0);
15197c478bdstevel@tonic-gate	    }
15207c478bdstevel@tonic-gate	    sprintf(get_line(0, 0), "Function = %d, %s",
15217c478bdstevel@tonic-gate		slp->function, slpv1_func(slp->function, B_FALSE));
15227c478bdstevel@tonic-gate	    sprintf(get_line(0, 0), "Message length = %u", ntohs(slp->length));
15237c478bdstevel@tonic-gate
15247c478bdstevel@tonic-gate	    /* flags */
15257c478bdstevel@tonic-gate	    sprintf(get_line(0, 0), "Flags = 0x%02x", slp->flags);
15267c478bdstevel@tonic-gate	    sprintf(get_line(0, 0), "      %s",
15277c478bdstevel@tonic-gate		    getflag(slp->flags, V1_OVERFLOW,
15287c478bdstevel@tonic-gate			    "overflow", "no overflow"));
15297c478bdstevel@tonic-gate	    sprintf(get_line(0, 0), "      %s",
15307c478bdstevel@tonic-gate		    getflag(slp->flags, V1_MONOLINGUAL,
15317c478bdstevel@tonic-gate			    "monolingual", "not monolingual"));
15327c478bdstevel@tonic-gate	    sprintf(get_line(0, 0), "      %s",
15337c478bdstevel@tonic-gate		    getflag(slp->flags, V1_URL_AUTH,
15347c478bdstevel@tonic-gate			    "url authentication", "no url authentication"));
15357c478bdstevel@tonic-gate	    sprintf(get_line(0, 0), "      %s",
15367c478bdstevel@tonic-gate		    getflag(slp->flags, V1_ATTR_AUTH,
15377c478bdstevel@tonic-gate		"attribute authentication", "no attribute authentication"));
15387c478bdstevel@tonic-gate	    sprintf(get_line(0, 0), "      %s",
15397c478bdstevel@tonic-gate		    getflag(slp->flags, V1_FRESH_REG,
15407c478bdstevel@tonic-gate			    "fresh registration", "no fresh registration"));
15417c478bdstevel@tonic-gate	    /* check reserved flags that must be zero */
15427c478bdstevel@tonic-gate	    if ((slp->flags & 7) != 0) {
15437c478bdstevel@tonic-gate		sprintf(get_line(0, 0),
15447c478bdstevel@tonic-gate			"      .... .xxx = %d (reserved flags nonzero)",
15457c478bdstevel@tonic-gate			slp->flags & 7);
15467c478bdstevel@tonic-gate	    }
15477c478bdstevel@tonic-gate	    /* end of flags */
15487c478bdstevel@tonic-gate
15497c478bdstevel@tonic-gate	    sprintf(get_line(0, 0), "Dialect = %u", slp->dialect);
15507c478bdstevel@tonic-gate	    sprintf(get_line(0, 0), "Language = 0x%02x%02x, %c%c",
15517c478bdstevel@tonic-gate		    slp->language[0], slp->language[1],
15527c478bdstevel@tonic-gate		    slp->language[0], slp->language[1]);
15537c478bdstevel@tonic-gate	    v1_charset = ntohs(slp->charset);
15547c478bdstevel@tonic-gate	    sprintf(get_line(0, 0), "Character encoding = %u, %s",
15557c478bdstevel@tonic-gate		    v1_charset,
15567c478bdstevel@tonic-gate		    slpv1_charset(v1_charset));
15577c478bdstevel@tonic-gate	    sprintf(get_line(0, 0), "XID = %u", ntohs(slp->xid));
15587c478bdstevel@tonic-gate
15597c478bdstevel@tonic-gate	    /* set msglength to remaining length of SLP message */
15607c478bdstevel@tonic-gate	    msglength -= sizeof (*slp);
15617c478bdstevel@tonic-gate	    p += sizeof (*slp);
15627c478bdstevel@tonic-gate	}
15637c478bdstevel@tonic-gate
15647c478bdstevel@tonic-gate	return (1);
15657c478bdstevel@tonic-gate}
15667c478bdstevel@tonic-gate
15677c478bdstevel@tonic-gatestatic char *slpv1_func(int t, boolean_t s) {
15687c478bdstevel@tonic-gate	static char buf[128];
15697c478bdstevel@tonic-gate	switch (t) {
15707c478bdstevel@tonic-gate	case V1_SRVREQ:	return s? "SrvRqst"  : "Service Request";
15717c478bdstevel@tonic-gate	case V1_SRVRPLY:	return s? "SrvRply"  : "Service Reply";
15727c478bdstevel@tonic-gate	case V1_SRVREG:	return s? "SrvReg"   : "Service Registration";
15737c478bdstevel@tonic-gate	case V1_SRVDEREG:	return s?
15747c478bdstevel@tonic-gate					"SrvDereg" : "Service Deregistration";
15757c478bdstevel@tonic-gate	case V1_SRVACK:	return s? "SrvAck"   : "Service Acknowledge";
15767c478bdstevel@tonic-gate	case V1_ATTRRQST:	return s? "AttrRqst" : "Attribute Request";
15777c478bdstevel@tonic-gate	case V1_ATTRRPLY:	return s? "AttrRply" : "Attribute Reply";
15787c478bdstevel@tonic-gate	case V1_DAADVERT:	return s? "DAAdvert" : "DA advertisement";
15797c478bdstevel@tonic-gate	case V1_SRVTYPERQST:return s? "SrvTypeRqst" : "Service Type Request";
15807c478bdstevel@tonic-gate	case V1_SRVTYPERPLY:return s? "SrvTypeRply" : "Service Type Reply";
15817c478bdstevel@tonic-gate	}
15827c478bdstevel@tonic-gate	sprintf(buf, "(func %d)", t);
15837c478bdstevel@tonic-gate	return (s ? buf : "unknown function");
15847c478bdstevel@tonic-gate}
15857c478bdstevel@tonic-gate
15867c478bdstevel@tonic-gatestatic char *slpv1_error(unsigned short code) {
15877c478bdstevel@tonic-gate	static char buf[128];
15887c478bdstevel@tonic-gate
15897c478bdstevel@tonic-gate	switch (code) {
15907c478bdstevel@tonic-gate	    case OK:			return "ok";
15917c478bdstevel@tonic-gate	    case LANG_NOT_SUPPORTED:	return "language not supported";
15927c478bdstevel@tonic-gate	    case PROTOCOL_PARSE_ERR:	return "protocol parse error";
15937c478bdstevel@tonic-gate	    case INVALID_REGISTRATION:	return "invalid registration";
15947c478bdstevel@tonic-gate	    case SCOPE_NOT_SUPPORTED:	return "scope not supported";
15957c478bdstevel@tonic-gate	    case CHARSET_NOT_UNDERSTOOD:return "character set not understood";
15967c478bdstevel@tonic-gate	    case AUTHENTICATION_INVALID:return "invalid authentication";
15977c478bdstevel@tonic-gate	    case NOT_SUPPORTED_YET:	return "not yet supported";
15987c478bdstevel@tonic-gate	    case REQUEST_TIMED_OUT:	return "request timed out";
15997c478bdstevel@tonic-gate	    case COULD_NOT_INIT_NET_RESOURCES:
16007c478bdstevel@tonic-gate				return ("could not initialize net resources");
16017c478bdstevel@tonic-gate	    case COULD_NOT_ALLOCATE_MEMORY:
16027c478bdstevel@tonic-gate					return ("could not allocate memory");
16037c478bdstevel@tonic-gate	    case PARAMETER_BAD:		return "bad parameter";
16047c478bdstevel@tonic-gate	    case INTERNAL_NET_ERROR:	return "internal network error";
16057c478bdstevel@tonic-gate	    case INTERNAL_SYSTEM_ERROR:	return "internal system error";
16067c478bdstevel@tonic-gate	}
16077c478bdstevel@tonic-gate	sprintf(buf, "error %d", code);
16087c478bdstevel@tonic-gate	return (buf);
16097c478bdstevel@tonic-gate}
16107c478bdstevel@tonic-gate
16117c478bdstevel@tonic-gate/*
16127c478bdstevel@tonic-gate *  Character set info from
16137c478bdstevel@tonic-gate *    www.isi.edu/in-notes/iana/assignments/character-sets
16147c478bdstevel@tonic-gate *
16157c478bdstevel@tonic-gate *	Assigned MIB enum Numbers
16167c478bdstevel@tonic-gate *	-------------------------
16177c478bdstevel@tonic-gate *	0               Reserved
16187c478bdstevel@tonic-gate *	1               Reserved
16197c478bdstevel@tonic-gate *	3-106           Set By Standards Organizations
16207c478bdstevel@tonic-gate *	1000-1010       Unicode / 10646
16217c478bdstevel@tonic-gate *	2000-2087       Vendor
16227c478bdstevel@tonic-gate *	2250-2258       Vendor
16237c478bdstevel@tonic-gate *
16247c478bdstevel@tonic-gate *	MIBenum: 3
16257c478bdstevel@tonic-gate *	Alias: US-ASCII (preferred MIME name)
16267c478bdstevel@tonic-gate *	Source: ECMA registry [RFC1345]
16277c478bdstevel@tonic-gate *
16287c478bdstevel@tonic-gate *	MIBenum: 106
16297c478bdstevel@tonic-gate *	Name: UTF-8
16307c478bdstevel@tonic-gate *	Source: RFC 2044
16317c478bdstevel@tonic-gate */
16327c478bdstevel@tonic-gate
16337c478bdstevel@tonic-gatestatic char *slpv1_charset(unsigned short code) {
16347c478bdstevel@tonic-gate	if (code <= 1)
16357c478bdstevel@tonic-gate	    return ("Reserved");
16367c478bdstevel@tonic-gate	if (code == 3)
16377c478bdstevel@tonic-gate	    return ("US-ASCII");
16387c478bdstevel@tonic-gate	if (code == 4)
16397c478bdstevel@tonic-gate	    return ("latin1");
16407c478bdstevel@tonic-gate	if (code == 106)
16417c478bdstevel@tonic-gate	    return ("UTF-8");
16427c478bdstevel@tonic-gate	if (code >= 3 && code <= 106)
16437c478bdstevel@tonic-gate	    return ("set by standards organization");
16447c478bdstevel@tonic-gate	if (code >= 1000 && code <= 1010)
16457c478bdstevel@tonic-gate	    return ("Unicode variant");
16467c478bdstevel@tonic-gate	if ((code >= 2000 && code <= 2087) ||
16477c478bdstevel@tonic-gate	    (code >= 2250 && code <= 2258))
16487c478bdstevel@tonic-gate	    return ("Vendor assigned");
16497c478bdstevel@tonic-gate
16507c478bdstevel@tonic-gate	return ("unknown");
16517c478bdstevel@tonic-gate}
16527c478bdstevel@tonic-gate
16537c478bdstevel@tonic-gate#ifdef VERIFYSLP
16547c478bdstevel@tonic-gatestatic int skip_v1authblock() {
16557c478bdstevel@tonic-gate	unsigned short length;
16567c478bdstevel@tonic-gate
16577c478bdstevel@tonic-gate	/* auth header: 12 bytes total */
16587c478bdstevel@tonic-gate	if (msglength < 12)
16597c478bdstevel@tonic-gate	    return (-1);
16607c478bdstevel@tonic-gate
16617c478bdstevel@tonic-gate	/* timestamp: 8 bytes */
16627c478bdstevel@tonic-gate	p += 8;			/* timestamp: 8 bytes */
16637c478bdstevel@tonic-gate	p += sizeof (short);		/* block descriptor: 2 bytes */
16647c478bdstevel@tonic-gate	nbtohs();
16657c478bdstevel@tonic-gate	length = netval;
16667c478bdstevel@tonic-gate	p += sizeof (short);
16677c478bdstevel@tonic-gate	msglength -= 12;
16687c478bdstevel@tonic-gate
16697c478bdstevel@tonic-gate	if (length > msglength) {
16707c478bdstevel@tonic-gate	    /* framing error: message is not long enough to contain data */
16717c478bdstevel@tonic-gate	    return (-1);
16727c478bdstevel@tonic-gate	}
16737c478bdstevel@tonic-gate
16747c478bdstevel@tonic-gate	p += length;
16757c478bdstevel@tonic-gate	msglength -= length;
16767c478bdstevel@tonic-gate	return (0);
16777c478bdstevel@tonic-gate}
16787c478bdstevel@tonic-gate#endif
16797c478bdstevel@tonic-gate
16807c478bdstevel@tonic-gatestatic int slpv1_authblock() {
16817c478bdstevel@tonic-gate	unsigned short bsd, length;
16827c478bdstevel@tonic-gate	char msgbuf[128];
16837c478bdstevel@tonic-gate	int n;
16847c478bdstevel@tonic-gate
16857c478bdstevel@tonic-gate	if (msglength < 12) {
16867c478bdstevel@tonic-gate	    sprintf(get_line(0, 0),
16877c478bdstevel@tonic-gate		    "  [no room for auth block: remaining msg length = %u]",
16887c478bdstevel@tonic-gate		    msglength);
16897c478bdstevel@tonic-gate	    return (-1);
16907c478bdstevel@tonic-gate	}
16917c478bdstevel@tonic-gate
16927c478bdstevel@tonic-gate	/* timestamp: 8 bytes */
16937c478bdstevel@tonic-gate	*msgbuf = '\0';
16947c478bdstevel@tonic-gate	for (n = 0; n < 8; n++, p += 1) {
16957c478bdstevel@tonic-gate	    char tmp[16];
16967c478bdstevel@tonic-gate	    sprintf(tmp, "%02x", (unsigned char)(*p));
16977c478bdstevel@tonic-gate	    strcat(msgbuf, tmp);
16987c478bdstevel@tonic-gate	}
16997c478bdstevel@tonic-gate
17007c478bdstevel@tonic-gate	nbtohs();
17017c478bdstevel@tonic-gate	bsd = netval;
17027c478bdstevel@tonic-gate	p += sizeof (short);
17037c478bdstevel@tonic-gate	nbtohs();
17047c478bdstevel@tonic-gate	length = netval;
17057c478bdstevel@tonic-gate	p += sizeof (short);
17067c478bdstevel@tonic-gate	msglength -= 12;
17077c478bdstevel@tonic-gate
17087c478bdstevel@tonic-gate	sprintf(get_line(0, 0),
17097c478bdstevel@tonic-gate		"  Auth block: timestamp = %s",
17107c478bdstevel@tonic-gate		msgbuf);
17117c478bdstevel@tonic-gate	sprintf(get_line(0, 0),
17127c478bdstevel@tonic-gate		"              block desc = 0x%04x, length = %u",
17137c478bdstevel@tonic-gate		bsd, length);
17147c478bdstevel@tonic-gate	if (length > msglength) {
17157c478bdstevel@tonic-gate	    /* framing error: message is not long enough to contain data */
17167c478bdstevel@tonic-gate	    sprintf(get_line(0, 0),
17177c478bdstevel@tonic-gate		"  [Framing error: remaining pkt length = %u]",  msglength);
17187c478bdstevel@tonic-gate	    return (-1);
17197c478bdstevel@tonic-gate	}
17207c478bdstevel@tonic-gate
17217c478bdstevel@tonic-gate	p += length;
17227c478bdstevel@tonic-gate	msglength -= length;
17237c478bdstevel@tonic-gate	return (0);
17247c478bdstevel@tonic-gate}
17257c478bdstevel@tonic-gate
17267c478bdstevel@tonic-gatestatic int slpv1_url(boolean_t auth_present) {
17277c478bdstevel@tonic-gate	time_t exp;
17287c478bdstevel@tonic-gate	int lifetime, length;
17297c478bdstevel@tonic-gate
17307c478bdstevel@tonic-gate	get_short();
17317c478bdstevel@tonic-gate	if ((lifetime = netval) < 0)
17327c478bdstevel@tonic-gate	    return (-1);
17337c478bdstevel@tonic-gate	get_short();
17347c478bdstevel@tonic-gate	if ((length = netval) < 0)
17357c478bdstevel@tonic-gate	    return (-1);
17367c478bdstevel@tonic-gate
17377c478bdstevel@tonic-gate	exp = time(0) + lifetime;
17387c478bdstevel@tonic-gate	sprintf(get_line(0, 0), "URL: length = %u, lifetime = %d (%24.24s)",
17397c478bdstevel@tonic-gate		length, lifetime, ctime(&exp));
17407c478bdstevel@tonic-gate	if (length > msglength) {
17417c478bdstevel@tonic-gate	    /* framing error: message is not long enough to contain data */
17427c478bdstevel@tonic-gate	    sprintf(get_line(0, 0),
17437c478bdstevel@tonic-gate		"  [Framing error: remaining pkt length = %u]",  msglength);
17447c478bdstevel@tonic-gate	    return (-1);
17457c478bdstevel@tonic-gate	}
17467c478bdstevel@tonic-gate
17477c478bdstevel@tonic-gate	if (length > 0) {
17487c478bdstevel@tonic-gate	    char *buf = malloc(length + 1);
17497c478bdstevel@tonic-gate	    if (buf != NULL) {
17507c478bdstevel@tonic-gate		if (!make_utf8(buf, length, p, length)) {
17517c478bdstevel@tonic-gate			strcpy(buf, "[Invalid Character Encoding]");
17527c478bdstevel@tonic-gate		}
17537c478bdstevel@tonic-gate		sprintf(get_line(0, 0), "  \"%s\"", buf);
17547c478bdstevel@tonic-gate		free(buf);
17557c478bdstevel@tonic-gate	    }
17567c478bdstevel@tonic-gate	}
17577c478bdstevel@tonic-gate	msglength -= length;
17587c478bdstevel@tonic-gate	p += length;
17597c478bdstevel@tonic-gate
17607c478bdstevel@tonic-gate	if (auth_present)
17617c478bdstevel@tonic-gate	    return (slpv1_authblock());
17627c478bdstevel@tonic-gate
17637c478bdstevel@tonic-gate	return (0);
17647c478bdstevel@tonic-gate}
17657c478bdstevel@tonic-gate
17667c478bdstevel@tonic-gatestatic int v1_srv_rqst(int flags) {
17677c478bdstevel@tonic-gate	if (flags & F_SUM) {
17687c478bdstevel@tonic-gate	    SKIPFIELD(FIELD_PREVRESP);	/* prev responders */
17697c478bdstevel@tonic-gate	    GETFIELD;			/* predicate */
17707c478bdstevel@tonic-gate	} else if (flags & F_DTAIL) {
17717c478bdstevel@tonic-gate	    DOFIELD("Previous responders", FIELD_PREVRESP);
17727c478bdstevel@tonic-gate	    DOFIELD("predicate string", FIELD_DEFAULT);
17737c478bdstevel@tonic-gate	}
17747c478bdstevel@tonic-gate
17757c478bdstevel@tonic-gate	return (1);
17767c478bdstevel@tonic-gate}
17777c478bdstevel@tonic-gate
17787c478bdstevel@tonic-gatestatic int v1_srv_rply(int flags) {
17797c478bdstevel@tonic-gate	unsigned short errcode, itemcnt;
17807c478bdstevel@tonic-gate	int n;
17817c478bdstevel@tonic-gate
17827c478bdstevel@tonic-gate	if (flags & F_SUM) {
17837c478bdstevel@tonic-gate	    GETSHORT(errcode);
17847c478bdstevel@tonic-gate	    if (errcode != OK) {
17857c478bdstevel@tonic-gate		strcat(msgbuf, slpv1_error(errcode));
17867c478bdstevel@tonic-gate	    } else {
17877c478bdstevel@tonic-gate		GETSHORT(itemcnt);
17887c478bdstevel@tonic-gate		sprintf(msgend, "%d URL entries", itemcnt);
17897c478bdstevel@tonic-gate#ifdef VERIFYSLP
17907c478bdstevel@tonic-gate		for (n = 0; n < itemcnt; n++) {
17917c478bdstevel@tonic-gate		    SKIPSHORT;		/* lifetime */
17927c478bdstevel@tonic-gate		    SKIPFIELD(FIELD_DEFAULT);	/* URL */
17937c478bdstevel@tonic-gate		    SKIPAUTH(url_auth);		/* URL auth */
17947c478bdstevel@tonic-gate		}
17957c478bdstevel@tonic-gate#endif
17967c478bdstevel@tonic-gate	    }
17977c478bdstevel@tonic-gate	} else if (flags & F_DTAIL) {
17987c478bdstevel@tonic-gate	    DOERRCODE;
17997c478bdstevel@tonic-gate	    GETSHORT(itemcnt);
18007c478bdstevel@tonic-gate	    sprintf(get_line(0, 0), "URL entry count = %d", itemcnt);
18017c478bdstevel@tonic-gate	    for (n = 0; n < itemcnt; n++) {
18027c478bdstevel@tonic-gate		DOURL;
18037c478bdstevel@tonic-gate	    }
18047c478bdstevel@tonic-gate	}
18057c478bdstevel@tonic-gate
18067c478bdstevel@tonic-gate	return (1);
18077c478bdstevel@tonic-gate}
18087c478bdstevel@tonic-gate
18097c478bdstevel@tonic-gatestatic int v1_srv_reg(int flags) {
18107c478bdstevel@tonic-gate	if (flags & F_SUM) {
18117c478bdstevel@tonic-gate	    SKIPSHORT;			/* lifetime */
18127c478bdstevel@tonic-gate	    GETFIELD;			/* URL */
18137c478bdstevel@tonic-gate#ifdef VERIFYSLP
18147c478bdstevel@tonic-gate	    SKIPAUTH(url_auth);		/* URL auth */
18157c478bdstevel@tonic-gate	    SKIPFIELD(FIELD_DEFAULT);	/* attribute list */
18167c478bdstevel@tonic-gate	    SKIPAUTH(attr_auth);		/* attr auth */
18177c478bdstevel@tonic-gate#endif
18187c478bdstevel@tonic-gate	} else if (flags & F_DTAIL) {
18197c478bdstevel@tonic-gate	    DOURL;
18207c478bdstevel@tonic-gate	    DOFIELD("Attribute list", FIELD_DEFAULT);
18217c478bdstevel@tonic-gate	    DOAUTH(attr_auth);
18227c478bdstevel@tonic-gate	}
18237c478bdstevel@tonic-gate
18247c478bdstevel@tonic-gate	return (1);
18257c478bdstevel@tonic-gate}
18267c478bdstevel@tonic-gate
18277c478bdstevel@tonic-gatestatic int v1_srv_ack(int flags) {
18287c478bdstevel@tonic-gate	unsigned short errcode;
18297c478bdstevel@tonic-gate
18307c478bdstevel@tonic-gate	if (flags & F_SUM) {
18317c478bdstevel@tonic-gate	    GETSHORT(errcode);
18327c478bdstevel@tonic-gate	    strcat(msgbuf, slpv1_error(errcode));
18337c478bdstevel@tonic-gate	    if (errcode == OK && fresh) {
18347c478bdstevel@tonic-gate		strcat(msgbuf, " [Fresh]");
18357c478bdstevel@tonic-gate	    }
18367c478bdstevel@tonic-gate	} else if (flags & F_DTAIL) {
18377c478bdstevel@tonic-gate	    DOERRCODE;
18387c478bdstevel@tonic-gate	}
18397c478bdstevel@tonic-gate
18407c478bdstevel@tonic-gate	return (1);
18417c478bdstevel@tonic-gate}
18427c478bdstevel@tonic-gate
18437c478bdstevel@tonic-gatestatic int v1_srv_dereg(int flags) {
18447c478bdstevel@tonic-gate	if (flags & F_SUM) {
18457c478bdstevel@tonic-gate	    GETFIELD;			/* URL */
18467c478bdstevel@tonic-gate#ifdef VERIFYSLP
18477c478bdstevel@tonic-gate	    SKIPAUTH(url_auth);
18487c478bdstevel@tonic-gate	    SKIPFIELD(FIELD_DEFAULT);	/* tag spec */
18497c478bdstevel@tonic-gate#endif
18507c478bdstevel@tonic-gate	} else if (flags & F_DTAIL) {
18517c478bdstevel@tonic-gate	    DOFIELD("URL", FIELD_DEFAULT);
18527c478bdstevel@tonic-gate	    DOAUTH(url_auth);
18537c478bdstevel@tonic-gate	    DOFIELD("Tag spec", FIELD_DEFAULT);
18547c478bdstevel@tonic-gate	}
18557c478bdstevel@tonic-gate
18567c478bdstevel@tonic-gate	return (1);
18577c478bdstevel@tonic-gate}
18587c478bdstevel@tonic-gate
18597c478bdstevel@tonic-gatestatic int v1_attr_rqst(int flags) {
18607c478bdstevel@tonic-gate	if (flags & F_SUM) {
18617c478bdstevel@tonic-gate	    SKIPFIELD(FIELD_PREVRESP);	/* prev responders */
18627c478bdstevel@tonic-gate	    GETFIELD;			/* URL */
18637c478bdstevel@tonic-gate#ifdef VERIFYSLP
18647c478bdstevel@tonic-gate	    SKIPFIELD(FIELD_DEFAULT);	/* scope */
18657c478bdstevel@tonic-gate	    SKIPFIELD(FIELD_DEFAULT);	/* select list */
18667c478bdstevel@tonic-gate#endif
18677c478bdstevel@tonic-gate	} else if (flags & F_DTAIL) {
18687c478bdstevel@tonic-gate	    DOFIELD("Previous responders", FIELD_PREVRESP);
18697c478bdstevel@tonic-gate	    DOFIELD("URL", FIELD_DEFAULT);
18707c478bdstevel@tonic-gate	    DOFIELD("Scope", FIELD_DEFAULT);
18717c478bdstevel@tonic-gate	    DOFIELD("Select list", FIELD_DEFAULT);
18727c478bdstevel@tonic-gate	}
18737c478bdstevel@tonic-gate
18747c478bdstevel@tonic-gate	return (1);
18757c478bdstevel@tonic-gate}
18767c478bdstevel@tonic-gate
18777c478bdstevel@tonic-gatestatic int v1_attr_rply(int flags) {
18787c478bdstevel@tonic-gate	unsigned short errcode;
18797c478bdstevel@tonic-gate
18807c478bdstevel@tonic-gate	if (flags & F_SUM) {
18817c478bdstevel@tonic-gate	    GETSHORT(errcode);
18827c478bdstevel@tonic-gate	    if (errcode != OK) {
18837c478bdstevel@tonic-gate		strcat(msgbuf, slpv1_error(errcode));
18847c478bdstevel@tonic-gate	    } else {
18857c478bdstevel@tonic-gate		GETFIELD;			/* attr list */
18867c478bdstevel@tonic-gate#ifdef VERIFYSLP
18877c478bdstevel@tonic-gate		SKIPAUTH(attr_auth);
18887c478bdstevel@tonic-gate#endif
18897c478bdstevel@tonic-gate	    }
18907c478bdstevel@tonic-gate	} else if (flags & F_DTAIL) {
18917c478bdstevel@tonic-gate	    DOERRCODE;
18927c478bdstevel@tonic-gate	    DOFIELD("Attribute list", FIELD_DEFAULT);
18937c478bdstevel@tonic-gate	    DOAUTH(attr_auth);
18947c478bdstevel@tonic-gate	}
18957c478bdstevel@tonic-gate
18967c478bdstevel@tonic-gate	return (1);
18977c478bdstevel@tonic-gate}
18987c478bdstevel@tonic-gate
18997c478bdstevel@tonic-gatestatic int v1_daadvert(int flags) {
19007c478bdstevel@tonic-gate	unsigned short errcode;
19017c478bdstevel@tonic-gate
19027c478bdstevel@tonic-gate	if (flags & F_SUM) {
19037c478bdstevel@tonic-gate	    GETSHORT(errcode);
19047c478bdstevel@tonic-gate	    if (errcode != OK) {
19057c478bdstevel@tonic-gate		strcat(msgbuf, slpv1_error(errcode));
19067c478bdstevel@tonic-gate	    } else {
19077c478bdstevel@tonic-gate		    GETFIELD;			/* URL */
19087c478bdstevel@tonic-gate#ifdef VERIFYSLP
19097c478bdstevel@tonic-gate		    SKIPFIELD(FIELD_DEFAULT);	/* scope list */
19107c478bdstevel@tonic-gate#endif
19117c478bdstevel@tonic-gate	    }
19127c478bdstevel@tonic-gate	} else if (flags & F_DTAIL) {
19137c478bdstevel@tonic-gate	    DOERRCODE;
19147c478bdstevel@tonic-gate	    DOFIELD("URL", FIELD_DEFAULT);
19157c478bdstevel@tonic-gate	    DOFIELD("Scope list", FIELD_DEFAULT);
19167c478bdstevel@tonic-gate	}
19177c478bdstevel@tonic-gate
19187c478bdstevel@tonic-gate	return (1);
19197c478bdstevel@tonic-gate}
19207c478bdstevel@tonic-gate
19217c478bdstevel@tonic-gatestatic int v1_srv_type_rqst(int flags) {
19227c478bdstevel@tonic-gate	if (flags & F_SUM) {
19237c478bdstevel@tonic-gate	    SKIPFIELD(FIELD_PREVRESP);	/* prev responders */
19247c478bdstevel@tonic-gate	    SKIPFIELD(FIELD_TYPENA);	/* naming authority */
19257c478bdstevel@tonic-gate	    GETFIELD;			/* scope */
19267c478bdstevel@tonic-gate	} else if (flags & F_DTAIL) {
19277c478bdstevel@tonic-gate	    DOFIELD("Previous responders", FIELD_PREVRESP);
19287c478bdstevel@tonic-gate	    DOFIELD("Naming authority", FIELD_TYPENA);
19297c478bdstevel@tonic-gate	    DOFIELD("Scope string", FIELD_DEFAULT);
19307c478bdstevel@tonic-gate	}
19317c478bdstevel@tonic-gate
19327c478bdstevel@tonic-gate	return (1);
19337c478bdstevel@tonic-gate}
19347c478bdstevel@tonic-gate
19357c478bdstevel@tonic-gatestatic int v1_srv_type_rply(int flags) {
19367c478bdstevel@tonic-gate	unsigned short errcode, itemcnt;
19377c478bdstevel@tonic-gate	int n;
19387c478bdstevel@tonic-gate
19397c478bdstevel@tonic-gate	if (flags & F_SUM) {
19407c478bdstevel@tonic-gate	    GETSHORT(errcode);
19417c478bdstevel@tonic-gate	    if (errcode != OK) {
19427c478bdstevel@tonic-gate		strcat(msgbuf, slpv1_error(errcode));
19437c478bdstevel@tonic-gate	    } else {
19447c478bdstevel@tonic-gate		GETSHORT(itemcnt);
19457c478bdstevel@tonic-gate		sprintf(msgend, "%d type entries", itemcnt);
19467c478bdstevel@tonic-gate#ifdef VERIFYSLP
19477c478bdstevel@tonic-gate		for (n = 0; n < itemcnt; n++) {
19487c478bdstevel@tonic-gate		    SKIPFIELD(FIELD_DEFAULT);  /* Service type item */
19497c478bdstevel@tonic-gate		}
19507c478bdstevel@tonic-gate#endif
19517c478bdstevel@tonic-gate	    }
19527c478bdstevel@tonic-gate	} else if (flags & F_DTAIL) {
19537c478bdstevel@tonic-gate	    DOERRCODE;
19547c478bdstevel@tonic-gate	    GETSHORT(itemcnt);
19557c478bdstevel@tonic-gate	    sprintf(get_line(0, 0), "Service type count = %d", itemcnt);
19567c478bdstevel@tonic-gate	    for (n = 0; n < itemcnt; n++) {
19577c478bdstevel@tonic-gate		DOFIELD("  Service type item", FIELD_DEFAULT);
19587c478bdstevel@tonic-gate	    }
19597c478bdstevel@tonic-gate	}
19607c478bdstevel@tonic-gate
19617c478bdstevel@tonic-gate	return (1);
19627c478bdstevel@tonic-gate}
1963