添加链接
注册
登录
link管理
链接快照平台
输入网页链接,自动生成快照
标签化管理网页链接
相关文章推荐
体贴的鸡蛋面
·
UmTRX » OpenBTS
·
1 周前
·
酒量小的针织衫
·
简单的使用ehcache-腾讯云开发者社区-腾讯云
·
1 月前
·
深沉的蘑菇
·
👍Bob ...
·
3 月前
·
俊逸的仙人球
·
JavaScript如何自动判断字符编码 ...
·
3 月前
·
魁梧的灭火器
·
Laravel 5.6 Import ...
·
7 月前
·
link管理
›
iptunnel-netlink-example/rtnetlink_tunnel.c at master · kristrev/iptunnel-netlink-example · GitHub
https://github.com/kristrev/iptunnel-netlink-example/blob/master/rtnetlink_tunnel.c
慷慨大方的洋葱
3 周前
You signed in with another tab or window.
Reload
to refresh your session.
You signed out in another tab or window.
Reload
to refresh your session.
You switched accounts on another tab or window.
Reload
to refresh your session.
Files
master
Breadcrumbs
iptunnel-netlink-example
/
rtnetlink_tunnel.c
Blame
Blame
Latest commit
History
History
74 lines (61 loc) · 2.25 KB
master
Breadcrumbs
iptunnel-netlink-example
/
rtnetlink_tunnel.c
Top
File metadata and controls
Code
Blame
74 lines (61 loc) · 2.25 KB
Raw
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#include
<stdio.h>
#include
<stdlib.h>
#include
<string.h>
#include
<libmnl/libmnl.h>
#include
<linux/rtnetlink.h>
#include
<netinet/in.h>
#include
<linux/if.h>
#include
<linux/ip.h>
#include
<linux/if_link.h>
#include
<linux/if_tunnel.h>
#include
<arpa/inet.h>
int
main
(
int
argc
,
char
*
argv
[]){
struct
mnl_socket
*
nl_sock
=
NULL
;
struct
nlmsghdr
*
nlh
=
NULL
;
struct
nlmsgerr
*
nlerr
=
NULL
;
struct
nlattr
*
linkinfo
=
NULL
,
*
tunnelinfo
=
NULL
;
struct
ifinfomsg
*
ifinfo
=
NULL
;
uint8_t
buf
[
MNL_SOCKET_BUFFER_SIZE
];
size_t
numbytes
=
0
;
struct
in_addr
addr
;
memset
(
buf
,
0
,
sizeof
(
buf
));
if
((
nl_sock
=
mnl_socket_open
(
NETLINK_ROUTE
))
==
NULL
){
perror
(
"mnl_socket_open: "
);
exit
(
EXIT_FAILURE
);
}
//Add and configure header
nlh
=
mnl_nlmsg_put_header
(
buf
);
//Create only if interface does not exists from before (EXCL)
nlh
->
nlmsg_flags
=
NLM_F_REQUEST
|
NLM_F_CREATE
|
NLM_F_EXCL
|
NLM_F_ACK
;
nlh
->
nlmsg_type
=
RTM_NEWLINK
;
//see rtnl_newlink in net/core/rtnetlink.c for observing how this function
//works
ifinfo
=
mnl_nlmsg_put_extra_header
(
nlh
,
sizeof
(
struct
ifinfomsg
));
ifinfo
->
ifi_family
=
AF_UNSPEC
;
//Add a name and mtu, for testing
mnl_attr_put_str
(
nlh
,
IFLA_IFNAME
,
"kre2"
);
mnl_attr_put_u32
(
nlh
,
IFLA_MTU
,
1234
);
//Type is required, set to IPIP
linkinfo
=
mnl_attr_nest_start
(
nlh
,
IFLA_LINKINFO
);
mnl_attr_put_str
(
nlh
,
IFLA_INFO_KIND
,
"ipip"
);
//Add information about the tunnel
tunnelinfo
=
mnl_attr_nest_start
(
nlh
,
IFLA_INFO_DATA
);
inet_pton
(
AF_INET
,
"192.168.203.19"
,
&
addr
);
mnl_attr_put_u32
(
nlh
,
IFLA_IPTUN_LOCAL
,
addr
.
s_addr
);
inet_pton
(
AF_INET
,
"10.0.0.2"
,
&
addr
);
mnl_attr_put_u32
(
nlh
,
IFLA_IPTUN_REMOTE
,
addr
.
s_addr
);
mnl_attr_nest_end
(
nlh
,
tunnelinfo
);
mnl_attr_nest_end
(
nlh
,
linkinfo
);
numbytes
=
mnl_socket_sendto
(
nl_sock
,
nlh
,
nlh
->
nlmsg_len
);
numbytes
=
mnl_socket_recvfrom
(
nl_sock
,
buf
,
sizeof
(
buf
));
nlh
=
(
struct
nlmsghdr
*
)
buf
;
if
(
nlh
->
nlmsg_type
==
NLMSG_ERROR
){
nlerr
=
mnl_nlmsg_get_payload
(
nlh
);
//error==0 for ack
if
(
nlerr
->
error
)
printf
(
"Error: %s\n"
,
strerror
(
-
nlerr
->
error
));
}
else
{
printf
(
"Link added\n"
);
}
return
EXIT_FAILURE
;
}
推荐文章
体贴的鸡蛋面
·
UmTRX » OpenBTS
1 周前
酒量小的针织衫
·
简单的使用ehcache-腾讯云开发者社区-腾讯云
1 月前
深沉的蘑菇
·
👍Bob Pro1.10.0破解版(划词翻译/截图翻译与截图OCR) – MtmUp
3 月前
俊逸的仙人球
·
JavaScript如何自动判断字符编码 – PingCode
3 月前
魁梧的灭火器
·
Laravel 5.6 Import Export to Excel and CSV example - ItSolutionStuff.com
7 月前