读取 /proc/sys/kernel/random/uuid 可以得到一个guid
来源:互联网 发布:电动剃须刀推荐 知乎 编辑:程序博客网 时间:2024/06/05 11:44
读取 /proc/sys/kernel/random/uuid 可以得到一个guid
string CommFun::GenGuid(int extend){char uuid[39];int fd = open("/proc/sys/kernel/random/uuid", O_RDONLY);if(fd>=0){read(fd, uuid+1, 36);}uuid[37] = 0;if(extend==0){ close(fd);return uuid+1;}uuid[0] = '{';uuid[37] = '}';uuid[38] = 0;return uuid;}
void GenGuid(void){char dbcode[] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'};long long int uuid[2];static long long int seed=0;int rfd;if ((rfd = open("/dev/urandom", O_RDWR)) < 0 ){*(int32_t*)(uuid) = random();*(int32_t*)(uuid+1) = random();*(int32_t*)(uuid+2) = random();*(int32_t*)(uuid+3) = random();}else{if(!seed){seed=time(0)+getpid();write(rfd, &seed, sizeof(seed));}if(read(rfd, uuid, 16)!=16){*(int32_t*)(uuid) = random();*(int32_t*)(uuid+1) = random();*(int32_t*)(uuid+2) = random();*(int32_t*)(uuid+3) = random();}close(rfd);}static char uuidstring[40] = "1E176852-AB1F-FFFF-FFFF-15CAF932FE70";int indx=0;for(int i = 0; i < 2; ++i){for(int j=0; j<16; ++indx){if(indx==8 || indx==13 || indx==18 || indx==23){uuidstring[indx] = '-';continue;}uuidstring[indx] = dbcode[uuid[i] & 0xf];++j;uuid[i] = uuid[i]>>4;}}uuidstring[37]='\0';printf("%s\n", uuidstring);}
- 读取 /proc/sys/kernel/random/uuid 可以得到一个guid
- [proc 系统] /proc/sys/kernel
- /proc/sys/kernel/printk
- /proc/sys/kernel/printk
- /proc/sys/kernel/printk
- /proc/sys/kernel/printk
- /proc/sys/kernel/hung_task_timeout_secs问题
- kobject_uevent,uevent_helper,/sys/kernel/uevent_helper,/proc/sys/kernel/hotplug
- Kernel Module with /proc/sys support
- /proc/sys/kernel/ 入口项的创建
- linux参数之/proc/sys/kernel详解
- echo 0 > /proc/sys/kernel/printk
- /proc/sys/kernel/printk 打印log设置
- 嵌入式 /proc/sys/kernel/sysrq and /proc/sysrq-trigger
- GUID/UUID
- Excel生成guid、uuid(2007以上可以直接使用)
- 关于热插拔usb hotplug /proc/sys/kernel mdev udev busybox
- 关于热插拔usb hotplug /proc/sys/kernel mdev udev busybox
- Java冒泡排序
- 北京邮电大学校长方滨兴在今年本科生毕业典礼上讲话
- 小窥计算机的工作奥秘
- Python log的说明
- Java正则表达式的多行匹配实战-将java文件中的单行和多行注释内容替换为空
- 读取 /proc/sys/kernel/random/uuid 可以得到一个guid
- JSON json-rpc 及json-c-0.9的例子
- 北京邮电大学校长方滨兴在今年本科生毕业典礼上讲话
- 使用的oracle 为10.2.0.1.0版本,道对应的应该下载哪个ODAC
- 如何获取动态加载DLL 类里面的事件?
- 采用OpenSSL生成Https的证书CA
- learn prolog now 5
- cocos2d-x游戏开发之一
- spring response json提示406问题的解决