本文整理汇总了C++中NLMSG_SPACE函数的典型用法代码示例。如果您正苦于以下问题:C++ NLMSG_SPACE函数的具体用法?C++ NLMSG_SPACE怎么用?C++ NLMSG_SPACE使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了NLMSG_SPACE函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: main
int main(int argc, char* argv[])
{
sock_fd = socket(PF_NETLINK, SOCK_RAW, 21);
memset(&msg, 0, sizeof(msg));
memset(&src_addr, 0, sizeof(src_addr));
src_addr.nl_family = AF_NETLINK;
src_addr.nl_pid = getpid(); /* self pid */
src_addr.nl_groups = 0; /* not in mcast groups */
bind(sock_fd, (struct sockaddr*)&src_addr, sizeof(src_addr));
memset(&dest_addr, 0, sizeof(dest_addr));
dest_addr.nl_family = AF_NETLINK;
dest_addr.nl_pid = 0; /* For Linux Kernel */
dest_addr.nl_groups = 0; /* unicast */
nlh=(struct nlmsghdr *)malloc(NLMSG_SPACE(MAX_PAYLOAD));
/* Fill the netlink message header */
nlh->nlmsg_len = NLMSG_SPACE(MAX_PAYLOAD);
nlh->nlmsg_pid = getpid(); /* self pid */
nlh->nlmsg_flags = 0;
/* Fill in the netlink message payload */
strcpy(NLMSG_DATA(nlh), "Hello you!");
iov.iov_base = (void *)nlh;
iov.iov_len = nlh->nlmsg_len;
msg.msg_name = (void *)&dest_addr;
msg.msg_namelen = sizeof(dest_addr);
msg.msg_iov = &iov;
msg.msg_iovlen = 1;
printf(" Sending message. ...\n");
sendmsg(sock_fd, &msg, 0);
/* Read message from kernel */
memset(nlh, 0, NLMSG_SPACE(MAX_PAYLOAD));
printf(" Waiting message. ...\n");
recvmsg(sock_fd, &msg, 0);
printf(" Received message payload: %s\n",
NLMSG_DATA(nlh));
/* Close Netlink Socket */
close(sock_fd);
}
开发者ID:jencce,项目名称:stuff,代码行数:42,代码来源:sender.c
示例2: sample_input
void sample_input (struct sk_buff *__skb)
{
struct sk_buff *skb;
struct nlmsghdr *nlh;
unsigned int pid;
int rc;
int len = NLMSG_SPACE(1200);
char data[100];
int dlen=0;
skb = skb_get(__skb);
if (skb->len >= NLMSG_SPACE(0))
{
nlh = nlmsg_hdr(skb);
dlen= nlh->nlmsg_len;
pid = nlh->nlmsg_pid;/*发送进程ID */
if(dlen>100)dlen=100;
memset(data,0,100);
memcpy(data,NLMSG_DATA(nlh),dlen);
printk("net_link: recv '%s' from process %d.\n",data,pid);
kfree_skb(skb);
skb = alloc_skb(len, GFP_ATOMIC);
if (!skb)
{
printk("net_link: alloc_skb failed.\n");
return;
}
nlh = nlmsg_put(skb,0,0,0,1200,0);
nlh ->nlmsg_len=dlen;
NETLINK_CB(skb).pid = 0;/* 发自内核*/
memcpy(NLMSG_DATA(nlh), data, strlen(data));
rc = netlink_unicast(nl_sk, skb, pid, MSG_DONTWAIT);
if (rc < 0)
{
printk("net_link: unicast skb error\n");
}
printk("net_link: send '%s' to process %d ok.\n",data,pid);
}
return;
}
开发者ID:gatieme,项目名称:LDD-LinuxDeviceDrivers,代码行数:42,代码来源:netlink.c
示例3: netlink_test_compute
int netlink_test_compute(int fd, struct sockaddr_nl *daddr)
{
int res;
char buf[40];
int *ptr;
int addr_len = sizeof(struct sockaddr_nl);
struct nlmsghdr *nlh;
nlh = (struct nlmsghdr *)malloc(NLMSG_SPACE(12));
if (!nlh) {
printf("malloc() error.\n");
return -1;
}
nlh->nlmsg_type = NLMSG_TEST_COMPUTE;
nlh->nlmsg_flags = NLM_F_REQUEST;
nlh->nlmsg_seq = 2;
nlh->nlmsg_pid = getpid();
ptr = NLMSG_DATA(nlh);
*ptr++ = NLMSG_TEST_COMPUTE_ADD;
*ptr++ = 3;
*ptr = 5;
nlh->nlmsg_len = NLMSG_LENGTH(12);
res = sendto(fd, nlh, NLMSG_SPACE(12), 0, (struct sockaddr *)daddr, addr_len);
if (res == -1) {
printf("sendto() error.\n");
goto error;
}
memset(buf, 0, 40);
res = recvfrom(fd, buf, 40, 0, (struct sockaddr *)daddr, &addr_len);
if (res == -1) {
printf("recvfrom() error.\n");
goto error;
}
ptr = NLMSG_DATA((struct nlmsghdr *)buf);
printf("3 + 5 = %d\n", *ptr);
error:
free(nlh);
return res;
}
开发者ID:tianqiu,项目名称:c,代码行数:42,代码来源:test_netlink_user.c
示例4: nl_send_unicast_message
static void nl_send_unicast_message(int dst_pid)
{
struct sk_buff *skb = NULL;
struct nlmsghdr *nlh = NULL;
int err;
int bt_state;
unsigned long flags;
dev_info(shm_dev->dev, "Sending unicast message\n");
/* prepare the NL message for unicast */
skb = alloc_skb(NLMSG_SPACE(MAX_PAYLOAD), GFP_KERNEL);
if (!skb) {
dev_err(shm_dev->dev, "%s:alloc_skb failed\n", __func__);
return;
}
nlh = (struct nlmsghdr *)skb->data;
nlh->nlmsg_len = NLMSG_SPACE(MAX_PAYLOAD);
dev_dbg(shm_dev->dev, "nlh->nlmsg_len = %d\n", nlh->nlmsg_len);
nlh->nlmsg_pid = 0; /* from kernel */
nlh->nlmsg_flags = 0;
spin_lock_irqsave(&boot_lock, flags);
bt_state = boot_state;
spin_unlock_irqrestore(&boot_lock, flags);
if (bt_state == BOOT_DONE)
*(int *)NLMSG_DATA(nlh) = SHRM_NL_STATUS_MOD_ONLINE;
else
*(int *)NLMSG_DATA(nlh) = SHRM_NL_STATUS_MOD_OFFLINE;
skb_put(skb, MAX_PAYLOAD);
/* sender is in group 1<<0 */
NETLINK_CB(skb).pid = 0; /* from kernel */
NETLINK_CB(skb).dst_group = 0;
/*unicast the message to the querying processes*/
err = netlink_unicast(shrm_nl_sk, skb, dst_pid, MSG_DONTWAIT);
dev_dbg(shm_dev->dev, "ret val from nl-unicast = %d\n", err);
}
开发者ID:CallMeVentus,项目名称:i9070_kernel_CoCore-P,代码行数:42,代码来源:shrm_protocol.c
示例5: print_ifinfomsg
static void
print_ifinfomsg(const unsigned int msg_len)
{
printf("{len=%u, type=RTM_GETLINK, flags=NLM_F_DUMP"
", seq=0, pid=0}, {ifi_family=AF_UNIX"
", ifi_type=ARPHRD_LOOPBACK"
", ifi_index=" IFINDEX_LO_STR
", ifi_flags=IFF_UP, ifi_change=0}"
", {{nla_len=%u, nla_type=IFLA_PORT_SELF}",
msg_len, msg_len - NLMSG_SPACE(hdrlen));
}
开发者ID:MIPS,项目名称:external-strace,代码行数:11,代码来源:nlattr_ifla_port.c
示例6: main
int main(int argc, char *argv[])
{
struct sockaddr_nl saddr, daddr;
struct nlmsghdr *nlhdr = NULL;
struct msghdr msg;
struct iovec iov;
int sd;
const char* text_line = "hello";
int ret = -1;
printf("pid: %d\n", getpid());
sd = socket(AF_NETLINK, SOCK_RAW, NETLINK_USERSOCK);
memset(&saddr, 0, sizeof(saddr));
memset(&daddr, 0, sizeof(daddr));
saddr.nl_family = AF_NETLINK;
saddr.nl_pid = getpid();
saddr.nl_groups = 0;
bind(sd, (struct sockaddr*)&saddr, sizeof(saddr));
daddr.nl_family = AF_NETLINK;
daddr.nl_pid = 0;
daddr.nl_groups = 0;
nlhdr = (struct nlmsghdr *)malloc(NLMSG_SPACE(1024));
memcpy(NLMSG_DATA(nlhdr), text_line, strlen(text_line));
memset(&msg, 0 ,sizeof(struct msghdr));
nlhdr->nlmsg_len = NLMSG_LENGTH(strlen(text_line));
nlhdr->nlmsg_pid = getpid(); /* self pid */
nlhdr->nlmsg_flags = 0;
iov.iov_base = (void *)nlhdr;
iov.iov_len = nlhdr->nlmsg_len;
msg.msg_name = (void *)&daddr;
msg.msg_namelen = sizeof(daddr);
msg.msg_iov = &iov;
msg.msg_iovlen = 1;
ret = sendmsg(sd, &msg, 0);
if (-1 == ret)
{
perror("sendmsg");
}
// msg.msg_name = (void *)&saddr;
// ret = recvmsg(sd, &msg, 0);
// if (ret == -1)
// {
// perror("recvmsg");
// }
close(sd);
}
开发者ID:lw1a2,项目名称:test,代码行数:54,代码来源:usermode_netlink.c
示例7: nfnl_check_attributes
int nfnl_check_attributes(const struct nfnl_handle *h,
const struct nlmsghdr *nlh,
struct nfattr *nfa[])
{
assert(h);
assert(nlh);
assert(nfa);
int min_len;
u_int8_t type = NFNL_MSG_TYPE(nlh->nlmsg_type);
u_int8_t subsys_id = NFNL_SUBSYS_ID(nlh->nlmsg_type);
const struct nfnl_subsys_handle *ssh;
struct nfnl_callback *cb;
if (subsys_id > NFNL_MAX_SUBSYS)
return -EINVAL;
ssh = &h->subsys[subsys_id];
cb = &ssh->cb[type];
#if 1
/* checks need to be enabled as soon as this is called from
* somebody else than __nfnl_handle_msg */
if (type >= ssh->cb_count)
return -EINVAL;
min_len = NLMSG_SPACE(sizeof(struct nfgenmsg));
if (nlh->nlmsg_len < min_len)
return -EINVAL;
#endif
memset(nfa, 0, sizeof(struct nfattr *) * cb->attr_count);
if (nlh->nlmsg_len > min_len) {
struct nfattr *attr = NFM_NFA(NLMSG_DATA(nlh));
int attrlen = nlh->nlmsg_len - NLMSG_ALIGN(min_len);
while (NFA_OK(attr, attrlen)) {
unsigned int flavor = NFA_TYPE(attr);
if (flavor) {
if (flavor > cb->attr_count) {
/* we have received an attribute from
* the kernel which we don't understand
* yet. We have to silently ignore this
* for the sake of future compatibility */
continue;
}
nfa[flavor - 1] = attr;
}
attr = NFA_NEXT(attr, attrlen);
}
}
return 0;
}
开发者ID:hrulez,项目名称:Actiontec-V1000H,代码行数:54,代码来源:libnfnetlink.c
示例8: netlink_send
void netlink_send(void)
{
struct sk_buff *skb;
struct nlmsghdr *nlh;
int a = strlen("Hi from the kernel");
int b = strlen("Test 2");
skb = alloc_skb(BUFFER, GFP_KERNEL);
nlh = (struct nlmsghdr *)skb_put(skb, NLMSG_SPACE(0));
nlh->nlmsg_flags = 0;
nlh->nlmsg_pid = 0;
nlh->nlmsg_seq = 0;
memcpy(skb_tail_pointer(skb), "Hi from the kernel", strlen("Hi from the kernel")+1);
skb_put(skb, strlen("Hi from the kernel"));
memcpy(skb_tail_pointer(skb), "Test 2", strlen("Test 2")+1);
skb_put(skb, strlen("Test 2"));
nlh->nlmsg_len = skb->len - NLMSG_SPACE(0);
printk(KERN_ALERT "a: %d b: %d skb->len: %d\n", a, b, skb->len - NLMSG_SPACE(0));
netlink_unicast(nl_sk, skb, nlk_pid, 0);
}
开发者ID:cor3ngine,项目名称:linuxopenbsm,代码行数:21,代码来源:netlink_test3.c
示例9: __event_send
/* event_mutex supposed to be held */
static int __event_send(const void *buf, int buf_len)
{
int res = 0, len;
struct sk_buff *skb;
struct nlmsghdr *nlh;
static u32 seq; /* protected by event_mutex */
TRACE_ENTRY();
if (ctr_open_state != ISCSI_CTR_OPEN_STATE_OPEN)
goto out;
len = NLMSG_SPACE(buf_len);
skb = alloc_skb(NLMSG_SPACE(len), GFP_KERNEL);
if (skb == NULL) {
PRINT_ERROR("alloc_skb() failed (len %d)", len);
res = -ENOMEM;
goto out;
}
nlh = __nlmsg_put(skb, iscsid_pid, seq++, NLMSG_DONE,
len - sizeof(*nlh), 0);
memcpy(NLMSG_DATA(nlh), buf, buf_len);
res = netlink_unicast(nl, skb, iscsid_pid, 0);
if (res <= 0) {
if (res != -ECONNREFUSED)
PRINT_ERROR("netlink_unicast() failed: %d", res);
else
TRACE(TRACE_MINOR, "netlink_unicast() failed: %s. "
"Not functioning user space?",
"Connection refused");
goto out;
}
out:
TRACE_EXIT_RES(res);
return res;
}
开发者ID:dmeister,项目名称:scst,代码行数:41,代码来源:event.c
示例10: main
int main(){
sock_fd = socket(PF_NETLINK, SOCK_RAW, NETLINK_USER);
if (sock_fd < 0){
return -1;
}
memset(&src_addr, 0, sizeof(src_addr));
src_addr.nl_family = AF_NETLINK;
src_addr.nl_pid = getpid();
bind(sock_fd, (struct sockaddr*)&src_addr, sizeof(src_addr));
memset(&dst_addr, 0, sizeof(dst_addr));
dst_addr.nl_family = AF_NETLINK;
dst_addr.nl_pid = 0;
dst_addr.nl_groups = 0;
nlh = (struct nlmsghdr*)malloc(NLMSG_SPACE(MAX_PAYLOAD));
memset(nlh, 0, NLMSG_SPACE(MAX_PAYLOAD));
nlh->nlmsg_len = NLMSG_SPACE(MAX_PAYLOAD);
nlh->nlmsg_pid = getpid();
nlh->nlmsg_flags = 0;
strcpy(NLMSG_DATA(nlh), "Hello");
iov.iov_base = (void*)nlh;
iov.iov_len = nlh->nlmsg_len;
msg.msg_name = (void*)&dst_addr;
msg.msg_namelen = sizeof(dst_addr);
msg.msg_iov = &iov;
msg.msg_iovlen = 1;
printf("Sending message to the kernel\n");
sendmsg(sock_fd, &msg, 0);
printf("Received message payload: %s\n", NLMSG_DATA(nlh));
close(sock_fd);
return 0;
}
开发者ID:sreesurendran,项目名称:NetlinkSockets,代码行数:40,代码来源:netlink_user.c
示例11: alloc_skb
/*
* Send Net Link interface ready indication to application daemon
* Each netlink message will have a message of type tAniMsgHdr inside.
*/
void nl_srv_nl_ready_indication
(
void
)
{
struct sk_buff *skb = NULL;
struct nlmsghdr *nlh;
int err;
skb = alloc_skb(NLMSG_SPACE(sizeof(driverLoaded)), GFP_KERNEL);
if (NULL == skb)
{
VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
"NLINK: skb alloc fail %s", __func__);
return;
}
nlh = (struct nlmsghdr *)skb->data;
nlh->nlmsg_pid = 0; /* from kernel */
nlh->nlmsg_flags = 0;
nlh->nlmsg_seq = 0;
nlh->nlmsg_len = sizeof(driverLoaded);
vos_mem_copy(((char *)nlh) + sizeof(struct nlmsghdr),
driverLoaded,
sizeof(driverLoaded));
skb_put(skb, NLMSG_SPACE(sizeof(driverLoaded)));
/* sender is in group 1<<0 */
NETLINK_CB(skb).dst_group = WLAN_NLINK_MCAST_GRP_ID;
/*multicast the message to all listening processes*/
err = netlink_broadcast(nl_srv_sock, skb, 0, 1, GFP_KERNEL);
if (err)
{
VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO_LOW,
"NLINK: Ready Indication Send Fail %s, err %d",
__func__, err);
}
return;
}
开发者ID:supercairos,项目名称:android_kernel_doro_msm8916_2,代码行数:44,代码来源:wlan_nlink_srv.c
示例12: initialize
static int initialize(int32_t sock_fd)
{
char *mesg = "Hello";
memset(&dest_addr, 0, sizeof(dest_addr));
dest_addr.nl_family = AF_NETLINK;
dest_addr.nl_pid = 0; /* For Linux Kernel */
dest_addr.nl_groups = 0; /* unicast */
if (nlh) {
free(nlh);
nlh = NULL;
}
nlh = (struct nlmsghdr *)malloc(NLMSG_SPACE(MAX_MSG_SIZE));
if (nlh == NULL) {
fprintf(stderr, "Cannot allocate memory \n");
close(sock_fd);
return -1;
}
memset(nlh, 0, NLMSG_SPACE(MAX_MSG_SIZE));
nlh->nlmsg_len = NLMSG_SPACE(MAX_MSG_SIZE);
nlh->nlmsg_pid = getpid();
nlh->nlmsg_type = WLAN_NL_MSG_CNSS_DIAG;
nlh->nlmsg_flags = NLM_F_REQUEST;
memcpy(NLMSG_DATA(nlh), mesg, strlen(mesg));
iov.iov_base = (void *)nlh;
iov.iov_len = nlh->nlmsg_len;
msg.msg_name = (void *)&dest_addr;
msg.msg_namelen = sizeof(dest_addr);
msg.msg_iov = &iov;
msg.msg_iovlen = 1;
if (sendmsg(sock_fd, &msg, 0) < 0) {
android_printf("%s error ", __func__);
return -1;
}
return 1;
}
开发者ID:handelxh,项目名称:ONEPLUS2RAZOR,代码行数:40,代码来源:cld-fwlog-netlink.c
示例13: kget_host_stats
static int kget_host_stats(uint64_t transport_handle, uint32_t host_no,
char *host_stats)
{
int rc = 0;
int ev_size;
struct iscsi_uevent ev;
struct iovec iov[2];
char nlm_ev[NLMSG_SPACE(sizeof(struct iscsi_uevent))];
struct nlmsghdr *nlh;
memset(&ev, 0, sizeof(struct iscsi_uevent));
ev.type = ISCSI_UEVENT_GET_HOST_STATS;
ev.transport_handle = transport_handle;
ev.u.get_host_stats.host_no = host_no;
iov[1].iov_base = &ev;
iov[1].iov_len = sizeof(ev);
rc = __kipc_call(iov, 2);
if (rc < 0)
return rc;
if ((rc = nl_read(ctrl_fd, nlm_ev,
NLMSG_SPACE(sizeof(struct iscsi_uevent)),
MSG_PEEK)) < 0) {
log_error("can not read nlm_ev, error %d", rc);
return rc;
}
nlh = (struct nlmsghdr *)nlm_ev;
ev_size = nlh->nlmsg_len - NLMSG_ALIGN(sizeof(struct nlmsghdr));
if ((rc = nlpayload_read(ctrl_fd, (void *)host_stats,
ev_size, 0)) < 0) {
log_error("can not read from NL socket, error %d", rc);
return rc;
}
return rc;
}
开发者ID:cleech,项目名称:open-iscsi,代码行数:40,代码来源:netlink.c
示例14: send_unicast
static void send_unicast(int dst_pid)
{
struct sk_buff *skb;
struct nlmsghdr *nlh;
if (netlink_sk == NULL) {
pr_err("could not send unicast, no socket\n");
return;
}
/* prepare the message for unicast */
skb = alloc_skb(NLMSG_SPACE(MAX_PAYLOAD), GFP_KERNEL);
if (!skb) {
pr_err("failed to allocate socket buffer\n");
return;
}
nlh = (struct nlmsghdr *)skb->data;
nlh->nlmsg_len = NLMSG_SPACE(MAX_PAYLOAD);
nlh->nlmsg_pid = 0; /* from kernel */
nlh->nlmsg_flags = 0;
if (modem_m6718_spi_is_boot_done()) {
pr_debug("sending netlink unicast message %d\n",
NETLINK_MODEM_STATUS_ONLINE);
*(int *)NLMSG_DATA(nlh) = NETLINK_MODEM_STATUS_ONLINE;
} else {
pr_debug("sending netlink unicast message %d\n",
NETLINK_MODEM_STATUS_OFFLINE);
*(int *)NLMSG_DATA(nlh) = NETLINK_MODEM_STATUS_OFFLINE;
}
skb_put(skb, MAX_PAYLOAD);
/* sender is in group 1<<0 */
NETLINK_CB(skb).pid = 0; /* from kernel */
NETLINK_CB(skb).dst_group = 0;
/* unicast the message to the querying process */
netlink_unicast(netlink_sk, skb, dst_pid, MSG_DONTWAIT);
}
开发者ID:1N4148,项目名称:android_kernel_samsung_golden,代码行数:40,代码来源:netlink.c
示例15: quota2_log
static void quota2_log(unsigned int hooknum,
const struct sk_buff *skb,
const struct net_device *in,
const struct net_device *out,
const char *prefix)
{
ulog_packet_msg_t *pm;
struct sk_buff *log_skb;
size_t size;
struct nlmsghdr *nlh;
if (!qlog_nl_event)
return;
size = NLMSG_SPACE(sizeof(*pm));
size = max(size, (size_t)NLMSG_GOODSIZE);
log_skb = alloc_skb(size, GFP_ATOMIC);
if (!log_skb) {
pr_err("xt_quota2: cannot alloc skb for logging\n");
return;
}
nlh = nlmsg_put(log_skb, /*pid*/0, /*seq*/0, qlog_nl_event,
sizeof(*pm), 0);
if (!nlh) {
pr_err("xt_quota2: nlmsg_put failed\n");
kfree_skb(log_skb);
return;
}
pm = nlmsg_data(nlh);
if (skb->tstamp.tv64 == 0)
__net_timestamp((struct sk_buff *)skb);
pm->data_len = 0;
pm->hook = hooknum;
if (prefix != NULL)
strlcpy(pm->prefix, prefix, sizeof(pm->prefix));
else
*(pm->prefix) = '\0';
if (in)
strlcpy(pm->indev_name, in->name, sizeof(pm->indev_name));
else
pm->indev_name[0] = '\0';
if (out)
strlcpy(pm->outdev_name, out->name, sizeof(pm->outdev_name));
else
pm->outdev_name[0] = '\0';
NETLINK_CB(log_skb).dst_group = 1;
pr_debug("throwing 1 packets to netlink group 1\n");
netlink_broadcast(nflognl, log_skb, 0, 1, GFP_ATOMIC);
}
开发者ID:AICP,项目名称:kernel_moto_shamu,代码行数:52,代码来源:xt_quota2.c
示例16: _do_command
int _do_command(int type, struct user_stat_msg * request)
{
int sock;
struct sockaddr_nl remote;
struct sockaddr_nl local;
struct nlmsghdr * nlhdr;
struct iovec iov;
struct msghdr msg;
sock = socket(PF_NETLINK, SOCK_RAW, NETLINK_ACCOUNT);
if(sock < 0){
return -1;
}
memset(&local, 0, sizeof(struct sockaddr_nl));
local.nl_family = AF_NETLINK;
local.nl_pid = getpid();
local.nl_groups = 0;
if(bind(sock, (struct sockaddr*)&local, sizeof(struct sockaddr_nl)) != 0){
close(sock);
return -1;
}
memset(&remote, 0, sizeof(struct sockaddr_nl));
remote.nl_family = AF_NETLINK;
remote.nl_pid = 0;
remote.nl_groups = 0;
memset(&msg, 0, sizeof(struct msghdr));
nlhdr = (struct nlmsghdr *)malloc(NLMSG_SPACE(sizeof(struct user_stat_entry) * 1024));
memcpy(NLMSG_DATA(nlhdr), (char *)request, sizeof(struct user_stat_msg));
nlhdr->nlmsg_len = NLMSG_LENGTH(sizeof(struct user_stat_msg));
nlhdr->nlmsg_pid = getpid(); /* self pid */
nlhdr->nlmsg_flags = NLM_F_REQUEST;
nlhdr->nlmsg_type = type;
iov.iov_base = (void *)nlhdr;
iov.iov_len = nlhdr->nlmsg_len;
msg.msg_name = (void *)&remote;
msg.msg_namelen = sizeof(remote);
msg.msg_iov = &iov;
msg.msg_iovlen = 1;
int ret = sendmsg(sock, &msg, 0);
if (ret == -1) {
return -1;
}
free(nlhdr);
return sock;
}
开发者ID:wfqGithubHome,项目名称:dailycode,代码行数:52,代码来源:flowstat.c
示例17: wlan_logging_srv_nl_ready_indication
/*
* Broadcast Logging service ready indication to any Logging application
* Each netlink message will have a message of type tAniMsgHdr inside.
*/
void wlan_logging_srv_nl_ready_indication(void)
{
struct sk_buff *skb = NULL;
struct nlmsghdr *nlh;
tAniNlHdr *wnl = NULL;
int payload_len;
int err;
static int rate_limit;
payload_len = sizeof(tAniHdr) + sizeof(wlan_logging_ready) +
sizeof(wnl->radio);
skb = dev_alloc_skb(NLMSG_SPACE(payload_len));
if (NULL == skb) {
if (!rate_limit) {
LOGGING_TRACE(VOS_TRACE_LEVEL_ERROR,
"NLINK: skb alloc fail %s", __func__);
}
rate_limit = 1;
return;
}
rate_limit = 0;
nlh = nlmsg_put(skb, 0, 0, ANI_NL_MSG_LOG, payload_len,
NLM_F_REQUEST);
if (NULL == nlh) {
LOGGING_TRACE(VOS_TRACE_LEVEL_ERROR,
"%s: nlmsg_put() failed for msg size[%d]",
__func__, payload_len);
kfree_skb(skb);
return;
}
wnl = (tAniNlHdr *) nlh;
wnl->radio = 0;
wnl->wmsg.type = ANI_NL_MSG_READY_IND_TYPE;
wnl->wmsg.length = sizeof(wlan_logging_ready);
memcpy((char*)&wnl->wmsg + sizeof(tAniHdr),
wlan_logging_ready,
sizeof(wlan_logging_ready));
/* sender is in group 1<<0 */
NETLINK_CB(skb).dst_group = WLAN_NLINK_MCAST_GRP_ID;
/*multicast the message to all listening processes*/
err = nl_srv_bcast(skb);
if (err) {
LOGGING_TRACE(VOS_TRACE_LEVEL_INFO_LOW,
"NLINK: Ready Indication Send Fail %s, err %d",
__func__, err);
}
return;
}
开发者ID:Defector,项目名称:Defkernel_F320,代码行数:56,代码来源:wlan_logging_sock_svc.c
示例18: nfnetlink_rcv_msg
/* Process one complete nfnetlink message. */
static int nfnetlink_rcv_msg(struct sk_buff *skb, struct nlmsghdr *nlh)
{
const struct nfnl_callback *nc;
const struct nfnetlink_subsystem *ss;
int type, err;
if (security_netlink_recv(skb, CAP_NET_ADMIN))
return -EPERM;
if (provenance_netlink_recv(skb, CAP_NET_ADMIN))
return -EPERM;
/* All the messages must at least contain nfgenmsg */
if (nlh->nlmsg_len < NLMSG_LENGTH(sizeof(struct nfgenmsg)))
return 0;
type = nlh->nlmsg_type;
replay:
ss = nfnetlink_get_subsys(type);
if (!ss) {
#ifdef CONFIG_MODULES
nfnl_unlock();
request_module("nfnetlink-subsys-%d", NFNL_SUBSYS_ID(type));
nfnl_lock();
ss = nfnetlink_get_subsys(type);
if (!ss)
#endif
return -EINVAL;
}
nc = nfnetlink_find_client(type, ss);
if (!nc)
return -EINVAL;
{
int min_len = NLMSG_SPACE(sizeof(struct nfgenmsg));
u_int8_t cb_id = NFNL_MSG_TYPE(nlh->nlmsg_type);
struct nlattr *cda[ss->cb[cb_id].attr_count + 1];
struct nlattr *attr = (void *)nlh + min_len;
int attrlen = nlh->nlmsg_len - min_len;
err = nla_parse(cda, ss->cb[cb_id].attr_count,
attr, attrlen, ss->cb[cb_id].policy);
if (err < 0)
return err;
err = nc->call(nfnl, skb, nlh, (const struct nlattr **)cda);
if (err == -EAGAIN)
goto replay;
return err;
}
}
开发者ID:daveti,项目名称:prov-kernel,代码行数:53,代码来源:nfnetlink.c
示例19: main
int
main(void)
{
skip_if_unavailable("/proc/self/fd/");
const int fd = create_nl_socket(NETLINK_ROUTE);
const unsigned int hdrlen = sizeof(struct ndmsg);
void *nlh0 = midtail_alloc(NLMSG_SPACE(hdrlen),
NLA_HDRLEN + sizeof(struct nda_cacheinfo));
static char pattern[4096];
fill_memory_ex(pattern, sizeof(pattern), 'a', 'z' - 'a' + 1);
const unsigned int nla_type = 0xffff & NLA_TYPE_MASK;
char nla_type_str[256];
sprintf(nla_type_str, "%#x /* NDA_??? */", nla_type);
TEST_NLATTR_(fd, nlh0, hdrlen,
init_ndmsg, print_ndmsg,
nla_type, nla_type_str,
4, pattern, 4,
print_quoted_hex(pattern, 4));
TEST_NLATTR(fd, nlh0, hdrlen,
init_ndmsg, print_ndmsg,
NDA_DST, 4, pattern, 4,
print_quoted_hex(pattern, 4));
static const struct nda_cacheinfo ci = {
.ndm_confirmed = 0xabcdedad,
.ndm_used = 0xbcdaedad,
.ndm_updated = 0xcdbadeda,
.ndm_refcnt = 0xdeadbeda
};
TEST_NLATTR_OBJECT(fd, nlh0, hdrlen,
init_ndmsg, print_ndmsg,
NDA_CACHEINFO, pattern, ci,
PRINT_FIELD_U("{", ci, ndm_confirmed);
PRINT_FIELD_U(", ", ci, ndm_used);
PRINT_FIELD_U(", ", ci, ndm_updated);
PRINT_FIELD_U(", ", ci, ndm_refcnt);
printf("}"));
const uint16_t port = 0xabcd;
TEST_NLATTR_OBJECT(fd, nlh0, hdrlen,
init_ndmsg, print_ndmsg,
NDA_PORT, pattern, port,
printf("htons(%u)", ntohs(port)));
puts("+++ exited with 0 +++");
return 0;
}
开发者ID:android,项目名称:platform_external_strace,代码行数:52,代码来源:nlattr_ndmsg.c
示例20: send_event
void send_event(int sock, char *buffer)
{
struct sockaddr_nl nladdr;
struct msghdr msg;
struct iovec iov;
struct nlmsghdr *nlh = NULL;
int buflen = NLMSG_SPACE(strlen(buffer) + 1);
memset(&msg, 0, sizeof(msg));
memset(&nlh, 0, sizeof(nlh));
memset(&nladdr, 0, sizeof(nladdr));
memset(&nladdr, 0, sizeof(nladdr));
nladdr.nl_family = AF_NETLINK;
nladdr.nl_pid = 0; /* 0 = send to Linux kernel */
nladdr.nl_groups = 0; /* 0 = unicast */
nlh = (struct nlmsghdr *)malloc(buflen);
nlh->nlmsg_len = NLMSG_SPACE(buflen);
nlh->nlmsg_pid = getpid();
nlh->nlmsg_flags = 0;
strcpy(NLMSG_DATA(nlh), buffer);
iov.iov_base = (void *)nlh;
iov.iov_len = nlh->nlmsg_len;
msg.msg_name = (void *) &(nladdr);
msg.msg_namelen = sizeof(nladdr);
msg.msg_iov = &iov;
msg.msg_iovlen = 1;
if (DEBUG)
printf("sending...\n");
sendmsg(sock, &msg, 0);
return;
}
开发者ID:LucaBongiorni,项目名称:LAF,代码行数:39,代码来源:laffun.c
注:本文中的NLMSG_SPACE函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论