/* 构建 NTP 协议包 */
int ConstructPacket(char *Packet)
{
char Version = 1;
long SecondFrom1900;
long Zero = 0;
int Port;
time_t timer;
strcpy(Protocol,NTPV1);
/* 判断协议版本 */
if(strcmp(Protocol, NTPV1) || strcmp(Protocol,NTPV2) || strcmp(Protocol, NTPV3) || strcmp(Protocol, NTPV4))
{
Port = NTPPORT;
Version = Protocol[6] - 0x30;
Packet[0] = (Version << 3) | 3; //LI--Version--Mode
Packet[1] = 0;
//Startum
Packet[2] = 0;
//Poll interval
Packet[3] = 0;
//Precision
/* 包括 Root delay、Root disperse 和 Ref Indentifier */
memset(&Packet[4], 0, 12);
/* 包括 Ref timestamp、Ori timastamp 和 Receive Timestamp */
memset(&Packet[16], 0, 24);
time(&timer);
SecondFrom1900 = SecondBef1970 + (long)timer;
SecondFrom1900 = htonl(SecondFrom1900);
memcpy(&Packet[40], &SecondFrom1900, 4);
memcpy(&Packet[44], &Zero, 4);
return 48;
}
else
// time/udp
{
Port = TIMEPORT;
memset(Packet, 0, 4);
return 4;
}
return 0;
}
这个构建NTP协议包不知道怎么转到vfp中,看了你前一阵子写的构建struct类型的数据,还是理解不了