Ò׽ؽØÍ¼Èí¼þ¡¢µ¥Îļþ¡¢Ãâ°²×°¡¢´¿ÂÌÉ«¡¢½ö160KB

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²Ù×÷ÏµÍ³ÍøÂç±à³Ì ԭʼÌ×½Ó×Ö £¨1£©

Linux²Ù×÷ÏµÍ³ÍøÂç±à³Ì--ԭʼÌ×½Ó×Ö £¨1£©
http://soft.zdnet.com.cn/software_zone/2007/1020/568223.shtml
ÎÒÃÇÔÚÇ°ÃæÒѾ­Ñ§Ï°¹ýÁËÍøÂç³ÌÐòµÄÁ½ÖÖÌ×½Ó×Ö(SOCK_STREAM,SOCK_DRAGM).ÔÚÕâÒ»Õ ÀïÃæÎÒÃÇÒ»ÆðÀ´Ñ§Ï°ÁíÍâÒ»ÖÖÌ×½Ó×Ö--ԭʼÌ×½Ó×Ö(SOCK_RAW)¡£Ó¦ÓÃԭʼÌ×½Ó×Ö,ÎÒÃÇ¿ÉÒÔ±àд³öÓÉTCPºÍUDPÌ×½Ó×Ö²»Äܹ»ÊµÏֵŦÄÜ. × ......

Linux Shell ÃüÁî ¼ò½é

°²×°openssh ·þÎñ¶Ë
sudo apt-get install openssh-server openssh-client
 
windows Ï¿ͻ§¶Ë
puTTY
  
 
³£ÓÃÃüÁî:
 
Ò»£®Ls ²é¿´Ä¿Â¼ÃüÁî
Ò»°ã·ÅÔÚhome Ŀ¼ÏÂ
Ls –l /  ¸ùĿ¼ÏµÄÁбí
Ls –a /  ¸ùĿ¼ÏÂËùÓеÄÎļþ
Ls –la  ×éºÏµÄÑ¡Ïî
Ls &n ......

Book Note: Linux Device Driver Dos and Don'ts

Book Note: Linux Device Driver Dos and Don'ts
http://janitor.kernelnewbies.org/docs/driver-howto.html
what a hardened (robust) device
driver should mean and how it should be implemented and measured.
1.3 Robust device drivers
-Follows the Linux CodingStyle.
-Efficient in managing faults and ha ......

Linux I2CºËÐÄ¡¢×ÜÏßÓëÉ豸Çý¶¯

Linux I2CºËÐÄ¡¢×ÜÏßÓëÉ豸Çý¶¯
×¢:
 ÔÚlinux2.6.32°æ±¾ÖÐÓÐÕâÑùµÄ´úÂëÓë×¢ÊÍ:
struct i2c_driver {
    unsigned int class;
    /* Notifies the driver that a new bus has appeared or is about to be
     * removed. You should avoid using this if y ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØÍ¼ | ¸ÓICP±¸09004571ºÅ