Fixed possible bug.

This commit is contained in:
irungentoo 2013-10-20 16:00:30 -04:00
parent 9303c18b0c
commit be06888517

View File

@ -42,6 +42,7 @@ static void fetch_broadcast_info(uint16_t port)
*/ */
broadcast_count = 0; broadcast_count = 0;
sock_t sock = 0; sock_t sock = 0;
if ((sock = socket(AF_INET, SOCK_STREAM, 0)) < 0) if ((sock = socket(AF_INET, SOCK_STREAM, 0)) < 0)
return; return;
@ -64,6 +65,7 @@ static void fetch_broadcast_info(uint16_t port)
* enough, for everybody!) * enough, for everybody!)
*/ */
int i, count = ifconf.ifc_len / sizeof(struct ifreq); int i, count = ifconf.ifc_len / sizeof(struct ifreq);
for (i = 0; i < count; i++) { for (i = 0; i < count; i++) {
/* there are interfaces with are incapable of broadcast */ /* there are interfaces with are incapable of broadcast */
if (ioctl(sock, SIOCGIFBRDADDR, &i_faces[i]) < 0) if (ioctl(sock, SIOCGIFBRDADDR, &i_faces[i]) < 0)
@ -74,6 +76,10 @@ static void fetch_broadcast_info(uint16_t port)
continue; continue;
struct sockaddr_in *sock4 = (struct sockaddr_in *)&i_faces[i].ifr_broadaddr; struct sockaddr_in *sock4 = (struct sockaddr_in *)&i_faces[i].ifr_broadaddr;
if (broadcast_count >= MAX_INTERFACES)
return;
IP_Port *ip_port = &broadcast_ip_port[broadcast_count]; IP_Port *ip_port = &broadcast_ip_port[broadcast_count];
ip_port->ip.family = AF_INET; ip_port->ip.family = AF_INET;
ip_port->ip.ip4.in_addr = sock4->sin_addr; ip_port->ip.ip4.in_addr = sock4->sin_addr;