Connecting Tech Pros Worldwide Help | Site Map

Comp. Error : request for member 'dst_group' in something not a structure or union

  #1  
Old July 3rd, 2008, 07:48 AM
Newbie
 
Join Date: Jul 2008
Location: Bangalore,India
Posts: 15
I have writtem kernel(2.4) module to commu. with user space appl. using netlink socket. I am getting compilation error.

kernel module:->


#include <linux/skbuff.h>
#include<linux/module.h>

#include <linux/socket.h>
#include <linux/config.h>
#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/init.h>
#include <linux/errno.h>
#include <linux/string.h>
#include <linux/stat.h>
#include <linux/netdevice.h>
#include <linux/netlink.h>
#include <linux/types.h>
#include <linux/capability.h>



#define MAX_PAYLOAD 1024

MODULE_LICENSE("GPL");
MODULE_AUTHOR("Test");
MODULE_DESCRIPTION("Testing Kernel/User socket");

//static int debug=0;

//module_param(debug,int ,0);
MODULE_PARM_DESC(debug,"Debug Information(default 0)");


static struct sock *nl_sk=NULL;

static nl_data_ready(struct sock *sk,int len)
{


struct sk_buff *skb=NULL;
struct nlmsghdr *nlh=NULL;
int err;
int pid;


printk("Netlink Socket is Ready\n");
printk("Received Data from User Space Application\n");
printk("Waiting .....\n");
skb = skb_recv_datagram(nl_sk,0,0,&err);
if(skb == NULL)
{
printk("Not Received Any data\n");
}
else
{
nlh =(struct nlmsghdr *)(skb->data);
printk("Kernel Received Message %s\n",NLMSG_DATA(nlh));


strcpy(NLMSG_DATA(nlh),"Its Kernel");
pid = nlh->nlmsg_pid;
skb->cb;
(*(struct netlink_skb_parm*)&((skb)->cb)).pid =0;
NETLINK_CB(skb).dst_groups;
NETLINK_CB(skb).groups = 0;
NETLINK_CB(skb).pid = pid;
//NETLINK_CB(skb).dst_groups = 0;

netlink_unicast(nl_sk,skb,pid,MSG_DONTWAIT);

}


// sock_release(nl_sk->sk_socket);
}
static void netlink_test()
{
int err;
int pid;

nl_sk = netlink_kernel_create(18,nl_data_ready);
if(nl_sk < 0)
{
printk("Socket Creation fails\n");
}
else
printk("Netlink socket created\n");



}
static int netsocket_init(void)
{
printk("Intializing netlink socket\n");
netlink_test();
return 0;
}
void netsocket_exit(void)
{
printk("Good Bye\n");
}
module_init(netsocket_init);
module_exit(netsocket_exit);

When i compile above module. it throw following errors:


..request for member 'dst_groups' in something not a structure or union
..request for member 'groups' in something not a structure or union
..request for member 'pid' in something not a structure or union
..request for member 'dst_groups' in something not a structure or union


plz help me

--
Shashidhara
  #2  
Old July 3rd, 2008, 04:24 PM
Moderator
 
Join Date: Mar 2007
Location: North Bend Washington USA
Posts: 5,340

re: Comp. Error : request for member 'dst_group' in something not a structure or union


This code:
Expand|Select|Wrap|Line Numbers
  1. NETLINK_CB(skb).dst_groups;
  2.  
This code looks like a call to a function named NETLINK_CB using skb as an argument. This is not a structure or union and is probably wehy you aere getting

..request for member 'dst_groups' in something not a structure or union

from your compiler.

Or NETLINK_CB is a macro expanded with skb. But that isn't a structure or union either.

What is it you are trying to do?
  #3  
Old July 3rd, 2008, 05:05 PM
Expert
 
Join Date: Sep 2007
Posts: 857

re: Comp. Error : request for member 'dst_group' in something not a structure or union


A quick Google search tells me that NETLINK_CB is supposed to return some sort of struct. Perhaps your input was not properly initialized, so null was returned instead?

EDIT: This is a compilation error, not a runtime error...the link will still likely be useful, though.
  #4  
Old July 3rd, 2008, 05:19 PM
Moderator
 
Join Date: Mar 2007
Location: North Bend Washington USA
Posts: 5,340

re: Comp. Error : request for member 'dst_group' in something not a structure or union


Yes, I should have used Google.

This is NETLINK_CB:
Expand|Select|Wrap|Line Numbers
  1. #define NETLINK_CB  (  skb    )     (*(struct netlink_skb_parms*)&((skb)->cb)) 
  2.  
That makes NETLINK_CB a macro. You can see that it is skb that is the struct or union.

The macro takes the address of the cb member of skb, typecasts it as a netlink_skb_parms pointer and then de-references it. That should yield a netlink_skb_parms variable, which is a struct and should have members.

It now appears the compiler does not know what netlink_skb_parms is or that the skb that is used is not struct or union.

That's the problem with these macros. You can't tell what the preprocessor did.

I suggest you stop your build after the translation unit has been completed and look to see how the macro was expanded. Then you will have your answer.
  #5  
Old July 4th, 2008, 06:27 AM
Newbie
 
Join Date: Jul 2008
Location: Bangalore,India
Posts: 15

re: Comp. Error : request for member 'dst_group' in something not a structure or union


Just i have added #define __KERNEL__ line in the kernel module, Its working.

Because "netlink_skb_parms" structure and NETLINLK_CB are defined in
"netlink.h" .

#ifdef __KERNEL__

netlink_skb_parm str defn.

NETLINK_CB(skb) ......
.....
.....
#endif /*__KERNEL__ */

Thanks for u r reply.

--shashidhara
Reply