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