113 lines
2.5 KiB
C
113 lines
2.5 KiB
C
#include <sys/socket.h>
|
|
#include <netinet/in.h>
|
|
#include <stdlib.h>
|
|
#include "parser.h"
|
|
|
|
// 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)
|
|
short length; // 1020 max
|
|
char *body;
|
|
} 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;
|
|
short port;
|
|
} neighbour;
|
|
|
|
// 18 octets
|
|
typedef struct network_hash {
|
|
unsigned char type;
|
|
unsigned char length;
|
|
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;
|
|
long node_id;
|
|
short seqno;
|
|
char node_hash[16];
|
|
} node_hash;
|
|
|
|
// 10 octets
|
|
typedef struct node_state_req {
|
|
unsigned char type;
|
|
unsigned char length;
|
|
long node_id;
|
|
} node_state_req;
|
|
|
|
// 28 octets min, 220 octets max (data 0 -> 192)
|
|
typedef struct node_state {
|
|
unsigned char type;
|
|
unsigned char length;
|
|
long node_id;
|
|
short seqno;
|
|
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;
|
|
} 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;
|
|
|
|
|
|
// creer un tlv
|
|
int build_tlv(tlv *tlv, cmd_token token);
|
|
|
|
// creer un tlv specifique
|
|
int build_pad1(tlv *tlv);
|
|
int build_padn(tlv *tlv, size_t len);
|
|
int build_neighbour_req(tlv *tlv);
|
|
int build_neighbour(tlv *tlv, struct in6_addr ip, short seqno);
|
|
int build_network_hash(tlv *tlv, char *network_hash);
|
|
int build_network_state_req(tlv *tlv);
|
|
int build_node_hash(tlv *tlv, long node_id, short seqno, char *node_hash);
|
|
int build_node_state_req(tlv *tlv, long node_id);
|
|
int build_node_state(tlv *tlv, long node_id, short seqno, char *node_hash, char *data);
|
|
int build_warning(tlv *tlv, char *message); |