1 /* Simple DNS record parser without textual name decoding.
2 Copyright (C) 2022-2023 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, see
17 <https://www.gnu.org/licenses/>. */
19 #include <arpa/nameser.h>
25 __ns_rr_cursor_next (struct ns_rr_cursor
*c
, struct ns_rr_wire
*rr
)
29 /* Extract the record owner name. */
30 int consumed
= __ns_name_unpack (c
->begin
, c
->end
, c
->current
,
31 rr
->rname
, sizeof (rr
->rname
));
34 memset (rr
, 0, sizeof (*rr
));
35 __set_errno (EMSGSIZE
);
38 c
->current
+= consumed
;
40 /* Extract the metadata. */
47 } __attribute__ ((packed
)) metadata
;
48 _Static_assert (sizeof (metadata
) == 10, "sizeof metadata");
49 if (c
->end
- c
->current
< sizeof (metadata
))
51 memset (rr
, 0, sizeof (*rr
));
52 __set_errno (EMSGSIZE
);
55 memcpy (&metadata
, c
->current
, sizeof (metadata
));
56 c
->current
+= sizeof (metadata
);
57 /* Endianess conversion. */
58 rr
->rtype
= ntohs (metadata
.rtype
);
59 rr
->rclass
= ntohs (metadata
.rclass
);
60 rr
->ttl
= ntohl (metadata
.ttl
);
61 rr
->rdlength
= ntohs (metadata
.rdlength
);
63 /* Extract record data. */
64 if (c
->end
- c
->current
< rr
->rdlength
)
66 memset (rr
, 0, sizeof (*rr
));
67 __set_errno (EMSGSIZE
);
70 rr
->rdata
= c
->current
;
71 c
->current
+= rr
->rdlength
;