c - Linux 以编程方式上/下接口(interface)内核

标签 c linux network-programming linux-kernel

在内核空间中启用或禁用接口(interface)的编程方式是什么?应该怎么办?

最佳答案

...通过使用 IOCTL 的...

ioctl(skfd, SIOCSIFFLAGS, &ifr);

...设置或取消设置 IFF_UP 位,具体取决于您是要相应地打开还是关闭接口(interface),即:

static int set_if_up(char *ifname, short flags)
{
    return set_if_flags(ifname, flags | IFF_UP);
}

static int set_if_down(char *ifname, short flags)
{
    return set_if_flags(ifname, flags & ~IFF_UP);
}

Linux networking documentation复制粘贴的代码.

关于c - Linux 以编程方式上/下接口(interface)内核,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5858655/

相关文章:

c - getaddrinfo() 中的段错误

c - 两个链表的合并功能不起作用

c - 最后一次性输出结果与使用for循环时逐一输出结果如何?

linux - 使用 unix 命令 "watch"的颜色?

linux - 将秒数转换为 hh :mm:ss format (or whatever format Excel or LibreOffice likes) and insert it back to a csv file in Bash

sockets - java.net.ConnectException : Connection refused: connect 异常

c - 在 C 中读取结构体并将其写入管道

c - fopen 一切 - 这可能吗?

c++ - 如何在 Linux 上可靠地监控驱动器挂载/卸载?

c++ - QHttpMultiPart 在 "1"中发送 post 请求结果