#ifndef TLV_H #define TLV_H #include #include #include #include #define LEN_NEIGHBOUR_REQ 0 #define LEN_NEIGHBOUR 18 #define LEN_NETWORK_HASH 16 #define LEN_NETWORK_STATE_REQ 0 #define LEN_NODE_HASH 26 #define LEN_NODE_STATE_REQ 8 #define MIN_LEN_NODE_STATE 26 #define MAX_LEN_NODE_STATE 218 // 8 octets min (struct pointer 4 octets), 1024 octets max typedef struct packet { unsigned char magic; // 95 (si autre, ignorer) unsigned char version; // 1 (si autre, ignorer) uint16_t length; // 1020 max char body[1020]; } packet; // 1 octet typedef struct pad1 { unsigned char type; } pad1; // 2 octets min, 258 octets max (unsigned char 0 -> 255) typedef struct padn { unsigned char type; unsigned char length; char mbz[256]; } padn; // 2 octets typedef struct neighbour_req { unsigned char type; unsigned char length; } neighbour_req; // 20 octets typedef struct neighbour { unsigned char type; unsigned char length; struct in6_addr ip; int16_t port; } neighbour; // 18 octets typedef struct network_hash { unsigned char type; unsigned char length; unsigned char network_hash[16]; } network_hash; // 2 octets typedef struct network_state_req { unsigned char type; unsigned char length; } network_state_req; // 28 octets typedef struct node_hash { unsigned char type; unsigned char length; uint64_t node_id; uint16_t seqno; unsigned char node_hash[16]; } node_hash; // 10 octets typedef struct node_state_req { unsigned char type; unsigned char length; uint64_t node_id; } node_state_req; // 28 octets min, 220 octets max (data 0 -> 192) typedef struct node_state { unsigned char type; unsigned char length; uint64_t node_id; uint16_t seqno; unsigned char node_hash[16]; char data[192]; } node_state; // 2 octets min, 258 ocets max (unsigned char 0 -> 255) typedef struct warning { unsigned char type; unsigned char length; char message[256]; } warning; typedef union tlv { pad1 *pad1; padn *padn; neighbour_req *neighbour_req; neighbour *neighbour; network_hash *network_hash; network_state_req *network_state_req; node_hash *node_hash; node_state_req *node_state_req; node_state *node_state; warning *warning; } tlv; #include "node.h" #include "hash.h" // build specific tlv int build_pad1(tlv *tlv); int build_padn(tlv *tlv, size_t len); int build_neighbour_req(union tlv *tlv); int build_neighbour(tlv *tlv, struct in6_addr ip, int16_t port); int build_network_hash(tlv *tlv, list *data_list); int build_network_state_req(tlv *tlv); int build_node_hash(tlv *tlv, uint64_t node_id, uint16_t seqno, char *data, unsigned char length); int build_node_state_req(tlv *tlv, uint64_t node_id); int build_node_state(tlv *tlv, uint64_t node_id, uint16_t seqno, char *data, size_t data_len); int build_warning(tlv *tlv, char *message, size_t message_len); #endif