open62541 1.3.12
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_SRV 33
76
77struct resource {
78 char *name;
79 unsigned short type, clazz;
80 unsigned long int ttl;
81 unsigned short int rdlength;
82 unsigned char *rdata;
83 union {
84 struct {
85 struct in_addr ip;
86 //cppcheck-suppress unusedStructMember
87 char *name;
88 } a;
89 struct {
90 //cppcheck-suppress unusedStructMember
91 char *name;
92 } ns;
93 struct {
94 //cppcheck-suppress unusedStructMember
95 char *name;
97 struct {
98 //cppcheck-suppress unusedStructMember
99 char *name;
101 struct {
102 //cppcheck-suppress unusedStructMember
103 unsigned short int priority, weight, port;
104 //cppcheck-suppress unusedStructMember
105 char *name;
108};
109
110struct message {
111 /* External data */
112 unsigned short int id;
113 struct {
114 //it would be better to use unsigned short, but gcc < 5 complaints when using pedantic
115 //cppcheck-suppress unusedStructMember
116 unsigned int qr:1, opcode:4, aa:1, tc:1, rd:1, ra:1, z:3, rcode:4;
118 unsigned short int qdcount, ancount, nscount, arcount;
119 struct question *qd;
120 struct resource *an, *ns, *ar;
121
122 /* Internal variables */
123 unsigned char *_buf;
124 unsigned char *_bufEnd;
126 size_t _len;
128
129 /* Packet acts as padding, easier mem management */
130 unsigned char _packet[MAX_PACKET_LEN];
131};
132
133
134uint16_t net2short(const unsigned char **bufp);
135uint32_t net2long (const unsigned char **bufp);
136
137
138void MDNSD_EXPORT short2net(uint16_t i, unsigned char **bufp);
139void MDNSD_EXPORT long2net (uint32_t l, unsigned char **bufp);
140
141
142bool MDNSD_EXPORT message_parse(struct message *m, unsigned char *packet, size_t packetLen);
143
144
145struct message *message_wire(void);
146
147
148void MDNSD_EXPORT message_qd(struct message *m, char *name, unsigned short int type, unsigned short int clazz);
149
150
151void MDNSD_EXPORT message_an(struct message *m, char *name, unsigned short int type, unsigned short int clazz, unsigned long ttl);
152void MDNSD_EXPORT message_ns(struct message *m, char *name, unsigned short int type, unsigned short int clazz, unsigned long ttl);
153void MDNSD_EXPORT message_ar(struct message *m, char *name, unsigned short int type, unsigned short int clazz, unsigned long ttl);
154
155
156void MDNSD_EXPORT message_rdata_long (struct message *m, struct in_addr l);
157void MDNSD_EXPORT message_rdata_name (struct message *m, char *name);
158void MDNSD_EXPORT message_rdata_srv (struct message *m, unsigned short int priority, unsigned short int weight,
159 unsigned short int port, char *name);
160void MDNSD_EXPORT message_rdata_raw (struct message *m, unsigned char *rdata, unsigned short int rdlength);
161
162
163unsigned char MDNSD_EXPORT * message_packet (struct message *m);
164int MDNSD_EXPORT message_packet_len (struct message *m);
165
166#ifdef __cplusplus
167} // extern "C"
168#endif
169
170#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:118
struct resource * ns
Definition 1035.h:120
unsigned short int ancount
Definition 1035.h:118
unsigned int ra
Definition 1035.h:116
unsigned int aa
Definition 1035.h:116
unsigned char * _buf
Definition 1035.h:123
unsigned int rcode
Definition 1035.h:116
struct question * qd
Definition 1035.h:119
struct resource * an
Definition 1035.h:120
struct resource * ar
Definition 1035.h:120
unsigned int opcode
Definition 1035.h:116
int _label
Definition 1035.h:127
unsigned short int qdcount
Definition 1035.h:118
unsigned int qr
Definition 1035.h:116
struct message::@6 header
unsigned char _packet[10000]
Definition 1035.h:130
size_t _len
Definition 1035.h:126
char * _labels[20]
Definition 1035.h:125
unsigned int rd
Definition 1035.h:116
unsigned short int id
Definition 1035.h:112
unsigned char * _bufEnd
Definition 1035.h:124
unsigned int tc
Definition 1035.h:116
unsigned int z
Definition 1035.h:116
unsigned short int nscount
Definition 1035.h:118
unsigned short clazz
Definition 1035.h:67
unsigned short type
Definition 1035.h:67
char * name
Definition 1035.h:66
struct resource::@0::@2 ns
struct resource::@0::@4 ptr
unsigned short int weight
Definition 1035.h:103
struct resource::@0::@5 srv
char * name
Definition 1035.h:78
unsigned char * rdata
Definition 1035.h:82
union resource::@0 known
unsigned short clazz
Definition 1035.h:79
unsigned short int port
Definition 1035.h:103
unsigned short int rdlength
Definition 1035.h:81
struct in_addr ip
Definition 1035.h:85
struct resource::@0::@3 cname
unsigned long int ttl
Definition 1035.h:80
struct resource::@0::@1 a
unsigned short type
Definition 1035.h:79
unsigned short int priority
Definition 1035.h:103