liboping error operation not allowed
I wrote such a function, used liboping linux, gives an error, maybe someone knows how to fix
QString msg;
pingobj_t *pingobj = ping_construct();
if (pingobj == nullptr)
{
msg = "Error: ";
msg += ping_get_error(pingobj);
}
ui->textEdit->setText(msg);
int timeout = 3;
for (;;)
{
double timeout_sec = ((double)timeout)/(double)(1000.0);
if (ping_setopt(pingobj, PING_OPT_TIMEOUT, &timeout_sec))
break;
if (ping_host_add(pingobj, ui->lineEdit->text().toStdString().c_str()))
break;
if (ping_send(pingobj) <= 0)
break;
res = true;
break;
}
if(res)
ui->textEdit->setText("Yes");
else
{
msg = "Error: ";
msg += ping_get_error(pingobj);
ui->textEdit->setText(msg);
}
ping_destroy(pingobj);
0
1 answers
In order for ping to work, it must be given permissions for direct access to the network stack.
sudo setcap cap_net_raw+ep myping
After compiling, run this command for the file being run and the ping will work.
You can add a build step to the SDK
0
Author: eri, 2020-03-28 12:21:45