xref: /titanic_52/usr/src/lib/libresolv/res_comp.c (revision 7c478bd95313f5f23a4c958a745db2134aa03244)
1*7c478bd9Sstevel@tonic-gate /*
2*7c478bd9Sstevel@tonic-gate  * CDDL HEADER START
3*7c478bd9Sstevel@tonic-gate  *
4*7c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*7c478bd9Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
6*7c478bd9Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
7*7c478bd9Sstevel@tonic-gate  * with the License.
8*7c478bd9Sstevel@tonic-gate  *
9*7c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10*7c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
11*7c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
12*7c478bd9Sstevel@tonic-gate  * and limitations under the License.
13*7c478bd9Sstevel@tonic-gate  *
14*7c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
15*7c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16*7c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
17*7c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
18*7c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
19*7c478bd9Sstevel@tonic-gate  *
20*7c478bd9Sstevel@tonic-gate  * CDDL HEADER END
21*7c478bd9Sstevel@tonic-gate  */
22*7c478bd9Sstevel@tonic-gate /*
23*7c478bd9Sstevel@tonic-gate  * Copyright 1996 Sun Microsystems, Inc.  All rights reserved.
24*7c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
25*7c478bd9Sstevel@tonic-gate  */
26*7c478bd9Sstevel@tonic-gate 
27*7c478bd9Sstevel@tonic-gate /*	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T	*/
28*7c478bd9Sstevel@tonic-gate /*	  All Rights Reserved  	*/
29*7c478bd9Sstevel@tonic-gate 
30*7c478bd9Sstevel@tonic-gate /*
31*7c478bd9Sstevel@tonic-gate  * University Copyright- Copyright (c) 1982, 1986, 1988
32*7c478bd9Sstevel@tonic-gate  * The Regents of the University of California
33*7c478bd9Sstevel@tonic-gate  * All Rights Reserved
34*7c478bd9Sstevel@tonic-gate  *
35*7c478bd9Sstevel@tonic-gate  * University Acknowledgment- Portions of this document are derived from
36*7c478bd9Sstevel@tonic-gate  * software developed by the University of California, Berkeley, and its
37*7c478bd9Sstevel@tonic-gate  * contributors.
38*7c478bd9Sstevel@tonic-gate  */
39*7c478bd9Sstevel@tonic-gate 
40*7c478bd9Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
41*7c478bd9Sstevel@tonic-gate 
42*7c478bd9Sstevel@tonic-gate #include "synonyms.h"
43*7c478bd9Sstevel@tonic-gate 
44*7c478bd9Sstevel@tonic-gate #include <sys/types.h>
45*7c478bd9Sstevel@tonic-gate #include <stdio.h>
46*7c478bd9Sstevel@tonic-gate #include <arpa/nameser.h>
47*7c478bd9Sstevel@tonic-gate 
48*7c478bd9Sstevel@tonic-gate static dn_find();
49*7c478bd9Sstevel@tonic-gate 
50*7c478bd9Sstevel@tonic-gate 
51*7c478bd9Sstevel@tonic-gate /*
52*7c478bd9Sstevel@tonic-gate  * Expand compressed domain name 'comp_dn' to full domain name.
53*7c478bd9Sstevel@tonic-gate  * 'msg' is a pointer to the begining of the message,
54*7c478bd9Sstevel@tonic-gate  * 'eomorig' points to the first location after the message,
55*7c478bd9Sstevel@tonic-gate  * 'exp_dn' is a pointer to a buffer of size 'length' for the result.
56*7c478bd9Sstevel@tonic-gate  * Return size of compressed name or -1 if there was an error.
57*7c478bd9Sstevel@tonic-gate  */
58*7c478bd9Sstevel@tonic-gate dn_expand(msg, eomorig, comp_dn, exp_dn, length)
59*7c478bd9Sstevel@tonic-gate 	u_char *msg, *eomorig, *comp_dn, *exp_dn;
60*7c478bd9Sstevel@tonic-gate 	int length;
61*7c478bd9Sstevel@tonic-gate {
62*7c478bd9Sstevel@tonic-gate 	register u_char *cp, *dn;
63*7c478bd9Sstevel@tonic-gate 	register int n, c;
64*7c478bd9Sstevel@tonic-gate 	u_char *eom;
65*7c478bd9Sstevel@tonic-gate 	int len = -1, checked = 0;
66*7c478bd9Sstevel@tonic-gate 
67*7c478bd9Sstevel@tonic-gate 	dn = exp_dn;
68*7c478bd9Sstevel@tonic-gate 	cp = comp_dn;
69*7c478bd9Sstevel@tonic-gate 	eom = exp_dn + length;
70*7c478bd9Sstevel@tonic-gate 	/*
71*7c478bd9Sstevel@tonic-gate 	 * fetch next label in domain name
72*7c478bd9Sstevel@tonic-gate 	 */
73*7c478bd9Sstevel@tonic-gate 	while (n = *cp++) {
74*7c478bd9Sstevel@tonic-gate 		/*
75*7c478bd9Sstevel@tonic-gate 		 * Check for indirection
76*7c478bd9Sstevel@tonic-gate 		 */
77*7c478bd9Sstevel@tonic-gate 		switch (n & INDIR_MASK) {
78*7c478bd9Sstevel@tonic-gate 		case 0:
79*7c478bd9Sstevel@tonic-gate 			if (dn != exp_dn) {
80*7c478bd9Sstevel@tonic-gate 				if (dn >= eom)
81*7c478bd9Sstevel@tonic-gate 					return (-1);
82*7c478bd9Sstevel@tonic-gate 				*dn++ = '.';
83*7c478bd9Sstevel@tonic-gate 			}
84*7c478bd9Sstevel@tonic-gate 			if (dn+n >= eom)
85*7c478bd9Sstevel@tonic-gate 				return (-1);
86*7c478bd9Sstevel@tonic-gate 			checked += n + 1;
87*7c478bd9Sstevel@tonic-gate 			while (--n >= 0) {
88*7c478bd9Sstevel@tonic-gate 				if ((c = *cp++) == '.') {
89*7c478bd9Sstevel@tonic-gate 					if (dn + n + 2 >= eom)
90*7c478bd9Sstevel@tonic-gate 						return (-1);
91*7c478bd9Sstevel@tonic-gate 					*dn++ = '\\';
92*7c478bd9Sstevel@tonic-gate 				}
93*7c478bd9Sstevel@tonic-gate 				*dn++ = c;
94*7c478bd9Sstevel@tonic-gate 				if (cp >= eomorig)	/* out of range */
95*7c478bd9Sstevel@tonic-gate 					return (-1);
96*7c478bd9Sstevel@tonic-gate 			}
97*7c478bd9Sstevel@tonic-gate 			break;
98*7c478bd9Sstevel@tonic-gate 
99*7c478bd9Sstevel@tonic-gate 		case INDIR_MASK:
100*7c478bd9Sstevel@tonic-gate 			if (len < 0)
101*7c478bd9Sstevel@tonic-gate 				len = cp - comp_dn + 1;
102*7c478bd9Sstevel@tonic-gate 			cp = msg + (((n & 0x3f) << 8) | (*cp & 0xff));
103*7c478bd9Sstevel@tonic-gate 			if (cp < msg || cp >= eomorig)	/* out of range */
104*7c478bd9Sstevel@tonic-gate 				return (-1);
105*7c478bd9Sstevel@tonic-gate 			checked += 2;
106*7c478bd9Sstevel@tonic-gate 			/*
107*7c478bd9Sstevel@tonic-gate 			 * Check for loops in the compressed name;
108*7c478bd9Sstevel@tonic-gate 			 * if we've looked at the whole message,
109*7c478bd9Sstevel@tonic-gate 			 * there must be a loop.
110*7c478bd9Sstevel@tonic-gate 			 */
111*7c478bd9Sstevel@tonic-gate 			if (checked >= eomorig - msg)
112*7c478bd9Sstevel@tonic-gate 				return (-1);
113*7c478bd9Sstevel@tonic-gate 			break;
114*7c478bd9Sstevel@tonic-gate 
115*7c478bd9Sstevel@tonic-gate 		default:
116*7c478bd9Sstevel@tonic-gate 			return (-1);			/* flag error */
117*7c478bd9Sstevel@tonic-gate 		}
118*7c478bd9Sstevel@tonic-gate 	}
119*7c478bd9Sstevel@tonic-gate 	*dn = '\0';
120*7c478bd9Sstevel@tonic-gate 	if (len < 0)
121*7c478bd9Sstevel@tonic-gate 		len = cp - comp_dn;
122*7c478bd9Sstevel@tonic-gate 	return (len);
123*7c478bd9Sstevel@tonic-gate }
124*7c478bd9Sstevel@tonic-gate 
125*7c478bd9Sstevel@tonic-gate /*
126*7c478bd9Sstevel@tonic-gate  * Compress domain name 'exp_dn' into 'comp_dn'.
127*7c478bd9Sstevel@tonic-gate  * Return the size of the compressed name or -1.
128*7c478bd9Sstevel@tonic-gate  * 'length' is the size of the array pointed to by 'comp_dn'.
129*7c478bd9Sstevel@tonic-gate  * 'dnptrs' is a list of pointers to previous compressed names. dnptrs[0]
130*7c478bd9Sstevel@tonic-gate  * is a pointer to the beginning of the message. The list ends with NULL.
131*7c478bd9Sstevel@tonic-gate  * 'lastdnptr' is a pointer to the end of the arrary pointed to
132*7c478bd9Sstevel@tonic-gate  * by 'dnptrs'. Side effect is to update the list of pointers for
133*7c478bd9Sstevel@tonic-gate  * labels inserted into the message as we compress the name.
134*7c478bd9Sstevel@tonic-gate  * If 'dnptr' is NULL, we don't try to compress names. If 'lastdnptr'
135*7c478bd9Sstevel@tonic-gate  * is NULL, we don't update the list.
136*7c478bd9Sstevel@tonic-gate  */
137*7c478bd9Sstevel@tonic-gate dn_comp(exp_dn, comp_dn, length, dnptrs, lastdnptr)
138*7c478bd9Sstevel@tonic-gate 	u_char *exp_dn, *comp_dn;
139*7c478bd9Sstevel@tonic-gate 	int length;
140*7c478bd9Sstevel@tonic-gate 	u_char **dnptrs, **lastdnptr;
141*7c478bd9Sstevel@tonic-gate {
142*7c478bd9Sstevel@tonic-gate 	register u_char *cp, *dn;
143*7c478bd9Sstevel@tonic-gate 	register int c, l;
144*7c478bd9Sstevel@tonic-gate 	u_char **cpp, **lpp, *sp, *eob;
145*7c478bd9Sstevel@tonic-gate 	u_char *msg;
146*7c478bd9Sstevel@tonic-gate 
147*7c478bd9Sstevel@tonic-gate 	dn = exp_dn;
148*7c478bd9Sstevel@tonic-gate 	cp = comp_dn;
149*7c478bd9Sstevel@tonic-gate 	eob = cp + length;
150*7c478bd9Sstevel@tonic-gate 	if (dnptrs != NULL) {
151*7c478bd9Sstevel@tonic-gate 		if ((msg = *dnptrs++) != NULL) {
152*7c478bd9Sstevel@tonic-gate 			for (cpp = dnptrs; *cpp != NULL; cpp++)
153*7c478bd9Sstevel@tonic-gate 				;
154*7c478bd9Sstevel@tonic-gate 			lpp = cpp;	/* end of list to search */
155*7c478bd9Sstevel@tonic-gate 		}
156*7c478bd9Sstevel@tonic-gate 	} else
157*7c478bd9Sstevel@tonic-gate 		msg = NULL;
158*7c478bd9Sstevel@tonic-gate 	for (c = *dn++; c != '\0'; /*EMPTY*/) {
159*7c478bd9Sstevel@tonic-gate 		/* look to see if we can use pointers */
160*7c478bd9Sstevel@tonic-gate 		if (msg != NULL) {
161*7c478bd9Sstevel@tonic-gate 			if ((l = dn_find(dn-1, msg, dnptrs, lpp)) >= 0) {
162*7c478bd9Sstevel@tonic-gate 				if (cp+1 >= eob)
163*7c478bd9Sstevel@tonic-gate 					return (-1);
164*7c478bd9Sstevel@tonic-gate 				*cp++ = (l >> 8) | INDIR_MASK;
165*7c478bd9Sstevel@tonic-gate 				*cp++ = l % 256;
166*7c478bd9Sstevel@tonic-gate 				return (cp - comp_dn);
167*7c478bd9Sstevel@tonic-gate 			}
168*7c478bd9Sstevel@tonic-gate 			/* not found, save it */
169*7c478bd9Sstevel@tonic-gate 			if (lastdnptr != NULL && cpp < lastdnptr-1) {
170*7c478bd9Sstevel@tonic-gate 				*cpp++ = cp;
171*7c478bd9Sstevel@tonic-gate 				*cpp = NULL;
172*7c478bd9Sstevel@tonic-gate 			}
173*7c478bd9Sstevel@tonic-gate 		}
174*7c478bd9Sstevel@tonic-gate 		sp = cp++;	/* save ptr to length byte */
175*7c478bd9Sstevel@tonic-gate 		do {
176*7c478bd9Sstevel@tonic-gate 			if (c == '.') {
177*7c478bd9Sstevel@tonic-gate 				c = *dn++;
178*7c478bd9Sstevel@tonic-gate 				break;
179*7c478bd9Sstevel@tonic-gate 			}
180*7c478bd9Sstevel@tonic-gate 			if (c == '\\') {
181*7c478bd9Sstevel@tonic-gate 				if ((c = *dn++) == '\0')
182*7c478bd9Sstevel@tonic-gate 					break;
183*7c478bd9Sstevel@tonic-gate 			}
184*7c478bd9Sstevel@tonic-gate 			if (cp >= eob) {
185*7c478bd9Sstevel@tonic-gate 				if (msg != NULL)
186*7c478bd9Sstevel@tonic-gate 					*lpp = NULL;
187*7c478bd9Sstevel@tonic-gate 				return (-1);
188*7c478bd9Sstevel@tonic-gate 			}
189*7c478bd9Sstevel@tonic-gate 			*cp++ = c;
190*7c478bd9Sstevel@tonic-gate 		} while ((c = *dn++) != '\0');
191*7c478bd9Sstevel@tonic-gate 		/* catch trailing '.'s but not '..' */
192*7c478bd9Sstevel@tonic-gate 		if ((l = cp - sp - 1) == 0 && c == '\0') {
193*7c478bd9Sstevel@tonic-gate 			cp--;
194*7c478bd9Sstevel@tonic-gate 			break;
195*7c478bd9Sstevel@tonic-gate 		}
196*7c478bd9Sstevel@tonic-gate 		if (l <= 0 || l > MAXLABEL) {
197*7c478bd9Sstevel@tonic-gate 			if (msg != NULL)
198*7c478bd9Sstevel@tonic-gate 				*lpp = NULL;
199*7c478bd9Sstevel@tonic-gate 			return (-1);
200*7c478bd9Sstevel@tonic-gate 		}
201*7c478bd9Sstevel@tonic-gate 		*sp = l;
202*7c478bd9Sstevel@tonic-gate 	}
203*7c478bd9Sstevel@tonic-gate 	if (cp >= eob) {
204*7c478bd9Sstevel@tonic-gate 		if (msg != NULL)
205*7c478bd9Sstevel@tonic-gate 			*lpp = NULL;
206*7c478bd9Sstevel@tonic-gate 		return (-1);
207*7c478bd9Sstevel@tonic-gate 	}
208*7c478bd9Sstevel@tonic-gate 	*cp++ = '\0';
209*7c478bd9Sstevel@tonic-gate 	return (cp - comp_dn);
210*7c478bd9Sstevel@tonic-gate }
211*7c478bd9Sstevel@tonic-gate 
212*7c478bd9Sstevel@tonic-gate /*
213*7c478bd9Sstevel@tonic-gate  * Skip over a compressed domain name. Return the size or -1.
214*7c478bd9Sstevel@tonic-gate  */
215*7c478bd9Sstevel@tonic-gate dn_skipname(comp_dn, eom)
216*7c478bd9Sstevel@tonic-gate 	u_char *comp_dn, *eom;
217*7c478bd9Sstevel@tonic-gate {
218*7c478bd9Sstevel@tonic-gate 	register u_char *cp;
219*7c478bd9Sstevel@tonic-gate 	register int n;
220*7c478bd9Sstevel@tonic-gate 
221*7c478bd9Sstevel@tonic-gate 	cp = comp_dn;
222*7c478bd9Sstevel@tonic-gate 	while (cp < eom && (n = *cp++)) {
223*7c478bd9Sstevel@tonic-gate 		/*
224*7c478bd9Sstevel@tonic-gate 		 * check for indirection
225*7c478bd9Sstevel@tonic-gate 		 */
226*7c478bd9Sstevel@tonic-gate 		switch (n & INDIR_MASK) {
227*7c478bd9Sstevel@tonic-gate 		case 0:		/* normal case, n == len */
228*7c478bd9Sstevel@tonic-gate 			cp += n;
229*7c478bd9Sstevel@tonic-gate 			continue;
230*7c478bd9Sstevel@tonic-gate 		default:	/* illegal type */
231*7c478bd9Sstevel@tonic-gate 			return (-1);
232*7c478bd9Sstevel@tonic-gate 		case INDIR_MASK:	/* indirection */
233*7c478bd9Sstevel@tonic-gate 			cp++;
234*7c478bd9Sstevel@tonic-gate 		}
235*7c478bd9Sstevel@tonic-gate 		break;
236*7c478bd9Sstevel@tonic-gate 	}
237*7c478bd9Sstevel@tonic-gate 	return (cp - comp_dn);
238*7c478bd9Sstevel@tonic-gate }
239*7c478bd9Sstevel@tonic-gate 
240*7c478bd9Sstevel@tonic-gate /*
241*7c478bd9Sstevel@tonic-gate  * Search for expanded name from a list of previously compressed names.
242*7c478bd9Sstevel@tonic-gate  * Return the offset from msg if found or -1.
243*7c478bd9Sstevel@tonic-gate  * dnptrs is the pointer to the first name on the list,
244*7c478bd9Sstevel@tonic-gate  * not the pointer to the start of the message.
245*7c478bd9Sstevel@tonic-gate  */
246*7c478bd9Sstevel@tonic-gate static
247*7c478bd9Sstevel@tonic-gate dn_find(exp_dn, msg, dnptrs, lastdnptr)
248*7c478bd9Sstevel@tonic-gate 	u_char *exp_dn, *msg;
249*7c478bd9Sstevel@tonic-gate 	u_char **dnptrs, **lastdnptr;
250*7c478bd9Sstevel@tonic-gate {
251*7c478bd9Sstevel@tonic-gate 	register u_char *dn, *cp, **cpp;
252*7c478bd9Sstevel@tonic-gate 	register int n;
253*7c478bd9Sstevel@tonic-gate 	u_char *sp;
254*7c478bd9Sstevel@tonic-gate 
255*7c478bd9Sstevel@tonic-gate 	for (cpp = dnptrs; cpp < lastdnptr; cpp++) {
256*7c478bd9Sstevel@tonic-gate 		dn = exp_dn;
257*7c478bd9Sstevel@tonic-gate 		sp = cp = *cpp;
258*7c478bd9Sstevel@tonic-gate 		while (n = *cp++) {
259*7c478bd9Sstevel@tonic-gate 			/*
260*7c478bd9Sstevel@tonic-gate 			 * check for indirection
261*7c478bd9Sstevel@tonic-gate 			 */
262*7c478bd9Sstevel@tonic-gate 			switch (n & INDIR_MASK) {
263*7c478bd9Sstevel@tonic-gate 			case 0:		/* normal case, n == len */
264*7c478bd9Sstevel@tonic-gate 				while (--n >= 0) {
265*7c478bd9Sstevel@tonic-gate 					if (*dn == '.')
266*7c478bd9Sstevel@tonic-gate 						goto next;
267*7c478bd9Sstevel@tonic-gate 					if (*dn == '\\')
268*7c478bd9Sstevel@tonic-gate 						dn++;
269*7c478bd9Sstevel@tonic-gate 					if (*dn++ != *cp++)
270*7c478bd9Sstevel@tonic-gate 						goto next;
271*7c478bd9Sstevel@tonic-gate 				}
272*7c478bd9Sstevel@tonic-gate 				if ((n = *dn++) == '\0' && *cp == '\0')
273*7c478bd9Sstevel@tonic-gate 					return (sp - msg);
274*7c478bd9Sstevel@tonic-gate 				if (n == '.')
275*7c478bd9Sstevel@tonic-gate 					continue;
276*7c478bd9Sstevel@tonic-gate 				goto next;
277*7c478bd9Sstevel@tonic-gate 
278*7c478bd9Sstevel@tonic-gate 			default:	/* illegal type */
279*7c478bd9Sstevel@tonic-gate 				return (-1);
280*7c478bd9Sstevel@tonic-gate 
281*7c478bd9Sstevel@tonic-gate 			case INDIR_MASK:	/* indirection */
282*7c478bd9Sstevel@tonic-gate 				cp = msg + (((n & 0x3f) << 8) | *cp);
283*7c478bd9Sstevel@tonic-gate 			}
284*7c478bd9Sstevel@tonic-gate 		}
285*7c478bd9Sstevel@tonic-gate 		if (*dn == '\0')
286*7c478bd9Sstevel@tonic-gate 			return (sp - msg);
287*7c478bd9Sstevel@tonic-gate 	next:	/*EMPTY*/;
288*7c478bd9Sstevel@tonic-gate 	}
289*7c478bd9Sstevel@tonic-gate 	return (-1);
290*7c478bd9Sstevel@tonic-gate }
291*7c478bd9Sstevel@tonic-gate 
292*7c478bd9Sstevel@tonic-gate /*
293*7c478bd9Sstevel@tonic-gate  * Routines to insert/extract short/long's. Must account for byte
294*7c478bd9Sstevel@tonic-gate  * order and non-alignment problems. This code at least has the
295*7c478bd9Sstevel@tonic-gate  * advantage of being portable.
296*7c478bd9Sstevel@tonic-gate  *
297*7c478bd9Sstevel@tonic-gate  * used by sendmail.
298*7c478bd9Sstevel@tonic-gate  */
299*7c478bd9Sstevel@tonic-gate 
300*7c478bd9Sstevel@tonic-gate u_short
301*7c478bd9Sstevel@tonic-gate _getshort(msgp)
302*7c478bd9Sstevel@tonic-gate 	u_char *msgp;
303*7c478bd9Sstevel@tonic-gate {
304*7c478bd9Sstevel@tonic-gate 	register u_char *p = (u_char *) msgp;
305*7c478bd9Sstevel@tonic-gate #ifdef vax
306*7c478bd9Sstevel@tonic-gate 	/*
307*7c478bd9Sstevel@tonic-gate 	 * vax compiler doesn't put shorts in registers
308*7c478bd9Sstevel@tonic-gate 	 */
309*7c478bd9Sstevel@tonic-gate 	register u_long u;
310*7c478bd9Sstevel@tonic-gate #else
311*7c478bd9Sstevel@tonic-gate 	register u_short u;
312*7c478bd9Sstevel@tonic-gate #endif
313*7c478bd9Sstevel@tonic-gate 
314*7c478bd9Sstevel@tonic-gate 	u = *p++ << 8;
315*7c478bd9Sstevel@tonic-gate 	return ((u_short)(u | *p));
316*7c478bd9Sstevel@tonic-gate }
317*7c478bd9Sstevel@tonic-gate 
318*7c478bd9Sstevel@tonic-gate u_long
319*7c478bd9Sstevel@tonic-gate _getlong(msgp)
320*7c478bd9Sstevel@tonic-gate 	u_char *msgp;
321*7c478bd9Sstevel@tonic-gate {
322*7c478bd9Sstevel@tonic-gate 	register u_char *p = (u_char *) msgp;
323*7c478bd9Sstevel@tonic-gate 	register u_long u;
324*7c478bd9Sstevel@tonic-gate 
325*7c478bd9Sstevel@tonic-gate 	u = *p++; u <<= 8;
326*7c478bd9Sstevel@tonic-gate 	u |= *p++; u <<= 8;
327*7c478bd9Sstevel@tonic-gate 	u |= *p++; u <<= 8;
328*7c478bd9Sstevel@tonic-gate 	return (u | *p);
329*7c478bd9Sstevel@tonic-gate }
330*7c478bd9Sstevel@tonic-gate 
331*7c478bd9Sstevel@tonic-gate 
332*7c478bd9Sstevel@tonic-gate putshort(s, msgp)
333*7c478bd9Sstevel@tonic-gate 	register u_short s;
334*7c478bd9Sstevel@tonic-gate 	register u_char *msgp;
335*7c478bd9Sstevel@tonic-gate {
336*7c478bd9Sstevel@tonic-gate 
337*7c478bd9Sstevel@tonic-gate 	msgp[1] = s;
338*7c478bd9Sstevel@tonic-gate 	msgp[0] = s >> 8;
339*7c478bd9Sstevel@tonic-gate }
340*7c478bd9Sstevel@tonic-gate 
341*7c478bd9Sstevel@tonic-gate putlong(l, msgp)
342*7c478bd9Sstevel@tonic-gate 	register u_long l;
343*7c478bd9Sstevel@tonic-gate 	register u_char *msgp;
344*7c478bd9Sstevel@tonic-gate {
345*7c478bd9Sstevel@tonic-gate 
346*7c478bd9Sstevel@tonic-gate 	msgp[3] = l;
347*7c478bd9Sstevel@tonic-gate 	msgp[2] = (l >>= 8);
348*7c478bd9Sstevel@tonic-gate 	msgp[1] = (l >>= 8);
349*7c478bd9Sstevel@tonic-gate 	msgp[0] = l >> 8;
350*7c478bd9Sstevel@tonic-gate }
351