]> git.sur5r.net Git - ngadmin/blob - raw/include/nsdp/packet.h
Raw: refactor attribute encoding and decoding
[ngadmin] / raw / include / nsdp / packet.h
1
2 #ifndef DEF_ENCODING
3 #define DEF_ENCODING
4
5
6 #include <stdbool.h>
7
8 #include <netinet/ether.h>
9
10 #include <nsdp/protocol.h>
11 #include <nsdp/net.h>
12 #include <nsdp/list.h>
13
14
15 struct nsdp_packet {
16         union {
17                 unsigned char *buffer;
18                 struct nsdp_header *nh;
19         };
20         int maxlen;
21         struct attr_header *ah;
22 };
23
24
25
26 void initNsdpHeader (struct nsdp_header *nh, const struct nsdp_cmd *nc);
27
28
29 bool extractNsdpHeader (const struct nsdp_header *nh, struct nsdp_cmd *nc);
30
31
32 static inline void initNsdpPacket (struct nsdp_packet *np)
33 {
34         np->ah = (struct attr_header*)np->nh->data;
35 }
36
37
38 static inline int getPacketTotalSize (const struct nsdp_packet *np)
39 {
40         return ((unsigned char*)np->ah) - np->buffer;
41 }
42
43
44 int addPacketAttributes (struct nsdp_packet *np, const List* attr);
45
46
47 int extractPacketAttributes (struct nsdp_packet *np, List *attr);
48
49
50 #endif
51