检测网线插拔状态

bool CheckCable(const char* _szInterfaceName)
{
	int s32Ret;
	struct ifreq ifr;
	int skfd = socket(AF_INET, SOCK_DGRAM, 0);
	assert(skfd != -1);
	strcpy(ifr.ifr_name, _szInterfaceName);
	s32Ret = ioctl(skfd, SIOCGIFFLAGS, &ifr);
	assert(s32Ret == 0);
	close(skfd);

	if(ifr.ifr_flags & IFF_RUNNING)
	{
		return true;
	}
	else
	{
		return false;
	}
}

你可能感兴趣的:(备忘)