精简的 BOOTP 守护进程/服务器






3.09/5 (5投票s)
这个项目展示了一个精简的 BOOTP 守护进程/服务器。Bootp 是一种通过 MAC 地址为设备分配 IP 地址的协议。

引言
这篇文章描述了一个非常精简的 bootp 守护进程/服务器。
我需要一个非常简单的 bootp 守护进程来用于我的当前项目,但我在 CodeProject 上找不到,所以我就编写了一个。
有关 bootp 协议的更多信息,请参阅维基百科网站。
Using the Code
这个 bootp 守护进程仅实现了 bootp RFC-951 的一个子集,但足以适用于像我在项目中使用的简单设备。服务器只能处理一个 MAC 和 IP 地址对,但很容易扩展代码以处理更多对。
#include "bootpd.h"
void main(void)
{
// Create the bootpd object
Bootpd bootpd;
// Set the broadcast address
// You can use a mask to limit the broadcast scale
// example '10.0.255.255'. In theory 255.255.255.255 means broadcast
// to everyone in the world, but in practice filter routers these
// messages.
bootpd.m_broadcastIp = "255.255.255.255";
// Set the server address
// Use 0.0.0.0 to listen to all network messages from anyone connected
// to the network.
bootpd.m_interfaceIp = "0.0.0.0";
// The IP address the bootp device should get.
bootpd.m_targetIp = "10.0.1.55";
// The mac address of the device. Case insensitive.
bootpd.m_targetMac = "00:11:22:33:aa:bb";
// Now start the server and listen to requests.
bootpd.Start();
}
Bootp 是一种无连接协议。这段代码将向您展示如何创建一个侦听套接字以侦听广播消息,以及如何发送广播消息。
历史
- 1.0 | 2007年6月9日 | 初始版本