diff options
author | irungentoo <irungentoo@gmail.com> | 2013-06-25 17:16:45 -0400 |
---|---|---|
committer | irungentoo <irungentoo@gmail.com> | 2013-06-25 17:16:45 -0400 |
commit | 1837745d96f98827c0fb4f0db920cd29c20260c0 (patch) | |
tree | 6518bb0360462022a4e9209d95cd31666001f453 /core/DHT.c | |
parent | adc9c64fe61db1614ece1164db670af3efbf9073 (diff) |
Fixed one possible bug in the DHT and added a basic TODO list.
Fixed a possible segfault which could have been cause by handling an
empty packet.
Diffstat (limited to 'core/DHT.c')
-rw-r--r-- | core/DHT.c | 4 |
1 files changed, 3 insertions, 1 deletions
@@ -15,14 +15,16 @@ int sendpacket(IP_Port ip_port, char * data, uint32_t length) | |||
15 | //Function to recieve data, ip and port of sender is put into ip_port | 15 | //Function to recieve data, ip and port of sender is put into ip_port |
16 | //the packet data into data | 16 | //the packet data into data |
17 | //the packet length into length. | 17 | //the packet length into length. |
18 | //dump all empty packets. | ||
18 | int recievepacket(IP_Port * ip_port, char * data, uint32_t * length) | 19 | int recievepacket(IP_Port * ip_port, char * data, uint32_t * length) |
19 | { | 20 | { |
20 | ADDR addr; | 21 | ADDR addr; |
21 | uint32_t addrlen = sizeof(addr); | 22 | uint32_t addrlen = sizeof(addr); |
22 | (*(int *)length) = recvfrom(sock, data, MAX_UDP_PACKET_SIZE, 0, (struct sockaddr *)&addr, &addrlen); | 23 | (*(int *)length) = recvfrom(sock, data, MAX_UDP_PACKET_SIZE, 0, (struct sockaddr *)&addr, &addrlen); |
23 | if(*(int *)length == -1) | 24 | if(*(int *)length <= 0) |
24 | { | 25 | { |
25 | //nothing recieved | 26 | //nothing recieved |
27 | //or empty packet | ||
26 | return -1; | 28 | return -1; |
27 | } | 29 | } |
28 | ip_port->ip = addr.ip; | 30 | ip_port->ip = addr.ip; |