在线看毛片网站电影-亚洲国产欧美日韩精品一区二区三区,国产欧美乱夫不卡无乱码,国产精品欧美久久久天天影视,精品一区二区三区视频在线观看,亚洲国产精品人成乱码天天看,日韩久久久一区,91精品国产91免费

<menu id="6qfwx"><li id="6qfwx"></li></menu>
    1. <menu id="6qfwx"><dl id="6qfwx"></dl></menu>

      <label id="6qfwx"><ol id="6qfwx"></ol></label><menu id="6qfwx"></menu><object id="6qfwx"><strike id="6qfwx"><noscript id="6qfwx"></noscript></strike></object>
        1. <center id="6qfwx"><dl id="6qfwx"></dl></center>

            新聞中心

            EEPW首頁(yè) > 嵌入式系統(tǒng) > 設(shè)計(jì)應(yīng)用 > 嵌入式Linux網(wǎng)絡(luò)編程之:實(shí)驗(yàn)內(nèi)容——NTP協(xié)議實(shí)現(xiàn)

            嵌入式Linux網(wǎng)絡(luò)編程之:實(shí)驗(yàn)內(nèi)容——NTP協(xié)議實(shí)現(xiàn)

            作者: 時(shí)間:2013-09-13 來(lái)源:網(wǎng)絡(luò) 收藏

            本文引用地址:http://www.biyoush.com/article/257114.htm

            /*獲取NTP時(shí)間*/

            intget_ntp_time(intsk,structaddrinfo*addr,structntp_packet*ret_time)

            {

            fd_setpending_data;

            structtimevalblock_time;

            chardata[NTP_PCK_LEN*8];

            intpacket_len,data_len=addr->ai_addrlen,count=0,result,i,re;

            if(!(packet_len=construct_packet(data)))

            {

            return0;

            }

            /*客戶端給服務(wù)器端發(fā)送數(shù)據(jù)包*/

            if((result=sendto(sk,data,

            packet_len,0,addr->ai_addr,data_len))0)

            {

            perror(sendto);

            return0;

            }

            /*調(diào)用select()函數(shù),并設(shè)定超時(shí)時(shí)間為1s*/

            FD_ZERO(pending_data);

            FD_SET(sk,pending_data);

            block_time.tv_sec=10;

            block_time.tv_usec=0;

            if(select(sk+1,pending_data,NULL,NULL,block_time)>0)

            {

            /*接收服務(wù)器端的信息*/

            if((count=recvfrom(sk,data,

            NTP_PCK_LEN*8,0,addr->ai_addr,data_len))0)

            {

            perror(recvfrom);

            return0;

            }

            if(protocol==TIME)

            {

            memcpy(ret_time->transmit_timestamp,data,4);

            return1;

            }

            elseif(countNTP_PCK_LEN)

            {

            return0;

            }

            /*設(shè)置接收NTP包的數(shù)據(jù)結(jié)構(gòu)*/

            ret_time->leap_ver_mode=ntohl(data[0]);

            ret_time->startum=ntohl(data[1]);

            ret_time->poll=ntohl(data[2]);

            ret_time->precision=ntohl(data[3]);

            ret_time->root_delay=ntohl(*(int*)(data[4]));

            ret_time->root_dispersion=ntohl(*(int*)(data[8]));

            ret_time->reference_identifier=ntohl(*(int*)(data[12]));

            ret_time->reference_timestamp.coarse=ntohl*(int*)(data[16]));

            ret_time->reference_timestamp.fine=ntohl(*(int*)(data[20]));

            ret_time->originage_timestamp.coarse=ntohl(*(int*)(data[24]));

            ret_time->originage_timestamp.fine=ntohl(*(int*)(data[28]));

            ret_time->receive_timestamp.coarse=ntohl(*(int*)(data[32]));

            ret_time->receive_timestamp.fine=ntohl(*(int*)(data[36]));

            ret_time->transmit_timestamp.coarse=ntohl(*(int*)(data[40]));

            ret_time->transmit_timestamp.fine=ntohl(*(int*)(data[44]));

            return1;

            }/*endofifselect*/

            return0;

            }

            linux操作系統(tǒng)文章專題:linux操作系統(tǒng)詳解(linux不再難懂)


            評(píng)論


            相關(guān)推薦

            技術(shù)專區(qū)

            關(guān)閉