djbdnscurve6
45
djbdnscurve6
Loading...
Searching...
No Matches
djbdnscurve6-45
src
tinydns-get.c
Go to the documentation of this file.
1
#include "str.h"
2
#include "byte.h"
3
#include "scan.h"
4
#include "exit.h"
5
#include "stralloc.h"
6
#include "buffer.h"
7
#include "logmsg.h"
8
#include "uint_t.h"
9
#include "
response.h
"
10
#include "case.h"
11
#include "
printpacket.h
"
12
#include "
parsetype.h
"
13
#include "ip.h"
14
#include "
dns.h
"
15
16
extern
int
respond
(
char
*,
char
*,
char
*);
17
int
rename
(
const
char
*,
const
char
*);
// keep compiler silent
18
19
#define WHO "tinydns-get "
20
21
void
usage
(
void
)
22
{
23
logmsg(
WHO
,100,USAGE,
"tinydns-get type name [ip]"
);
24
}
25
void
oops
(
void
)
26
{
27
logmsg(
WHO
,111,FATAL,
"unable to parse"
);
28
}
29
30
static
char
ip
[16];
31
static
char
type
[2];
32
static
char
*q;
33
34
static
stralloc out;
35
36
int
main
(
int
argc,
char
**argv)
37
{
38
uint16 u16;
39
40
if
(!*argv)
usage
();
41
42
if
(!*++argv)
usage
();
43
if
(!
parsetype
(*argv,
type
))
usage
();
44
45
if
(!*++argv)
usage
();
46
if
(
dns_domain_fromdot
(&q,*argv,str_len(*argv)) <= 0)
oops
();
47
48
if
(*++argv)
49
if
(!ip6_scan(*argv,
ip
))
usage
();
50
51
if
(!stralloc_copys(&out,
""
))
oops
();
52
uint16_unpack_big(
type
,&u16);
53
if
(!stralloc_catulong0(&out,u16,0))
oops
();
54
if
(!stralloc_cats(&out,
" "
))
oops
();
55
if
(
dns_domain_todot_cat
(&out,q) <= 0)
oops
();
56
if
(!stralloc_cats(&out,
":\n"
))
oops
();
57
58
if
(!
response_query
(q,
type
,
DNS_C_IN
))
oops
();
59
response
[3] &= ~128;
60
response
[2] &= ~1;
61
response
[2] |= 4;
62
case_lowerb(q,
dns_domain_length
(q));
63
64
if
(byte_equal(
type
,2,
DNS_T_AXFR
)) {
65
response
[3] &= ~15;
66
response
[3] |= 4;
67
}
68
else
69
if
(!
respond
(q,
type
,
ip
))
goto
DONE;
70
71
if
(!
printpacket_cat
(&out,
response
,
response_len
))
oops
();
72
73
DONE:
74
buffer_putflush(buffer_1,out.s,out.len);
75
_exit(0);
76
}
ip
char ip[16]
Definition:
axfrdns.c:125
main
int main()
Definition:
axfrdns.c:323
dns.h
DNS_T_AXFR
#define DNS_T_AXFR
Definition:
dns.h:84
DNS_C_IN
#define DNS_C_IN
Definition:
dns.h:53
dns_domain_fromdot
int dns_domain_fromdot(char **out, const char *buf, unsigned int n)
Definition:
dns_dfd.c:6
dns_domain_length
unsigned int dns_domain_length(const char *dn)
Definition:
dns_domain.c:6
dns_domain_todot_cat
int dns_domain_todot_cat(stralloc *out, const char *d)
Definition:
dns_dtda.c:11
type
char type[2]
Definition:
dnsq.c:56
parsetype.h
parsetype
int parsetype(char *, char *)
printpacket.h
printpacket_cat
unsigned int printpacket_cat(stralloc *, char *, unsigned int)
Definition:
printpacket.c:14
response.h
response
char response[]
Definition:
response.c:6
response_len
unsigned int response_len
Definition:
response.c:7
response_query
int response_query(const char *, const char *, const char *)
rename
int rename(const char *, const char *)
oops
void oops(void)
Definition:
tinydns-get.c:25
respond
int respond(char *, char *, char *)
WHO
#define WHO
Definition:
tinydns-get.c:19
usage
void usage(void)
Definition:
tinydns-get.c:21
Generated on Fri Aug 30 2024 11:58:34 for djbdnscurve6 by
1.9.6