open62541 1.4.19
Open source implementation of OPC UA
Loading...
Searching...
No Matches
1035.h
Go to the documentation of this file.
1/** Standalone DNS parsing, RFC10350
2 *
3 * Copyright (c) 2003 Jeremie Miller <jer@jabber.org>
4 * Copyright (c) 2016-2026 Joachim Wiberg <troglobit@gmail.com>
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions are met:
9 * * Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * * Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * * Neither the name of the copyright holders nor the names of its
15 * contributors may be used to endorse or promote products derived from
16 * this software without specific prior written permission.
17 *
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
22 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28 * POSSIBILITY OF SUCH DAMAGE.
29 */
30
31/** Familiarize yourself with RFC1035 if you want to know what all the
32 * variable names mean. This file hides most of the dirty work all of
33 * this code depends on the buffer space a packet is in being 4096 and
34 * zero'd before the packet is copied in also conveniently decodes srv
35 * rr's, type 33, see RFC2782
36 */
37#ifndef MDNS_1035_H_
38#define MDNS_1035_H_
39
40#include <arpa/inet.h>
41#include <netinet/in.h>
42#include <sys/socket.h>
43
44/*
45 * At least FreeBSD, OpenBSD and NexentaCore do not define the
46 * s6_addr32, s6_addr8, and s6_addr16 for user land.
47 */
48#if !defined s6_addr32 && defined __sun__
49# define s6_addr32 _S6_un._S6_u32
50#elif !defined s6_addr32 && ( defined __OpenBSD__ || defined __FreeBSD__ || defined __NetBSD__ )
51# define s6_addr32 __u6_addr.__u6_addr32
52#endif /* !defined s6_addr32 */
53
54/** Should be reasonably large, for UDP */
55#define MAX_PACKET_LEN 65535
56#define MAX_NUM_LABELS 512
57
58struct question {
59 char *name;
60 unsigned short int type, class;
61};
62
63#define QTYPE_A 1
64#define QTYPE_NS 2
65#define QTYPE_CNAME 5
66#define QTYPE_PTR 12
67#define QTYPE_TXT 16
68#define QTYPE_AAAA 28
69#define QTYPE_SRV 33
70#define QTYPE_ANY 255
71
72struct resource {
73 char *name;
74 unsigned short int type, class;
75 unsigned long int ttl;
76 unsigned short int rdlength;
77 unsigned char *rdata;
78 union {
79 struct {
80 struct in_addr ip;
81 char *name;
82 } a;
83 struct {
84 struct in6_addr ip6;
85 char *name;
87 struct {
88 char *name;
89 } ns;
90 struct {
91 char *name;
93 struct {
94 char *name;
95 } ptr;
96 struct {
97 unsigned short int priority, weight, port;
98 char *name;
99 } srv;
101};
102
103struct message {
104 /* External data */
105 unsigned short int id;
106 struct {
107 unsigned short qr:1, opcode:4, aa:1, tc:1, rd:1, ra:1, z:3, rcode:4;
109 unsigned short int qdcount, ancount, nscount, arcount;
110 struct question *qd;
111 struct resource *an, *ns, *ar;
112
113 /* Internal variables */
114 unsigned char *_buf;
117
118 /* Packet acts as padding, easier mem management */
119 unsigned char _packet[MAX_PACKET_LEN];
120};
121
122
123unsigned short int net2short(unsigned char **buf);
124unsigned long int net2long (unsigned char **buf);
125
126
127void short2net(unsigned short int i, unsigned char **buf);
128void long2net (unsigned long int l, unsigned char **buf);
129
130
131int message_parse(struct message *m, unsigned char *packet);
132
133
134struct message *message_wire(void);
135
136
137void message_qd(struct message *m, char *name, unsigned short int type, unsigned short int class);
138
139
140void message_an(struct message *m, char *name, unsigned short int type, unsigned short int class, unsigned long int ttl);
141void message_ns(struct message *m, char *name, unsigned short int type, unsigned short int class, unsigned long int ttl);
142void message_ar(struct message *m, char *name, unsigned short int type, unsigned short int class, unsigned long int ttl);
143
144
145void message_rdata_long (struct message *m, unsigned long l);
146void message_rdata_ipv4 (struct message *m, struct in_addr a);
147void message_rdata_ipv6 (struct message *m, struct in6_addr a6);
148void message_rdata_name (struct message *m, char *name);
149void message_rdata_srv (struct message *m, unsigned short int priority, unsigned short int weight,
150 unsigned short int port, char *name);
151void message_rdata_raw (struct message *m, unsigned char *rdata, unsigned short int rdlength);
152
153
154unsigned char *message_packet (struct message *m);
156
157#endif /* MDNS_1035_H_ */
unsigned short int net2short(unsigned char **buf)
void message_rdata_raw(struct message *m, unsigned char *rdata, unsigned short int rdlength)
int message_parse(struct message *m, unsigned char *packet)
void message_qd(struct message *m, char *name, unsigned short int type, unsigned short int class)
unsigned char * message_packet(struct message *m)
void message_rdata_srv(struct message *m, unsigned short int priority, unsigned short int weight, unsigned short int port, char *name)
#define MAX_PACKET_LEN
Standalone DNS parsing, RFC10350.
Definition 1035.h:55
unsigned long int net2long(unsigned char **buf)
void short2net(unsigned short int i, unsigned char **buf)
int message_packet_len(struct message *m)
#define MAX_NUM_LABELS
Definition 1035.h:56
void message_rdata_long(struct message *m, unsigned long l)
void message_rdata_ipv6(struct message *m, struct in6_addr a6)
void message_rdata_name(struct message *m, char *name)
void long2net(unsigned long int l, unsigned char **buf)
void message_ns(struct message *m, char *name, unsigned short int type, unsigned short int class, unsigned long int ttl)
void message_ar(struct message *m, char *name, unsigned short int type, unsigned short int class, unsigned long int ttl)
void message_rdata_ipv4(struct message *m, struct in_addr a)
void message_an(struct message *m, char *name, unsigned short int type, unsigned short int class, unsigned long int ttl)
struct message * message_wire(void)
unsigned short int arcount
Definition 1035.h:109
struct resource * ns
Definition 1035.h:111
unsigned short int ancount
Definition 1035.h:109
char * _labels[512]
Definition 1035.h:115
unsigned short rd
Definition 1035.h:107
unsigned char * _buf
Definition 1035.h:114
struct question * qd
Definition 1035.h:110
int _len
Definition 1035.h:116
struct resource * an
Definition 1035.h:111
unsigned short qr
Definition 1035.h:107
struct resource * ar
Definition 1035.h:111
unsigned char _packet[65535]
Definition 1035.h:119
unsigned short rcode
Definition 1035.h:107
unsigned short ra
Definition 1035.h:107
int _label
Definition 1035.h:116
unsigned short int qdcount
Definition 1035.h:109
unsigned short z
Definition 1035.h:107
unsigned short aa
Definition 1035.h:107
unsigned short int id
Definition 1035.h:105
unsigned short tc
Definition 1035.h:107
struct message::@7 header
unsigned short opcode
Definition 1035.h:107
unsigned short int nscount
Definition 1035.h:109
char * name
Definition 1035.h:59
unsigned short int type
Definition 1035.h:60
struct resource::@0::@4 cname
unsigned short int weight
Definition 1035.h:97
struct resource::@0::@2 aaaa
char * name
Definition 1035.h:73
unsigned char * rdata
Definition 1035.h:77
union resource::@0 known
struct resource::@0::@5 ptr
unsigned short int port
Definition 1035.h:97
struct resource::@0::@3 ns
unsigned short int type
Definition 1035.h:74
struct resource::@0::@6 srv
unsigned short int rdlength
Definition 1035.h:76
struct in_addr ip
Definition 1035.h:80
unsigned long int ttl
Definition 1035.h:75
struct resource::@0::@1 a
unsigned short int priority
Definition 1035.h:97
qn name
Definition types.h:517
const UA_DataType * type
Definition types.h:626