2N/A * The contents of this file are subject to the terms of the 2N/A * Common Development and Distribution License (the "License"). 2N/A * You may not use this file except in compliance with the License. 2N/A * See the License for the specific language governing permissions 2N/A * and limitations under the License. 2N/A * When distributing Covered Code, include this CDDL HEADER in each 2N/A * If applicable, add the following below this CDDL HEADER, with the 2N/A * fields enclosed by brackets "[]" replaced with your own identifying 2N/A * information: Portions Copyright [yyyy] [name of copyright owner] 2N/A * Copyright 2008 Sun Microsystems, Inc. All rights reserved. 2N/A * Use is subject to license terms. 2N/A/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */ 2N/A/* All Rights Reserved */ 2N/A * University Copyright- Copyright (c) 1982, 1986, 1988 2N/A * The Regents of the University of California 2N/A * All Rights Reserved 2N/A * University Acknowledgment- Portions of this document are derived from 2N/A * software developed by the University of California, Berkeley, and its 2N/A#
pragma ident "%Z%%M% %I% %E% SMI" 2N/A * Expand compressed domain name 'comp_dn' to full domain name. 2N/A * 'msg' is a pointer to the begining of the message, 2N/A * 'eomorig' points to the first location after the message, 2N/A * 'exp_dn' is a pointer to a buffer of size 'length' for the result. 2N/A * Return size of compressed name or -1 if there was an error. 2N/A * fetch next label in domain name 2N/A * Check for indirection 2N/A if ((c = *
cp++) ==
'.') {
2N/A * Check for loops in the compressed name; 2N/A * if we've looked at the whole message, 2N/A * there must be a loop. 2N/A return (-
1);
/* flag error */ 2N/A * Compress domain name 'exp_dn' into 'comp_dn'. 2N/A * Return the size of the compressed name or -1. 2N/A * 'length' is the size of the array pointed to by 'comp_dn'. 2N/A * 'dnptrs' is a list of pointers to previous compressed names. dnptrs[0] 2N/A * is a pointer to the beginning of the message. The list ends with NULL. 2N/A * 'lastdnptr' is a pointer to the end of the arrary pointed to 2N/A * by 'dnptrs'. Side effect is to update the list of pointers for 2N/A * labels inserted into the message as we compress the name. 2N/A * If 'dnptr' is NULL, we don't try to compress names. If 'lastdnptr' 2N/A * is NULL, we don't update the list. 2N/A for (c = *
dn++; c !=
'\0';
/*EMPTY*/) {
2N/A /* look to see if we can use pointers */ 2N/A /* not found, save it */ 2N/A sp =
cp++;
/* save ptr to length byte */ 2N/A }
while ((c = *
dn++) !=
'\0');
2N/A /* catch trailing '.'s but not '..' */ 2N/A if ((l =
cp -
sp -
1) == 0 && c ==
'\0') {
2N/A * Skip over a compressed domain name. Return the size or -1. 2N/A * check for indirection 2N/A case 0:
/* normal case, n == len */ 2N/A default:
/* illegal type */ 2N/A * Search for expanded name from a list of previously compressed names. 2N/A * Return the offset from msg if found or -1. 2N/A * dnptrs is the pointer to the first name on the list, 2N/A * not the pointer to the start of the message. 2N/A * check for indirection 2N/A case 0:
/* normal case, n == len */ 2N/A if ((n = *
dn++) ==
'\0' && *
cp ==
'\0')
2N/A default:
/* illegal type */ 2N/A * order and non-alignment problems. This code at least has the 2N/A * advantage of being portable. 2N/A * vax compiler doesn't put shorts in registers