7 #include <ObjectList.h>
11 #include <arpa/inet.h>
24 BRawNetBuffer(off_t size
);
25 BRawNetBuffer(const void* buf
, size_t size
);
27 // functions like in BNetBuffer but no type and size info is writen.
28 // functions return B_NO_MEMORY or B_OK
29 status_t
AppendUint16(uint16 value
);
30 status_t
AppendString(const char* string
);
32 status_t
ReadUint16(uint16
& value
);
33 status_t
ReadUint32(uint32
& value
);
34 status_t
ReadString(BString
& string
);
36 status_t
SkipReading(off_t off
);
38 void *Data(void) const { return (void*)fBuffer
.Buffer(); }
39 size_t Size(void) const { return fBuffer
.BufferLength(); }
40 size_t SetSize(off_t size
) { return fBuffer
.SetSize(size
); }
41 void SetWritePosition(off_t pos
) { fWritePosition
= pos
; }
44 void _Init(const void* buf
, size_t size
);
45 ssize_t
_ReadStringAt(BString
& string
, off_t pos
);
55 static status_t
GetDNSServers(BObjectList
<BString
>* serverList
);
56 static BString
ConvertToDNSName(const BString
& string
);
57 static BString
ConvertFromDNSName(const BString
& string
);
60 // see also http://prasshhant.blogspot.com/2007/03/dns-query.html
70 uint16 id
; // A 16 bit identifier
72 unsigned char qr
:1; // query (0), or a response (1)
73 unsigned char opcode
:4; // A four bit field
74 unsigned char aa
:1; // Authoritative Answer
75 unsigned char tc
:1; // Truncated Message
76 unsigned char rd
:1; // Recursion Desired
77 unsigned char ra
:1; // Recursion Available
78 unsigned char z
:3; // Reserved for future use
79 unsigned char rcode
:4; // Response code
81 uint16 q_count
; // number of question entries
82 uint16 ans_count
; // number of answer entries
83 uint16 auth_count
; // number of authority entries
84 uint16 add_count
; // number of resource entries
87 // resource record without resource data
88 struct resource_record_head
{
101 status_t
ReadDNSServer(in_addr
* add
);
102 status_t
GetMXRecords(const BString
& serverName
,
103 BObjectList
<mx_record
>* mxList
,
104 bigtime_t timeout
= 500000);
107 uint16
_GetUniqueID();
108 void _SetMXHeader(dns_header
* header
);
109 void _AppendQueryHeader(BRawNetBuffer
& buffer
,
110 const dns_header
* header
);
111 void _ReadQueryHeader(BRawNetBuffer
& buffer
,
113 void _ReadMXRecord(BRawNetBuffer
& buffer
,
114 mx_record
* mxRecord
);
116 void _ReadResourceRecord(BRawNetBuffer
& buffer
,
117 resource_record_head
* rrHead
);
121 #endif // DNS_QUERY_H