473,325 Members | 2,860 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,325 software developers and data experts.

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
5 6354
weaknessforcats
9,208 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
Laharl
849 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
9,208 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

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

Similar topics

7
by: tyler_durden | last post by:
thanks a lot for all your help..I'm really appreciated... with all the help I've been getting in forums I've been able to continue my program and it's almost done, but I'm having a big problem that...
7
by: elmafiacs | last post by:
I need some help with an error I'm getting... Sorry if this is basic stuff, but I'm still a newbie on C programming (working up, though). Also, I'm using gcc as my compiler ('gcc t.c -o t', no...
7
by: Roman Mashak | last post by:
Hello, All! I'm trying to compile some driver for MIPS target, and get errors. I assumed these may be related to C language. tigon3.h:2225: unnamed fields of type other than struct or union...
3
by: Hallvard B Furuseth | last post by:
to find the required alignment of a struct, I've used #include <stddef.h> struct Align_helper { char dummy; struct S align; }; enum { S_alignment = offsetof(struct Align_helper, align) };
2
by: venu reddy | last post by:
Hi all, I wrote an example code like this. I am getting error as " conversion to non-scalar type requested error". help me!!. #include<string.h> typedef struct { int val; char data;
4
by: cpptutor2000 | last post by:
Could someone please help me? I have the following C struct. typedef struct _FIREWALL_RULE_INFO { ULONG Precedence; BOOL bEnabled; BOOL ...
14
by: deepak | last post by:
Hi Experts, I'm getting this compilation error while trying to access a member in structure. at what time we will get this error message? Thanks, Deepak
6
by: mdh | last post by:
I understand *why* this produces an error and how to correct it, (add parentheses) but the error itself is a bit eclectic? As I am sure this will arise again, could anyone throw some logic at it. ...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.