ares_expand_string.c
Go to the documentation of this file.
1 
2 /* Copyright 1998 by the Massachusetts Institute of Technology.
3  *
4  * Permission to use, copy, modify, and distribute this
5  * software and its documentation for any purpose and without
6  * fee is hereby granted, provided that the above copyright
7  * notice appear in all copies and that both that copyright
8  * notice and this permission notice appear in supporting
9  * documentation, and that the name of M.I.T. not be used in
10  * advertising or publicity pertaining to distribution of the
11  * software without specific, written prior permission.
12  * M.I.T. makes no representations about the suitability of
13  * this software for any purpose. It is provided "as is"
14  * without express or implied warranty.
15  */
16 
17 #include "ares_setup.h"
18 
19 #ifdef HAVE_NETINET_IN_H
20 # include <netinet/in.h>
21 #endif
22 
23 #include "ares_nameser.h"
24 
25 #include "ares.h"
26 #include "ares_private.h" /* for the memdebug */
27 
28 /* Simply decodes a length-encoded character string. The first byte of the
29  * input is the length of the string to be returned and the bytes thereafter
30  * are the characters of the string. The returned result will be NULL
31  * terminated.
32  */
33 int ares_expand_string(const unsigned char *encoded,
34  const unsigned char *abuf,
35  int alen,
36  unsigned char **s,
37  long *enclen)
38 {
39  unsigned char *q;
40  union {
41  ares_ssize_t sig;
42  size_t uns;
43  } elen;
44 
45  if (encoded == abuf+alen)
46  return ARES_EBADSTR;
47 
48  elen.uns = *encoded;
49  if (encoded+elen.sig+1 > abuf+alen)
50  return ARES_EBADSTR;
51 
52  encoded++;
53 
54  *s = ares_malloc(elen.uns+1);
55  if (*s == NULL)
56  return ARES_ENOMEM;
57  q = *s;
58  strncpy((char *)q, (char *)encoded, elen.uns);
59  q[elen.uns] = '\0';
60 
61  *s = q;
62 
63  *enclen = (long)(elen.sig+1);
64 
65  return ARES_SUCCESS;
66 }
67 
ARES_ENOMEM
#define ARES_ENOMEM
Definition: ares.h:117
ares.h
ares_malloc
void *(* ares_malloc)(size_t size)=default_malloc
Definition: ares_library_init.c:58
ARES_EBADSTR
#define ARES_EBADSTR
Definition: ares.h:119
ARES_SUCCESS
#define ARES_SUCCESS
Definition: ares.h:98
ares_setup.h
ares_private.h
ares_nameser.h
ares_expand_string
int ares_expand_string(const unsigned char *encoded, const unsigned char *abuf, int alen, unsigned char **s, long *enclen)
Definition: ares_expand_string.c:33
ares_ssize_t
CARES_TYPEOF_ARES_SSIZE_T ares_ssize_t
Definition: ares_build.h:210
google::protobuf.internal.decoder.long
long
Definition: bloaty/third_party/protobuf/python/google/protobuf/internal/decoder.py:89


grpc
Author(s):
autogenerated on Fri May 16 2025 02:57:43