【问题标题】:c++ unable to open raw socket using Ubuntu and Netbeans 6.9c++ 无法使用 Ubuntu 和 Netbeans 6.9 打开原始套接字
【发布时间】:2013-11-03 11:07:33
【问题描述】:

我正在尝试在 Ubuntu 下发送/接收原始以太网。

我通过终端在 c 中运行代码没有问题。

但是,当我尝试使用将代码转换为 c++ 时 Netbeans IDE 6.9 无法打开原始套接字。 调用:

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

总是返回 -1。错误:“不允许操作”

【问题讨论】:

  • 如果您通过终端以 root 身份运行应用程序,它是否有效?
  • 我发现使用“sudo”通过终端运行代码可以解决问题。谷歌搜索我知道有可能配置 Netbeans 来做同样的事情。我仍然没有设法这样做..

标签: c++ ubuntu netbeans raw-ethernet


【解决方案1】:

您总是需要 root 权限才能通过 原始套接字 发送/接收内容。

以下是配置 NetBeans 以以 root 身份运行应用程序的方法:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-09-11
    • 2021-09-30
    • 2021-06-11
    • 1970-01-01
    • 1970-01-01
    • 2017-10-28
    • 2011-11-18
    相关资源
    最近更新 更多