[英]Creating a raw socket - Debian + Codeblocks
I'm currently working on the start phase of my bachelor thesis and my problem is to implement a gateway (aka router). 我目前正在研究学士学位论文的开始阶段,而我的问题是实现网关(又称路由器)。 I'm currently trying to open a raw socket so I can shred open an Ethernet packet and check what different kind of fields it contains. 我目前正在尝试打开一个原始套接字,以便可以粉碎打开一个以太网数据包,并检查它包含哪些不同类型的字段。
I'm using Codeblocks IDE to write C++ code on a Debian VM. 我正在使用Codeblocks IDE在Debian VM上编写C ++代码。
When try to open the raw socket through the following code I get an error saying: 当尝试通过以下代码打开原始套接字时,出现错误消息:
Error creating raw socket: Operation not permitted
Code: 码:
int CreateRawSocket(int protocol_to_sniff)
{
int s;
if((s = socket(PF_PACKET, RAW_SOCK, htons(protocol_to_sniff))) == -1)
{
perror("Error creating raw socket");
exit(-1);
}
return s;
}
int main()
{
int s = CreateRawSocket(ETH_P_ALL);
}
I've searched around a little but I cannot seem to fix the problem, although I think I know what the problem is. 我进行了一些搜索,但似乎无法解决问题,尽管我认为我知道问题出在哪里。 So far as I've figured out it is a problem with permissions, but I have no clue on how to give codeblocks sudo permissions. 据我了解,这是一个权限问题,但是我不知道如何赋予代码块sudo权限。
Any ideas? 有任何想法吗?
Solved it. 解决了。 It was really simple actually. 实际上,这真的很简单。
I entered: 我进入了:
sudo codeblocks
and it opened codeblocks with sudo rights, but I had to keep that terminal window running or it would shutdown codeblocks. 并且它以sudo权限打开了代码块,但是我必须保持该终端窗口运行,否则它将关闭代码块。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.