LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 01-04-2007, 08:37 AM   #1
nandac
LQ Newbie
 
Registered: Oct 2006
Posts: 16

Rep: Reputation: 0
Thumbs up 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
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
FC4: Error creating netlink socket jakubi Fedora 3 07-10-2006 12:29 PM
NETLINK SOCKET Error thegreatest Programming 2 12-14-2005 11:06 PM
'RT netlink socket initialing problem' menaka Linux - Hardware 3 02-22-2005 03:35 AM
netlink routing socket to observe interface changes trotters78 Programming 2 11-29-2004 06:13 PM
boot hangs at "Initializing RT netlink socket" CraigG Red Hat 0 12-24-2003 10:51 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 05:40 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration