⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 utils.c

📁 Adhoc无线网络路由协议源码
💻 C
字号:
#include "utils.h"#include "common.h"/* * *   Gets the current time in milliseconds since 1 jan 1970 * *   Return: *     u_int64_t - On error -1 is returned otherwise the time. */u_int64_tgetcurrtime(){  struct timeval tv;  if (gettimeofday(&tv, NULL) < 0)    /* Couldn't get time of day */    return -1;  return ((u_int64_t)tv.tv_sec) * 1000 + ((u_int64_t)tv.tv_usec) / 1000;}/* *  dot_ip() : converts ip address from int to dot.dot notation. *  is a wrapper around inet_ntoa so that you do not have to declare a, in_addr structure  *   *	 dot_ip can be called only once in one statement. *	 this is because dot_ip uses inet_ntoa which returns in a statically  *	 allocated buffer which is overwritten in each call. * hence you have to break up the printfs if there are multiple calls to dot_ip **/char *dot_ip(u_int32_t ipint){	struct in_addr ip;	ip.s_addr = ipint ;	return inet_ntoa(ip);}/* This is a routine to do a 'mknod' on the /dev/tun<n> if possible: * Return: 0 is ok, -1=already open, etc. *  * From sourcode of user-mode-linux by Jeff Dike --vikas */int mk_node(char *devname, int major, int minor){  struct stat statval;  int retval;  /* first do a stat on the node to see whether it exists and we   * had some other reason to fail:   */  retval = stat(devname, &statval);  if(retval == 0) return(0);  else if(errno != ENOENT){    /* it does exist. We are just going to return -1, 'cause there     * was some other problem in the open :-(.     */    return -1;  }  /* It doesn't exist. We can create it. */  return(mknod(devname, S_IFCHR|S_IREAD|S_IWRITE, makedev(major, minor)));}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -