当前位置: 首页>>代码示例>>C++>>正文


C++ rtnl_close函数代码示例

本文整理汇总了C++中rtnl_close函数的典型用法代码示例。如果您正苦于以下问题:C++ rtnl_close函数的具体用法?C++ rtnl_close怎么用?C++ rtnl_close使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了rtnl_close函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: flush_rule

static int flush_rule(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg)
{
	struct rtnl_handle rth2;
	struct rtmsg *r = NLMSG_DATA(n);
	int len = n->nlmsg_len;
	struct rtattr * tb[FRA_MAX+1];

	len -= NLMSG_LENGTH(sizeof(*r));
	if (len < 0)
		return -1;

	parse_rtattr(tb, FRA_MAX, RTM_RTA(r), len);

	if (tb[FRA_PRIORITY]) {
		n->nlmsg_type = RTM_DELRULE;
		n->nlmsg_flags = NLM_F_REQUEST;

		if (rtnl_open(&rth2, 0) < 0)
			return -1;

		if (rtnl_talk(&rth2, n, 0, 0, NULL, NULL, NULL) < 0)
			return -2;

		rtnl_close(&rth2);
	}

	return 0;
}
开发者ID:Einheri,项目名称:wl500g,代码行数:28,代码来源:iprule.c

示例2: iface_gre_del

int
iface_gre_del(const char *gre_iface)
{
    struct softgred_config *cfg = softgred_config_ref();
    int ret;
    errno = 0;

    if ((ret=rtnl_open(&cfg->rth, 0)) < 0)
    {
        D_DEBUG1("Cannot open rtnetlink\n");
        return EXIT_FAILURE;
    }

    if(!iplink_have_newlink())
    {
        D_DEBUG1("iplink_have_newlink ret=%d strerror='%s'\n", ret, strerror(errno));
    }
    else
    {
        ret = iplink_modify(RTM_DELLINK, 0, gre_iface, NULL, NULL, NULL, NULL);
        if (ret != 0)
        {
            D_DEBUG1("iplink_modify(RTM_DELLINK) ret=%d strerror='%s'\n", ret, strerror(errno));
        }
    }

    rtnl_close(&cfg->rth);

    return 1;
}
开发者ID:jinjing007,项目名称:softgre,代码行数:30,代码来源:iface_gre.c

示例3: ipaddr_list

/****************************************************************
 NAME	: ipaddr_list				00/06/02 20:02:23
 AIM	: 
 REMARK	:
****************************************************************/
int ipaddr_list( int ifindex, uint32_t *array, int max_elem )
{
	struct rtnl_handle	rth;
	iplist_ctx	ctx;
	/* init the struct */
	ctx.ifindex	= ifindex;
	ctx.addr	= array;
	ctx.max_elem	= max_elem;
	ctx.nb_elem	= 0;
	/* open the rtnetlink socket */
	if( rtnl_open( &rth, 0) )
		return -1;
	/* send the request */
	if (rtnl_wilddump_request(&rth, AF_INET, RTM_GETADDR) < 0) {
		perror("Cannot send dump request");
		return -1;
	}
	/* parse the answer */
	if (rtnl_dump_filter(&rth, get_addrinfo, &ctx, NULL, NULL) < 0) {
		fprintf(stderr, "Flush terminated\n");
		exit(1);
	}
	
	/* to close the clocket */
 	rtnl_close( &rth );
	
	return ctx.nb_elem;
}
开发者ID:HzyGit,项目名称:Vrrpd,代码行数:33,代码来源:ipaddr.c

示例4: ipoe_nl_delete

void ipoe_nl_delete(int ifindex)
{
	struct rtnl_handle rth;
	struct nlmsghdr *nlh;
	struct genlmsghdr *ghdr;
	struct {
		struct nlmsghdr n;
		char buf[1024];
	} req;

	if (rtnl_open_byproto(&rth, 0, NETLINK_GENERIC)) {
		log_ppp_error("ipoe: cannot open generic netlink socket\n");
		return;
	}

	nlh = &req.n;
	nlh->nlmsg_len = NLMSG_LENGTH(GENL_HDRLEN);
	nlh->nlmsg_flags = NLM_F_REQUEST | NLM_F_ACK;
	nlh->nlmsg_type = ipoe_genl_id;

	ghdr = NLMSG_DATA(&req.n);
	ghdr->cmd = IPOE_CMD_DELETE;

	addattr32(nlh, 128, IPOE_ATTR_IFINDEX, ifindex);

	if (rtnl_talk(&rth, nlh, 0, 0, nlh, NULL, NULL, 0) < 0 )
		log_ppp_error("ipoe: nl_delete: error talking to kernel\n");

	rtnl_close(&rth);
}
开发者ID:jorgeluiztaioque,项目名称:accel-ppp-fork,代码行数:30,代码来源:ipoe_netlink.c

示例5: route_del

int route_del(struct sockaddr_storage *destination, struct sockaddr_storage *gateway,int prefix,unsigned int metric){
	struct rtnl_handle rth;

	// structure of the netlink packet. 
	struct{
		struct nlmsghdr n;
		struct rtmsg r;
		char buf[1024];
	} req;

	char mxbuf[256];
	struct rtattr * mxrta = (void*)mxbuf;
	//unsigned mxlock = 0;
	memset(&req, 0, sizeof(req));

	// Initialisation of a few parameters 
	req.n.nlmsg_len = NLMSG_LENGTH(sizeof(struct rtmsg));
	req.n.nlmsg_flags = NLM_F_REQUEST|NLM_F_CREATE;
	req.n.nlmsg_type = RTM_DELROUTE;
	req.r.rtm_family = destination->ss_family;
	req.r.rtm_table = get_eigrp_routing_table_number();
	req.r.rtm_dst_len = prefix;
	req.r.rtm_protocol = get_eigrp_routing_protocol_number();
	req.r.rtm_scope = RT_SCOPE_UNIVERSE;
	req.r.rtm_type = RTN_UNICAST;
	mxrta->rta_type = RTA_METRICS;
	mxrta->rta_len = RTA_LENGTH(0);
	
	// RTA_DST and RTA_GW are the two esential parameters for adding a route
	// for ipv4, the length of the address is 4 bytes.
	if(destination->ss_family == AF_INET){
		struct sockaddr_in *dest = (struct sockaddr_in *)destination;
		struct sockaddr_in *gate = (struct sockaddr_in *)gateway;
		addattr_l(&req.n, sizeof(req), RTA_DST, &dest->sin_addr.s_addr, 4);
		addattr_l(&req.n, sizeof(req), RTA_GATEWAY, &gate->sin_addr.s_addr, 4);
	}else{
		struct sockaddr_in6 *dest = (struct sockaddr_in6 *)destination;
		struct sockaddr_in6 *gate = (struct sockaddr_in6 *)gateway;
		addattr_l(&req.n, sizeof(req), RTA_DST, &dest->sin6_addr.s6_addr, sizeof(dest->sin6_addr.s6_addr));
		addattr_l(&req.n, sizeof(req), RTA_GATEWAY, &gate->sin6_addr.s6_addr, sizeof(dest->sin6_addr.s6_addr));
	}

	addattr_l(&req.n, sizeof(req), RTA_PRIORITY, &metric, sizeof(metric));

	int status = 0;

	// opening the netlink socket to communicate with the kernel
	if (rtnl_open(&rth, 0) < 0){
		printf("cannot open rtnetlink\n");
		return -1;
	}

	// sending the packet to the kernel.
	status = rtnl_talk(&rth, &req.n, 0, 0, NULL);
	if (status < 0)
		return status;
	
	rtnl_close(&rth);
	return 0;
}
开发者ID:dervel,项目名称:eigrp,代码行数:60,代码来源:netlink.c

示例6: xfrm_spd_getinfo

static int xfrm_spd_getinfo(int argc, char **argv)
{
	struct rtnl_handle rth;
	struct {
		struct nlmsghdr			n;
		__u32				flags;
		char 				ans[128];
	} req;

	memset(&req, 0, sizeof(req));

	req.n.nlmsg_len = NLMSG_LENGTH(sizeof(__u32));
	req.n.nlmsg_flags = NLM_F_REQUEST;
	req.n.nlmsg_type = XFRM_MSG_GETSPDINFO;
	req.flags = 0XFFFFFFFF;

	if (rtnl_open_byproto(&rth, 0, NETLINK_XFRM) < 0)
		exit(1);

	if (rtnl_talk(&rth, &req.n, 0, 0, &req.n, NULL, NULL) < 0)
		exit(2);

	print_spdinfo(&req.n, (void*)stdout);

	rtnl_close(&rth);

	return 0;
}
开发者ID:WiseMan787,项目名称:ralink_sdk,代码行数:28,代码来源:xfrm_policy.c

示例7: load_info

static void load_info(void)
{
	struct ifstat_ent *db, *n;
	struct rtnl_handle rth;

	if (rtnl_open(&rth, 0) < 0)
		exit(1);

	if (rtnl_wilddump_request(&rth, AF_INET, RTM_GETLINK) < 0) {
		perror("Cannot send dump request");
		exit(1);
	}

	if (rtnl_dump_filter(&rth, get_netstat_nlmsg, NULL, NULL, NULL) < 0) {
		fprintf(stderr, "Dump terminated\n");
		exit(1);
	}

	rtnl_close(&rth);

	db = kern_db;
	kern_db = NULL;

	while (db) {
		n = db;
		db = db->next;
		n->next = kern_db;
		kern_db = n;
	}
}
开发者ID:jelaas,项目名称:ifstat2,代码行数:30,代码来源:ifstat2.c

示例8: flush_addrlabel

static int flush_addrlabel(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg)
{
	struct rtnl_handle rth2;
	struct rtmsg *r = NLMSG_DATA(n);
	int len = n->nlmsg_len;
	struct rtattr * tb[IFAL_MAX+1];

	len -= NLMSG_LENGTH(sizeof(*r));
	if (len < 0)
		return -1;

	parse_rtattr(tb, IFAL_MAX, RTM_RTA(r), len);

	if (tb[IFAL_ADDRESS]) {
		n->nlmsg_type = RTM_DELADDRLABEL;
		n->nlmsg_flags = NLM_F_REQUEST;

		if (rtnl_open(&rth2, 0) < 0)
			return -1;

		if (rtnl_talk(&rth2, n, NULL, 0) < 0)
			return -2;

		rtnl_close(&rth2);
	}

	return 0;
}
开发者ID:Distrotech,项目名称:iproute2,代码行数:28,代码来源:ipaddrlabel.c

示例9: rule_flush_table_range

/*
 * rule_flush_table_range: deletes all the rules which lookup the table X.
 * The table X is any table in the range of `a' <= X <= `b'.
 */
int
rule_flush_table_range(int family, int a, int b)
{
	struct rtnl_handle rth;
	int arg[2];

	if (rtnl_open(&rth, 0) < 0)
		return 1;

	if (rtnl_wilddump_request(&rth, family, RTM_GETRULE) < 0) {
		error("Cannot dump the routing rule table");
		return -1;
	}

	arg[0] = a;
	arg[1] = b;
	if (rtnl_dump_filter
		(&rth, rule_flush_table_range_filter, arg, NULL, NULL) < 0) {
		error("Flush terminated");
		return -1;
	}

	rtnl_close(&rth);

	return 0;
}
开发者ID:Netsukuku,项目名称:netsukuku,代码行数:30,代码来源:krnl_rule.c

示例10: rule_flush_table_range_filter

/* 
 * rule_flush_table_range_filter: rtnl_dump filter for
 * rule_flush_table_range() (see below)
 */
int
rule_flush_table_range_filter(const struct sockaddr_nl *who,
							  struct nlmsghdr *n, void *arg)
{
	struct rtnl_handle rth2;
	struct rtmsg *r = NLMSG_DATA(n);
	int len = n->nlmsg_len;
	struct rtattr *tb[RTA_MAX + 1];
	u_int a = *(u_int *) arg;
	u_int b = *((u_int *) arg + 1);

	len -= NLMSG_LENGTH(sizeof(*r));
	if (len < 0)
		return -1;

	parse_rtattr(tb, RTA_MAX, RTM_RTA(r), len);

	if (tb[RTA_PRIORITY] && (r->rtm_table >= a && r->rtm_table <= b)) {
		n->nlmsg_type = RTM_DELRULE;
		n->nlmsg_flags = NLM_F_REQUEST;

		if (rtnl_open(&rth2, 0) < 0)
			return -1;

		if (rtnl_talk(&rth2, n, 0, 0, NULL, NULL, NULL) < 0)
			return -2;

		rtnl_close(&rth2);
	}

	return 0;
}
开发者ID:Netsukuku,项目名称:netsukuku,代码行数:36,代码来源:krnl_rule.c

示例11: tc_qdisc_list

int tc_qdisc_list(int argc, char **argv)
{
	struct tcmsg t;
	struct rtnl_handle rth;
	char d[16];

	memset(&t, 0, sizeof(t));
	t.tcm_family = AF_UNSPEC;
	memset(&d, 0, sizeof(d));
	
	while (argc > 0) {
		if (strcmp(*argv, "dev") == 0) {
			NEXT_ARG();
			strncpy(d, *argv, sizeof(d)-1);
#ifdef TC_H_INGRESS
                } else if (strcmp(*argv, "ingress") == 0) {
                             if (t.tcm_parent) {
                                     fprintf(stderr, "Duplicate parent ID\n");
                                     usage();
                             }
                             t.tcm_parent = TC_H_INGRESS;
#endif
		} else if (matches(*argv, "help") == 0) {
			usage();
		} else {
			fprintf(stderr, "What is \"%s\"? Try \"tc qdisc help\".\n", *argv);
			return -1;
		}

		argc--; argv++;
	}

	if (rtnl_open(&rth, 0) < 0) {
		fprintf(stderr, "Cannot open rtnetlink\n");
		exit(1);
	}

	ll_init_map(&rth);

	if (d[0]) {
		if ((t.tcm_ifindex = ll_name_to_index(d)) == 0) {
			fprintf(stderr, "Cannot find device \"%s\"\n", d);
			exit(1);
		}
		filter_ifindex = t.tcm_ifindex;
	}

	if (rtnl_dump_request(&rth, RTM_GETQDISC, &t, sizeof(t)) < 0) {
		perror("Cannot send dump request");
		exit(1);
	}

	if (rtnl_dump_filter(&rth, print_qdisc, stdout, NULL, NULL) < 0) {
		fprintf(stderr, "Dump terminated\n");
		exit(1);
	}

	rtnl_close(&rth);
	return 0;
}
开发者ID:BackupTheBerlios,项目名称:wl530g-svn,代码行数:60,代码来源:tc_qdisc.c

示例12: calloc

/** Initialize interface table
 *
 * Initialize rtnl interface and interface table
 * Call this before any nlif_* function
 *
 * \return file descriptor to netlink socket
 */
struct nlif_handle *nlif_open(void)
{
	struct nlif_handle *h;

	h = calloc(1,  sizeof(struct nlif_handle));
	if (h == NULL)
		goto err;

	h->ifadd_handler.nlmsg_type = RTM_NEWLINK;
	h->ifadd_handler.handlefn = iftable_add;
	h->ifadd_handler.arg = h;
	h->ifdel_handler.nlmsg_type = RTM_DELLINK;
	h->ifdel_handler.handlefn = iftable_del;
	h->ifdel_handler.arg = h;

	h->rtnl_handle = rtnl_open();
	if (h->rtnl_handle == NULL)
		goto err;

	if (rtnl_handler_register(h->rtnl_handle, &h->ifadd_handler) < 0)
		goto err_close;

	if (rtnl_handler_register(h->rtnl_handle, &h->ifdel_handler) < 0)
		goto err_unregister;

	return h;

err_unregister:
	rtnl_handler_unregister(h->rtnl_handle, &h->ifdel_handler);
err_close:
	rtnl_close(h->rtnl_handle);
	free(h);
err:
	return NULL;
}
开发者ID:antonywcl,项目名称:AR-5315u_PLD,代码行数:42,代码来源:iftable.c

示例13: main

int main(int argc, char **argv)
{
	int ret;
	int do_batching = 0;
	char *batchfile = NULL;

	while (argc > 1) {
		if (argv[1][0] != '-')
			break;
		if (matches(argv[1], "-stats") == 0 ||
			 matches(argv[1], "-statistics") == 0) {
			++show_stats;
		} else if (matches(argv[1], "-details") == 0) {
			++show_details;
		} else if (matches(argv[1], "-raw") == 0) {
			++show_raw;
		} else if (matches(argv[1], "-pretty") == 0) {
			++show_pretty;
		} else if (matches(argv[1], "-Version") == 0) {
			printf("tc utility, iproute2-ss%s\n", SNAPSHOT);
			return 0;
		} else if (matches(argv[1], "-iec") == 0) {
			++use_iec;
		} else if (matches(argv[1], "-help") == 0) {
			usage();
			return 0;
		} else if (matches(argv[1], "-force") == 0) {
			++force;
		} else 	if (matches(argv[1], "-batch") == 0) {
			do_batching = 1;
			if (argc > 2)
				batchfile = argv[2];
			argc--;	argv++;
		} else {
			fprintf(stderr, "Option \"%s\" is unknown, try \"tc -help\".\n", argv[1]);
			return -1;
		}
		argc--;	argv++;
	}

	if (do_batching)
		return batch(batchfile);

	if (argc <= 1) {
		usage();
		return 0;
	}

	tc_core_init();
	if (rtnl_open(&rth, 0) < 0) {
		fprintf(stderr, "Cannot open rtnetlink\n");
		exit(1);
	}

	ret = do_cmd(argc-1, argv+1);
	rtnl_close(&rth);

	return ret;
}
开发者ID:AntonGorynya,项目名称:LAB3_1,代码行数:59,代码来源:tc.c

示例14: main

int
main(int argc, char **argv)
{
	while (argc > 1) {
		char *opt = argv[1];
		if (strcmp(opt,"--") == 0) {
			argc--; argv++;
			break;
		}
		if (opt[0] != '-')
			break;
		if (opt[1] == '-')
			opt++;

		if (matches(opt, "-help") == 0) {
			usage();
		} else if (matches(opt, "-Version") == 0) {
			printf("bridge utility, 0.0\n");
			exit(0);
		} else if (matches(opt, "-stats") == 0 ||
			   matches(opt, "-statistics") == 0) {
			++show_stats;
		} else if (matches(opt, "-details") == 0) {
			++show_details;
		} else if (matches(opt, "-timestamp") == 0) {
			++timestamp;
                } else if (matches(opt, "-family") == 0) {
			argc--;
			argv++;
			if (argc <= 1)
				usage();
			if (strcmp(argv[1], "inet") == 0)
				preferred_family = AF_INET;
			else if (strcmp(argv[1], "inet6") == 0)
				preferred_family = AF_INET6;
			else if (strcmp(argv[1], "help") == 0)
				usage();
			else
				invarg("invalid protocol family", argv[1]);
		} else if (strcmp(opt, "-4") == 0) {
			preferred_family = AF_INET;
		} else if (strcmp(opt, "-6") == 0) {
			preferred_family = AF_INET6;
		} else {
			fprintf(stderr, "Option \"%s\" is unknown, try \"bridge help\".\n", opt);
			exit(-1);
		}
		argc--;	argv++;
	}

	if (rtnl_open(&rth, 0) < 0)
		exit(1);

	if (argc > 1)
		return do_cmd(argv[1], argc-1, argv+1);

	rtnl_close(&rth);
	usage();
}
开发者ID:SamB,项目名称:iproute2,代码行数:59,代码来源:bridge.c

示例15: do_monitor

int do_monitor(int argc, char **argv)
{
	char *file = NULL;
	unsigned groups = ~RTMGRP_TC;
	int llink=0;
	int lneigh=0;

	rtnl_close(&rth);

	while (argc > 0) {
		if (matches(*argv, "file") == 0) {
			NEXT_ARG();
			file = *argv;
		} else if (matches(*argv, "link") == 0) {
			llink=1;
			groups = 0;
		} else if (matches(*argv, "fdb") == 0) {
			lneigh = 1;
			groups = 0;
		} else if (strcmp(*argv, "all") == 0) {
			groups = ~RTMGRP_TC;
			prefix_banner=1;
		} else if (matches(*argv, "help") == 0) {
			usage();
		} else {
			fprintf(stderr, "Argument \"%s\" is unknown, try \"bridge monitor help\".\n", *argv);
			exit(-1);
		}
		argc--;	argv++;
	}

	if (llink)
		groups |= nl_mgrp(RTNLGRP_LINK);

	if (lneigh) {
		groups |= nl_mgrp(RTNLGRP_NEIGH);
	}

	if (file) {
		FILE *fp;
		fp = fopen(file, "r");
		if (fp == NULL) {
			perror("Cannot fopen");
			exit(-1);
		}
		return rtnl_from_file(fp, accept_msg, stdout);
	}

	if (rtnl_open(&rth, groups) < 0)
		exit(1);
	ll_init_map(&rth);

	if (rtnl_listen(&rth, accept_msg, stdout) < 0)
		exit(2);

	return 0;
}
开发者ID:SamB,项目名称:iproute2,代码行数:57,代码来源:monitor.c


注:本文中的rtnl_close函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。