Modifcations of the sendout of packets
This commit is contained in:
parent
822b344a57
commit
eb4770e36c
12
src/node.c
12
src/node.c
@ -421,8 +421,10 @@ int add_tlv(packet *pack, tlv *tlv, struct sockaddr_in6 *dest, int socket_num) {
|
|||||||
|
|
||||||
// Send length bytes from packet
|
// Send length bytes from packet
|
||||||
int send_packet(char *packet_buff, int16_t length, struct sockaddr_in6 *dest, int socket_num) {
|
int send_packet(char *packet_buff, int16_t length, struct sockaddr_in6 *dest, int socket_num) {
|
||||||
|
((packet*) packet_buff)->length = htons(((packet*) packet_buff)->length);
|
||||||
|
|
||||||
// Vectorized buffer
|
// Vectorized buffer
|
||||||
struct iovec vec_buff = {.iov_len = sizeof(packet_buff), .iov_base = packet_buff};
|
struct iovec vec_buff = {.iov_len = length, .iov_base = packet_buff};
|
||||||
|
|
||||||
int error_while_sending = 0;
|
int error_while_sending = 0;
|
||||||
|
|
||||||
@ -442,7 +444,7 @@ int send_packet(char *packet_buff, int16_t length, struct sockaddr_in6 *dest, in
|
|||||||
printf(">> Sent out only part of the packet.\n");
|
printf(">> Sent out only part of the packet.\n");
|
||||||
error_while_sending = 1;
|
error_while_sending = 1;
|
||||||
} else {
|
} else {
|
||||||
printf(">> Send out packet to peer\n");
|
printf(">> Send out packet to peer, size : %i\n", response_code);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (error_while_sending == 1) {
|
if (error_while_sending == 1) {
|
||||||
@ -519,6 +521,7 @@ int send_single_tlv(tlv *tlv, struct sockaddr_in6 *dest, int socket_num) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Send the packet
|
// Send the packet
|
||||||
|
printf("(%i)\n", pack.length );
|
||||||
return send_packet((char*) &pack, pack.length, dest, socket_num);
|
return send_packet((char*) &pack, pack.length, dest, socket_num);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -652,7 +655,8 @@ int check_header(char * received_data_buffer, int received_data_len, struct pack
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (packet_to_return->length + 4 > received_data_len ) {
|
printf("packet : %i, %i \n", packet_to_return->length + 4,received_data_len );
|
||||||
|
if (packet_to_return->length + 4 < received_data_len ) {
|
||||||
perror(">> The packet length is bigger than the UDP datagram, which is not possible with the current laws of physics.");
|
perror(">> The packet length is bigger than the UDP datagram, which is not possible with the current laws of physics.");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
@ -1002,7 +1006,7 @@ int run_node(int sock_fd){
|
|||||||
if (bytes > 0) {
|
if (bytes > 0) {
|
||||||
printf("Received %i bytes as : %s\n", (int)bytes, output_buffer);
|
printf("Received %i bytes as : %s\n", (int)bytes, output_buffer);
|
||||||
// Treat incoming packets.
|
// Treat incoming packets.
|
||||||
int work_tlv_status = listen_for_packets(output_buffer, bytes, &sender, sock_fd);
|
int work_tlv_status = listen_for_packets(&output_buffer, bytes, &sender, sock_fd);
|
||||||
if (work_tlv_status < 0) {
|
if (work_tlv_status < 0) {
|
||||||
perror(">> Error while treating the incoming packet.");
|
perror(">> Error while treating the incoming packet.");
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user