1/* Compress a DNS domain name in presentation format.
2 * Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC")
3 * Copyright (c) 1996,1999 by Internet Software Consortium.
4 *
5 * Permission to use, copy, modify, and distribute this software for any
6 * purpose with or without fee is hereby granted, provided that the above
7 * copyright notice and this permission notice appear in all copies.
8 *
9 * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES
10 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR
12 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
15 * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16 */
17
18#include <arpa/nameser.h>
19#include <shlib-compat.h>
20
21/* Compresses a domain name into wire format, using compression pointers.
22 Returns the number of bytes consumed in DST or -1 (with errno set).
23
24 DNPTRS is an array of pointers to previous compressed names.
25 DNPTRS[0] is a pointer to the beginning of the message.
26
27 The list ends with NULL. LASTDNPTR is a pointer to the end of the
28 array pointed to by DNPTRS. Side effect is to update the list of
29 pointers for labels inserted into the message as we compress the
30 name. If DNPTRS is NULL, we don't try to compress names. If
31 LASTDNPTR * is NULL, we don't update the list. */
32int
33___ns_name_compress (const char *src, unsigned char *dst, size_t dstsiz,
34 const unsigned char **dnptrs,
35 const unsigned char **lastdnptr)
36{
37 unsigned char tmp[NS_MAXCDNAME];
38
39 if (__ns_name_pton (src, tmp, sizeof tmp) < 0)
40 return -1;
41 return __ns_name_pack (tmp, dst, dstsiz, dnptrs, lastdnptr);
42}
43versioned_symbol (libc, ___ns_name_compress, ns_name_compress, GLIBC_2_34);
44versioned_symbol (libc, ___ns_name_compress, __ns_name_compress,
45 GLIBC_PRIVATE);
46libc_hidden_ver (___ns_name_compress, __ns_name_compress)
47
48#if OTHER_SHLIB_COMPAT (libresolv, GLIBC_2_9, GLIBC_2_34)
49compat_symbol (libresolv, ___ns_name_compress, ns_name_compress, GLIBC_2_9);
50#endif
51

source code of glibc/resolv/ns_name_compress.c