我现在使用W5200嵌入做一个TCP/IP通讯端. 使用DHCP能动态自动获取IP地址. 在同网络中能ping到W5200,但却无法使用gethostbyname从w5200名称得到该IP地址. 我的DHCP报文中RIP_MSG数据如下:
void send_DHCP_REQUEST(uint8_t s, uint8_t *Cip, uint8_t *d_addr)
{
int i;
uint8_t ip[10];
uint16_t k = 0;
memset((unsigned char*)&MSG,0,sizeof(MSG));
MSG.op = DHCP_BOOTREQUEST;
MSG.htype = DHCP_HTYPE10MB;
MSG.hlen = DHCP_HLENETHERNET;
MSG.hops = DHCP_HOPS;
MSG.xid = DHCP_XID;
MSG.secs = DHCP_SECS;
//MSG.flags = DHCP_FLAGSBROADCAST;
if (d_addr[0] == 0xff)
MSG.flags = DHCP_FLAGSBROADCAST;
else
MSG.flags = DHCP_FLAGSUNICAST;
MSG.ciaddr[0] = Cip[0];
MSG.ciaddr[1] = Cip[1];
MSG.ciaddr[2] = Cip[2];
MSG.ciaddr[3] = Cip[3];
MSG.yiaddr[0] = 0;
MSG.yiaddr[1] = 0;
MSG.yiaddr[2] = 0;
MSG.yiaddr[3] = 0;
MSG.siaddr[0] = 0;
MSG.siaddr[1] = 0;
MSG.siaddr[2] = 0;
MSG.siaddr[3] = 0;
MSG.giaddr[0] = 0;
MSG.giaddr[1] = 0;
MSG.giaddr[2] = 0;
MSG.giaddr[3] = 0;
MSG.chaddr[0] = Config_Msg.Mac[0];
MSG.chaddr[1] = Config_Msg.Mac[1];
MSG.chaddr[2] = Config_Msg.Mac[2];
MSG.chaddr[3] = Config_Msg.Mac[3];
MSG.chaddr[4] = Config_Msg.Mac[4];
MSG.chaddr[5] = Config_Msg.Mac[5];
for (i = 6; i < 16; i++) MSG.chaddr[i] = 0;
for (i = 0; i < 64; i++) MSG.sname[i] = 0;
for (i = 0; i < 128; i++) MSG.file[i] = 0;
// MAGIC_COOKIE
MSG.OPT[k++] = 0x63;
MSG.OPT[k++] = 0x82;
MSG.OPT[k++] = 0x53;
MSG.OPT[k++] = 0x63;
// Option Request Param.
MSG.OPT[k++] = dhcpMessageType;
MSG.OPT[k++] = 0x01;
MSG.OPT[k++] = DHCP_REQUEST;
MSG.OPT[k++] = dhcpClientIdentifier;
MSG.OPT[k++] = 0x07;
MSG.OPT[k++] = 0x01;
MSG.OPT[k++] = Config_Msg.Mac[0];
MSG.OPT[k++] = Config_Msg.Mac[1];
MSG.OPT[k++] = Config_Msg.Mac[2];
MSG.OPT[k++] = Config_Msg.Mac[3];
MSG.OPT[k++] = Config_Msg.Mac[4];
MSG.OPT[k++] = Config_Msg.Mac[5];
if (d_addr[0] == 0xff)
{
MSG.OPT[k++] = dhcpRequestedIPaddr;
MSG.OPT[k++] = 0x04;
MSG.OPT[k++] = Config_Msg.Lip[0];
MSG.OPT[k++] = Config_Msg.Lip[1];
MSG.OPT[k++] = Config_Msg.Lip[2];
MSG.OPT[k++] = Config_Msg.Lip[3];
MSG.OPT[k++] = dhcpServerIdentifier;
MSG.OPT[k++] = 0x04;
MSG.OPT[k++] = DHCP_SIP[0];
MSG.OPT[k++] = DHCP_SIP[1];
MSG.OPT[k++] = DHCP_SIP[2];
MSG.OPT[k++] = DHCP_SIP[3];
}
// host name
MSG.OPT[k++] = hostName;
MSG.OPT[k++] = 8; // length of hostname
MSG.OPT[k++] = HOST_NAME[0];
MSG.OPT[k++] = HOST_NAME[1];
MSG.OPT[k++] = HOST_NAME[2];
MSG.OPT[k++] = HOST_NAME[3];
MSG.OPT[k++] = HOST_NAME[4];
MSG.OPT[k++] = HOST_NAME[5];
MSG.OPT[k++] = HOST_NAME[6];
MSG.OPT[k++] = HOST_NAME[7];
//----------------------------
MSG.OPT[k++] = dpcpClientFullyQDN;
MSG.OPT[k++] = 11; // length of hostname
MSG.OPT[k++] = 0;
MSG.OPT[k++] = 0;
MSG.OPT[k++] = 0;
MSG.OPT[k++] = HOST_NAME[0];
MSG.OPT[k++] = HOST_NAME[1];
MSG.OPT[k++] = HOST_NAME[2];
MSG.OPT[k++] = HOST_NAME[3];
MSG.OPT[k++] = HOST_NAME[4];
MSG.OPT[k++] = HOST_NAME[5];
MSG.OPT[k++] = HOST_NAME[6];
MSG.OPT[k++] = HOST_NAME[7];
MSG.OPT[k++] = dhcpClassIdentifier;
MSG.OPT[k++] = 8;
MSG.OPT[k++] = 'M';
MSG.OPT[k++] = 'S';
MSG.OPT[k++] = 'F';
MSG.OPT[k++] = 'T';
MSG.OPT[k++] = ' ';
MSG.OPT[k++] = '5';
MSG.OPT[k++] = '.';
MSG.OPT[k++] = '0';
//----------------------------
MSG.OPT[k++] = dhcpParamRequest;
MSG.OPT[k++] = 0x09;
MSG.OPT[k++] = subnetMask;
MSG.OPT[k++] = routersOnSubnet;
MSG.OPT[k++] = dns;
MSG.OPT[k++] = netBIOSnameServer;
MSG.OPT[k++] = domainName;
MSG.OPT[k++] = dhcpT1value;
MSG.OPT[k++] = dhcpT2value;
MSG.OPT[k++] = performRouterDiscovery;
MSG.OPT[k++] = staticRoute;
MSG.OPT[k++] = endOption;
for (i = k; i < OPT_SIZE; i++)
MSG.OPT[i] = 0;
// send broadcasting packet
for (i = 0; i < 4; i++)
ip[i] = d_addr[i];
DBG_PRINTF("\r\n> send DHCP_Request");
/// sendto(s, (uint8_t *)(&MSG.op), RIP_MSG_SIZE, ip, DHCP_SERVER_PORT);
sendto(s, (uint8_t *)(&MSG.op), 236 + k, ip, DHCP_SERVER_PORT);
}
请问以上哪里设置有问题导致服务器无法记住设备名称"ASIXXISA". 同网段其他设备无法通过pHost = gethostbyname(("ASIXXISA"));得到IP地址等等 |