mikroSDK Reference Manual
nbns_common.h
Go to the documentation of this file.
1
31#ifndef _NBNS_COMMON_H
32#define _NBNS_COMMON_H
33
34//Dependencies
35#include "core/net.h"
36#include "dns/dns_common.h"
37
38//Default resource record TTL (cache lifetime)
39#ifndef NBNS_DEFAULT_RESOURCE_RECORD_TTL
40 #define NBNS_DEFAULT_RESOURCE_RECORD_TTL 120
41#elif (NBNS_DEFAULT_RESOURCE_RECORD_TTL < 1)
42 #error NBNS_DEFAULT_RESOURCE_RECORD_TTL parameter is not valid
43#endif
44
45//NBNS port number
46#define NBNS_PORT 137
47
48//Macro definition
49#define NBNS_ENCODE_H(c) ('A' + (((c) >> 4) & 0x0F))
50#define NBNS_ENCODE_L(c) ('A' + ((c) & 0x0F))
51
52//C++ guard
53#ifdef __cplusplus
54extern "C" {
55#endif
56
57
62typedef enum
63{
64 NBNS_ONT_BNODE = 0x0000,
65 NBNS_ONT_PNODE = 0x2000,
66 NBNS_ONT_MNODE = 0x4000,
67 NBNS_G_UNIQUE = 0x0000,
68 NBNS_G_GROUP = 0x8000
69} DnsFlags;
70
71
72//CodeWarrior or Win32 compiler?
73#if defined(__CWCC__) || defined(_WIN32)
74 #pragma pack(push, 1)
75#endif
76
77
83{
84 uint16_t id; //0-1
85#if defined(_CPU_BIG_ENDIAN) && !defined(__ICCRX__)
86 uint8_t qr : 1; //2
87 uint8_t opcode : 4;
88 uint8_t aa : 1;
89 uint8_t tc : 1;
90 uint8_t rd : 1;
91 uint8_t ra : 1; //3
92 uint8_t z : 2;
93 uint8_t b : 1;
94 uint8_t rcode : 4;
95#else
96 uint8_t rd : 1; //2
97 uint8_t tc : 1;
98 uint8_t aa : 1;
99 uint8_t opcode : 4;
100 uint8_t qr : 1;
101 uint8_t rcode : 4; //3
102 uint8_t b : 1;
103 uint8_t z : 2;
104 uint8_t ra : 1;
105#endif
106 uint16_t qdcount; //4-5
107 uint16_t ancount; //6-7
108 uint16_t nscount; //8-9
109 uint16_t arcount; //10-11
110 uint8_t questions[]; //12
111} NbnsHeader;
112
113
118typedef __packed_struct
119{
120 uint16_t flags;
121 Ipv4Addr addr;
122} NbnsAddrEntry;
123
124
125//CodeWarrior or Win32 compiler?
126#if defined(__CWCC__) || defined(_WIN32)
127 #pragma pack(pop)
128#endif
129
130//NBNS related functions
131error_t nbnsInit(NetInterface *interface);
132
133void nbnsProcessMessage(NetInterface *interface,
134 const IpPseudoHeader *pseudoHeader, const UdpHeader *udpHeader,
135 const NetBuffer *buffer, size_t offset, const NetRxAncillary *ancillary,
136 void *param);
137
138size_t nbnsEncodeName(const char_t *src, uint8_t *dest);
139
140size_t nbnsParseName(const NbnsHeader *message,
141 size_t length, size_t pos, char_t *dest);
142
143bool_t nbnsCompareName(const NbnsHeader *message,
144 size_t length, size_t pos, const char_t *name);
145
146//C++ guard
147#ifdef __cplusplus
148}
149#endif
150
151#endif
Common DNS routines.
error_t
Error codes.
Definition error.h:43
uint32_t Ipv4Addr
IPv4 network address.
Definition ipv4.h:267
DnsFlags
NBNS flags.
Definition nbns_common.h:63
typedef __packed_struct
NBNS message header.
Definition nbns_common.h:83
TCP/IP stack core.
IP pseudo header.
Definition ip.h:91
Structure describing a buffer that spans multiple chunks.
Definition net_mem.h:89