Articles of c + +

在/ dev / input / event *中dynamic查找鼠标事件ID

我正在使用这段代码来读取Linux中的鼠标input事件。 #define MOUSEFILE "/dev/input/event13" if((fd = open(MOUSEFILE, O_RDONLY)) == -1) { perror("opening device"); exit(EXIT_FAILURE); } while(read(fd, &ie, sizeof(struct input_event))) { } 我手动使用terminal中的cat /proc/bus/input/devices来查找连接的鼠标的事件ID,每次我重新启动linux时都会有所不同。 有没有办法通过我可以dynamic地find我连接的鼠标的事件ID。

inotify错误地多次通知一个新文件

使用inotify通过在目录中添加监视来监视在目录中创build的任何新文件的目录 fd = inotify_init(); wd = inotify_add_watch(fd, "filename_with_path", IN_CLOSE_WRITE); inotify_add_watch(fd, directory_name, IN_CLOSE_WRITE); const int event_size = sizeof(struct inotify_event); const int buf_len = 1024 * (event_size + FILENAME_MAX); while(true) { char buf[buf_len]; int no_of_events, count = 0; no_of_events = read(fd, buf, buf_len); while(count < no_of_events) { struct inotify_event *event = (struct inotify_event *) &buf[count]; if (event->len) […]

检测控制台应用程序中的按键?

我需要在控制台应用程序中检测按键,而不会提示用户。 基本上,我的应用程序通常是一个监听特殊input设备的守护进程,但是我需要在交互模式下使用键盘在开发箱上进行仿真。 我怎样才能做到这一点? – 我在一个Linux系统上。

Ubuntu 10中的实验性缓冲区溢出(汇编)

我正在尝试使用C程序在Ubuntu 10.04中溢出缓冲区,并将返回地址转移到函数“junk”。 但是我不能用未使用的函数“垃圾”的地址覆盖返回地址。 它只是在12个字节的堆栈上转储一些未知的地址。 请帮我解决它。 这里是C代码: – (gdb) list 1 #include<stdio.h> 2 void display() 3 { 4 char buff[8]; 5 gets(buff); 6 puts(buff); 7 } 8 main() 9 { 10 display(); (gdb) 11 return(0); 12 } 13 junk() 14 { 15 printf("cracked"); 16 } main的disasambled代码是: – 函数main的汇编代码转储: 0x08048462 <+0>: push %ebp 0x08048463 <+1>: mov %esp,%ebp […]

访问内核中用户空间结构的成员会给出错误的值

我看到一个怪异的,我不明白在我的代码的输出。 我有一个头文件中定义的结构。 我在用户空间填充一个结构,然后通过ioctl发送给一个内核模块。 内核模块应该从用户复制它,然后报告用户存储的值。 该结构被定义为: typedef struct Command_par { int cmd; /**< special driver command */ int target; /**< special configuration target */ unsigned long val1; /**< 1. parameter for the target */ unsigned long val2; /**< 2. parameter for the target */ int error; /**< return value */ unsigned long retval; /**< return value […]

使用.cfg文件的指针警告

我尝试使用libconfig来设置ac程序。 有example1.c: int main() { const char **channel; config_t config; config_init(&config); config_read_file(&config, "example.cfg"); if( config_lookup_string(&config,"value.channel",&channel) == CONFIG_FALSE) { printf("Failed to read fields\n"); return 1; } printf("argumente = %s\n", (char *)channel); return 0; } 和example.cfg文件 value = {channel =“hello”; } 如果我编译它 gcc example1.c -lconfig 它说: example1.c:39:3: Warning: delivery of arguments 3 from »config_lookup_string« of a incompatible […]

VirtualBox如何处理来宾Linux的中断?

我正在练习在VirtualBox guest Linux中编写简单的键盘驱动程序。 问题是,我的代码只是注册一个中断处理程序,并打印scancode到日志文件。 而且我不会将这些传入的扫描码发送到任何上层的代码,比如Linux input core 。 insmod ,我可以看到使用dmesg捕获的扫描码。 但为什么我的terminal仍然得到正确的input? terminal不应收到任何东西。 我的代码如下所示: static int __init init_simple_keyboard_driver(void) { free_irq (IRQ_1, NULL); return request_irq (IRQ_1, my_handler, …); } static irqreturn_t my_handler(int irq, void *dev_id) { unsigned char scancode = get_scancode_from_port_0x60(); printk(…scancode…); } 在insmod之后,我可以在内核日志中看到消息。 我的free_irq调用导致一些消息Can't free already freed IRQ 。 (我不知道为什么…它不应该被释放) atkbd司机抱怨说有人要求处理IRQ_1 。 那些扫描码可以正确打印。 [最奇怪的]主动控制台仍然得到正确的键盘input。 因此,我可以使用这个简单的驱动程序来执行一个rmmod 。 […]

什么是开发iptables模块的最好方法

我有iptv提供商,通过使用私钥udp组播stream量encryption传递video。 这个时间stream用解码版本的udp2http代理解码。 我想开发iptables模块来“解密”数据包,因为我的电视上的iptv频道swtich在udpstream上更快,而不是http(并获得一些写iptables模块的经验)。 有两种方法可以做到这一点(我认为) 在模块本身写解密algorithm 编写模块将数据发送到用户空间,编写守护进程解密数据包,并将数据包发送回filter。 首先会更快,第二更安全的系统(因为networking堆栈的延迟可能会降低系统的整体性能),并可能有更多的function,易于debugging等。 哪种方法最好? 哪种方式有利有弊?

linux mq_open忽略mq_msgsize属性

所有人都曾经认为我是理智的,现在不太确定。 我正在尝试创build一个消息队列,其mq_msgsize属性不是8192,这似乎是默认值。 我已经附上了我的代码 – 它有一些printf显示的价值。 如果你能指出我做错了什么,我会永远感激。 bool Subscriber::Subscribe( void ) { mqd_t qid; bool brv = false; msg_topic_t topic = this->GetTopic(); struct mq_attr q_attr; int rv = 0; if (VALID_TOPIC( topic )) { if (this->GetName().length() > 0) { string qnamestr = this->GetName(); if (qnamestr[0] != '/') { qnamestr = "/" + qnamestr; this->SetName(qnamestr); } const […]

如何将coredump位置/pathconfiguration为特定于进程?

我有两个相同的程序运行的进程。 我需要他们在不同的可configuration的位置coredump。 这可能吗?