summaryrefslogtreecommitdiff
path: root/lib/libc/net/getrrsetbyname.3
blob: 6a42edcc93bc72dae42769d227fc218e3d059595 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
.\" $OpenBSD: getrrsetbyname.3,v 1.20 2014/11/05 15:12:23 jmc Exp $
.\"
.\" Copyright (C) 2000, 2001  Internet Software Consortium.
.\"
.\" Permission to use, copy, modify, and distribute this software for any
.\" purpose with or without fee is hereby granted, provided that the above
.\" copyright notice and this permission notice appear in all copies.
.\"
.\" THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM
.\" DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL
.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL
.\" INTERNET SOFTWARE CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT,
.\" INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING
.\" FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
.\" NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
.\" WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
.\"
.Dd $Mdocdate: November 5 2014 $
.Dt GETRRSETBYNAME 3
.Os
.Sh NAME
.Nm freerrset ,
.Nm getrrsetbyname
.Nd retrieve DNS records
.Sh SYNOPSIS
.In netdb.h
.Ft int
.Fn getrrsetbyname "const char *hostname" "unsigned int rdclass" \
"unsigned int rdtype" "unsigned int flags" "struct rrsetinfo **res"
.Ft void
.Fn freerrset "struct rrsetinfo *rrset"
.Sh DESCRIPTION
.Fn getrrsetbyname
gets a set of resource records associated with a
.Fa hostname ,
.Fa rdclass ,
and
.Fa rdtype .
.Fa hostname
is a pointer to a NUL-terminated string.
The
.Fa flags
field is currently unused and must be zero.
.Pp
After a successful call to
.Fn getrrsetbyname ,
.Fa *res
is a pointer to an
.Li rrsetinfo
structure, containing a list of one or more
.Li rdatainfo
structures containing resource records and potentially another list of
.Li rdatainfo
structures containing SIG resource records associated with those records.
The members
.Li rri_rdclass
and
.Li rri_rdtype
are copied from the parameters.
.Li rri_ttl
and
.Li rri_name
are properties of the obtained rrset.
The resource records contained in
.Li rri_rdatas
and
.Li rri_sigs
are in uncompressed DNS wire format.
Properties of the rdataset are represented in the
.Li rri_flags
bitfield.
If the
.Dv RRSET_VALIDATED
bit is set, the data has been DNSSEC
validated and the signatures verified.
.Pp
The following structures are used:
.Bd -literal -offset indent
struct  rdatainfo {
	unsigned int	rdi_length;	/* length of data */
	unsigned char	*rdi_data;	/* record data */
};

struct  rrsetinfo {
	unsigned int	 rri_flags;	/* RRSET_VALIDATED ... */
	unsigned int	 rri_rdclass;	/* class number */
	unsigned int	 rri_rdtype;	/* RR type number */
	unsigned int	 rri_ttl;	/* time to live */
	unsigned int	 rri_nrdatas;	/* size of rdatas array */
	unsigned int	 rri_nsigs;	/* size of sigs array */
	char		 *rri_name;	/* canonical name */
	struct rdatainfo *rri_rdatas;	/* individual records */
	struct rdatainfo *rri_sigs;	/* individual signatures */
};
.Ed
.Pp
All of the information returned by
.Fn getrrsetbyname
is dynamically allocated: the
.Li rrsetinfo
and
.Li rdatainfo
structures,
and the canonical host name strings pointed to by the
.Li rrsetinfo
structure.
Memory allocated for the dynamically allocated structures created by
a successful call to
.Fn getrrsetbyname
is released by
.Fn freerrset .
.Li rrset
is a pointer to a
.Li struct rrsetinfo
created by a call to
.Fn getrrsetbyname .
.\" .Pp
.\" If the EDNS0 option is activated in
.\" .Xr resolv.conf 5 ,
.\" .Fn getrrsetbyname
.\" will request DNSSEC authentication using the EDNS0 DNSSEC OK (DO) bit.
.Sh RETURN VALUES
.Fn getrrsetbyname
returns zero on success, and one of the following error
codes if an error occurred:
.Bl -tag -width ERRSET_NOMEMORY
.It Bq Er ERRSET_NONAME
The name does not exist.
.It Bq Er ERRSET_NODATA
The name exists, but does not have data of the desired type.
.It Bq Er ERRSET_NOMEMORY
Memory could not be allocated.
.It Bq Er ERRSET_INVAL
A parameter is invalid.
.It Bq Er ERRSET_FAIL
Other failure.
.El
.Sh SEE ALSO
.Xr resolver 3 ,
.Xr resolv.conf 5
.Sh HISTORY
.Fn getrrsetbyname
first appeared in
.Ox 3.0 .
The API first appeared in ISC BIND version 9.
.Sh AUTHORS
.An Jakob Schlyter Aq Mt jakob@openbsd.org
.Sh CAVEATS
The
.Dv RRSET_VALIDATED
flag in
.Li rri_flags
is set if the AD (authenticated data) bit in the DNS answer is
set.
This flag
.Em should not
be trusted unless the transport between the nameserver and the resolver
is secure (e.g. IPsec, trusted network, loopback communication).
.Sh BUGS
The data in
.Li *rdi_data
should be returned in uncompressed wire format.
Currently, the data is in compressed format and the caller can't
uncompress since it doesn't have the full message.