1*0Sstevel@tonic-gate /*
2*0Sstevel@tonic-gate * CDDL HEADER START
3*0Sstevel@tonic-gate *
4*0Sstevel@tonic-gate * The contents of this file are subject to the terms of the
5*0Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only
6*0Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance
7*0Sstevel@tonic-gate * with the License.
8*0Sstevel@tonic-gate *
9*0Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10*0Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing.
11*0Sstevel@tonic-gate * See the License for the specific language governing permissions
12*0Sstevel@tonic-gate * and limitations under the License.
13*0Sstevel@tonic-gate *
14*0Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each
15*0Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16*0Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the
17*0Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying
18*0Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner]
19*0Sstevel@tonic-gate *
20*0Sstevel@tonic-gate * CDDL HEADER END
21*0Sstevel@tonic-gate */
22*0Sstevel@tonic-gate /*
23*0Sstevel@tonic-gate * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
24*0Sstevel@tonic-gate * Use is subject to license terms.
25*0Sstevel@tonic-gate */
26*0Sstevel@tonic-gate
27*0Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI"
28*0Sstevel@tonic-gate
29*0Sstevel@tonic-gate #include <sys/types.h>
30*0Sstevel@tonic-gate #include <sys/cmn_err.h>
31*0Sstevel@tonic-gate #include <sys/systm.h>
32*0Sstevel@tonic-gate #include <sys/socket.h>
33*0Sstevel@tonic-gate #include <sys/sunddi.h>
34*0Sstevel@tonic-gate #include <netinet/in.h>
35*0Sstevel@tonic-gate #include <inet/led.h>
36*0Sstevel@tonic-gate
37*0Sstevel@tonic-gate static void convert2ascii(char *, const in6_addr_t *);
38*0Sstevel@tonic-gate static char *strchr_w(const char *, int);
39*0Sstevel@tonic-gate static int str2inet_addr(char *, ipaddr_t *);
40*0Sstevel@tonic-gate
41*0Sstevel@tonic-gate /*
42*0Sstevel@tonic-gate * inet_ntop -- Convert an IPv4 or IPv6 address in binary form into
43*0Sstevel@tonic-gate * printable form, and return a pointer to that string. Caller should
44*0Sstevel@tonic-gate * provide a buffer of correct length to store string into.
45*0Sstevel@tonic-gate * Note: this routine is kernel version of inet_ntop. It has similar
46*0Sstevel@tonic-gate * format as inet_ntop() defined in rfc2553. But it does not do
47*0Sstevel@tonic-gate * error handling operations exactly as rfc2553 defines. This function
48*0Sstevel@tonic-gate * is used by kernel inet directory routines only for debugging.
49*0Sstevel@tonic-gate * This inet_ntop() function, does not return NULL if third argument
50*0Sstevel@tonic-gate * is NULL. The reason is simple that we don't want kernel to panic
51*0Sstevel@tonic-gate * as the output of this function is directly fed to ip<n>dbg macro.
52*0Sstevel@tonic-gate * Instead it uses a local buffer for destination address for
53*0Sstevel@tonic-gate * those calls which purposely pass NULL ptr for the destination
54*0Sstevel@tonic-gate * buffer. This function is thread-safe when the caller passes a non-
55*0Sstevel@tonic-gate * null buffer with the third argument.
56*0Sstevel@tonic-gate */
57*0Sstevel@tonic-gate /* ARGSUSED */
58*0Sstevel@tonic-gate char *
inet_ntop(int af,const void * addr,char * buf,int addrlen)59*0Sstevel@tonic-gate inet_ntop(int af, const void *addr, char *buf, int addrlen)
60*0Sstevel@tonic-gate {
61*0Sstevel@tonic-gate static char local_buf[INET6_ADDRSTRLEN];
62*0Sstevel@tonic-gate static char *err_buf1 = "<badaddr>";
63*0Sstevel@tonic-gate static char *err_buf2 = "<badfamily>";
64*0Sstevel@tonic-gate in6_addr_t *v6addr;
65*0Sstevel@tonic-gate uchar_t *v4addr;
66*0Sstevel@tonic-gate char *caddr;
67*0Sstevel@tonic-gate
68*0Sstevel@tonic-gate /*
69*0Sstevel@tonic-gate * We don't allow thread unsafe inet_ntop calls, they
70*0Sstevel@tonic-gate * must pass a non-null buffer pointer. For DEBUG mode
71*0Sstevel@tonic-gate * we use the ASSERT() and for non-debug kernel it will
72*0Sstevel@tonic-gate * silently allow it for now. Someday we should remove
73*0Sstevel@tonic-gate * the static buffer from this function.
74*0Sstevel@tonic-gate */
75*0Sstevel@tonic-gate
76*0Sstevel@tonic-gate ASSERT(buf != NULL);
77*0Sstevel@tonic-gate if (buf == NULL)
78*0Sstevel@tonic-gate buf = local_buf;
79*0Sstevel@tonic-gate buf[0] = '\0';
80*0Sstevel@tonic-gate
81*0Sstevel@tonic-gate /* Let user know politely not to send NULL or unaligned addr */
82*0Sstevel@tonic-gate if (addr == NULL || !(OK_32PTR(addr))) {
83*0Sstevel@tonic-gate #ifdef DEBUG
84*0Sstevel@tonic-gate cmn_err(CE_WARN, "inet_ntop: addr is <null> or unaligned");
85*0Sstevel@tonic-gate #endif
86*0Sstevel@tonic-gate return (err_buf1);
87*0Sstevel@tonic-gate }
88*0Sstevel@tonic-gate
89*0Sstevel@tonic-gate
90*0Sstevel@tonic-gate #define UC(b) (((int)b) & 0xff)
91*0Sstevel@tonic-gate switch (af) {
92*0Sstevel@tonic-gate case AF_INET:
93*0Sstevel@tonic-gate ASSERT(addrlen >= INET_ADDRSTRLEN);
94*0Sstevel@tonic-gate v4addr = (uchar_t *)addr;
95*0Sstevel@tonic-gate (void) sprintf(buf, "%03d.%03d.%03d.%03d",
96*0Sstevel@tonic-gate UC(v4addr[0]), UC(v4addr[1]), UC(v4addr[2]), UC(v4addr[3]));
97*0Sstevel@tonic-gate return (buf);
98*0Sstevel@tonic-gate
99*0Sstevel@tonic-gate case AF_INET6:
100*0Sstevel@tonic-gate ASSERT(addrlen >= INET6_ADDRSTRLEN);
101*0Sstevel@tonic-gate v6addr = (in6_addr_t *)addr;
102*0Sstevel@tonic-gate if (IN6_IS_ADDR_V4MAPPED(v6addr)) {
103*0Sstevel@tonic-gate caddr = (char *)addr;
104*0Sstevel@tonic-gate (void) sprintf(buf, "::ffff:%d.%d.%d.%d",
105*0Sstevel@tonic-gate UC(caddr[12]), UC(caddr[13]),
106*0Sstevel@tonic-gate UC(caddr[14]), UC(caddr[15]));
107*0Sstevel@tonic-gate } else if (IN6_IS_ADDR_V4COMPAT(v6addr)) {
108*0Sstevel@tonic-gate caddr = (char *)addr;
109*0Sstevel@tonic-gate (void) sprintf(buf, "::%d.%d.%d.%d",
110*0Sstevel@tonic-gate UC(caddr[12]), UC(caddr[13]), UC(caddr[14]),
111*0Sstevel@tonic-gate UC(caddr[15]));
112*0Sstevel@tonic-gate } else if (IN6_IS_ADDR_UNSPECIFIED(v6addr)) {
113*0Sstevel@tonic-gate (void) sprintf(buf, "::");
114*0Sstevel@tonic-gate } else {
115*0Sstevel@tonic-gate convert2ascii(buf, v6addr);
116*0Sstevel@tonic-gate }
117*0Sstevel@tonic-gate return (buf);
118*0Sstevel@tonic-gate
119*0Sstevel@tonic-gate default:
120*0Sstevel@tonic-gate return (err_buf2);
121*0Sstevel@tonic-gate }
122*0Sstevel@tonic-gate #undef UC
123*0Sstevel@tonic-gate }
124*0Sstevel@tonic-gate
125*0Sstevel@tonic-gate /*
126*0Sstevel@tonic-gate *
127*0Sstevel@tonic-gate * v6 formats supported
128*0Sstevel@tonic-gate * General format xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx
129*0Sstevel@tonic-gate * The short hand notation :: is used for COMPAT addr
130*0Sstevel@tonic-gate * Other forms : fe80::xxxx:xxxx:xxxx:xxxx
131*0Sstevel@tonic-gate */
132*0Sstevel@tonic-gate static void
convert2ascii(char * buf,const in6_addr_t * addr)133*0Sstevel@tonic-gate convert2ascii(char *buf, const in6_addr_t *addr)
134*0Sstevel@tonic-gate {
135*0Sstevel@tonic-gate int hexdigits;
136*0Sstevel@tonic-gate int head_zero = 0;
137*0Sstevel@tonic-gate int tail_zero = 0;
138*0Sstevel@tonic-gate /* tempbuf must be big enough to hold ffff:\0 */
139*0Sstevel@tonic-gate char tempbuf[6];
140*0Sstevel@tonic-gate char *ptr;
141*0Sstevel@tonic-gate uint16_t *addr_component;
142*0Sstevel@tonic-gate size_t len;
143*0Sstevel@tonic-gate boolean_t first = B_FALSE;
144*0Sstevel@tonic-gate boolean_t med_zero = B_FALSE;
145*0Sstevel@tonic-gate boolean_t end_zero = B_FALSE;
146*0Sstevel@tonic-gate
147*0Sstevel@tonic-gate addr_component = (uint16_t *)addr;
148*0Sstevel@tonic-gate ptr = buf;
149*0Sstevel@tonic-gate
150*0Sstevel@tonic-gate /* First count if trailing zeroes higher in number */
151*0Sstevel@tonic-gate for (hexdigits = 0; hexdigits < 8; hexdigits++) {
152*0Sstevel@tonic-gate if (*addr_component == 0) {
153*0Sstevel@tonic-gate if (hexdigits < 4)
154*0Sstevel@tonic-gate head_zero++;
155*0Sstevel@tonic-gate else
156*0Sstevel@tonic-gate tail_zero++;
157*0Sstevel@tonic-gate }
158*0Sstevel@tonic-gate addr_component++;
159*0Sstevel@tonic-gate }
160*0Sstevel@tonic-gate addr_component = (uint16_t *)addr;
161*0Sstevel@tonic-gate if (tail_zero > head_zero && (head_zero + tail_zero) != 7)
162*0Sstevel@tonic-gate end_zero = B_TRUE;
163*0Sstevel@tonic-gate
164*0Sstevel@tonic-gate for (hexdigits = 0; hexdigits < 8; hexdigits++) {
165*0Sstevel@tonic-gate
166*0Sstevel@tonic-gate /* if entry is a 0 */
167*0Sstevel@tonic-gate
168*0Sstevel@tonic-gate if (*addr_component == 0) {
169*0Sstevel@tonic-gate if (!first && *(addr_component + 1) == 0) {
170*0Sstevel@tonic-gate if (end_zero && (hexdigits < 4)) {
171*0Sstevel@tonic-gate *ptr++ = '0';
172*0Sstevel@tonic-gate *ptr++ = ':';
173*0Sstevel@tonic-gate } else {
174*0Sstevel@tonic-gate /*
175*0Sstevel@tonic-gate * address starts with 0s ..
176*0Sstevel@tonic-gate * stick in leading ':' of pair
177*0Sstevel@tonic-gate */
178*0Sstevel@tonic-gate if (hexdigits == 0)
179*0Sstevel@tonic-gate *ptr++ = ':';
180*0Sstevel@tonic-gate /* add another */
181*0Sstevel@tonic-gate *ptr++ = ':';
182*0Sstevel@tonic-gate first = B_TRUE;
183*0Sstevel@tonic-gate med_zero = B_TRUE;
184*0Sstevel@tonic-gate }
185*0Sstevel@tonic-gate } else if (first && med_zero) {
186*0Sstevel@tonic-gate if (hexdigits == 7)
187*0Sstevel@tonic-gate *ptr++ = ':';
188*0Sstevel@tonic-gate addr_component++;
189*0Sstevel@tonic-gate continue;
190*0Sstevel@tonic-gate } else {
191*0Sstevel@tonic-gate *ptr++ = '0';
192*0Sstevel@tonic-gate *ptr++ = ':';
193*0Sstevel@tonic-gate }
194*0Sstevel@tonic-gate addr_component++;
195*0Sstevel@tonic-gate continue;
196*0Sstevel@tonic-gate }
197*0Sstevel@tonic-gate if (med_zero)
198*0Sstevel@tonic-gate med_zero = B_FALSE;
199*0Sstevel@tonic-gate
200*0Sstevel@tonic-gate tempbuf[0] = '\0';
201*0Sstevel@tonic-gate (void) sprintf(tempbuf, "%x:", ntohs(*addr_component) & 0xffff);
202*0Sstevel@tonic-gate len = strlen(tempbuf);
203*0Sstevel@tonic-gate bcopy(tempbuf, ptr, len);
204*0Sstevel@tonic-gate ptr = ptr + len;
205*0Sstevel@tonic-gate addr_component++;
206*0Sstevel@tonic-gate }
207*0Sstevel@tonic-gate *--ptr = '\0';
208*0Sstevel@tonic-gate }
209*0Sstevel@tonic-gate
210*0Sstevel@tonic-gate /*
211*0Sstevel@tonic-gate * search for char c, terminate on trailing white space
212*0Sstevel@tonic-gate */
213*0Sstevel@tonic-gate static char *
strchr_w(const char * sp,int c)214*0Sstevel@tonic-gate strchr_w(const char *sp, int c)
215*0Sstevel@tonic-gate {
216*0Sstevel@tonic-gate /* skip leading white space */
217*0Sstevel@tonic-gate while (*sp && (*sp == ' ' || *sp == '\t')) {
218*0Sstevel@tonic-gate sp++;
219*0Sstevel@tonic-gate }
220*0Sstevel@tonic-gate
221*0Sstevel@tonic-gate do {
222*0Sstevel@tonic-gate if (*sp == (char)c)
223*0Sstevel@tonic-gate return ((char *)sp);
224*0Sstevel@tonic-gate if (*sp == ' ' || *sp == '\t')
225*0Sstevel@tonic-gate return (NULL);
226*0Sstevel@tonic-gate } while (*sp++);
227*0Sstevel@tonic-gate return (NULL);
228*0Sstevel@tonic-gate }
229*0Sstevel@tonic-gate
230*0Sstevel@tonic-gate static int
str2inet_addr(char * cp,ipaddr_t * addrp)231*0Sstevel@tonic-gate str2inet_addr(char *cp, ipaddr_t *addrp)
232*0Sstevel@tonic-gate {
233*0Sstevel@tonic-gate char *end;
234*0Sstevel@tonic-gate long byte;
235*0Sstevel@tonic-gate int i;
236*0Sstevel@tonic-gate ipaddr_t addr = 0;
237*0Sstevel@tonic-gate
238*0Sstevel@tonic-gate for (i = 0; i < 4; i++) {
239*0Sstevel@tonic-gate if (ddi_strtol(cp, &end, 10, &byte) != 0 || byte < 0 ||
240*0Sstevel@tonic-gate byte > 255) {
241*0Sstevel@tonic-gate return (0);
242*0Sstevel@tonic-gate }
243*0Sstevel@tonic-gate addr = (addr << 8) | (uint8_t)byte;
244*0Sstevel@tonic-gate if (i < 3) {
245*0Sstevel@tonic-gate if (*end != '.') {
246*0Sstevel@tonic-gate return (0);
247*0Sstevel@tonic-gate } else {
248*0Sstevel@tonic-gate cp = end + 1;
249*0Sstevel@tonic-gate }
250*0Sstevel@tonic-gate } else {
251*0Sstevel@tonic-gate cp = end;
252*0Sstevel@tonic-gate }
253*0Sstevel@tonic-gate }
254*0Sstevel@tonic-gate *addrp = addr;
255*0Sstevel@tonic-gate return (1);
256*0Sstevel@tonic-gate }
257*0Sstevel@tonic-gate
258*0Sstevel@tonic-gate /*
259*0Sstevel@tonic-gate * inet_pton: This function takes string format IPv4 or IPv6 address and
260*0Sstevel@tonic-gate * converts it to binary form. The format of this function corresponds to
261*0Sstevel@tonic-gate * inet_pton() in the socket library.
262*0Sstevel@tonic-gate * It returns 0 for invalid IPv4 and IPv6 address
263*0Sstevel@tonic-gate * 1 when successfully converts ascii to binary
264*0Sstevel@tonic-gate * -1 when af is not AF_INET or AF_INET6
265*0Sstevel@tonic-gate */
266*0Sstevel@tonic-gate int
inet_pton(int af,char * inp,void * outp)267*0Sstevel@tonic-gate inet_pton(int af, char *inp, void *outp)
268*0Sstevel@tonic-gate {
269*0Sstevel@tonic-gate int i;
270*0Sstevel@tonic-gate long byte;
271*0Sstevel@tonic-gate char *end;
272*0Sstevel@tonic-gate
273*0Sstevel@tonic-gate switch (af) {
274*0Sstevel@tonic-gate case AF_INET:
275*0Sstevel@tonic-gate return (str2inet_addr(inp, (ipaddr_t *)outp));
276*0Sstevel@tonic-gate case AF_INET6: {
277*0Sstevel@tonic-gate union v6buf_u {
278*0Sstevel@tonic-gate uint16_t v6words_u[8];
279*0Sstevel@tonic-gate in6_addr_t v6addr_u;
280*0Sstevel@tonic-gate } v6buf, *v6outp;
281*0Sstevel@tonic-gate uint16_t *dbl_col = NULL;
282*0Sstevel@tonic-gate char lastbyte = NULL;
283*0Sstevel@tonic-gate
284*0Sstevel@tonic-gate v6outp = (union v6buf_u *)outp;
285*0Sstevel@tonic-gate
286*0Sstevel@tonic-gate if (strchr_w(inp, '.') != NULL) {
287*0Sstevel@tonic-gate /* v4 mapped or v4 compatable */
288*0Sstevel@tonic-gate if (strncmp(inp, "::ffff:", 7) == 0) {
289*0Sstevel@tonic-gate ipaddr_t ipv4_all_zeroes = 0;
290*0Sstevel@tonic-gate /* mapped - first init prefix and then fill */
291*0Sstevel@tonic-gate IN6_IPADDR_TO_V4MAPPED(ipv4_all_zeroes,
292*0Sstevel@tonic-gate &v6outp->v6addr_u);
293*0Sstevel@tonic-gate return (str2inet_addr(inp + 7,
294*0Sstevel@tonic-gate &(v6outp->v6addr_u.s6_addr32[3])));
295*0Sstevel@tonic-gate } else if (strncmp(inp, "::", 2) == 0) {
296*0Sstevel@tonic-gate /* v4 compatable - prefix all zeroes */
297*0Sstevel@tonic-gate bzero(&v6outp->v6addr_u, sizeof (in6_addr_t));
298*0Sstevel@tonic-gate return (str2inet_addr(inp + 2,
299*0Sstevel@tonic-gate &(v6outp->v6addr_u.s6_addr32[3])));
300*0Sstevel@tonic-gate }
301*0Sstevel@tonic-gate return (0);
302*0Sstevel@tonic-gate }
303*0Sstevel@tonic-gate for (i = 0; i < 8; i++) {
304*0Sstevel@tonic-gate int error;
305*0Sstevel@tonic-gate /*
306*0Sstevel@tonic-gate * if ddi_strtol() fails it could be because
307*0Sstevel@tonic-gate * the string is "::". That is valid and
308*0Sstevel@tonic-gate * checked for below so just set the value to
309*0Sstevel@tonic-gate * 0 and continue.
310*0Sstevel@tonic-gate */
311*0Sstevel@tonic-gate if ((error = ddi_strtol(inp, &end, 16, &byte)) != 0) {
312*0Sstevel@tonic-gate if (error == ERANGE)
313*0Sstevel@tonic-gate return (0);
314*0Sstevel@tonic-gate byte = 0;
315*0Sstevel@tonic-gate }
316*0Sstevel@tonic-gate if (byte < 0 || byte > 0x0ffff) {
317*0Sstevel@tonic-gate return (0);
318*0Sstevel@tonic-gate }
319*0Sstevel@tonic-gate v6buf.v6words_u[i] = (uint16_t)byte;
320*0Sstevel@tonic-gate if (*end == NULL || i == 7) {
321*0Sstevel@tonic-gate inp = end;
322*0Sstevel@tonic-gate break;
323*0Sstevel@tonic-gate }
324*0Sstevel@tonic-gate if (inp == end) { /* not a number must be */
325*0Sstevel@tonic-gate if (*inp == ':' &&
326*0Sstevel@tonic-gate ((i == 0 && *(inp + 1) == ':') ||
327*0Sstevel@tonic-gate lastbyte == ':')) {
328*0Sstevel@tonic-gate if (dbl_col) {
329*0Sstevel@tonic-gate return (0);
330*0Sstevel@tonic-gate }
331*0Sstevel@tonic-gate if (byte != 0)
332*0Sstevel@tonic-gate i++;
333*0Sstevel@tonic-gate dbl_col = &v6buf.v6words_u[i];
334*0Sstevel@tonic-gate if (i == 0)
335*0Sstevel@tonic-gate inp++;
336*0Sstevel@tonic-gate } else if (*inp == NULL || *inp == ' ' ||
337*0Sstevel@tonic-gate *inp == '\t') {
338*0Sstevel@tonic-gate break;
339*0Sstevel@tonic-gate } else {
340*0Sstevel@tonic-gate return (0);
341*0Sstevel@tonic-gate }
342*0Sstevel@tonic-gate } else {
343*0Sstevel@tonic-gate inp = end;
344*0Sstevel@tonic-gate }
345*0Sstevel@tonic-gate if (*inp != ':') {
346*0Sstevel@tonic-gate return (0);
347*0Sstevel@tonic-gate }
348*0Sstevel@tonic-gate inp++;
349*0Sstevel@tonic-gate if (*inp == NULL || *inp == ' ' || *inp == '\t') {
350*0Sstevel@tonic-gate break;
351*0Sstevel@tonic-gate }
352*0Sstevel@tonic-gate lastbyte = *inp;
353*0Sstevel@tonic-gate }
354*0Sstevel@tonic-gate if (*inp != NULL && *inp != ' ' && *inp != '\t') {
355*0Sstevel@tonic-gate return (0);
356*0Sstevel@tonic-gate }
357*0Sstevel@tonic-gate /*
358*0Sstevel@tonic-gate * v6words now contains the bytes we could translate
359*0Sstevel@tonic-gate * dbl_col points to the word (should be 0) where
360*0Sstevel@tonic-gate * a double colon was found
361*0Sstevel@tonic-gate */
362*0Sstevel@tonic-gate if (i == 7) {
363*0Sstevel@tonic-gate v6outp->v6addr_u = v6buf.v6addr_u;
364*0Sstevel@tonic-gate } else {
365*0Sstevel@tonic-gate int rem;
366*0Sstevel@tonic-gate int word;
367*0Sstevel@tonic-gate int next;
368*0Sstevel@tonic-gate if (dbl_col == NULL) {
369*0Sstevel@tonic-gate return (0);
370*0Sstevel@tonic-gate }
371*0Sstevel@tonic-gate bzero(&v6outp->v6addr_u, sizeof (in6_addr_t));
372*0Sstevel@tonic-gate rem = dbl_col - &v6buf.v6words_u[0];
373*0Sstevel@tonic-gate for (next = 0; next < rem; next++) {
374*0Sstevel@tonic-gate v6outp->v6words_u[next] = v6buf.v6words_u[next];
375*0Sstevel@tonic-gate }
376*0Sstevel@tonic-gate next++; /* skip dbl_col 0 */
377*0Sstevel@tonic-gate rem = i - rem;
378*0Sstevel@tonic-gate word = 8 - rem;
379*0Sstevel@tonic-gate while (rem > 0) {
380*0Sstevel@tonic-gate v6outp->v6words_u[word] = v6buf.v6words_u[next];
381*0Sstevel@tonic-gate word++;
382*0Sstevel@tonic-gate rem--;
383*0Sstevel@tonic-gate next++;
384*0Sstevel@tonic-gate }
385*0Sstevel@tonic-gate }
386*0Sstevel@tonic-gate return (1); /* Success */
387*0Sstevel@tonic-gate }
388*0Sstevel@tonic-gate } /* switch */
389*0Sstevel@tonic-gate return (-1); /* return -1 for default case */
390*0Sstevel@tonic-gate }
391