• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C++ NLA_DATA函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: get_family_id

int get_family_id(int sd)
{
	struct msgtemplate msg;
	int	len;
	int	recv_len;
	int	rc;
	struct nlattr *na;

	rc = send_cmd(sd, GENL_ID_CTRL, CTRL_CMD_GETFAMILY,
			CTRL_ATTR_FAMILY_NAME, SAMPLE_NETLINK_NL_FAMILY_NAME,
			strlen(SAMPLE_NETLINK_NL_FAMILY_NAME)+1, NLM_F_REQUEST);
	if (rc < 0) {
		printf("Error sending family cmd (%d:%s)\n",
				errno, strerror(errno));
		return -1;
	}
	recv_len = recv(sd, &msg, sizeof(msg), 0);
	if (msg.n.nlmsg_type == NLMSG_ERROR) {
		printf("Error: recv family error msg\n");
		return -1;
	}
	if (recv_len < 0) {
		printf("Error: recv family (%d)\n", recv_len);
		return -1;
	}
	if (!NLMSG_OK((&msg.n), recv_len)) {
		printf("Error: recv family msg nok\n");
		return -1;
	}

	len = 0;
	recv_len = GENLMSG_PAYLOAD(&msg.n);
	na = (struct nlattr *) GENLMSG_DATA(&msg);
	while (len < recv_len) {
		len += NLA_ALIGN(na->nla_len);
		switch (na->nla_type) {
			case CTRL_ATTR_FAMILY_ID:
				nl_family_id = *(uint16_t *) NLA_DATA(na);
				printf("family id:%d\n", nl_family_id);
				break;
			case CTRL_ATTR_MCAST_GROUPS:
				parse_groups(NLA_DATA(na),
						NLA_PAYLOAD_LEN(na->nla_len));
				break;
			case CTRL_ATTR_FAMILY_NAME:
			case CTRL_ATTR_VERSION:
			case CTRL_ATTR_HDRSIZE:
			case CTRL_ATTR_MAXATTR:
			case CTRL_ATTR_OPS:
				printf("Unused family attr %d\n", na->nla_type);
				break;
			default:
				printf("Unknown family attr %d\n", na->nla_type);
				break;
		}
		na = (struct nlattr *) (GENLMSG_DATA(&msg) + len);
	}

	return nl_family_id;
}
开发者ID:caiyuchao,项目名称:program,代码行数:60,代码来源:netlink.c


示例2: get_pfc_cfg

static int get_pfc_cfg(char *ifname, __u8 *pfc)
{
	struct nlmsghdr *nlh;
	struct dcbmsg *d;
	struct rtattr *rta_parent, *rta_child;
	int i;

	nlh = start_msg(RTM_GETDCB, DCB_CMD_PFC_GCFG);
	if (NULL==nlh)
		return -EIO;

	add_rta(nlh, DCB_ATTR_IFNAME, (void *)ifname,
		strlen(ifname) + 1);
	rta_parent = add_rta(nlh, DCB_ATTR_PFC_CFG, NULL, 0);

	rta_child = add_rta(nlh, DCB_PFC_UP_ATTR_ALL, NULL, 0);
	rta_parent->rta_len += NLMSG_ALIGN(rta_child->rta_len);

	if (send_msg(nlh))
		return -EIO;

	nlh = get_msg();
	if (!nlh)
		return -EIO;

	d = (struct dcbmsg *)NLMSG_DATA(nlh);
	rta_parent = (struct rtattr *)(((char *)d) +
		NLMSG_ALIGN(sizeof(struct dcbmsg)));

	if (d->cmd != DCB_CMD_PFC_GCFG) {
		printf("Hmm, this is not the message we were expecting.\n");
		return -EIO;
	}
	if (rta_parent->rta_type != DCB_ATTR_PFC_CFG) {
		/* Do we really want to code up an attribute parser?? */
		printf("A full libnetlink (with genl and attribute support) "
		       "would sure be nice.\n");
		return -EIO;
	}
	rta_child = NLA_DATA(rta_parent);
	rta_parent = (struct rtattr *)((char *)rta_parent +
				       NLMSG_ALIGN(rta_parent->rta_len));
	for (i = 0; rta_parent > rta_child; i++) {
		if (i == 8) {
			printf("pfc array out of range\n");
			break;
		}
		pfc[rta_child->rta_type - DCB_PFC_UP_ATTR_0] =
			*(__u8 *)NLA_DATA(rta_child);
		rta_child = (struct rtattr *)((char *)rta_child +
					      NLMSG_ALIGN(rta_child->rta_len));
	}
	if (rta_parent != rta_child)
		printf("rta pointers are off\n");

	return 0;
}
开发者ID:openSUSE,项目名称:lldpad,代码行数:57,代码来源:nltest.c


示例3: cputimer_get

void cputimer_get(int tid, long long int *times, xbt_cpu_timer_t timer)
{
	struct msgtemplate msg;
	int rep_len;
	struct nlattr *na;
	struct taskstats *stats;

	netlink_sock_send(timer->_id, TASKSTATS_CMD_GET, TASKSTATS_CMD_ATTR_PID, &tid, sizeof(__u32), timer);

	rep_len = recv(timer->_nl_sd, &msg, sizeof(msg), 0);
	xbt_assert(rep_len >= 0, "error while receiving the answer from netlink socket: %s", strerror(errno));

	xbt_assert((msg.n.nlmsg_type != NLMSG_ERROR && NLMSG_OK((&msg.n), rep_len)),
			"received a fatal error from the netlink socket: %s", strerror(errno));

	rep_len = GENLMSG_PAYLOAD(&msg.n);

	na = (struct nlattr *) GENLMSG_DATA(&msg);
	int len = 0;
	int aggr_len, len2;
	while (len < rep_len) {
		len += NLA_ALIGN(na->nla_len);
		switch (na->nla_type) {
		case TASKSTATS_TYPE_AGGR_PID:
			aggr_len = NLA_PAYLOAD(na->nla_len);
			len2 = 0;
			/* For nested attributes, na follows */
			na = (struct nlattr *) NLA_DATA(na);
			while (len2 < aggr_len) {
				switch (na->nla_type) {
				case TASKSTATS_TYPE_PID:
					break;
				case TASKSTATS_TYPE_STATS:
					/* here we collect info */
					stats = (struct taskstats *) NLA_DATA(na);
					//times[0] = (long long int)stats->ac_etime;
					times[1] = (long long int) stats->ac_utime;   /* User CPU time [usec] */
					times[2] = (long long int) stats->ac_stime;   /* SYstem CPU time [usec] */
					break;
				default:
					XBT_ERROR("Unknown nested" " nla_type %d\n", na->nla_type);
					break;
				}
				len2 += NLA_ALIGN(na->nla_len);
				na = (struct nlattr *) ((char *) na + len2);
			}
			break;
		default:
			XBT_ERROR("Unknown nla_type %d\n", na->nla_type);
			break;
		}
		na = (struct nlattr *) ((char *) GENLMSG_DATA(&msg) + len);
	}
}
开发者ID:abronan,项目名称:simterpose,代码行数:54,代码来源:cputimer.c


示例4: parse_groups

	static void
parse_groups(struct nlattr *na, int tot_len)
{
	int	len;
	int	grp_len;
	int	aggr_len;
	struct nlattr *grp_na;
	int find = 0;
	char group_name[GENL_NAMSIZ] = {0};
	int group_id = -1;

	len = 0;
	while (len < tot_len) {
		len += NLA_ALIGN(na->nla_len);
		printf("grp #%02d\n", na->nla_type);
#if 0
		if (na->nla_type > 1) {
			/* only one group supported for now */
			//na = (struct nlattr *) ((char *) na + len);
			//continue;
			printf("!!multi group, loop to find!!\n");
		}
#endif
		aggr_len = NLA_PAYLOAD_LEN(na->nla_len);
		grp_na = (struct nlattr *) NLA_DATA(na);
		grp_len = 0;
		while (grp_len < aggr_len) {
			grp_len += NLA_ALIGN(grp_na->nla_len);
			switch (grp_na->nla_type) {
				case CTRL_ATTR_MCAST_GRP_ID:
					group_id = *(uint32_t *) NLA_DATA(grp_na);
					printf("grp id = %d\n", nl_grp_id);
					break;
				case CTRL_ATTR_MCAST_GRP_NAME:
					strcpy(group_name, (char *)NLA_DATA(grp_na));
					printf("grp name %s\n", group_name);
					break;
				default:
					printf("Unknown grp nested attr %d\n", 	grp_na->nla_type);
					break;
			}
			grp_na = (struct nlattr *) ((char *) grp_na + grp_len);
		}
		if (-1 != group_id && strlen(group_name) > 0) {
			if (0 == strcmp(group_name, nl_grp_name)) {
				printf("find grp name:%s, id=%d\n", group_name, group_id);
				nl_grp_id = group_id;
				break;
			}
		}
		na = (struct nlattr *) ((char *) na + len);
	}
}
开发者ID:caiyuchao,项目名称:program,代码行数:53,代码来源:netlink.c


示例5: send_security_response

int send_security_response(int sd, __u16 nlmsg_type, __u8 genl_cmd,
		uint16_t flags, void *sec_flag, void *query_id)
{
	struct nlattr *na;
	struct sockaddr_nl nladdr;
	int r, buflen;
	char *buf;
	uint32_t attr_len = 0;

	struct msgtemplate msg;

	msg.n.nlmsg_len = NLMSG_LENGTH(GENL_HDRLEN);
	msg.n.nlmsg_type = nlmsg_type;
	msg.n.nlmsg_flags = flags;
	msg.n.nlmsg_seq = 0;
	msg.n.nlmsg_pid = pid;
	msg.g.cmd = genl_cmd;
	msg.g.version = 0x1;

	na = (struct nlattr *) GENLMSG_DATA(&msg);
	na->nla_type = SAMPLE_NETLINK_ATTR_SEC_QID;
	na->nla_len = sizeof(int) + NLA_HDRLEN;
	memcpy(NLA_DATA(na), query_id, sizeof(int));
	attr_len += na->nla_len;

	na = (struct nlattr *) (GENLMSG_DATA(&msg) + attr_len);
	na->nla_type = SAMPLE_NETLINK_ATTR_SECURITY_FLAG;
	na->nla_len = sizeof(int) + NLA_HDRLEN;
	memcpy(NLA_DATA(na), sec_flag, sizeof(int));
	attr_len += na->nla_len;


	msg.n.nlmsg_len += NLMSG_ALIGN(attr_len);

	buf = (char *) &msg;
	buflen = msg.n.nlmsg_len ;
	memset(&nladdr, 0, sizeof(nladdr));
	nladdr.nl_family = AF_NETLINK;

	while ((r = sendto(sd, buf, buflen, 0, (struct sockaddr *) &nladdr,
					sizeof(nladdr))) < buflen) {
		printf("sending (r=%d)\n", r);
		if (r > 0) {
			buf += r;
			buflen -= r;
		} else if (errno != EAGAIN)
			return r;
	}
	printf("msg sent (r=%d)\n", r);

	return 0;
}
开发者ID:caiyuchao,项目名称:program,代码行数:52,代码来源:netlink.c


示例6: getpid

/*
 * Probe the controller in genetlink to find the family id
 */
int ResetManager::get_family_id(int sk, const char *family_name)
{
    struct nlattr *na;
    int rep_len;
    int id = -1;
    GENERIC_NETLINK_PACKET family_req, ans;

    /* Get family name */
    family_req.n.nlmsg_type = GENL_ID_CTRL;
    family_req.n.nlmsg_flags = NLM_F_REQUEST;
    family_req.n.nlmsg_seq = 0;
    family_req.n.nlmsg_pid = getpid();
    family_req.n.nlmsg_len = NLMSG_LENGTH(GENL_HDRLEN);
    family_req.g.cmd = CTRL_CMD_GETFAMILY;
    family_req.g.version = 0x1;

    na = (struct nlattr *) GENLMSG_DATA(&family_req);
    na->nla_type = CTRL_ATTR_FAMILY_NAME;
    na->nla_len = strlen(family_name) + 1 + NLA_HDRLEN;
    strcpy((char *)NLA_DATA(na), family_name);
 
    family_req.n.nlmsg_len += NLMSG_ALIGN(na->nla_len);

    if (sendto_fd(sk, (char *) &family_req, family_req.n.nlmsg_len) < 0) {
        return -1;
    }

    rep_len = recv(sk, &ans, sizeof(ans), 0);
    if (rep_len < 0){
        LOGE("no response\n");
        return -1;
    }
    /* Validate response message */
    else if (!NLMSG_OK((&ans.n), (unsigned int)rep_len)){
        LOGE("invalid reply message\n");
        return -1;
    }
    else if (ans.n.nlmsg_type == NLMSG_ERROR) { /* error */
        LOGE("received error\n");
        return -1;
    }

    na = (struct nlattr *) GENLMSG_DATA(&ans);
    na = (struct nlattr *) ((char *) na + NLA_ALIGN(na->nla_len));
    if (na->nla_type == CTRL_ATTR_FAMILY_ID) {
        id = *(__u16 *) NLA_DATA(na);
    }

    return id;
}
开发者ID:AwaisKing,项目名称:mt6577_aosp_source,代码行数:53,代码来源:ResetManager.cpp


示例7: wait_taskstats

static struct taskstats *
wait_taskstats (void)
{
	static struct msgtemplate msg;
	int rep_len;

	for (;;) {
		while ((rep_len = recv (netlink_socket, &msg, sizeof(msg), 0)) < 0 && errno == EINTR);
  
		if (msg.n.nlmsg_type == NLMSG_ERROR ||
		    !NLMSG_OK((&msg.n), rep_len)) {
			/* process died before we got to it or somesuch */
			/* struct nlmsgerr *err = NLMSG_DATA(&msg);
			   fprintf (stderr, "fatal reply error,  errno %d\n", err->error); */
			return NULL;
		}
  
		int rep_len = GENLMSG_PAYLOAD(&msg.n);
		struct nlattr *na = (struct nlattr *) GENLMSG_DATA(&msg);
		int len = 0;
		
		while (len < rep_len) {
			len += NLA_ALIGN(na->nla_len);
			switch (na->nla_type) {
			case TASKSTATS_TYPE_AGGR_PID: {
				int aggr_len = NLA_PAYLOAD(na->nla_len);
				int len2 = 0;

				/* For nested attributes, na follows */
				na = (struct nlattr *) NLA_DATA(na);
				
				/* find the record we care about */
				while (na->nla_type != TASKSTATS_TYPE_STATS) {
					len2 += NLA_ALIGN(na->nla_len);

					if (len2 >= aggr_len)
						goto next_attr;
					na = (struct nlattr *) ((char *) na + len2);
				}
				return (struct taskstats *) NLA_DATA(na);
			}
			}
		next_attr:
			na = (struct nlattr *) (GENLMSG_DATA(&msg) + len);
		}
	}
	return NULL;
}
开发者ID:sesam,项目名称:bootchart,代码行数:48,代码来源:collector.c


示例8: get_family_id

/*
 * Probe the controller in genetlink to find the family id
 * for the TASKSTATS family
 */
static int get_family_id(xbt_cpu_timer_t timer)
{
	struct {
		struct nlmsghdr n;
		struct genlmsghdr g;
		char buf[256];
	} ans;

	int id = 0;
	struct nlattr *na;
	int rep_len;
	char name[100];
	int sd = timer->_nl_sd;


	strcpy(name, TASKSTATS_GENL_NAME);
	netlink_sock_send(GENL_ID_CTRL, CTRL_CMD_GETFAMILY,
			CTRL_ATTR_FAMILY_NAME, (void *) name, strlen(TASKSTATS_GENL_NAME) + 1, timer);

	rep_len = recv(sd, &ans, sizeof(ans), 0);
	xbt_assert(rep_len >= 0, "Answer to request on the family id is zero-sized");

	xbt_assert(ans.n.nlmsg_type != NLMSG_ERROR && NLMSG_OK((&ans.n), rep_len),
			"Error while retrieving the family id thru netlink: %s", strerror(errno));

	na = (struct nlattr *) GENLMSG_DATA(&ans);
	na = (struct nlattr *) ((char *) na + NLA_ALIGN(na->nla_len));
	if (na->nla_type == CTRL_ATTR_FAMILY_ID) {
		id = *(__u16 *) NLA_DATA(na);
	}
	return id;
}
开发者ID:abronan,项目名称:simterpose,代码行数:36,代码来源:cputimer.c


示例9: get_pfc_state

static int get_pfc_state(char *ifname, __u8 *state)
{
	struct nlmsghdr *nlh;
	struct dcbmsg *d;
	struct rtattr *rta;

	nlh = start_msg(RTM_GETDCB, DCB_CMD_PFC_GSTATE);
	if (NULL==nlh)
		return -EIO;

	add_rta(nlh, DCB_ATTR_IFNAME, (void *)ifname, strlen(ifname) + 1);

	if (send_msg(nlh))
		return -EIO;
	free(nlh);

	nlh = get_msg();
	if (!nlh)
		return -EIO;

	d = (struct dcbmsg *)NLMSG_DATA(nlh);
	rta = (struct rtattr *)(((char *)d) +
		NLMSG_ALIGN(sizeof(struct dcbmsg)));

	if (d->cmd != DCB_CMD_PFC_GSTATE) {
		printf("Hmm, this is not the message we were expecting.\n");
		return -EIO;
	}

	if (rta->rta_type != DCB_ATTR_PFC_STATE) {
		return -EIO;
	}
	*state = *(__u8 *)NLA_DATA(rta);
	return 0;
}
开发者ID:openSUSE,项目名称:lldpad,代码行数:35,代码来源:nltest.c


示例10: recv_msg

static int recv_msg(int cmd, int attr)
{
	struct nlmsghdr *nlh;
	struct dcbmsg *d;
	struct rtattr *rta;
	int rval;

	nlh = get_msg();

	if (NULL == nlh)
		return -EIO;

	d = (struct dcbmsg *)NLMSG_DATA(nlh);
	rta = (struct rtattr *)(((char *)d) +
		NLMSG_ALIGN(sizeof(struct dcbmsg)));

	if ((d->cmd != cmd) || (rta->rta_type != attr)) {
		printf("Bad netlink message attribute.");
		return -EIO;
	}

	rval = *(__u8 *)NLA_DATA(rta);
	free(nlh);
	return rval;
}
开发者ID:openSUSE,项目名称:lldpad,代码行数:25,代码来源:nltest.c


示例11: process_netlink

void process_netlink(int ci)
{
	struct msgtemplate msg;
	struct nlattr *na;
	int len;
	int fd;

	fd = client_fd(ci);

	len = recv(fd, &msg, sizeof(msg), 0);

	if (len < 0) {
		log_error("nonfatal netlink error: errno %d", errno);
		return;
	}

	if (msg.n.nlmsg_type == NLMSG_ERROR || !NLMSG_OK((&msg.n), len)) {
		struct nlmsgerr *err = NLMSG_DATA(&msg);
		log_error("fatal netlink error: errno %d", err->error);
		return;
	}

	na = (struct nlattr *) GENLMSG_DATA(&msg);

	process_timewarn((struct dlm_lock_data *) NLA_DATA(na));
}
开发者ID:beekhof,项目名称:dlm,代码行数:26,代码来源:netlink.c


示例12: test_nfacct_del

static void test_nfacct_del(struct netlink_info *netlink, const char *name)
{
	struct nfgenmsg *hdr;
	size_t len, name_len;

	name_len = strlen(name) + 1;
	len = NLMSG_ALIGN(sizeof(struct nfgenmsg)) +
		NLA_ALIGN(sizeof(struct nlattr)) +
		name_len;

	hdr = g_malloc0(len);

	hdr->nfgen_family = AF_UNSPEC;
	hdr->version = NFNETLINK_V0;
	hdr->res_id = 0;

	append_attr_str(NLA_DATA(hdr), NFACCT_NAME, name_len, name);

	netlink_send(netlink,
			NFNL_SUBSYS_ACCT << 8 | NFNL_MSG_ACCT_DEL,
			NLM_F_ACK, hdr, len,
			test_nfacct_callback, NULL, NULL);

	g_free(hdr);
}
开发者ID:HoraceWeebler,项目名称:connman,代码行数:25,代码来源:netlink-test.c


示例13: get_family_id

/*
 * Probe the controller in genetlink to find the family id
 * for the TASKSTATS family
 */
static int get_family_id(int sd)
{
	struct {
		struct nlmsghdr n;
		struct genlmsghdr g;
		char buf[256];
	} ans;

	int id = 0, rc;
	struct nlattr *na;
	int rep_len;

        char name[100];
	strcpy(name, TASKSTATS_GENL_NAME);
	rc = send_cmd (sd, GENL_ID_CTRL, getpid(), CTRL_CMD_GETFAMILY,
			CTRL_ATTR_FAMILY_NAME, (void *)name,
			strlen(TASKSTATS_GENL_NAME)+1);

	rep_len = recv(sd, &ans, sizeof(ans), 0);
	if (ans.n.nlmsg_type == NLMSG_ERROR ||
	    (rep_len < 0) || !NLMSG_OK((&ans.n), rep_len))
		return -1;

	na = (struct nlattr *) GENLMSG_DATA(&ans);
	na = (struct nlattr *) ((char *) na + NLA_ALIGN(na->nla_len));
	if (na->nla_type == CTRL_ATTR_FAMILY_ID) {
		id = *(__u16 *) NLA_DATA(na);
	}
	return id;
}
开发者ID:sesam,项目名称:bootchart,代码行数:34,代码来源:collector.c


示例14: get_perm_hwaddr

static int get_perm_hwaddr(char *ifname, __u8 *buf_perm, __u8 *buf_san)
{
	struct nlmsghdr *nlh;
	struct dcbmsg *d;
	struct rtattr *rta;

	nlh = start_msg(RTM_GETDCB, DCB_CMD_GPERM_HWADDR);
	if (NULL==nlh)
		return -EIO;

	add_rta(nlh, DCB_ATTR_IFNAME, (void *)ifname, strlen(ifname) + 1);
	add_rta(nlh, DCB_ATTR_PERM_HWADDR, NULL, 0);
	if (send_msg(nlh))
		return -EIO;

	nlh = get_msg();
	if (!nlh) {
		printf("get msg failed\n");
		return -EIO;
	}

	d = (struct dcbmsg *)NLMSG_DATA(nlh);
	rta = (struct rtattr *)(((char *)d) +
		NLMSG_ALIGN(sizeof(struct dcbmsg)));

	if (d->cmd != DCB_CMD_GPERM_HWADDR) {
		printf("Hmm, this is not the message we were expecting.\n");
		return -EIO;
	}

	if (rta->rta_type != DCB_ATTR_PERM_HWADDR) {
		/* Do we really want to code up an attribute parser?? */
		printf("A full libnetlink (with genl and attribute support) "
		       "would sure be nice.\n");
		return -EIO;
	}

	memcpy(buf_perm, NLA_DATA(rta), ETH_ALEN);
	memcpy(buf_san, NLA_DATA(rta + ETH_ALEN*sizeof(__u8)), ETH_ALEN);

	return 0;
}
开发者ID:openSUSE,项目名称:lldpad,代码行数:42,代码来源:nltest.c


示例15: nl_parse_gen_ctrl

struct nl_response *
nl_parse_gen_ctrl(struct nl_client *cl)
{
    int len;
    struct nlattr *nla;
    struct genl_ctrl_message *msg;
    char *buf = cl->cl_buf + cl->cl_buf_offset;
    struct nl_response *resp = &cl->resp;

    msg = (struct genl_ctrl_message *)cl->cl_resp_buf;
    resp->nl_data = (uint8_t *)(msg);
    memset(msg, 0, sizeof(*msg));
    msg->family_id = -1;

    len = cl->cl_msg_len - (cl->cl_buf_offset - cl->cl_msg_start);
    nla = (struct nlattr *)buf;

    while (len > 0 && len > NLA_HDRLEN) {
        if (len < NLA_ALIGN(nla->nla_len))
            return nl_set_resp_err(cl, -EINVAL);

        switch (nla->nla_type) {
        case CTRL_ATTR_FAMILY_NAME:
            strncpy(msg->family_name, NLA_DATA(nla), sizeof(msg->family_name) - 1);
            break;

        case CTRL_ATTR_FAMILY_ID:
            msg->family_id = *(unsigned short *)NLA_DATA(nla);
            break;

        default:
            break;
        }

        cl->cl_buf_offset += NLA_ALIGN(nla->nla_len);
        len -= NLA_ALIGN(nla->nla_len);
        nla = (struct nlattr *)((char *)nla + NLA_ALIGN(nla->nla_len));
    }

    return resp;
}
开发者ID:avallark,项目名称:contrail-vrouter,代码行数:41,代码来源:nl_util.c


示例16: append_attr_str

static void append_attr_str(struct nlattr *attr,
                                uint16_t type, size_t size, const char *str)
{
	char *dst;

	attr->nla_len = NLA_HDRLEN + size;
	attr->nla_type = NFACCT_NAME;

	dst = (char *)NLA_DATA(attr);
	strncpy(dst, str, size);
	dst[size - 1] = '\0';
}
开发者ID:HoraceWeebler,项目名称:connman,代码行数:12,代码来源:netlink-test.c


示例17: test_nfacct_dump_callback

static void test_nfacct_dump_callback(unsigned int error, uint16_t type,
				const void *data, uint32_t len, void *user_data)
{
	const struct nfgenmsg *msg = data;
	const struct nlattr *attr;
	uint64_t packets = 0 , bytes = 0;
	char *name = NULL;
	int attrlen;

	if (error == EINVAL)
		printf("nfnetlink_acct not loaded\n");

	g_assert_cmpuint(error, ==, 0);

	attrlen = len - NLMSG_ALIGN(sizeof(struct nfgenmsg));

	for (attr = NFGEN_DATA(msg); NLA_OK(attr, attrlen);
		     attr = NLA_NEXT(attr, attrlen)) {
		switch (attr->nla_type) {
		case NFACCT_NAME:
			name = NLA_DATA(attr);
			break;
		case NFACCT_PKTS:
			packets = be64toh(*(uint64_t *) NLA_DATA(attr));
			break;
		case NFACCT_BYTES:
			bytes = be64toh(*(uint64_t *) NLA_DATA(attr));
			break;
		case NFACCT_USE:
			break;
		}
	}

	printf("%s packets %" PRIu64 " bytes %" PRIu64 "\n",
		name, packets, bytes);

	g_main_loop_quit(mainloop);
}
开发者ID:HoraceWeebler,项目名称:connman,代码行数:38,代码来源:netlink-test.c


示例18: memcpy

static struct rtattr *add_rta(struct nlmsghdr *nlh, __u16 rta_type,
			      void *attr, __u16 rta_len)
{
	struct rtattr *rta;

	rta = (struct rtattr *)((char *)nlh + nlh->nlmsg_len);
	rta->rta_type = rta_type;
	rta->rta_len = rta_len + NLA_HDRLEN;
	if (attr)
		memcpy(NLA_DATA(rta), attr, rta_len);
	nlh->nlmsg_len += NLMSG_ALIGN(rta->rta_len);

	return rta;
}
开发者ID:openSUSE,项目名称:lldpad,代码行数:14,代码来源:nltest.c


示例19: receive_msg

static int receive_msg(u_int16_t fid, int sock, struct packet *data)
{
    int ret;
    nlmsg msg;
    struct nlattr *na;

    ret = recv(sock, &msg, sizeof(msg), 0);
    if (ret < 0 || msg.n.nlmsg_type == NLMSG_ERROR ||
            msg.n.nlmsg_type != fid || fid == 0)
        return -1;

    na = (struct nlattr *) GENLMSG_DATA(&msg);
    *data = *(struct packet *) NLA_DATA(na);
    return 0;
}
开发者ID:foruy,项目名称:multipath,代码行数:15,代码来源:NetClient.c


示例20: send_cmd

/*
 *           Netlink interface
 */
int send_cmd(int sd, __u16 nlmsg_type, __u8 genl_cmd, __u16 nla_type,
		void *nla_data, int nla_len, uint16_t flags)
{
	struct nlattr *na;
	struct sockaddr_nl nladdr;
	int r, buflen;
	char *buf;

	struct msgtemplate msg;

	msg.n.nlmsg_len = NLMSG_LENGTH(GENL_HDRLEN);
	msg.n.nlmsg_type = nlmsg_type;
	msg.n.nlmsg_flags = flags;
	msg.n.nlmsg_seq = 0;
	msg.n.nlmsg_pid = pid;
	msg.g.cmd = genl_cmd;
	msg.g.version = 0x1;
	na = (struct nlattr *) GENLMSG_DATA(&msg);
	na->nla_type = nla_type;
	na->nla_len = nla_len + NLA_HDRLEN;
	memcpy(NLA_DATA(na), nla_data, nla_len);
	msg.n.nlmsg_len += NLMSG_ALIGN(na->nla_len);

	buf = (char *) &msg;
	buflen = msg.n.nlmsg_len ;
	memset(&nladdr, 0, sizeof(nladdr));
	nladdr.nl_family = AF_NETLINK;

	while ((r = sendto(sd, buf, buflen, 0, (struct sockaddr *) &nladdr,
					sizeof(nladdr))) < buflen) {
		printf("sending (r=%d)\n", r);
		if (r > 0) {
			buf += r;
			buflen -= r;
		} else if (errno != EAGAIN)
			return r;
	}
	printf("msg sent (r=%d)\n", r);

	return 0;
}
开发者ID:caiyuchao,项目名称:program,代码行数:44,代码来源:netlink.c



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++ NLA_PUT函数代码示例发布时间:2022-05-30
下一篇:
C++ NLA_ALIGN函数代码示例发布时间:2022-05-30
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap