Netlink socket issue?
Hi All,
I am using netlink socket for the first time.
I have a kernel module that send a message on netlink a synchronously.
I am able to open the socket in Application, and even my netlink socket become readable when data arrived on it, but i am not able to correctly retrieved that data.
Please provide some help, it would be very helpfull
**************
sample code:
**********
Kernel code::
**************
{
SAdetResponseMsg resp;
resp.num = 10;
skb = alloc_skb(sizeof(SAdetResponseMsg), GFP_KERNEL);
pos = skb_put(skb,sizeof(SAdetResponseMsg));
memcpy(pos, &resp, sizeof(SAdetResponseMsg));
NETLINK_CB(skb).groups = 0;
NETLINK_CB(skb).pid = 0;
NETLINK_CB(skb).dst_pid = g_Tid;
NETLINK_CB(skb).dst_groups = 0;
netlink_unicast(nl_sk, skb, g_AdetTid, MSG_DONTWAIT);
}
************************************
corresponding user space code::
**********************************
{
struct sockaddr_nl nladdr;
struct msghdr msg;
struct iovec iov;
struct nlmsghdr* nlh;
int ret;
memset(&nladdr, 0 , sizeof(nladdr));
nlh = (struct ghdr*)malloc(NLMSG_SPACE(sizeof(SAdetResponseMsg)));
memset(nlh, 0, NLMSG_SPACE(sizeof(SAdetResponseMsg)));
iov.iov_base = (void*)nlh;
iov.iov_len = NLMSG_SPACE(sizeof(SAdetResponseMsg));
msg.msg_name = (void*)&nladdr;
msg.msg_namelen = sizeof(nladdr);
msg.msg_iov = &iov;
msg.msg_iovlen = 1;
ret = recvmsg(sock, &msg, 0);
if (ret < 0)
{
return ret;
}
SAdetResponseMsg *resp = (SAdetResponseMsg*)NLMSG_DATA(nlh);
if(resp == NULL)
{
printf("\n%d %s: Fails to recieved data from the kernel application \n",__LINE__,__FUNCTION__);
}
printf("\n Number = %d\n", resp->num); <-- This number comes out to be different from what I have passed -->
return 0;
}
please provide help if you can ...
thanks
nandac
|