467,885 Members | 1,270 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 467,885 developers. It's quick & easy.

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

I have writtem kernel(2.4) module to commu. with user space appl. using netlink socket. I am getting compilation error.
kernel module:->

Expand|Select|Wrap|Line Numbers
  1. #include <linux/skbuff.h>
  2. #include<linux/module.h>
  3.  
  4. #include <linux/socket.h>
  5. #include <linux/config.h>
  6. #include <linux/module.h>
  7. #include <linux/kernel.h>
  8. #include <linux/init.h>
  9. #include <linux/errno.h>
  10. #include <linux/string.h>
  11. #include <linux/stat.h>
  12. #include <linux/netdevice.h>
  13. #include <linux/netlink.h>
  14. #include <linux/types.h>
  15. #include <linux/capability.h>
  16.  
  17.  
  18.  
  19. #define MAX_PAYLOAD 1024
  20.  
  21. MODULE_LICENSE("GPL");
  22. MODULE_AUTHOR("Test");
  23. MODULE_DESCRIPTION("Testing Kernel/User socket");
  24.  
  25. //static int debug=0;
  26.  
  27. //module_param(debug,int ,0);
  28. MODULE_PARM_DESC(debug,"Debug Information(default 0)");
  29.  
  30.  
  31. static struct sock *nl_sk=NULL;
  32.  
  33. static nl_data_ready(struct sock *sk,int len)
  34. {
  35.  
  36.  
  37.     struct sk_buff *skb=NULL;
  38.     struct nlmsghdr *nlh=NULL;
  39.     int err;
  40.     int pid;
  41.  
  42.  
  43.     printk("Netlink Socket is Ready\n");
  44.     printk("Received Data from User Space Application\n");
  45.     printk("Waiting  .....\n");
  46.   skb = skb_recv_datagram(nl_sk,0,0,&err);
  47.     if(skb == NULL)
  48.     {
  49.         printk("Not Received Any data\n");
  50.     }
  51.     else
  52.     {
  53.         nlh =(struct nlmsghdr *)(skb->data);
  54.         printk("Kernel Received Message %s\n",NLMSG_DATA(nlh));
  55.  
  56.  
  57.         strcpy(NLMSG_DATA(nlh),"Its Kernel");
  58.             pid = nlh->nlmsg_pid;
  59.             skb->cb;
  60.             (*(struct netlink_skb_parm*)&((skb)->cb)).pid =0;
  61.             NETLINK_CB(skb).dst_groups;
  62.             NETLINK_CB(skb).groups = 0;
  63.             NETLINK_CB(skb).pid = pid;
  64.             //NETLINK_CB(skb).dst_groups = 0;
  65.  
  66.         netlink_unicast(nl_sk,skb,pid,MSG_DONTWAIT);
  67.  
  68.     }
  69.  
  70.  
  71. //  sock_release(nl_sk->sk_socket);
  72. }
  73. static void netlink_test()
  74. {
  75.     int err;
  76.     int pid;
  77.  
  78.     nl_sk = netlink_kernel_create(18,nl_data_ready);
  79.     if(nl_sk < 0)
  80.     {
  81.         printk("Socket Creation fails\n");
  82.     }
  83.     else
  84.     printk("Netlink socket created\n");
  85.  
  86.  
  87.  
  88. }
  89. static int netsocket_init(void)
  90. {
  91.     printk("Intializing netlink socket\n");
  92.     netlink_test();
  93.     return 0;
  94. }
  95. void netsocket_exit(void)
  96. {
  97.  printk("Good Bye\n");
  98. }
  99. module_init(netsocket_init);
  100. module_exit(netsocket_exit);
  101.  
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
Jul 3 '08 #1
  • viewed: 5948
Share:
5 Replies
weaknessforcats
Expert Mod 8TB
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?
Jul 3 '08 #2
Expert 512MB
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.
Jul 3 '08 #3
weaknessforcats
Expert Mod 8TB
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.
Jul 3 '08 #4
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
Jul 4 '08 #5
Hi,
I'm a netlink newbie developing a kernel module (as stated above) for 2.6.x kernels.
I'm simply truing to pass a(any) message between the user space and the kernel.

The changes to the netlink APIs from kernel to kernel are confusing.
Below is my kernel code:
Expand|Select|Wrap|Line Numbers
  1. #include
  2. #include
  3. #include
  4. #include
  5. #include
  6. #include
  7. #include
  8. #include
  9. #include
  10.  
  11. #define NETLINK_TEST 17
  12. #define VFW_GROUP 0
  13. #define MSG_SIZE NLMSG_SPACE(1024)
  14.  
  15. static struct sock *nl_sk = NULL;
  16.  
  17. static void nltest_rcv(struct sock *sk, int len)
  18. {
  19. struct sk_buff *nl_skb;
  20. struct nlmsghdr *nl_hdr;
  21. int pid;
  22. while ((nl_skb = skb_dequeue(&sk->sk_receive_queue)) != NULL) {
  23. nl_hdr = (struct nlmsghdr *)nl_skb->data;
  24. pid = nl_hdr->nlmsg_pid;
  25. printk(KERN_ALERT "*** Message from user with PID: (pid = %d) is %s\n", pid, (char*)NLMSG_DATA(nl_hdr));
  26. nl_skb = alloc_skb(MSG_SIZE, in_interrupt() ? GFP_ATOMIC : GFP_KERNEL);
  27. skb_put(nl_skb, MSG_SIZE);
  28. nl_hdr = (struct nlmsghdr *)nl_skb->data;
  29. nl_hdr->nlmsg_len = MSG_SIZE;
  30. nl_hdr->nlmsg_pid = pid;
  31. nl_hdr->nlmsg_flags = 0;
  32. strcpy(NLMSG_DATA(nl_hdr), "HELLO HELLO HELLO");
  33. NETLINK_CB(nl_skb).pid = 0;
  34. NETLINK_CB(nl_skb).dst_pid = pid;
  35. NETLINK_CB(nl_skb).dst_group = VFW_GROUP;
  36. netlink_unicast(nl_sk, nl_skb, pid, 0);
  37. kfree_skb(nl_skb);
  38. }
  39. }
  40.  
  41. /* LXR reference:http://lxr.linux.no/#linux+v2.6.26.7/net/netlink/af_netlink.c#L1358
  42. struct sock * netlink_kernel_create
  43. (struct net *net, int unit, unsigned int groups,void (*input)(struct sk_buff *skb),struct mutex *cb_mutex, struct module *module)
  44. */
  45.  
  46. static int __init nltest_init(void)
  47. {
  48. struct net *net;
  49. printk(KERN_ALERT "INIT/START: nltest\n");
  50. nl_sk = netlink_kernel_create(net,NETLINK_TEST, VFW_GROUP, nltest_rcv, 0, THIS_MODULE);
  51. if (!nl_sk) {
  52. printk(KERN_ALERT "ERROR: nltest - netlink_kernel_create() failed\n");
  53. return -1;
  54. }
  55. return 0;
  56. }
  57. static void __exit nltest_exit(void)
  58. {
  59. printk(KERN_ALERT "EXIT: nltest\n");
  60. sock_release(nl_sk->sk_socket);
  61.  
  62. return;
  63. }
  64. module_init(nltest_init);
  65. module_exit(nltest_exit);
  66.  
  67. MODULE_DESCRIPTION("Module_Test_Netlink");
  68. MODULE_LICENSE("GPL");
  69.  
when I run a make on this file, it shows the following errors:

root@ubuntu:/home/p# make
make -C /lib/modules/2.6.27-15-generic/build M=/home/p modules
make[1]: Entering directory `/usr/src/linux-headers-2.6.27-15-generic'
CC [M] /home/priyanka/kern.o
/home/p/kern.c: In function ‘nltest_rcv’:
/home/p/kern.c:37: error: ‘struct netlink_skb_parms’ has no member named ‘dst_pid’
/home/p/kern.c: In function ‘nltest_init’:
/home/p/kern.c:54: warning: passing argument 4 of ‘netlink_kernel_create’ from incompatible pointer type
make[2]: *** [/home/p/kern.o] Error 1
make[1]: *** [_module_/home/p] Error 2
make[1]: Leaving directory `/usr/src/linux-headers-2.6.27-15-generic'
make: *** [all] Error 2

The two errors are for
1. netlink_kernel_create function
2. struct netlink_skb_parms

Can anyone help me figure out how to solve these errors?

Thanks!
Nov 26 '09 #6

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

7 posts views Thread by tyler_durden | last post: by
7 posts views Thread by Roman Mashak | last post: by
3 posts views Thread by Hallvard B Furuseth | last post: by
2 posts views Thread by venu reddy | last post: by
4 posts views Thread by cpptutor2000 | last post: by
6 posts views Thread by mdh | last post: by
reply views Thread by MrMoon | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.