-
Notifications
You must be signed in to change notification settings - Fork 6
/
dns.h
86 lines (70 loc) · 2.27 KB
/
dns.h
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
/*
* Copyright (C) 2014 John Crispin <blogic@openwrt.org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License version 2.1
* as published by the Free Software Foundation
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*/
#ifndef _DNS_H__
#define _DNS_H__
#include <stdint.h>
#include <arpa/inet.h>
#define FLAG_RESPONSE 0x8000
#define FLAG_AUTHORATIVE 0x0400
#define TYPE_A 0x0001
#define TYPE_PTR 0x000C
#define TYPE_TXT 0x0010
#define TYPE_AAAA 0x001c
#define TYPE_SRV 0x0021
#define TYPE_ANY 0x00ff
#define IS_COMPRESSED(x) ((x & 0xc0) == 0xc0)
#define MCAST_ADDR "224.0.0.251"
#define MCAST_ADDR6 "ff02::fb"
#define MCAST_PORT 5353
#define CLASS_FLUSH 0x8000
#define CLASS_UNICAST 0x8000
#define CLASS_IN 0x0001
#define MAX_NAME_LEN 8096
#define MAX_DATA_LEN 8096
#define C_DNS_SD "_services._dns-sd._udp.local"
struct dns_header {
uint16_t id;
uint16_t flags;
uint16_t questions;
uint16_t answers;
uint16_t authority;
uint16_t additional;
} __attribute__((packed));
struct dns_srv_data {
uint16_t priority;
uint16_t weight;
uint16_t port;
} __attribute__((packed));
struct dns_answer {
uint16_t type;
uint16_t class;
uint32_t ttl;
uint16_t rdlength;
} __attribute__((packed));
struct dns_question {
uint16_t type;
uint16_t class;
} __attribute__((packed));
struct interface;
extern int cfg_proto;
extern int cfg_no_subnet;
void dns_send_question(struct interface *iface, struct sockaddr *to,
const char *question, int type, int multicast);
void dns_init_answer(void);
void dns_add_answer(int type, const uint8_t *rdata, uint16_t rdlength, int ttl);
void dns_send_answer(struct interface *iface, struct sockaddr *to, const char *answer);
void dns_reply_a(struct interface *iface, struct sockaddr *to, int ttl, const char *hostname);
void dns_reply_a_additional(struct interface *iface, struct sockaddr *to, int ttl);
const char* dns_type_string(uint16_t type);
void dns_handle_packet(struct interface *iface, struct sockaddr *s, uint16_t port, uint8_t *buf, int len);
#endif