diff options
author | eric <> | 2012-07-13 17:49:54 +0000 |
---|---|---|
committer | eric <> | 2012-07-13 17:49:54 +0000 |
commit | 9204e59073bcf27e1487ec4ac46e981902ddd904 (patch) | |
tree | c9d57f5a2812d08f0e504c69deb162dc89ae78a9 /src/regress/lib/libc/asr/bin/common.h | |
parent | 1cb24e474ab651a39f96d1b0c7582a081ea8c2b8 (diff) | |
download | openbsd-9204e59073bcf27e1487ec4ac46e981902ddd904.tar.gz openbsd-9204e59073bcf27e1487ec4ac46e981902ddd904.tar.bz2 openbsd-9204e59073bcf27e1487ec4ac46e981902ddd904.zip |
import regression suite for asr
Diffstat (limited to 'src/regress/lib/libc/asr/bin/common.h')
-rw-r--r-- | src/regress/lib/libc/asr/bin/common.h | 136 |
1 files changed, 136 insertions, 0 deletions
diff --git a/src/regress/lib/libc/asr/bin/common.h b/src/regress/lib/libc/asr/bin/common.h new file mode 100644 index 0000000000..87df4ae4a2 --- /dev/null +++ b/src/regress/lib/libc/asr/bin/common.h | |||
@@ -0,0 +1,136 @@ | |||
1 | /* $OpenBSD: common.h,v 1.1.1.1 2012/07/13 17:49:53 eric 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 | #include <sys/types.h> | ||
18 | #include <sys/socket.h> | ||
19 | |||
20 | #include <arpa/nameser.h> | ||
21 | |||
22 | #include <netinet/in.h> | ||
23 | |||
24 | #include <netdb.h> | ||
25 | |||
26 | |||
27 | #define unpack_rr __unpack_rr | ||
28 | #define unpack_header __unpack_header | ||
29 | #define packed_init __packed_init | ||
30 | #define unpack_query __unpack_query | ||
31 | #define sockaddr_from_str __sockaddr_from_str | ||
32 | #define print_addr __print_addr | ||
33 | |||
34 | extern int long_err; | ||
35 | extern int gai_errno; | ||
36 | extern int rrset_errno; | ||
37 | |||
38 | const char *classtostr(uint16_t); | ||
39 | const char *typetostr(uint16_t); | ||
40 | const char *rcodetostr(uint16_t); | ||
41 | |||
42 | uint16_t strtotype(const char*); | ||
43 | uint16_t strtoclass(const char*); | ||
44 | |||
45 | void print_rrsetinfo(struct rrsetinfo *); | ||
46 | void print_addrinfo(struct addrinfo *); | ||
47 | void print_errors(void); | ||
48 | void print_hostent(struct hostent *); | ||
49 | void print_netent(struct netent *); | ||
50 | |||
51 | int sockaddr_from_str(struct sockaddr *, int, const char *); | ||
52 | int addr_from_str(char *, int *, int *, const char *); | ||
53 | char* gethostarg(char *); | ||
54 | |||
55 | #define QR_MASK (0x1 << 15) | ||
56 | #define OPCODE_MASK (0xf << 11) | ||
57 | #define AA_MASK (0x1 << 10) | ||
58 | #define TC_MASK (0x1 << 9) | ||
59 | #define RD_MASK (0x1 << 8) | ||
60 | #define RA_MASK (0x1 << 7) | ||
61 | #define Z_MASK (0x7 << 4) | ||
62 | #define RCODE_MASK (0xf) | ||
63 | |||
64 | #define OPCODE(v) ((v) & OPCODE_MASK) | ||
65 | #define RCODE(v) ((v) & RCODE_MASK) | ||
66 | |||
67 | |||
68 | struct packed { | ||
69 | char *data; | ||
70 | size_t len; | ||
71 | size_t offset; | ||
72 | const char *err; | ||
73 | }; | ||
74 | |||
75 | struct header { | ||
76 | uint16_t id; | ||
77 | uint16_t flags; | ||
78 | uint16_t qdcount; | ||
79 | uint16_t ancount; | ||
80 | uint16_t nscount; | ||
81 | uint16_t arcount; | ||
82 | }; | ||
83 | |||
84 | struct query { | ||
85 | char q_dname[MAXDNAME]; | ||
86 | uint16_t q_type; | ||
87 | uint16_t q_class; | ||
88 | }; | ||
89 | |||
90 | struct rr { | ||
91 | char rr_dname[MAXDNAME]; | ||
92 | uint16_t rr_type; | ||
93 | uint16_t rr_class; | ||
94 | uint32_t rr_ttl; | ||
95 | union { | ||
96 | struct { | ||
97 | char cname[MAXDNAME]; | ||
98 | } cname; | ||
99 | struct { | ||
100 | uint16_t preference; | ||
101 | char exchange[MAXDNAME]; | ||
102 | } mx; | ||
103 | struct { | ||
104 | char nsname[MAXDNAME]; | ||
105 | } ns; | ||
106 | struct { | ||
107 | char ptrname[MAXDNAME]; | ||
108 | } ptr; | ||
109 | struct { | ||
110 | char mname[MAXDNAME]; | ||
111 | char rname[MAXDNAME]; | ||
112 | uint32_t serial; | ||
113 | uint32_t refresh; | ||
114 | uint32_t retry; | ||
115 | uint32_t expire; | ||
116 | uint32_t minimum; | ||
117 | } soa; | ||
118 | struct { | ||
119 | struct in_addr addr; | ||
120 | } in_a; | ||
121 | struct { | ||
122 | struct in6_addr addr6; | ||
123 | } in_aaaa; | ||
124 | struct { | ||
125 | uint16_t rdlen; | ||
126 | const void *rdata; | ||
127 | } other; | ||
128 | } rr; | ||
129 | }; | ||
130 | |||
131 | void packed_init(struct packed*, char*, size_t); | ||
132 | int pack_header(struct packed*, const struct header*); | ||
133 | int pack_query(struct packed*, uint16_t, uint16_t, const char*); | ||
134 | int unpack_header(struct packed*, struct header*); | ||
135 | int unpack_query(struct packed*, struct query*); | ||
136 | int unpack_rr(struct packed*, struct rr*); | ||