#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
#ifndef INFINITY_LIFE_TIME
#define INFINITY_LIFE_TIME 0xFFFFFFFFU
#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))
enum {
PREFIXLEN_SPECIFIED = (1 << 0),
ADDRTYPE_INET = (1 << 1),
ADDRTYPE_UNSPEC = (1 << 2),
ADDRTYPE_MULTI = (1 << 3),
ADDRTYPE_INET_UNSPEC = ADDRTYPE_INET | ADDRTYPE_UNSPEC,
ADDRTYPE_INET_MULTI = ADDRTYPE_INET | ADDRTYPE_MULTI
};
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);
typedef struct
{
__u16 flags;
__u16 bytelen;
__s16 bitlen;
/* These next two fields match rtvia */
__u16 family;
__u32 data[64];
} inet_prefix;
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;
address add 8.8.8.8 dev eno1 label eno1:10 scope link 实现代码
最新推荐文章于 2023-07-31 20:42:45 发布
本文详细介绍了如何通过编程实现将IP地址8.8.8.8添加到设备的eno1接口,并创建名为eno1:10的子接口,同时设置为链路本地范围。这一过程对于网络配置和管理至关重要。
摘要由CSDN通过智能技术生成