linux 修改openwrt ntp服务器
来源:互联网 发布:宿迁12345网络问政电话 编辑:程序博客网 时间:2024/06/06 03:15
修改openwrt ntp 服务器的demo
系统ntp配置文件如下:
config system
option hostname 'OpenWrt'
option zonename 'Asia/Shanghai'
option timezone 'CST-8'
option conloglevel '8'
option cronloglevel '5'
option log_file '/mnt/usr/log/system.log'
option log_size '2048'
option log_buffer_size '1024'
option log_ip '192.168.178.100'
option log_port '6666'
config timeserver 'ntp'
list server '0.openwrt.pool.ntp.org'
list server 'cn.ntp.org.cn'
list server 'cn.pool.ntp.org'
list server 'pool.ntp.org'
option enabled '1'
#include <stdio.h>
#include <stdlib.h>#include <string.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <stdarg.h>
#include <arpa/inet.h>
int main(int argc, char *argv[])
{
if (argc < 3)
{
printf("two few argument \n");
return -1;
}
else
{
printf("file name is %s , add server is %s argc is %d \n", argv[1], argv[2], argc);
}
FILE *fd;
fd = fopen(argv[1], "r+");
if (fd == NULL)
{
printf("can not open file %s \n", argv[1]);
return -1;
}
struct stat fileStat;
stat(argv[1], &fileStat);
printf("file size if %d \n", fileStat.st_size);
unsigned char *fbuf = (unsigned char *)malloc(fileStat.st_size);
memset(fbuf, 0, fileStat.st_size);
char buf[256] = {0};
char server[10][100] = {{0}, {0}, {0}, {0}, {0}, {0}, {0}, {0}, {0}, {0}};
int list = 0;
while(fgets(buf, 256, fd) != NULL)
{
if (strstr(buf, "list server"))
{
strcpy(server[list], strstr(buf, "list server") + 13);
server[list][strlen(server[list]) - 2] = '\0';
printf("server id is %d is %s \n", list, server[list++]);
}
if (strstr(buf, "option enabled"))
{
printf("ntp file end %s \n", buf);
break;
}
strcat(fbuf, buf);
memset(buf, 0, 256);
}
system("rm /etc/config/system");
FILE *fdNew;
fdNew = fopen(argv[1], "w");
if (fdNew == NULL)
return -1;
fwrite(fbuf, strlen(fbuf), 1, fdNew);
char buf1[256] = {0};
for (list = 0; list < argc - 2; list++)
{
sprintf(buf1, "\tlist server '%s'\n", argv[2+list]);
printf("add server is %s \n", buf1);
fwrite(buf1, strlen(buf1), 1, fdNew);
memset(buf1, 0, sizeof(buf1));
}
fwrite(buf, strlen(buf), 1, fdNew);
fclose(fdNew);
fclose(fd);
free(fbuf);
system("reboot");
}
阅读全文
0 0
- linux 修改openwrt ntp服务器
- linux搭建ntp服务器
- Linux NTP服务器
- Linux配置NTP服务器
- linux NTP服务器搭建
- Linux NTP服务器配置
- ntp服务器配置for linux
- linux 顶级ntp服务器配置
- Linux搭建NTP时间服务器
- Linux中构建NTP服务器
- Linux搭建NTP时间服务器
- Linux上搭建NTP服务器
- Linux下NTP服务器配置
- 搭建Linux下NTP服务器
- Linux 之 NTP 服务 服务器
- ntp服务器搭建与修改时区
- windows 7 设置NTP服务器,linux作为NTP客户端同步
- [Linux] Linux下配置NTP时间服务器
- Spring MVC在maven下用$ajaxFileUpload()上传图片
- Centos6.5使用Siege压力测试
- 网络数据包类型
- linux各文件夹的作用
- IAR开发环境使用串口printf输出(基于STM8L15x系列单片机)
- linux 修改openwrt ntp服务器
- Spring的java配置方式
- Yii2 使用select2 组件实现下拉搜索
- 面向对象六大原则
- 有序符号表(二叉树实现,JAVA,算法(四))
- Struts2 官方教程:通用方法选择
- 项目管理——如何有效的沟通
- 51nod 1307 绳子与重物
- hyperscan示例解读pcapscan