#include <stdio.h>
#include <ctype.h>
#include <stdbool.h>
#include <stdlib.h>
#include <unistd.h>
#include <inttypes.h>
#include <fcntl.h>
#include <net/if.h>
#include <sys/ioctl.h>
#include <sys/socket.h>
#include <sys/param.h>
#include <errno.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <string.h>
#include <fnmatch.h>
#include <time.h>
#include <linux/netdevice.h>
#include <linux/if_arp.h>
#include <linux/sockios.h>
#include <linux/net_namespace.h>
#include <linux/rtnetlink.h>
#define IPLINK_IOCTL_COMPAT 1
#ifndef LIBDIR
#define LIBDIR "/usr/lib"
#endif
#ifndef GSO_MAX_SIZE
#define GSO_MAX_SIZE 65536
#endif
#ifndef GSO_MAX_SEGS
#define GSO_MAX_SEGS 65535
#endif
#define IDXMAP_SIZE 1024
//已定义在netlink.h
//#define NLMSG_ALIGNTO 4U
//#define NLMSG_ALIGN(len) (((len) + NLMSG_ALIGNTO - 1) & ~(NLMSG_ALIGNTO - 1))
//#define NLMSG_ALIGN(len) (((len) + 4U - 1) & ~(4U - 1))
#define NLMSG_TAIL(nmsg) ((struct rtattr *)(((void *)(nmsg)) + NLMSG_ALIGN((nmsg)->nlmsg_len)))
#define rtnl_dump_filter(rth, filter, arg) rtnl_dump_filter_nc(rth, filter, arg, 0)
#define hlist_for_each(pos, head) for (pos = (head)->first; pos; pos = pos->next)
#define offsetof(type, member) ((size_t) & ((type *)0)->member)
#define container_of(ptr, type, member) ({ const typeof( ((type *)0)->member ) *__mptr = (ptr); (type *)( (char *)__mptr - offsetof(type,member) ); })
#define format_host_rta(af, rta) format_host(af, RTA_PAYLOAD(rta), RTA_DATA(rta))
typedef int (*rtnl_filter_t)(struct nlmsghdr *n, void *);
typedef int (*req_filter_fn_t)(struct nlmsghdr *nlh, int reqlen);
typedef int (*nl_ext_ack_fn_t)(const char *errmsg, uint32_t off, const struct nlmsghdr *inner_nlh);
struct iplink_req {
struct nlmsghdr n;
struct ifinfomsg i;
char buf[1024];
};
struct rtnl_handle
{
int fd;
struct sockaddr_nl local;
struct sockaddr_nl peer;
__u32 seq;
__u32 dump;
int proto;
FILE *dump_fp;
#define RTNL_HANDLE_F_LISTEN_ALL_NSID 0x01
#define RTNL_HANDLE_F_SUPPRESS_NLERR 0x02
int flags;
};
enum output_type
{
PRINT_FP = 1,
PRINT_JSON = 2,
PRINT_ANY = 4,
};
struct rtnl_dump_filter_arg
{
rtnl_filter_t filter;
void *arg1;
__u16 nc_flags;
};
struct nlmsg_list
{
struct nlmsg_list *next;
struct nlmsghdr h;
};
struct nlmsg_chain
{
struct nlmsg_list *head;
struct nlmsg_list *tail;
};
struct hlist_head
{
struct hlist_node *first;
};
struct hlist_node
{
struct hli
[ip link set dev ethx up]实现
最新推荐文章于 2024-09-08 22:45:00 发布
本文详细介绍了如何通过Linux命令行工具`ip`来设置和启用网络接口ethx,包括步骤和常见问题解析,帮助用户理解网络接口状态管理和网络配置。
摘要由CSDN通过智能技术生成