work with tlvs check packet length

This commit is contained in:
gonzalef 2020-04-27 20:08:30 +02:00
parent ecc168cbf4
commit bda49e5e92

View File

@ -36,16 +36,16 @@ int ask_for_peers(int socket_num) {
struct in6_addr ip = peer->ip; struct in6_addr ip = peer->ip;
int16_t port = peer->port; int16_t port = peer->port;
int ifindex = if_nametoindex("enp3s0"); /*int ifindex = if_nametoindex("enp3s0");
if(ifindex == 0) { if(ifindex == 0) {
int ifindex = if_nametoindex("eth0"); int ifindex = if_nametoindex("eth0");
if(ifindex == 0) { if(ifindex == 0) {
perror("if_nametoindex failed"); perror("if_nametoindex failed");
return -1; return -1;
} }
} }*/
ifindex = 0; int ifindex = 0;
// Initialize sockaddr // Initialize sockaddr
struct sockaddr_in6 dest; struct sockaddr_in6 dest;
@ -687,9 +687,15 @@ int add_message(char * message, int message_len){
return 0; return 0;
} }
// We then look at the differents TLVs in the packet. // We then look at the differents TLVs in the packet.
int work_with_tlvs(char * data, int16_t packet_len, struct sockaddr_in6 *sender, int socket_num){ int work_with_tlvs(char * data, int16_t total_packet_len, struct sockaddr_in6 *sender, int socket_num){
int16_t packet_len = ntohs(((packet*) data)->length);
int pos = 0; if(packet_len != total_packet_len - 4) {
fprintf(stderr, ">> Length indicated in packet differs from real length of packet received.\n");
return -1;
}
int pos = 4;
unsigned char tlv_len, hash[16]; unsigned char tlv_len, hash[16];
char warn[32]; char warn[32];
tlv new_tlv, cur_tlv; tlv new_tlv, cur_tlv;
@ -703,6 +709,7 @@ int work_with_tlvs(char * data, int16_t packet_len, struct sockaddr_in6 *sender,
packet pack = (packet) {.magic = 95, .version = 1, .length = 0}; packet pack = (packet) {.magic = 95, .version = 1, .length = 0};
memset(pack.body, 0, 1020); memset(pack.body, 0, 1020);
/*
int ifindex = if_nametoindex("enp3s0"); int ifindex = if_nametoindex("enp3s0");
if(ifindex == 0) { if(ifindex == 0) {
int ifindex = if_nametoindex("eth0"); int ifindex = if_nametoindex("eth0");
@ -711,6 +718,8 @@ int work_with_tlvs(char * data, int16_t packet_len, struct sockaddr_in6 *sender,
return -1; return -1;
} }
} }
*/
int ifindex = 0;
ifindex = 0; ifindex = 0;
while(pos < packet_len) { while(pos < packet_len) {