From 24925a24ec012c6dda40f5e9ab6ab139ca1fde8b Mon Sep 17 00:00:00 2001 From: irungentoo Date: Thu, 27 Jun 2013 10:01:31 -0400 Subject: [PATCH] Cleaned up some stuff. --- core/network.c | 9 +++++++++ core/network.h | 6 +++++- testing/DHT_test.c | 31 ++++++++++++++++--------------- 3 files changed, 30 insertions(+), 16 deletions(-) diff --git a/core/network.c b/core/network.c index 70536abf..81da3f1b 100644 --- a/core/network.c +++ b/core/network.c @@ -121,4 +121,13 @@ int init_networking(IP ip ,uint16_t port) bind(sock, (struct sockaddr*)&addr, sizeof(addr)); return 0; +} + +//function to cleanup networking stuff +void shutdown_networking() +{ + #ifdef WIN32 + WSACleanup(); + #endif + return; } \ No newline at end of file diff --git a/core/network.h b/core/network.h index a35ca214..24f7281d 100644 --- a/core/network.h +++ b/core/network.h @@ -96,4 +96,8 @@ int recievepacket(IP_Port * ip_port, char * data, uint32_t * length); //returns 0 if no problems //TODO: add something to check if there are errors int init_networking(IP ip ,uint16_t port); -#endif \ No newline at end of file + + +//function to cleanup networking stuff(doesn't do much right now) +void shutdown_networking(); +#endif diff --git a/testing/DHT_test.c b/testing/DHT_test.c index 1eae74a0..799d31ad 100644 --- a/testing/DHT_test.c +++ b/testing/DHT_test.c @@ -80,7 +80,19 @@ void print_friendlist() } } - +void printpacket(char * data, uint32_t length, IP_Port ip_port) +{ + uint32_t i; + printf("UNHANDLED PACKET RECEIVED\nLENGTH:%u\nCONTENTS:\n", length); + printf("--------------------BEGIN-----------------------------\n"); + for(i = 0; i < length; i++) + { + if(data[i] < 16) + printf("0"); + printf("%hhX",data[i]); + } + printf("\n--------------------END-----------------------------\n\n\n"); +} int main(int argc, char *argv[]) { @@ -116,8 +128,6 @@ int main(int argc, char *argv[]) char data[MAX_UDP_PACKET_SIZE]; uint32_t length; - uint32_t i; - while(1) { @@ -127,15 +137,8 @@ int main(int argc, char *argv[]) { if(DHT_handlepacket(data, length, ip_port)) { - printf("UNHANDLED PACKET RECEIVED\nLENGTH:%u\nCONTENTS:\n", length); - printf("--------------------BEGIN-----------------------------\n"); - for(i = 0; i < length; i++) - { - if(data[i] < 16) - printf("0"); - printf("%hhX",data[i]); - } - printf("\n--------------------END-----------------------------\n\n\n"); + //unhandled packet + printpacket(data, length, ip_port); } else { @@ -147,8 +150,6 @@ int main(int argc, char *argv[]) c_sleep(300); } - #ifdef WIN32 - WSACleanup(); - #endif + shutdown_networking(); return 0; } \ No newline at end of file