SmartOS/TinyIP/Arp.h

36 lines
794 B
C++
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#ifndef _TinyIP_ARP_H_
#define _TinyIP_ARP_H_
#include "TinyIP.h"
// ARP协议
class ArpSocket : public TinySocket
{
private:
// ARP表
typedef struct
{
IPAddr IP;
MacAddr Mac;
int Time; // 生存时间,秒
}ARP_ITEM;
ARP_ITEM* _Arps; // Arp表动态分配
public:
byte Count; // Arp表行数默认16行
ArpSocket(TinyIP* tip);
virtual ~ArpSocket();
// 处理数据包
virtual bool Process(IP_HEADER& ip, Stream& ms);
// 请求Arp并返回其Mac。timeout超时3秒如果没有超时时间表示异步请求不用等待结果
bool Request(const IPAddress& ip, MacAddress& mac, int timeout = 3);
bool Resolve(const IPAddress& ip, MacAddress& mac);
void Add(const IPAddress& ip, const MacAddress& mac);
};
#endif