Answer.h
Go to the documentation of this file.
1 /****
2  * Sming Framework Project - Open Source framework for high efficiency native ESP8266 development.
3  * Created 2015 by Skurydin Alexey
4  * http://github.com/SmingHub/Sming
5  * All files of the Sming Core are provided under the LGPL v3 license.
6  *
7  * Answer.h
8  *
9  ****/
10 
11 #pragma once
12 
13 #include <Data/LinkedObjectList.h>
14 #include "Name.h"
15 #include "Resource.h"
16 
17 namespace mDNS
18 {
19 class Message;
20 struct Packet;
21 
25 class Answer : public LinkedObjectTemplate<Answer>
26 {
27 public:
30 
31  enum class Kind : uint8_t {
32  answer,
34  additional,
35  };
36 
37  Answer(Message& message, Kind kind) : message(message), kind(kind)
38  {
39  }
40 
41  bool parse(Packet& pkt);
42 
46  Kind getKind() const
47  {
48  return kind;
49  }
50 
54  Name getName() const
55  {
56  return Name(message, namePtr);
57  }
58 
63 
67  uint16_t getClass() const;
68 
72  bool isCachedFlush() const;
73 
77  uint32_t getTtl() const;
78 
82  String getRecordString() const;
83 
84  Message& getResponse() const
85  {
86  return message;
87  }
88 
89  uint8_t* getRecord() const;
90 
94  uint16_t getRecordPtr() const
95  {
96  return namePtr + nameLen + 10;
97  }
98 
103  {
104  return recordSize;
105  }
106 
107  // Writing
108  uint16_t init(uint16_t namePtr, const String& name, Resource::Type type, uint16_t rclass, bool flush, uint32_t ttl);
109  uint16_t init(uint16_t namePtr, const Name& name, Resource::Type type, uint16_t rclass, bool flush, uint32_t ttl);
110  void allocate(uint16_t size);
111 
112 private:
113  Message& message;
114  uint16_t namePtr{0};
115  uint16_t recordSize{0};
116  uint16_t nameLen{0};
117  Kind kind;
118 };
119 
120 } // namespace mDNS
121 
LinkedObjectListTemplate< Answer > List
Definition: Answer.h:36
Base class template for linked items with type casting.
Definition: LinkedObject.h:61
uint16_t getClass() const
ResourceRecord Class: Normally the value 1 for Internet (“IN”)
bool isCachedFlush() const
Flush cache of records matching this name.
String toString(mDNS::Answer::Kind kind)
The String class.
Definition: WString.h:136
bool parse(Packet &pkt)
Kind getKind() const
Identifies what kind of answer this is.
Definition: Answer.h:54
uint16_t getRecordPtr() const
Get pointer to Resource Record data.
Definition: Answer.h:102
Definition: Answer.h:17
Kind
Definition: Answer.h:39
Helper class for reading/writing packet content.
Definition: Packet.h:18
Type
Definition: Resource.h:41
OwnedLinkedObjectListTemplate< Answer > OwnedList
Definition: Answer.h:37
uint16_t getRecordSize() const
Get size of Resource Record.
Definition: Answer.h:110
Answer(Message &message, Kind kind)
Definition: Answer.h:45
void allocate(uint16_t size)
uint32_t getTtl() const
ResourceRecord Time To Live: Number of seconds this should be remembered.
Encoded DNS name.
Definition: Name.h:45
Name getName() const
Object, domain or zone name.
Definition: Answer.h:62
Message & getResponse() const
Definition: Answer.h:92
A single mDNS Answer.
Definition: Answer.h:33
uint16_t init(uint16_t namePtr, const String &name, Resource::Type type, uint16_t rclass, bool flush, uint32_t ttl)
String getRecordString() const
Get content of record as string.
Encapsulates a message packet for flexible introspection.
Definition: MDNS/src/include/Network/Mdns/Message.h:36
Resource::Type getType() const
ResourceRecord type.
uint8_t * getRecord() const