#include<stdio.h>
#include<string.h>
int is_network_ready(void)
{
int ret = 0;
FILE *fp;
char buf[128] = {0};
fp = popen("ip ro show", "r");
if(!fp)
{
return 0;
}
while(fgets(buf, sizeof(buf), fp) != NULL)
{
if(strstr(buf, "default"))
{
ret = 1;
break;
}
}
pclose(fp);
return ret;
}
int main(int argc, char *argv[])
{
while(1)
{
printf("Network state : %d\n", is_network_ready());
sleep(2);
}
return 0;
}