GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: lib/libc/asr/getrrsetbyname.c Lines: 0 26 0.0 %
Date: 2017-11-07 Branches: 0 18 0.0 %

Line Branch Exec Source
1
/*	$OpenBSD: getrrsetbyname.c,v 1.6 2015/09/14 07:38:37 guenther Exp $	*/
2
/*
3
 * Copyright (c) 2012 Eric Faurot <eric@openbsd.org>
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 THE AUTHOR DISCLAIMS ALL WARRANTIES
10
 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11
 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR 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 OF
15
 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16
 */
17
18
#include <sys/types.h>
19
#include <sys/socket.h>
20
#include <netinet/in.h>
21
#include <netdb.h>
22
23
#include <asr.h>
24
#include <errno.h>
25
#include <resolv.h>
26
#include <stdlib.h>
27
28
int
29
getrrsetbyname(const char *name, unsigned int class, unsigned int type,
30
    unsigned int flags, struct rrsetinfo **res)
31
{
32
	struct asr_query *as;
33
	struct asr_result ar;
34
	int r, saved_errno = errno;
35
36
	res_init();
37
38
	as = getrrsetbyname_async(name, class, type, flags, NULL);
39
	if (as == NULL) {
40
		r = (errno == ENOMEM) ? ERRSET_NOMEMORY : ERRSET_FAIL;
41
		errno = saved_errno;
42
		return (r);
43
	}
44
45
	asr_run_sync(as, &ar);
46
47
	*res = ar.ar_rrsetinfo;
48
49
	return (ar.ar_rrset_errno);
50
}
51
52
/* from net/getrrsetbyname.c */
53
void
54
freerrset(struct rrsetinfo *rrset)
55
{
56
	u_int16_t i;
57
58
	if (rrset == NULL)
59
		return;
60
61
	if (rrset->rri_rdatas) {
62
		for (i = 0; i < rrset->rri_nrdatas; i++) {
63
			if (rrset->rri_rdatas[i].rdi_data == NULL)
64
				break;
65
			free(rrset->rri_rdatas[i].rdi_data);
66
		}
67
		free(rrset->rri_rdatas);
68
	}
69
70
	if (rrset->rri_sigs) {
71
		for (i = 0; i < rrset->rri_nsigs; i++) {
72
			if (rrset->rri_sigs[i].rdi_data == NULL)
73
				break;
74
			free(rrset->rri_sigs[i].rdi_data);
75
		}
76
		free(rrset->rri_sigs);
77
	}
78
79
	if (rrset->rri_name)
80
		free(rrset->rri_name);
81
	free(rrset);
82
}
83
DEF_WEAK(freerrset);