parent
b5e53811b3
commit
b03a44bec5
|
@ -47,7 +47,9 @@ void Dhcp::SendDhcp(DHCP_HEADER* dhcp, uint len)
|
|||
len = (byte*)opt + 1 - p;
|
||||
}
|
||||
|
||||
memcpy(dhcp->ClientMac, (byte*)&Tip->Mac.Value, 6);
|
||||
//memcpy(dhcp->ClientMac, (byte*)&Tip->Mac.Value, 6);
|
||||
for(int i=0; i<6; i++)
|
||||
dhcp->ClientMac[i] = Tip->Mac[i];
|
||||
|
||||
RemoteIP = IPAddress::Broadcast;
|
||||
|
||||
|
|
|
@ -78,7 +78,7 @@ bool PingCallback(TinyIP* tip, void* param, Stream& ms)
|
|||
}
|
||||
|
||||
// Ping目的地址,附带a~z重复的负载数据
|
||||
bool IcmpSocket::Ping(IPAddress ip, uint payloadLength)
|
||||
bool IcmpSocket::Ping(IPAddress& ip, uint payloadLength)
|
||||
{
|
||||
byte buf[sizeof(ETH_HEADER) + sizeof(IP_HEADER) + sizeof(ICMP_HEADER) + 64];
|
||||
uint bufSize = ArrayLength(buf);
|
||||
|
|
|
@ -20,7 +20,7 @@ public:
|
|||
PingHandler OnPing;
|
||||
|
||||
// Ping目的地址,附带a~z重复的负载数据
|
||||
bool Ping(IPAddress ip, uint payloadLength = 32);
|
||||
bool Ping(IPAddress& ip, uint payloadLength = 32);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
@ -8,7 +8,7 @@ bool Callback(TinyIP* tip, void* param, Stream& ms);
|
|||
|
||||
TcpSocket::TcpSocket(TinyIP* tip) : Socket(tip)
|
||||
{
|
||||
Type = IP_TCP;
|
||||
Type = IP_TCP;
|
||||
|
||||
Port = 0;
|
||||
RemoteIP = 0;
|
||||
|
@ -398,7 +398,7 @@ void TcpSocket::Send(const byte* buf, uint len)
|
|||
}
|
||||
|
||||
// 连接远程服务器,记录远程服务器IP和端口,后续发送数据和关闭连接需要
|
||||
bool TcpSocket::Connect(IPAddress ip, ushort port)
|
||||
bool TcpSocket::Connect(IPAddress& ip, ushort port)
|
||||
{
|
||||
if(ip.IsAny() || port == 0) return false;
|
||||
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
class TcpSocket : public Socket, public ITransport
|
||||
{
|
||||
private:
|
||||
//byte seqnum;
|
||||
uint Seq; // 序列号,本地发出数据包
|
||||
uint Ack; // 确认号,对方发送数据包的序列号+1
|
||||
|
||||
|
@ -22,6 +23,12 @@ public:
|
|||
Established = 3,
|
||||
}TCP_STATUS;
|
||||
|
||||
ushort Port; // 本地端口,接收该端口数据包。0表示接收所有端口的数据包
|
||||
ushort BindPort; // 绑定端口,用于发出数据包的源端口。默认为Port,若Port为0,则从1024算起,累加
|
||||
IPAddress RemoteIP; // 远程地址
|
||||
ushort RemotePort; // 远程端口
|
||||
IPAddress LocalIP; // 本地IP地址
|
||||
ushort LocalPort; // 本地端口,收到数据包的目的端口
|
||||
TCP_STATUS Status; // 状态
|
||||
|
||||
TCP_HEADER* Header;
|
||||
|
@ -31,7 +38,7 @@ public:
|
|||
// 处理数据包
|
||||
virtual bool Process(IP_HEADER& ip, Stream& ms);
|
||||
|
||||
bool Connect(IPAddress ip, ushort port); // 连接远程服务器,记录远程服务器IP和端口,后续发送数据和关闭连接需要
|
||||
bool Connect(IPAddress& ip, ushort port); // 连接远程服务器,记录远程服务器IP和端口,后续发送数据和关闭连接需要
|
||||
void Send(const byte* buf, uint len); // 向Socket发送数据,可能是外部数据包
|
||||
void Disconnect(); // 关闭Socket
|
||||
|
||||
|
|
|
@ -15,19 +15,9 @@ class TinyIP;
|
|||
class Socket
|
||||
{
|
||||
public:
|
||||
TinyIP* Tip; // TinyIP控制器
|
||||
IP_TYPE Type; // 类型
|
||||
bool Enable; // 启用
|
||||
|
||||
IP_HEADER* IPHeader;
|
||||
|
||||
ushort Port; // 本地端口,接收该端口数据包。0表示接收所有端口的数据包
|
||||
ushort BindPort; // 绑定端口,用于发出数据包的源端口。默认为Port,若Port为0,则从1024算起,累加
|
||||
|
||||
IPAddress RemoteIP; // 远程地址。当前数据包
|
||||
ushort RemotePort; // 远程端口。当前数据包
|
||||
IPAddress LocalIP; // 本地IP地址。当前数据包
|
||||
ushort LocalPort; // 本地端口,收到数据包的目的端口
|
||||
TinyIP* Tip; // TinyIP控制器
|
||||
IP_TYPE Type; // 类型
|
||||
bool Enable; // 启用
|
||||
|
||||
Socket(TinyIP* tip);
|
||||
virtual ~Socket();
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
|
||||
UdpSocket::UdpSocket(TinyIP* tip) : Socket(tip)
|
||||
{
|
||||
Type = IP_UDP;
|
||||
Type = IP_UDP;
|
||||
Port = 0;
|
||||
RemoteIP = 0;
|
||||
RemotePort = 0;
|
||||
|
@ -151,7 +151,7 @@ UDP_HEADER* UdpSocket::Create()
|
|||
}
|
||||
|
||||
// 发送UDP数据到目标地址
|
||||
void UdpSocket::Send(const byte* buf, uint len, IPAddress ip, ushort port)
|
||||
void UdpSocket::Send(const byte* buf, uint len, IPAddress& ip, ushort port)
|
||||
{
|
||||
if(!ip.IsAny())
|
||||
{
|
||||
|
|
|
@ -10,6 +10,12 @@ private:
|
|||
UDP_HEADER* Create();
|
||||
|
||||
public:
|
||||
ushort Port; // 本地端口,接收该端口数据包。0表示接收所有端口的数据包
|
||||
ushort BindPort; // 绑定端口,用于发出数据包的源端口。默认为Port,若Port为0,则从1024算起,累加
|
||||
IPAddress RemoteIP; // 远程地址
|
||||
ushort RemotePort; // 远程端口
|
||||
IPAddress LocalIP; // 本地IP地址
|
||||
ushort LocalPort; // 本地端口,收到数据包的目的端口
|
||||
|
||||
UdpSocket(TinyIP* tip);
|
||||
|
||||
|
@ -21,7 +27,7 @@ public:
|
|||
UdpHandler OnReceived;
|
||||
|
||||
// 发送UDP数据到目标地址
|
||||
void Send(const byte* buf, uint len, IPAddress ip = 0, ushort port = 0);
|
||||
void Send(const byte* buf, uint len, IPAddress& ip = IPAddress::Any, ushort port = 0);
|
||||
|
||||
virtual string ToString();
|
||||
|
||||
|
|
Loading…
Reference in New Issue