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 12-14-2005, 04:40 AM   #1
thegreatest
LQ Newbie
 
Registered: Nov 2005
Posts: 9

Rep: Reputation: 0
NETLINK SOCKET Error


I am trying to have a communication between kernel and user space...The code i am using is as follows

//************KERNEL SPACE CODE***********************
#include <linux/config.h>
#include <linux/module.h>
#include <linux/kernel.h>
#include <sys/socket.h>
#include <linux/netlink.h>
#include <linux/init.h>

MODULE_LICENSE("GPL");
#define NETLINK_TEST 17
#define wake_up_interruptible(x)
void nl_data_ready (struct sock *sk, int len);
static int debug = 0;
struct sock *netlink_kernel_create(int unit, void (*input)(struct sock *sk, int len));
module_param(debug, int, 0);
MODULE_PARM_DESC(debug, "Debug information (default 0)");

static struct sock *nl_sk = NULL
void nl_data_ready (struct sock *sk, int len)
{
wake_up_interruptible(sk->sk_sleep);
}

void netlink_test()
{
struct sk_buff *skb = NULL;
struct nlmsghdr *nlh = NULL;
int err;
u32 pid;

nl_sk = netlink_kernel_create(NETLINK_TEST,nl_data_ready);
skb = skb_recv_datagram(nl_sk, 0, 0, &err);

nlh = (struct nlmsghdr *)skb->data;
printk(KERN_INFO "%s: received netlink message payload: %s\n", __FUNCTION__, NLMSG_DATA(nlh));

pid = nlh->nlmsg_pid;
//NETLINK_CB(skb).groups = 0;
NETLINK_CB(skb).pid = 0;
NETLINK_CB(skb).dst_pid = pid;
//NETLINK_CB(skb).dst_groups = 0;
netlink_unicast(nl_sk, skb, pid, MSG_DONTWAIT);
//sock_release(nl_sk->sk_socket);
}

static int __init my_module_init(void)
{
printk(KERN_INFO "Initializing Netlink Socket");
netlink_test();
return 0;
}

static void __exit my_module_exit(void)
{
printk(KERN_INFO "Goodbye");
}

module_init(my_module_init);
module_exit(my_module_exit);
//****************************************************
while compiling the make file i get the error as
/root/socket/sirk.c:13: error: conflicting types for `netlink_kernel_create'
include/linux/netlink.h:130: error: previous declaration of `netlink_kernel_create'
/root/socket/sirk.c:18: error: syntax error before "void"

can anybody tell me the solution for these errors
 
Old 12-14-2005, 09:06 PM   #2
freegianghu
Member
 
Registered: Oct 2004
Location: somewhere in the street
Distribution: Window$
Posts: 192

Rep: Reputation: 30
Pay attention at red characters:

Quote:
Originally Posted by thegreatest
Code:
.....................
static int debug = 0;
/* you should commented out below line */
extern struct sock *netlink_kernel_create(int unit, void (*input)(struct sock *sk, int len)); 
module_param(debug, int, 0);
MODULE_PARM_DESC(debug, "Debug information (default 0)");

static struct sock *nl_sk = NULL;
void nl_data_ready (struct sock *sk, int len)
{
    wake_up_interruptible(sk->sk_sleep);
}
......................
//****************************************************
while compiling the make file i get the error as
/root/socket/sirk.c:13: error: conflicting types for `netlink_kernel_create'
include/linux/netlink.h:130: error: previous declaration of `netlink_kernel_create'
/root/socket/sirk.c:18: error: syntax error before "void"

can anybody tell me the solution for these errors
BTW, What is output of command "uname -r" at your box???

Good luck,
Giang Hu.

Last edited by freegianghu; 12-14-2005 at 09:07 PM.
 
Old 12-14-2005, 11:06 PM   #3
kshkid
Member
 
Registered: Dec 2005
Distribution: RHEL3, FC3
Posts: 383

Rep: Reputation: 30
As the error message states netlink_kernel_create declaration is contradicting

netlink_kernel_create available in netlink.h
as the following signature
struct sock *netlink_kernel_create(int unit, void (*input)(struct sock *sk, int len));

you have used,
sock *netlink_kernel_create(int unit, void (*input)(struct sock *sk, int len));

with an undefined datatype sock

hope this helps!!!
 
  


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
Unable to connect to UNIX socket /tmp/.esd/socket error while using grip dr_zayus69 Linux - Software 4 08-23-2005 07:28 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
socket error adoyee Programming 3 02-07-2004 11:11 AM
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 07:38 AM.

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