diff options
-rw-r--r-- | core/network.c | 9 | ||||
-rw-r--r-- | core/network.h | 6 | ||||
-rw-r--r-- | 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) | |||
121 | bind(sock, (struct sockaddr*)&addr, sizeof(addr)); | 121 | bind(sock, (struct sockaddr*)&addr, sizeof(addr)); |
122 | return 0; | 122 | return 0; |
123 | 123 | ||
124 | } | ||
125 | |||
126 | //function to cleanup networking stuff | ||
127 | void shutdown_networking() | ||
128 | { | ||
129 | #ifdef WIN32 | ||
130 | WSACleanup(); | ||
131 | #endif | ||
132 | return; | ||
124 | } \ No newline at end of file | 133 | } \ 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); | |||
96 | //returns 0 if no problems | 96 | //returns 0 if no problems |
97 | //TODO: add something to check if there are errors | 97 | //TODO: add something to check if there are errors |
98 | int init_networking(IP ip ,uint16_t port); | 98 | int init_networking(IP ip ,uint16_t port); |
99 | #endif \ No newline at end of file | 99 | |
100 | |||
101 | //function to cleanup networking stuff(doesn't do much right now) | ||
102 | void shutdown_networking(); | ||
103 | #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() | |||
80 | } | 80 | } |
81 | } | 81 | } |
82 | 82 | ||
83 | 83 | void printpacket(char * data, uint32_t length, IP_Port ip_port) | |
84 | { | ||
85 | uint32_t i; | ||
86 | printf("UNHANDLED PACKET RECEIVED\nLENGTH:%u\nCONTENTS:\n", length); | ||
87 | printf("--------------------BEGIN-----------------------------\n"); | ||
88 | for(i = 0; i < length; i++) | ||
89 | { | ||
90 | if(data[i] < 16) | ||
91 | printf("0"); | ||
92 | printf("%hhX",data[i]); | ||
93 | } | ||
94 | printf("\n--------------------END-----------------------------\n\n\n"); | ||
95 | } | ||
84 | 96 | ||
85 | int main(int argc, char *argv[]) | 97 | int main(int argc, char *argv[]) |
86 | { | 98 | { |
@@ -116,8 +128,6 @@ int main(int argc, char *argv[]) | |||
116 | char data[MAX_UDP_PACKET_SIZE]; | 128 | char data[MAX_UDP_PACKET_SIZE]; |
117 | uint32_t length; | 129 | uint32_t length; |
118 | 130 | ||
119 | uint32_t i; | ||
120 | |||
121 | while(1) | 131 | while(1) |
122 | { | 132 | { |
123 | 133 | ||
@@ -127,15 +137,8 @@ int main(int argc, char *argv[]) | |||
127 | { | 137 | { |
128 | if(DHT_handlepacket(data, length, ip_port)) | 138 | if(DHT_handlepacket(data, length, ip_port)) |
129 | { | 139 | { |
130 | printf("UNHANDLED PACKET RECEIVED\nLENGTH:%u\nCONTENTS:\n", length); | 140 | //unhandled packet |
131 | printf("--------------------BEGIN-----------------------------\n"); | 141 | printpacket(data, length, ip_port); |
132 | for(i = 0; i < length; i++) | ||
133 | { | ||
134 | if(data[i] < 16) | ||
135 | printf("0"); | ||
136 | printf("%hhX",data[i]); | ||
137 | } | ||
138 | printf("\n--------------------END-----------------------------\n\n\n"); | ||
139 | } | 142 | } |
140 | else | 143 | else |
141 | { | 144 | { |
@@ -147,8 +150,6 @@ int main(int argc, char *argv[]) | |||
147 | c_sleep(300); | 150 | c_sleep(300); |
148 | } | 151 | } |
149 | 152 | ||
150 | #ifdef WIN32 | 153 | shutdown_networking(); |
151 | WSACleanup(); | ||
152 | #endif | ||
153 | return 0; | 154 | return 0; |
154 | } \ No newline at end of file | 155 | } \ No newline at end of file |