• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 #include <netlink/netlink.h>
2 #include <netlink/route/link.h>
3 #include <netlink/route/link/veth.h>
4 
main(int argc,char * argv[])5 int main(int argc, char *argv[])
6 {
7 	struct rtnl_link *link;
8 	struct nl_sock *sk;
9 	int err;
10 	struct rtnl_link *peer;
11 
12 	sk = nl_socket_alloc();
13 	if ((err = nl_connect(sk, NETLINK_ROUTE)) < 0) {
14 		nl_perror(err, "Unable to connect socket");
15 		return err;
16 	}
17 
18 #if 0
19 	rtnl_link_veth_add(sk, "veth2", "veth3", getpid());
20 #else
21 	link = rtnl_link_veth_alloc();
22 	if (!link) {
23 		nl_perror(err, "Unable to alloc link");
24 		return err;
25 	}
26 
27 	rtnl_link_set_name(link, "veth8");
28 	peer = rtnl_link_veth_get_peer(link);
29 	rtnl_link_set_name(peer, "veth9");
30 
31 	if ((err = rtnl_link_add(sk, link, NLM_F_CREATE)) < 0) {
32 		nl_perror(err, "Unable to add link");
33 		return err;
34 	}
35 	printf("peer is %s\n", rtnl_link_get_name(peer));
36 	rtnl_link_put(peer);
37 	rtnl_link_put(link);
38 #endif
39 	nl_close(sk);
40 
41 	return 0;
42 }
43