简体   繁体   English

C ++无法使用Ubuntu和Netbeans 6.9打开原始套接字

[英]c++ unable to open raw socket using Ubuntu and Netbeans 6.9

I'm trying to send/recv raw ethernet under Ubuntu. 我正在尝试在Ubuntu下发送/接收原始以太网。

I've no problem running code in c through the terminal. 我没有问题通过终端在c中运行代码。

However when i've tried to convert the code to c++ using Netbeans IDE 6.9 it fails to open the raw socket. 但是,当我尝试使用Netbeans IDE 6.9将代码转换为c ++时,无法打开原始套接字。 calling: 致电:

socket(PF_PACKET, SOCK_RAW, htons(ETH_P_ALL))) == -1)

always return -1. 总是返回-1。 error : "operation not permitted" 错误:“不允许操作”

You always need root permissions to send / receive something through raw sockets . 您始终需要root权限才能通过原始套接字发送/接收内容。

Here's how to configure NetBeans to run your application as root: 以下是配置NetBeans以root身份运行应用程序的方法:

  1. Right click on project -> Properties -> Run
  2. Set Run Command to sudo "${OUTPUT_PATH}" (default is "${OUTPUT_PATH}" ) Run Command设置为sudo "${OUTPUT_PATH}" (默认为"${OUTPUT_PATH}"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM