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


C++ NLMSG_TAIL函数代码示例

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


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

示例1: vlan_parse_qos_map

static int vlan_parse_qos_map(int *argcp, char ***argvp, struct nlmsghdr *n,
			      int attrtype)
{
	int argc = *argcp;
	char **argv = *argvp;
	struct ifla_vlan_qos_mapping m;
	struct rtattr *tail;

	tail = NLMSG_TAIL(n);
	addattr_l(n, 1024, attrtype, NULL, 0);

	while (argc > 0) {
		char *colon = strchr(*argv, ':');

		if (!colon)
			break;
		*colon = '\0';

		if (get_u32(&m.from, *argv, 0))
			return 1;
		if (get_u32(&m.to, colon + 1, 0))
			return 1;
		argc--, argv++;

		addattr_l(n, 1024, IFLA_VLAN_QOS_MAPPING, &m, sizeof(m));
	}

	tail->rta_len = (void *) NLMSG_TAIL(n) - (void *)tail;

	*argcp = argc;
	*argvp = argv;
	return 0;
}
开发者ID:6WIND,项目名称:iproute2,代码行数:33,代码来源:iplink_vlan.c

示例2: qdisc_tbf

static int qdisc_tbf(struct qdisc_opt *qopt, struct nlmsghdr *n)
{
	struct tc_tbf_qopt opt;
	__u32 rtab[256];
	int Rcell_log = -1;
	unsigned int linklayer = LINKLAYER_ETHERNET; /* Assume ethernet */
	struct rtattr *tail;

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

	opt.rate.rate = qopt->rate;
	opt.limit = (double)qopt->rate * qopt->latency + qopt->buffer;
	opt.rate.mpu = conf_mpu;
	if (tc_calc_rtable(&opt.rate, rtab, Rcell_log, conf_mtu, linklayer) < 0) {
		log_ppp_error("shaper: failed to calculate rate table.\n");
		return -1;
	}
	opt.buffer = tc_calc_xmittime(opt.rate.rate, qopt->buffer);

	tail = NLMSG_TAIL(n);
	addattr_l(n, TCA_BUF_MAX, TCA_OPTIONS, NULL, 0);
	addattr_l(n, TCA_BUF_MAX, TCA_TBF_PARMS, &opt, sizeof(opt));
	addattr_l(n, TCA_BUF_MAX, TCA_TBF_RTAB, rtab, 1024);
	tail->rta_len = (void *) NLMSG_TAIL(n) - (void *) tail;

	return 0;
}
开发者ID:themiron,项目名称:accel-ppp,代码行数:27,代码来源:limiter.c

示例3: form_request_add

int form_request_add()
{
	int ifcn = 1; //interface number

	bzero(&req, sizeof(req));
	req.nl.nlmsg_len = NLMSG_LENGTH(sizeof(struct rtmsg));
	rtap = NLMSG_TAIL(&req.nl);
	rtap->rta_type = RTA_DST;
	rtap->rta_len = RTA_LENGTH(4);
	inet_pton(AF_INET, dsts,
			((char *)rtap) + sizeof(struct rtattr));
	req.nl.nlmsg_len = NLMSG_ALIGN(req.nl.nlmsg_len) + RTA_ALIGN(rtap->rta_len);

	rtap = NLMSG_TAIL(&req.nl);;
	rtap->rta_type = RTA_OIF;//Output interface index
	rtap->rta_len = RTA_LENGTH(sizeof(int));
	memcpy(((char *)rtap) + sizeof(struct rtattr),
			&ifcn, sizeof(int));

	req.nl.nlmsg_len = NLMSG_ALIGN(req.nl.nlmsg_len) + RTA_ALIGN(rtap->rta_len);
	req.nl.nlmsg_flags = NLM_F_REQUEST | NLM_F_CREATE | NLM_F_ACK;
	req.nl.nlmsg_type = RTM_NEWROUTE;

	req.rt.rtm_family = AF_INET;
	req.rt.rtm_table = RT_TABLE_MAIN;
	req.rt.rtm_protocol = RTPROT_STATIC;
	req.rt.rtm_scope = RT_SCOPE_UNIVERSE;
	req.rt.rtm_type = RTN_UNICAST;
	req.rt.rtm_dst_len = pn;
	return 0;
}
开发者ID:0x7f454c46,项目名称:criu-1,代码行数:31,代码来源:netlink00.c

示例4: drr_parse_class_opt

static int drr_parse_class_opt(struct qdisc_util *qu, int argc, char **argv,
			       struct nlmsghdr *n)
{
	struct rtattr *tail;
	__u32 tmp;

	tail = NLMSG_TAIL(n);
	addattr_l(n, 1024, TCA_OPTIONS, NULL, 0);

	while (argc > 0) {
		if (strcmp(*argv, "quantum") == 0) {
			NEXT_ARG();
			if (get_size(&tmp, *argv)) {
				fprintf(stderr, "Illegal \"quantum\"\n");
				return -1;
			}
			addattr_l(n, 1024, TCA_DRR_QUANTUM, &tmp, sizeof(tmp));
		} else if (strcmp(*argv, "help") == 0) {
			explain2();
			return -1;
		} else {
			fprintf(stderr, "What is \"%s\"?\n", *argv);
			explain2();
			return -1;
		}
		argc--; argv++;
	}

	tail->rta_len = (void *) NLMSG_TAIL(n) - (void *)tail;
	return 0;
}
开发者ID:AntonGorynya,项目名称:LAB3_1,代码行数:31,代码来源:q_drr.c

示例5: veth_parse_opt

static int veth_parse_opt(struct link_util *lu, int argc, char **argv,
			  struct nlmsghdr *hdr)
{
	char *name = NULL;
	char *type = NULL;
	char *link = NULL;
	char *dev = NULL;
	int err, len;
	struct rtattr * data;

	if (strcmp(argv[0], "peer") != 0) {
		usage();
		return -1;
	}

	data = NLMSG_TAIL(hdr);
	addattr_l(hdr, 1024, VETH_INFO_PEER, NULL, 0);

	hdr->nlmsg_len += sizeof(struct ifinfomsg);

	err = iplink_parse(argc - 1, argv + 1, (struct iplink_req *)hdr,
			   &name, &type, &link, &dev);
	if (err < 0)
		return err;

	if (name) {
		len = strlen(name) + 1;
		if (len > IFNAMSIZ)
			invarg("\"name\" too long\n", *argv);
		addattr_l(hdr, 1024, IFLA_IFNAME, name, len);
	}

	data->rta_len = (void *)NLMSG_TAIL(hdr) - (void *)data;
	return argc - 1 - err;
}
开发者ID:STALKER80,项目名称:iproute,代码行数:35,代码来源:link_veth.c

示例6: netlink_link_add_vmac

int
netlink_link_add_vmac(vrrp_rt *vrrp)
{
	struct rtattr *linkinfo;
	interface *ifp;
	char ifname[IFNAMSIZ];
	struct {
		struct nlmsghdr n;
		struct ifinfomsg ifi;
		char buf[256];
	} req;

	if (!vrrp->ifp)
		return -1;

	memset(&req, 0, sizeof (req));
	memset(ifname, 0, IFNAMSIZ);
	strncpy(ifname, vrrp->vmac_ifname, IFNAMSIZ - 1);

	req.n.nlmsg_len = NLMSG_LENGTH(sizeof (struct ifinfomsg));
	req.n.nlmsg_flags = NLM_F_REQUEST | NLM_F_CREATE | NLM_F_EXCL;
	req.n.nlmsg_type = RTM_NEWLINK;
	req.ifi.ifi_family = AF_INET;

	/* macvlan settings */
	linkinfo = NLMSG_TAIL(&req.n);
	addattr_l(&req.n, sizeof(req), IFLA_LINKINFO, NULL, 0);
	addattr_l(&req.n, sizeof(req), IFLA_INFO_KIND, (void *)ll_kind, strlen(ll_kind));
	linkinfo->rta_len = (void *)NLMSG_TAIL(&req.n) - (void *)linkinfo;
	addattr_l(&req.n, sizeof(req), IFLA_LINK, &IF_INDEX(vrrp->ifp), sizeof(uint32_t));
	addattr_l(&req.n, sizeof(req), IFLA_IFNAME, ifname, strlen(ifname));

	if (netlink_talk(&nl_cmd, &req.n) < 0)
		return -1;

	/*
	 * Update interface queue and vrrp instance interface binding.
	 * bring it UP !
	 */
	netlink_interface_lookup();
	ifp = if_get_by_ifname(ifname);
	if (!ifp)
		return -1;
	vrrp->ifp = ifp;
	vrrp->vmac |= 2;
	netlink_link_setlladdr(vrrp);
	netlink_link_up(vrrp);

	/*
	 * By default MACVLAN interface are in VEPA mode which filters
	 * out received packets whose MAC source address matches that
	 * of the MACVLAN interface. Setting MACVLAN interface in private
	 * mode will not filter based on source MAC address.
	 */
	netlink_link_setmode(vrrp);

	return 1;
}
开发者ID:bfg,项目名称:keepalived,代码行数:58,代码来源:vrrp_vmac.c

示例7: codel_parse_opt

static int codel_parse_opt(struct qdisc_util *qu, int argc, char **argv,
			   struct nlmsghdr *n)
{
	unsigned limit = 0;
	unsigned target = 0;
	unsigned interval = 0;
	int ecn = -1;
	struct rtattr *tail;

	while (argc > 0) {
		if (strcmp(*argv, "limit") == 0) {
			NEXT_ARG();
			if (get_unsigned(&limit, *argv, 0)) {
				fprintf(stderr, "Illegal \"limit\"\n");
				return -1;
			}
		} else if (strcmp(*argv, "target") == 0) {
			NEXT_ARG();
			if (get_time(&target, *argv)) {
				fprintf(stderr, "Illegal \"target\"\n");
				return -1;
			}
		} else if (strcmp(*argv, "interval") == 0) {
			NEXT_ARG();
			if (get_time(&interval, *argv)) {
				fprintf(stderr, "Illegal \"interval\"\n");
				return -1;
			}
		} else if (strcmp(*argv, "ecn") == 0) {
			ecn = 1;
		} else if (strcmp(*argv, "noecn") == 0) {
			ecn = 0;
		} else if (strcmp(*argv, "help") == 0) {
			explain();
			return -1;
		} else {
			fprintf(stderr, "What is \"%s\"?\n", *argv);
			explain();
			return -1;
		}
		argc--; argv++;
	}

	tail = NLMSG_TAIL(n);
	addattr_l(n, 1024, TCA_OPTIONS, NULL, 0);
	if (limit)
		addattr_l(n, 1024, TCA_CODEL_LIMIT, &limit, sizeof(limit));
	if (interval)
		addattr_l(n, 1024, TCA_CODEL_INTERVAL, &interval, sizeof(interval));
	if (target)
		addattr_l(n, 1024, TCA_CODEL_TARGET, &target, sizeof(target));
	if (ecn != -1)
		addattr_l(n, 1024, TCA_CODEL_ECN, &ecn, sizeof(ecn));
	tail->rta_len = (void *) NLMSG_TAIL(n) - (void *) tail;
	return 0;
}
开发者ID:AllardJ,项目名称:Tomato,代码行数:56,代码来源:q_codel.c

示例8: dsmark_parse_opt

static int dsmark_parse_opt(struct qdisc_util *qu, int argc, char **argv,
    struct nlmsghdr *n)
{
	struct rtattr *tail;
	__u16 ind;
	char *end;
	int dflt,set_tc_index;

	ind = set_tc_index = 0;
	dflt = -1;
	while (argc > 0) {
		if (!strcmp(*argv,"indices")) {
			NEXT_ARG();
			ind = strtoul(*argv,&end,0);
			if (*end) {
				explain();
				return -1;
			}
		}
		else if (!strcmp(*argv,"default_index") || !strcmp(*argv,
		    "default")) {
			NEXT_ARG();
			dflt = strtoul(*argv,&end,0);
			if (*end) {
				explain();
				return -1;
			}
		}
		else if (!strcmp(*argv,"set_tc_index")) {
			set_tc_index = 1;
		}
		else {
			explain();
			return -1;
		}
		argc--;
		argv++;
	}
	if (!ind) {
		explain();
		return -1;
	}
	tail = NLMSG_TAIL(n);
	addattr_l(n,1024,TCA_OPTIONS,NULL,0);
	addattr_l(n,1024,TCA_DSMARK_INDICES,&ind,sizeof(ind));
	if (dflt != -1) {
	    __u16 tmp = dflt;

	    addattr_l(n,1024,TCA_DSMARK_DEFAULT_INDEX,&tmp,sizeof(tmp));
	}
	if (set_tc_index) addattr_l(n,1024,TCA_DSMARK_SET_TC_INDEX,NULL,0);
	tail->rta_len = (void *) NLMSG_TAIL(n) - (void *) tail;
	return 0;
}
开发者ID:qtekfun,项目名称:htcDesire820Kernel,代码行数:54,代码来源:q_dsmark.c

示例9: addraw_l

int addraw_l(struct nlmsghdr *n, int maxlen, const void *data, int len)
{
	if (NLMSG_ALIGN(n->nlmsg_len) + NLMSG_ALIGN(len) > maxlen) {
		fprintf(stderr, "addraw_l ERROR: message exceeded bound of %d\n",maxlen);
		return -1;
	}

	memcpy(NLMSG_TAIL(n), data, len);
	memset((void *) NLMSG_TAIL(n) + len, 0, NLMSG_ALIGN(len) - len);
	n->nlmsg_len = NLMSG_ALIGN(n->nlmsg_len) + NLMSG_ALIGN(len);
	return 0;
}
开发者ID:MichaelQQ,项目名称:Quagga-PE,代码行数:12,代码来源:libnetlink.c

示例10: addraw_l

int
addraw_l(struct nlmsghdr *n, size_t maxlen, const void *data, size_t len)
{
	size_t align_len = NLMSG_ALIGN(len);

	if (n->nlmsg_len + align_len > maxlen)
		return -1;

	memcpy(NLMSG_TAIL(n), data, len);
	memset((void *) NLMSG_TAIL(n) + len, 0, align_len - len);
	n->nlmsg_len += (uint32_t)align_len;
	return 0;
}
开发者ID:Oefenweb,项目名称:keepalived,代码行数:13,代码来源:vrrp_netlink.c

示例11: psp_parse_class_opt

static int psp_parse_class_opt(struct qdisc_util *qu, int argc, char **argv,
			       struct nlmsghdr *n)
{
	struct tc_psp_copt copt;
	struct rtattr *tail;

	memset(&copt, 0, sizeof(copt));
	copt.mode = TC_PSP_MODE_STATIC; /* default mode */

	while (argc > 0) {
		if (matches(*argv, "rate") == 0) {
			NEXT_ARG();
			if (GET_RATE(&copt.rate, *argv)) {
				explain1("rate");
				return -1;
			}
		} else if (matches(*argv, "mode") == 0) {
			NEXT_ARG();
			if (get_u32(&copt.mode, *argv, 16)) {
				explain1("mode");
				return -1;
			}
		} else if (matches(*argv, "help") == 0) {
			explain();
			return -1;
		} else {
			fprintf(stderr, "What is \"%s\"?\n", *argv);
			explain();
			return -1;
		}
		argc--; argv++;
	}

	if (copt.mode == TC_PSP_MODE_NORMAL && copt.rate != 0) {
		fprintf(stderr, "You can not set to \"rate\" parameter "
			"in normal mode\n");
		explain1("rate");
		return -1;
	} else if (copt.mode == TC_PSP_MODE_STATIC && copt.rate == 0) {
		fprintf(stderr, "You need set to \"rate\" parameter "
			"in static target rate mode.\n");
		explain1("rate");
		return -1;
	}

	tail = NLMSG_TAIL(n);
	addattr_l(n, 1024, TCA_OPTIONS, NULL, 0);
	addattr_l(n, 1024, TCA_PSP_COPT, &copt, sizeof(copt));
	tail->rta_len = (void *)NLMSG_TAIL(n) - (void *)tail;
	return 0;
}
开发者ID:stanhu,项目名称:pspacer,代码行数:51,代码来源:q_psp.c

示例12: NLMSG_TAIL

struct rtattr *addattr_nest(struct nlmsghdr *n, int type)
{
	struct rtattr *nest = NLMSG_TAIL(n);

	addattr_l(n, type, NULL, 0);
	return nest;
}
开发者ID:openSUSE,项目名称:lldpad,代码行数:7,代码来源:nltest.c

示例13: psp_parse_opt

static int psp_parse_opt(struct qdisc_util *qu, int argc, char **argv,
			 struct nlmsghdr *n)
{
	struct tc_psp_qopt qopt;
	struct rtattr *tail;

	memset(&qopt, 0, sizeof(qopt));
	qopt.ifg = 12;

	while (argc > 0) {
		if (matches(*argv, "rate") == 0) {
			NEXT_ARG();
			if (GET_RATE(&qopt.rate, *argv)) {
				explain1("rate");
				return -1;
			}
		} else if (matches(*argv, "default") == 0) {
			NEXT_ARG();
			if (get_u32(&qopt.defcls, *argv, 16)) {
				explain1("default");
				return -1;
			}
		} else if (matches(*argv, "ifg") == 0) {
			NEXT_ARG();
			if (get_u32(&qopt.ifg, *argv, 10)) {
				explain1("ifg");
				return -1;
			}
		} else if (matches(*argv, "help") == 0) {
			explain();
			return -1;
		} else {
			fprintf(stderr, "What is \"%s\"?\n", *argv);
			explain();
			return -1;
		}
		argc--;
		argv++;
	}

	tail = NLMSG_TAIL(n);
	addattr_l(n, 1024, TCA_OPTIONS, NULL, 0);
	addattr_l(n, 1024, TCA_PSP_QOPT, &qopt, sizeof(qopt));
	tail->rta_len = (void *) NLMSG_TAIL(n) - (void *) tail;
	return 0;
}
开发者ID:stanhu,项目名称:pspacer,代码行数:46,代码来源:q_psp.c

示例14: memset

std::string KernelNetlinkProtocol::build_vlan(uint16_t vlan_id, uint16_t link, const std::string& name)
{
    struct
    {
        nlmsghdr nl_hdr;
        ifinfomsg if_msg;
        char buf[1024];
    } req;

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

    req.nl_hdr.nlmsg_len = NLMSG_LENGTH(sizeof(req.if_msg));
    req.nl_hdr.nlmsg_type = RTM_NEWLINK;
    req.nl_hdr.nlmsg_flags = NLM_F_REQUEST | NLM_F_ACK | NLM_F_CREATE | NLM_F_EXCL;
    req.nl_hdr.nlmsg_pid = cmd_local_addr_.nl_pid;
    req.nl_hdr.nlmsg_seq = ++seq_num;

    // physical device id, required
    addattr_32(&req.nl_hdr, sizeof(req), IFLA_LINK, link);


    if (!name.empty())
    {
        addattr_l(&req.nl_hdr, sizeof(req), IFLA_IFNAME, name.c_str(), name.size() + 1);
    }

//	if (!address.empty()) // optional vlan MAC address setting
//	{
//		addattr_l(&req.nl_hdr, sizeof(req), IFLA_ADDRESS, address.data(), address.size());
//	}

    rtattr* linkinfo = NLMSG_TAIL(&req.nl_hdr);
    addattr_l(&req.nl_hdr, sizeof(req), IFLA_LINKINFO, NULL, 0);
    addattr_l(&req.nl_hdr, sizeof(req), IFLA_INFO_KIND, "vlan", strlen("vlan"));

    rtattr* data = NLMSG_TAIL(&req.nl_hdr);
    addattr_l(&req.nl_hdr, sizeof(req), IFLA_INFO_DATA, NULL, 0);
    addattr_l(&req.nl_hdr, sizeof(req), IFLA_VLAN_ID, &vlan_id, 2);
    // not adding vlan flags

    data->rta_len = (char *) NLMSG_TAIL(&req.nl_hdr) - (char *) data;
    linkinfo->rta_len = (char *) NLMSG_TAIL(&req.nl_hdr) - (char *) linkinfo;
    assert(req.nl_hdr.nlmsg_len > 0);

    return std::string(reinterpret_cast<char*>(&req), req.nl_hdr.nlmsg_len);
}
开发者ID:carriercomm,项目名称:dropgit,代码行数:46,代码来源:kernel_netlink.cpp

示例15: netlink_link_setmode

static int
netlink_link_setmode(vrrp_rt *vrrp)
{
    int status = 1;
    struct {
        struct nlmsghdr n;
        struct ifinfomsg ifi;
        char buf[256];
    } req;
    struct rtattr *linkinfo;
    struct rtattr *data;

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

    req.n.nlmsg_len = NLMSG_LENGTH(sizeof (struct ifinfomsg));
    req.n.nlmsg_flags = NLM_F_REQUEST;
    req.n.nlmsg_type = RTM_NEWLINK;
    req.ifi.ifi_family = AF_INET;
    req.ifi.ifi_index = IF_INDEX(vrrp->xmit_ifp);

    linkinfo = NLMSG_TAIL(&req.n);
    addattr_l(&req.n, sizeof(req), IFLA_LINKINFO, NULL, 0);
    addattr_l(&req.n, sizeof(req), IFLA_INFO_KIND, (void *)ll_kind,
              strlen(ll_kind));

    data = NLMSG_TAIL(&req.n);
    addattr_l(&req.n, sizeof(req), IFLA_INFO_DATA, NULL, 0);

    /*
     * In private mode, macvlan will receive frames with same MAC addr
     * as configured on the interface.
     */
#ifndef MACVLAN_MODE_VRRP
#define MACVLAN_MODE_VRRP 16
#endif
    addattr32(&req.n, sizeof(req), IFLA_MACVLAN_MODE,
              MACVLAN_MODE_VRRP);
    data->rta_len = (void *)NLMSG_TAIL(&req.n) - (void *)data;

    linkinfo->rta_len = (void *)NLMSG_TAIL(&req.n) - (void *)linkinfo;

    if (netlink_talk(&nl_cmd, &req.n) < 0)
        status = -1;

    return status;
}
开发者ID:tomjepp,项目名称:vyatta-keepalived,代码行数:46,代码来源:vrrp_vmac.c


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