获取系统时间

int getlocaltime(struct tm *time)
{
    struct timeval tv;
    time_t second;
    struct tm *temp;

    gettimeofday(&tv, NULL);
    second = tv.tv_sec;

    temp = localtime(&second);
    temp->tm_year += ;
    temp->tm_mon += ;
    memcpy(time, temp,sizeof(struct tm));

    ;
}

设置系统时间

int setlocaltime(struct tm *tm)
{
    time_t timesec;
    struct timeval tv;
    struct tm temptm;

    memcpy(&temptm,tm,sizeof(temptm));
    temptm.tm_year = tm->tm_year - ;
    temptm.tm_yday = ;
    temptm.tm_isdst = -;                /* Be sure to recheck dst. */
    timesec = mktime(&temptm);
    tv.tv_sec = timesec;
    tv.tv_usec    = ;
    settimeofday(&tv,);        //设置系统时间
    ;
}

获取IP地址

void getip(unsigned char* ip_buf,char * name)
{
    struct ifreq temp;
    struct sockaddr_in *myaddr;
    ;
    ;
    strcpy(temp.ifr_name, name);

    ))<)
    {
        return NULL;
    }
    ret = ioctl(fd, SIOCGIFADDR, &temp);
    close(fd);
    )
        return NULL;
    myaddr = (struct sockaddr_in *)&(temp.ifr_addr);
    strcpy(ip_buf, inet_ntoa(myaddr->sin_addr));
    printf("getip:%s\n",ip_buf);

} 

设置IP地址

int setip(char* ip)
{
    struct ifreq temp;
    struct sockaddr_in *addr;
    ;
    ;
    strcpy(temp.ifr_name, "eth0");

    ))<)
    {
        ;
    }

    addr = (struct sockaddr_in *)&(temp.ifr_addr);
    addr->sin_family = AF_INET;
    addr->sin_addr.s_addr = inet_addr(ip);
    ret = ioctl(fd, SIOCSIFADDR, &temp);
    close(fd);
    )
        ;
    ;
} 

检查网线是否连接

int check_nic(void)
{
    struct ifreq ifr;
    );  

    strcpy(ifr.ifr_name, "eth0");
    )
    {
        close(skfd);
        ;
    } 

    if(ifr.ifr_flags & IFF_RUNNING)
    {
        printf("link up\n");
        close(skfd);
        ; // 网卡已插上网线
    }
    else
    {
        printf("link down\n");
        close(skfd);
        ;
    }
}  

读取本机MAC地址

int read_mac(unsigned char *buf,char *name)
{
    int sock;
    int ret;
    struct ifreq ifr; 

    sock = socket(AF_INET, SOCK_DGRAM, );
    )
    {
        perror("socket error");
        ;
    } 

    memset(&ifr, , sizeof(ifr));
    strcpy(ifr.ifr_name, name);
    ifr.ifr_name[] = '\0';

    ret = ioctl(sock,SIOCGIFHWADDR,&ifr);
    )
    {
        memcpy(buf, ifr.ifr_hwaddr.sa_data, );
        printf("HW address is: %02x:%02x:%02x:%02x:%02x:%02x \n",
        (unsigned ], (unsigned ], (unsigned ],
        (unsigned ], (unsigned ], (unsigned ]);

    }
    else
    {
        perror("ioctl error!\n");
    }

    close(sock);

    return ret;
}

判断文件是否存在

int is_file_exist(const char *file_path)
{
    if(file_path == NULL)
        ;
    )
        ;
    ;
}

最新文章

  1. collection of vim vim tutorial for beginner
  2. STL学习之vector
  3. 关于配置服务器(IIS7)
  4. AJAX状态值与状态码
  5. angularjs入门学习【应用剖析中篇】
  6. 【转】http响应状态代码含义及跳转的类型
  7. SQL Server 已提交读快照 测试
  8. EF|CodeFirst数据并发管理
  9. JS之代理模式
  10. CentOS7编译安装MySQL5.7.24
  11. CentOS 7.6安装桌面
  12. 解决CPC撰写文档报错问题“无法获取“AxforApplication”控件的窗口句柄。不支持无窗口的 ActiveX 控件”
  13. LINUX系统配置
  14. 《精通CSS层叠样式表》
  15. Excel脱拽或者下拉公式时, 保持公式里单元格数字不变
  16. Redis的认识和基本操作
  17. Codeforces 578.C Weakness and Poorness
  18. python虚拟机运行原理
  19. (二)Fiddler抓取Firefox、Chrome浏览器上的https协议
  20. Primer 三四五章

热门文章

  1. CSS3带小图标垂直下拉菜单
  2. get_called_class--后期静态绑定(&quot;Late Static Binding&quot;)类的名称
  3. (十三)linux文件系统详解(基于ext2文件系统)【转】
  4. java 类装载器原理
  5. MapReduce-从HBase读取数据处理后再写入HBase
  6. [转]Android:改变Activity切换方式
  7. 使用log4j2打印Log,log4j不能打印日志信息,log4j2不能打印日志信息,log4j和logj2,idea控制台信息乱码(文末)
  8. codeforces675D Tree Construction
  9. hibernate.cfg.xml_属性&quot;connection.url&quot;_指定字符集
  10. 无法锁定管理目录(/var/lib/dpkg/),是否有其他进程正占用它