summaryrefslogtreecommitdiff
path: root/toxcore/LAN_discovery.c
diff options
context:
space:
mode:
authorirungentoo <irungentoo@gmail.com>2013-10-20 16:00:30 -0400
committerirungentoo <irungentoo@gmail.com>2013-10-20 16:00:30 -0400
commitbe068885177f61485567dff38ec1631e5306d94d (patch)
tree58a983b00da772d45a1b5b964cf3eea5f1698764 /toxcore/LAN_discovery.c
parent9303c18b0c4d0156607d0050a32be5d96569f21c (diff)
Fixed possible bug.
Diffstat (limited to 'toxcore/LAN_discovery.c')
-rw-r--r--toxcore/LAN_discovery.c8
1 files changed, 7 insertions, 1 deletions
diff --git a/toxcore/LAN_discovery.c b/toxcore/LAN_discovery.c
index 26366d0f..a4f1ccc2 100644
--- a/toxcore/LAN_discovery.c
+++ b/toxcore/LAN_discovery.c
@@ -42,6 +42,7 @@ static void fetch_broadcast_info(uint16_t port)
42 */ 42 */
43 broadcast_count = 0; 43 broadcast_count = 0;
44 sock_t sock = 0; 44 sock_t sock = 0;
45
45 if ((sock = socket(AF_INET, SOCK_STREAM, 0)) < 0) 46 if ((sock = socket(AF_INET, SOCK_STREAM, 0)) < 0)
46 return; 47 return;
47 48
@@ -64,6 +65,7 @@ static void fetch_broadcast_info(uint16_t port)
64 * enough, for everybody!) 65 * enough, for everybody!)
65 */ 66 */
66 int i, count = ifconf.ifc_len / sizeof(struct ifreq); 67 int i, count = ifconf.ifc_len / sizeof(struct ifreq);
68
67 for (i = 0; i < count; i++) { 69 for (i = 0; i < count; i++) {
68 /* there are interfaces with are incapable of broadcast */ 70 /* there are interfaces with are incapable of broadcast */
69 if (ioctl(sock, SIOCGIFBRDADDR, &i_faces[i]) < 0) 71 if (ioctl(sock, SIOCGIFBRDADDR, &i_faces[i]) < 0)
@@ -74,6 +76,10 @@ static void fetch_broadcast_info(uint16_t port)
74 continue; 76 continue;
75 77
76 struct sockaddr_in *sock4 = (struct sockaddr_in *)&i_faces[i].ifr_broadaddr; 78 struct sockaddr_in *sock4 = (struct sockaddr_in *)&i_faces[i].ifr_broadaddr;
79
80 if (broadcast_count >= MAX_INTERFACES)
81 return;
82
77 IP_Port *ip_port = &broadcast_ip_port[broadcast_count]; 83 IP_Port *ip_port = &broadcast_ip_port[broadcast_count];
78 ip_port->ip.family = AF_INET; 84 ip_port->ip.family = AF_INET;
79 ip_port->ip.ip4.in_addr = sock4->sin_addr; 85 ip_port->ip.ip4.in_addr = sock4->sin_addr;
@@ -101,7 +107,7 @@ static uint32_t send_broadcasts(Networking_Core *net, uint16_t port, uint8_t *da
101 107
102 int i; 108 int i;
103 109
104 for(i = 0; i < broadcast_count; i++) 110 for (i = 0; i < broadcast_count; i++)
105 sendpacket(net, broadcast_ip_port[i], data, 1 + crypto_box_PUBLICKEYBYTES); 111 sendpacket(net, broadcast_ip_port[i], data, 1 + crypto_box_PUBLICKEYBYTES);
106 112
107 return 1; 113 return 1;