11#include "common/netif.h"
22#include "common/io.h"
3- #include "common/mallocHelper.h"
43
54#include <net/if.h>
65#include <net/if_dl.h>
@@ -98,7 +97,16 @@ bool ffNetifGetDefaultRouteImplV4(FFNetifDefaultRouteResult* result) {
9897 return false;
9998 }
10099
101- while (recv (pfRoute , & rtmsg , sizeof (rtmsg ), 0 ) > 0 && !(rtmsg .hdr .rtm_seq == 1 && rtmsg .hdr .rtm_pid == (pid_t ) pid ));
100+ bool gotResponse = false;
101+ while (recv (pfRoute , & rtmsg , sizeof (rtmsg ), 0 ) > 0 ) {
102+ if (rtmsg .hdr .rtm_seq == 1 && rtmsg .hdr .rtm_pid == (pid_t ) pid ) {
103+ gotResponse = true;
104+ break ;
105+ }
106+ }
107+ if (!gotResponse ) {
108+ return false;
109+ }
102110
103111#ifndef __sun // On Solaris, the RTF_GATEWAY flag is not set for default routes for some reason
104112 if ((rtmsg .hdr .rtm_flags & (RTF_UP | RTF_GATEWAY )) == (RTF_UP | RTF_GATEWAY ))
@@ -109,6 +117,7 @@ bool ffNetifGetDefaultRouteImplV4(FFNetifDefaultRouteResult* result) {
109117#ifndef __sun
110118 && sdl -> sdl_len
111119#endif
120+ && sdl -> sdl_family == AF_LINK
112121 ) {
113122 if (sdl -> sdl_nlen > IF_NAMESIZE ) {
114123 return false;
@@ -173,7 +182,16 @@ bool ffNetifGetDefaultRouteImplV6(FFNetifDefaultRouteResult* result) {
173182 return false;
174183 }
175184
176- while (recv (pfRoute , & rtmsg , sizeof (rtmsg ), 0 ) > 0 && !(rtmsg .hdr .rtm_seq == 2 && rtmsg .hdr .rtm_pid == (pid_t ) pid ));
185+ bool gotResponse = false;
186+ while (recv (pfRoute , & rtmsg , sizeof (rtmsg ), 0 ) > 0 ) {
187+ if (rtmsg .hdr .rtm_seq == 2 && rtmsg .hdr .rtm_pid == (pid_t ) pid ) {
188+ gotResponse = true;
189+ break ;
190+ }
191+ }
192+ if (!gotResponse ) {
193+ return false;
194+ }
177195
178196#ifndef __sun // On Solaris, the RTF_GATEWAY flag is not set for default routes for some reason
179197 if ((rtmsg .hdr .rtm_flags & (RTF_UP | RTF_GATEWAY )) == (RTF_UP | RTF_GATEWAY ))
@@ -184,6 +202,7 @@ bool ffNetifGetDefaultRouteImplV6(FFNetifDefaultRouteResult* result) {
184202#ifndef __sun
185203 && sdl -> sdl_len
186204#endif
205+ && sdl -> sdl_family == AF_LINK
187206 ) {
188207 if (sdl -> sdl_nlen > IF_NAMESIZE ) {
189208 return false;
0 commit comments