Thank you Jonathan for the advice, as it does help solved the problem of sending 0 bytes. Think it's the problem of having missed shifting skb->tail to point to the end of the data. Thank you once again. cheers Chiang -----Original Message----- From: Jonathan Khoo [mailto:khoohuit@xxxxxxxxx] Sent: Thursday, July 21, 2005 10:30 PM To: Tan, Chiang Kang Cc: kernelnewbies@xxxxxxxxxxxx Subject: Re: Using netlink for kernel -> userspace communication Hi, How about adding these lines... len is the length of your data.. skb->len = sizeof(struct nlmsghdr) + len; skb->tail = skb->data + skb->len; skb->truesize = skb->len; netlink_unicast (nl_sk, skb, pid, MSG_DONTWAIT); On 7/20/05, Tan, Chiang Kang <Chiang.Tan@xxxxxxxxxxxxxxx> wrote: > Hi all, > Actually I have this problem, which is more fundamental really. I > wanted to create a new message to send to the userspace. However everytime > I try to do so, using netlink_unicast, 0 bytes is sent. The listening > userspace application (using recvmsg) confirms that 0 bytes is received, > so I think a message IS sent from the kernel, but I don't understand why > I'm unable to send the entire message properly. Below is the code > > skb_nl = alloc_skb(NLMSG_SPACE(MAX_PAYLOAD), GFP_ATOMIC); > > if (skb_nl == NULL) { > printk("%s: skb allocation fails!\n", __FUNCTION__); > goto out; > } > > nlh = (struct nlmsghdr *)skb_nl->data; > > /* Fill in the netlink message header */ > nlh->nlmsg_len = NLMSG_SPACE(MAX_PAYLOAD); > nlh->nlmsg_pid = 0; > nlh->nlmsg_flags = 0; > /* Fill in the netlink message payload */ > strcpy(NLMSG_DATA(nlh), "Greeting from kernel!"); > > NETLINK_CB(skb_nl).groups = 0; /* not in mcast group */ > NETLINK_CB(skb_nl).pid = 0; /* from kernel */ > NETLINK_CB(skb_nl).dst_pid = nlq_pid; /* pid of userspace process */ > NETLINK_CB(skb_nl).dst_groups = 0; /* unicast */ > > err = netlink_unicast(nl_sk, skb_nl, nlq_pid, MSG_DONTWAIT); > > I really do hope someone can shed some light from this problem. > Thank you in advanced. > > cheers > Chiang > > -- > Kernelnewbies: Help each other learn about the Linux kernel. > Archive: http://mail.nl.linux.org/kernelnewbies/ > FAQ: http://kernelnewbies.org/faq/ > > -- cheers, jonathan khoo -- Kernelnewbies: Help each other learn about the Linux kernel. Archive: http://mail.nl.linux.org/kernelnewbies/ FAQ: http://kernelnewbies.org/faq/