linuxÏÂntpʵÏÖ
#include <sys/types.h>
#include <sys/socket.h>
#include <netdb.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#define NTP_SERVER "clock.via.net"
#define NTP_PORT 123
//
//rfc1305 defined from 1900 so also 2208988800 (1900 - 1970 ) seconds left
//
//timeval.tv_sec + JAN_1970 = timestamp.coarse
#define JAN_1970 0x83aa7e80
//timeval.tv_usec=>timestamp.fine
#define NTPFRAC(x) (4294 * (x) + ((1981 * (x))>>11))
//timeval.tv_usec<=timestamp.fine
#define USEC(x) (((x) >> 12) - 759 * ((((x) >> 10) + 32768) >> 16))
#define Data(i) ntohl(((unsigned int *)data)[i])
#define LI 0
#define VN 3
#define MODE 3
#define STRATUM 0
#define POLL 4
#define PREC -6
struct ntptime
{
unsigned int coarse;
unsigned int fine;
};
void send_packet(int fd)
{
unsigned int data[12];
struct timeval now;
int ret;
if (sizeof(data) != 48)
{
fprintf(stderr,"size error\n");
return;
}
memset((char*)data, 0, sizeof(data));
data[0] = htonl((LI << 30) | (VN << 27) | (MODE << 24)
| (STRATUM << 16) | (POLL << 8) | (PREC & 0xff));
data[1] = htonl(1<<16); /* Root Delay (seconds) */
data[2] = htonl(1<<16); /* Root Dispersion (seconds) */
gettimeofday(&now, NULL);
data[10] = htonl(now.tv_sec + JAN_1970); /* Transmit Timestamp coarse */
data[11] = htonl(NTPFRAC(now.tv_usec)); /* Transmit Timestamp fine */
send(fd, data, 48, 0);
}
void get_udp_arrival_local_timestamp(struct ntptime *udp_arrival_local_timestamp)
{
struct timeval udp_arrival_local_time;
gettimeofday(&udp_arrival_local_time, NULL);
//print just precise to second
printf("local time=>%s\n",ctime(&(udp_arrival_local_time.tv_sec)));
}
void get_new_time(unsigned i
Ïà¹ØÎĵµ£º
linuxÄÚºËÉè¼ÆÓëʵÏÖ£¨9£©¶¨Ê±Æ÷ºÍʱ¼ä¹ÜÀí
ʱ¼ä¹ÜÀíÔÚÄÚºËÖÐÕ¼Óзdz£ÖØÒªµÄµØÎ»¡£Ïà¶ÔÓÚʼþÇý¶¯£¬ÄÚºËÖÐÓдóÁ¿µÄº¯Êý¶¼ÊÇ»ùÓÚʱ¼äÇý¶¯µÄ¡£Äں˱ØÐë¹ÜÀíϵͳµÄÔËÐÐʱ¼äÒÔ¼°µ±Ç°µÄÈÕÆÚºÍʱ¼ä¡£
ÖÜÆÚ²úÉúµÄʼþ¶¼ÊÇÓÉϵͳ¶¨Ê±Æ÷Çý¶¯µÄ¡£ÏµÍ³¶¨Ê±Æ÷ÊÇÒ»Öֿɱà³ÌÓ²¼þоƬ£¬ËüÒѹ̶¨ÆµÂʲúÉúÖ ......
²»ÖªµÀÔÚʲçÛʱºò£¬×ªÔØLinux ³öÏÖÁË module ÕâÖÖ¶«Î÷£¬µÄÈ·£¬ËüÊÇ Linux µÄÒ»´ó¸ïС£ÓÐÁË module Ö®ºó£¬Ð´
device driver ²»ÔÙÊÇÒ»Ïî¶ñÃΣ¬ÐÞ¸Ä kernel Ò²²»ÔÙÊÇÒ»¼þÍ´¿àµÄÊÂÁË¡£ÒòΪÄã²»ÐèҪÿ´ÎÒª²âÊÔ driver ¾ÍÖØÐÂ
compile kernel Ò»´Î¡£ÄǼòÖ±ÊÇ»áÀÛËÀÈË¡£Module ¿ÉÒÔÔÊÐíÎÒÃǶ¯Ì¬µÄ¸Ä±ä kernel£¬¼ÓÔØ device
dri ......
<!--
@page { margin: 2cm }
P { margin-bottom: 0.21cm }
-->
Linux
·¢ÐаæÓë
Linux
²úÆ·Á½ÕßÏà²îºÜ´ó£¬ÓÐʱÈÝÒ×»ìÏý£¬·¢ÉúÎó½â£¬ÉõÖÁÒªÄÖ³ö´óЦ»°À´¡£ÎªÊ²Ã´£¿
´Ó×ÖÃæÉÏÀ´½²£¬·¢Ðа棨
Distribution
£©ºÍ²úÆ ......
ÒýÓãºhttp://blog.chinaunix.net/u/12207/showart_2061214.html
¹ØÓÚ2.6.31Óöµ½µÄÎÊÌâ
´íÎóÌáʾ1£º
drivers/built-in.o(.init.text+0x3bad): In function `con_init':
include/trace/events/kmem.h:47: undefined reference to `.L1452'
½â¾ö£º
vi /usr/src/linux/drivers/char/vt.c ÕÒµ½static int __init con_init ......