使用raw socket发送magic packet

本文介绍了如何使用raw socket在数据链路层直接发送Magic Packet,实现网络唤醒。内容涵盖Magic Packet的原理、TCP/IP网络模型、以太网报头、raw socket相关技术要点,并提供了完整的C语言源代码示例。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Magic Packet是进行网络唤醒的数据包,将这个数据包以广播的形式发到局域网上,与数据包中所关联的MAC相同的电脑就会被唤醒开机,通常我们都是使用UDP报文的形式来发送这个数据包,但实际上在进行网络唤醒的时候,只要报文中包含Magic Packet应该就可以唤醒相关的计算机,与IP协议、UDP协议没有任何关系,本文将试图抛开网络层(IP层)和传输层(TCP/UDP层),直接在数据链路层发出Magic Packet,并成功实现网络唤醒,本文将提供完整的源代码。阅读本文需要有较好的网络编程基础,本文对网络编程的初学者有一定难度。

1. Magic Packet

  • 我比较喜欢把这个数据包称作"网络唤醒包";有很多地方把它翻译成"魔术包"或者"魔法数据包",我个人觉着太过表面,无法表达其实际的含义;本文将这个数据包称为"网络唤醒包"或者"Magic Packet",二者具有完全相同的含义;
  • 以前写过一篇与嵌入式相关的文章《远程开机:一个简单的嵌入式项目开发》,在嵌入式环境下使用Magic Packet进行远程开机的小项目
PCnet Magic Packet(TM) Utility 1.00, September 9, 1997 ------------------------------------------------------- INTRODUCTION ~~~~~~~~~~~~ This is the release notice for the PCnet Magic Packet(TM) Utility Revision 1.00 software. All files are in DOS FAT format. AMD抯 Magic Packet utility is a convenient tool for system administrators for remotely powering up groups of workstations at preset times. The utility provides the following two basic functions: ?Creates a table of IP and hardware addresses for all hosts in a local area network. ?Associates each group of workstations/hosts to an alarm clock, and power on each group when the time comes. This utility supports the Microsoft Windows NT 4.0 and Windows 95 operating system environments. CONTENTS ~~~~~~~~~~~~~ The Rev 1.00 files are distributed as follows: Directory 1 - release.txt : the file you are viewing currently. - magpac.exe - magpac.hlp - conspawn.exe - magpac.cnt Directory 2 - msvcrt.dll - mfc42.dll - magpacbg.bmp Documents - mpuser.doc : Microsoft Word 6.0 document that describes the usage of the utility - testrept.doc : Test Report in Microsoft Word 6.0 format. DOCUMENTATION ~~~~~~~~~~~~~ This release contains version 1.0 of AMD's PCnet Magic Packet Utility User's Guide (MPuser.doc) and a test report (TestRept.Doc) describing the scope and content of tests that were conducted with this release of the utility. These documents are available in the distribution media. INSTALLATION INSTRUCTIONS ~~~~~~~~~~~~~~~~~~~~~~~~~ These instructions apply for both Windows 95 and Windows NT 4.0. 1. Open a DOS window 2. Create a directory such as c:\mputil 3. Copy all files contained in Directory 1 to the c:\mputil directory 4. For Windows 95, change to the windows system directory (default is c:\windows) directory For Windows NT, change to the Windows NT system32 sub-directory (default is c:\winnt\system32) Copy the *.dll files in Direc
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

whowin

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值