open62541 1.3.15
Open source implementation of OPC UA
Loading...
Searching...
No Matches
1035.h
Go to the documentation of this file.
1/** Familiarize yourself with RFC1035 if you want to know what all the
2 * variable names mean. This file hides most of the dirty work all of
3 * this code depends on the buffer space a packet is in being 4096 and
4 * zero'd before the packet is copied in also conveniently decodes srv
5 * rr's, type 33, see RFC2782
6 */
7#ifndef MDNS_1035_H_
8#define MDNS_1035_H_
9
10#ifdef __cplusplus
11extern "C" {
12#endif
13
14#include "mdnsd_config.h"
15
16#ifdef _WIN32
17
18/** Backup definition of SLIST_ENTRY on mingw winnt.h */
19#ifdef SLIST_ENTRY
20# pragma push_macro("SLIST_ENTRY")
21# undef SLIST_ENTRY
22# define POP_SLIST_ENTRY
23#endif
24
25/** winnt.h redefines SLIST_ENTRY */
26# define _WINSOCK_DEPRECATED_NO_WARNINGS /* inet_ntoa is deprecated on MSVC but used for compatibility */
27# include <winsock2.h>
28# include <ws2tcpip.h>
29
30#ifndef in_addr_t
31#define in_addr_t unsigned __int32
32#endif
33
34/** restore definition */
35#ifdef POP_SLIST_ENTRY
36# undef SLIST_ENTRY
37# undef POP_SLIST_ENTRY
38# pragma pop_macro("SLIST_ENTRY")
39#endif
40
41
42#else
43# include <arpa/inet.h>
44#endif
45
46#if !defined(__bool_true_false_are_defined) && defined(_MSC_VER) && _MSC_VER < 1600
47// VS 2008 has no stdbool.h
48#define bool short
49#define true 1
50#define false 0
51#else
52#include <stdbool.h>
53#endif
54
55#ifdef _MSC_VER
56#include "ms_stdint.h" /* Includes stdint.h or workaround for older Visual Studios */
57#else
58#include <stdint.h>
59#endif
60
61/** Should be reasonably large, for UDP */
62#define MAX_PACKET_LEN 10000
63#define MAX_NUM_LABELS 20
64
65struct question {
66 char *name;
67 unsigned short type, clazz;
68};
69
70#define QTYPE_A 1
71#define QTYPE_NS 2
72#define QTYPE_CNAME 5
73#define QTYPE_PTR 12
74#define QTYPE_TXT 16
75#define QTYPE_AAAA 28
76#define QTYPE_SRV 33
77
78struct resource {
79 char *name;
80 unsigned short type, clazz;
81 unsigned long int ttl;
82 unsigned short int rdlength;
83 unsigned char *rdata;
84 union {
85 struct {
86 struct in_addr ip;
87 //cppcheck-suppress unusedStructMember
88 char *name;
89 } a;
90 struct {
91 struct in6_addr ip6;
92 //cppcheck-suppress unusedStructMember
93 char *name;
95 struct {
96 //cppcheck-suppress unusedStructMember
97 char *name;
98 } ns;
99 struct {
100 //cppcheck-suppress unusedStructMember
101 char *name;
103 struct {
104 //cppcheck-suppress unusedStructMember
105 char *name;
107 struct {
108 //cppcheck-suppress unusedStructMember
109 unsigned short int priority, weight, port;
110 //cppcheck-suppress unusedStructMember
111 char *name;
114};
115
116struct message {
117 /* External data */
118 unsigned short int id;
119 struct {
120 //it would be better to use unsigned short, but gcc < 5 complaints when using pedantic
121 //cppcheck-suppress unusedStructMember
122 unsigned int qr:1, opcode:4, aa:1, tc:1, rd:1, ra:1, z:3, rcode:4;
124 unsigned short int qdcount, ancount, nscount, arcount;
125 struct question *qd;
126 struct resource *an, *ns, *ar;
127
128 /* Internal variables */
129 unsigned char *_buf;
130 unsigned char *_bufEnd;
132 size_t _len;
134
135 /* Packet acts as padding, easier mem management */
136 unsigned char _packet[MAX_PACKET_LEN];
137};
138
139
140uint16_t net2short(const unsigned char **bufp);
141uint32_t net2long (const unsigned char **bufp);
142
143
144void MDNSD_EXPORT short2net(uint16_t i, unsigned char **bufp);
145void MDNSD_EXPORT long2net (uint32_t l, unsigned char **bufp);
146
147
148bool MDNSD_EXPORT message_parse(struct message *m, unsigned char *packet, size_t packetLen);
149
150
151struct message *message_wire(void);
152
153
154void MDNSD_EXPORT message_qd(struct message *m, char *name, unsigned short int type, unsigned short int clazz);
155
156
157void MDNSD_EXPORT message_an(struct message *m, char *name, unsigned short int type, unsigned short int clazz, unsigned long ttl);
158void MDNSD_EXPORT message_ns(struct message *m, char *name, unsigned short int type, unsigned short int clazz, unsigned long ttl);
159void MDNSD_EXPORT message_ar(struct message *m, char *name, unsigned short int type, unsigned short int clazz, unsigned long ttl);
160
161
162void MDNSD_EXPORT message_rdata_long (struct message *m, struct in_addr l);
163void MDNSD_EXPORT message_rdata_name (struct message *m, char *name);
164void MDNSD_EXPORT message_rdata_srv (struct message *m, unsigned short int priority, unsigned short int weight,
165 unsigned short int port, char *name);
166void MDNSD_EXPORT message_rdata_raw (struct message *m, unsigned char *rdata, unsigned short int rdlength);
167
168
169unsigned char MDNSD_EXPORT * message_packet (struct message *m);
170int MDNSD_EXPORT message_packet_len (struct message *m);
171
172#ifdef __cplusplus
173} // extern "C"
174#endif
175
176#endif /* MDNS_1035_H_ */
int MDNSD_EXPORT message_packet_len(struct message *m)
unsigned char MDNSD_EXPORT * message_packet(struct message *m)
void MDNSD_EXPORT message_rdata_name(struct message *m, char *name)
void MDNSD_EXPORT message_ar(struct message *m, char *name, unsigned short int type, unsigned short int clazz, unsigned long ttl)
void MDNSD_EXPORT message_qd(struct message *m, char *name, unsigned short int type, unsigned short int clazz)
void MDNSD_EXPORT message_rdata_srv(struct message *m, unsigned short int priority, unsigned short int weight, unsigned short int port, char *name)
#define MAX_PACKET_LEN
Familiarize yourself with RFC1035 if you want to know what all the variable names mean.
Definition 1035.h:62
void MDNSD_EXPORT message_rdata_raw(struct message *m, unsigned char *rdata, unsigned short int rdlength)
void MDNSD_EXPORT message_an(struct message *m, char *name, unsigned short int type, unsigned short int clazz, unsigned long ttl)
uint16_t net2short(const unsigned char **bufp)
void MDNSD_EXPORT message_rdata_long(struct message *m, struct in_addr l)
void MDNSD_EXPORT long2net(uint32_t l, unsigned char **bufp)
uint32_t net2long(const unsigned char **bufp)
#define MAX_NUM_LABELS
Definition 1035.h:63
bool MDNSD_EXPORT message_parse(struct message *m, unsigned char *packet, size_t packetLen)
void MDNSD_EXPORT message_ns(struct message *m, char *name, unsigned short int type, unsigned short int clazz, unsigned long ttl)
void MDNSD_EXPORT short2net(uint16_t i, unsigned char **bufp)
struct message * message_wire(void)
unsigned short int arcount
Definition 1035.h:124
struct resource * ns
Definition 1035.h:126
unsigned short int ancount
Definition 1035.h:124
unsigned int ra
Definition 1035.h:122
unsigned int aa
Definition 1035.h:122
unsigned char * _buf
Definition 1035.h:129
unsigned int rcode
Definition 1035.h:122
struct question * qd
Definition 1035.h:125
struct resource * an
Definition 1035.h:126
struct resource * ar
Definition 1035.h:126
unsigned int opcode
Definition 1035.h:122
int _label
Definition 1035.h:133
unsigned short int qdcount
Definition 1035.h:124
unsigned int qr
Definition 1035.h:122
unsigned char _packet[10000]
Definition 1035.h:136
size_t _len
Definition 1035.h:132
char * _labels[20]
Definition 1035.h:131
unsigned int rd
Definition 1035.h:122
unsigned short int id
Definition 1035.h:118
unsigned char * _bufEnd
Definition 1035.h:130
struct message::@7 header
unsigned int tc
Definition 1035.h:122
unsigned int z
Definition 1035.h:122
unsigned short int nscount
Definition 1035.h:124
unsigned short clazz
Definition 1035.h:67
unsigned short type
Definition 1035.h:67
char * name
Definition 1035.h:66
struct resource::@0::@4 cname
unsigned short int weight
Definition 1035.h:109
struct resource::@0::@2 aaaa
char * name
Definition 1035.h:79
unsigned char * rdata
Definition 1035.h:83
union resource::@0 known
unsigned short clazz
Definition 1035.h:80
struct resource::@0::@5 ptr
unsigned short int port
Definition 1035.h:109
struct resource::@0::@3 ns
struct resource::@0::@6 srv
unsigned short int rdlength
Definition 1035.h:82
struct in_addr ip
Definition 1035.h:86
unsigned long int ttl
Definition 1035.h:81
struct resource::@0::@1 a
unsigned short type
Definition 1035.h:80
unsigned short int priority
Definition 1035.h:109