From ab568befcf92ac5f13a3a0dd9a759bfda0dc33d5 Mon Sep 17 00:00:00 2001 From: Quentin Dufour Date: Thu, 14 Feb 2019 15:40:05 +0100 Subject: [PATCH] Fix comaprison bug --- src/donar_client.c | 2 ++ src/packet.c | 10 +++++----- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/donar_client.c b/src/donar_client.c index 3308b29..30ccbb6 100644 --- a/src/donar_client.c +++ b/src/donar_client.c @@ -67,8 +67,10 @@ void donar_client(struct donar_client_ctx* ctx, struct algo_skel* algo, char* on load_onion_services (ctx, onion_file, CLIENT_PORT_SIZE); printf("--- Onion services loaded\n"); + init_tcp_clients(ctx); printf("--- TCP Clients Connected\n"); + init_udp_server (ctx, port); printf("--- UDP Server is listening\n"); diff --git a/src/packet.c b/src/packet.c index 4aca9e3..fb1768b 100644 --- a/src/packet.c +++ b/src/packet.c @@ -1,7 +1,7 @@ #include "packet.h" enum FD_STATE read_packet_from_tcp(int fd, struct buffer_packet* bp) { - int nread; + ssize_t nread; size_t pkt_size_size = sizeof(bp->ip.ap.str.size); if (bp->mode == BP_WRITING) return FDS_ERR; @@ -28,7 +28,7 @@ enum FD_STATE read_packet_from_tcp(int fd, struct buffer_packet* bp) { } enum FD_STATE write_packet_to_tcp(int fd, struct buffer_packet* bp) { - int nwrite; + ssize_t nwrite; while (bp->awrite < bp->ip.ap.str.size) { nwrite = send(fd, &(bp->ip.ap.raw), bp->ip.ap.str.size, 0); @@ -44,7 +44,7 @@ enum FD_STATE write_packet_to_tcp(int fd, struct buffer_packet* bp) { } enum FD_STATE write_packet_to_udp(int fd, struct buffer_packet* bp, struct sockaddr* addr, socklen_t addrlen) { - int nwrite, bytes_to_send; + ssize_t nwrite, bytes_to_send; size_t pkt_size_size = sizeof(bp->ip.ap.str.size); if (bp->mode == BP_READING) return FDS_ERR; @@ -66,7 +66,7 @@ enum FD_STATE write_packet_to_udp(int fd, struct buffer_packet* bp, struct socka } enum FD_STATE read_packet_from_udp (int fd, struct buffer_packet* bp, struct sockaddr* addr, socklen_t* addrlen) { - int nread; + ssize_t nread; if (bp->mode == BP_WRITING) return FDS_ERR; *addrlen = sizeof(struct sockaddr_in); @@ -76,7 +76,7 @@ enum FD_STATE read_packet_from_udp (int fd, struct buffer_packet* bp, struct soc nread = recvfrom(fd, &(bp->ip.ap.str.payload), udp_packet_size, MSG_TRUNC, addr, addrlen); - if (nread > udp_packet_size) return FDS_ERR; + if ((int)nread > (int)udp_packet_size) return FDS_ERR; if (nread == -1 && errno == EAGAIN) return FDS_AGAIN; if (nread == -1) return FDS_ERR;