技术点——Qt封装MagicPacket

技术点——Qt封装MagicPacket

QByteArray getMagicPacket(QString strMacAdd)
{
	//Magic Packge:6个0xff + 16次重复的Mac地址
	char MACAddr[6];
	char MagicPacket[102];//实现远程开机的Magic包
	QStringList macList = strMacAdd.split(":"); //将MAC地址分离开

	for (int i =0 ; i < macList.count();i++)
	{
		MACAddr[i] = char(macList[i].toInt(nullptr,16) & 0xFF);
	}

	if (macList.length() != 6)
	{
		return "" ;
	}

	//把magicpacket数组前6个字符设置成16进制的ff
	memset(MagicPacket, 0xFF, 6);

	int packetsize = 6;//初始值是6
	//构建MagicPacket
	for (int i = 0; i < 16; i++)
	{
		memcpy(MagicPacket + packetsize, MACAddr, 6);
		packetsize += 6;
	}
	return MagicPacket;
}
发布了28 篇原创文章 · 获赞 4 · 访问量 7404

猜你喜欢

转载自blog.csdn.net/JuicyActiveGilbert/article/details/59483248