Char kernel driver with network support (UDP)

Hello, experts. I am ne to Linux programming at all.
  I need some help in writing such basic char kernel driver. Will be thank for some info in this topic.
  Maybe, there is a sample. I can't find it.
  The functionality I need is:
    - char driver that could send and receive UDP packs.
    - it can do that sync or async.

  Thanks.
 
P.S> have already wrote some simple driver under linux, but how to connect to network card device and what sys calls should I execute - I don't knew... :(((
LVL 5
-Thespian-Asked:
Who is Participating?
 
jainrahConnect With a Mentor Commented:
There are no socket functions. sundance.c is the NIC driver. Sockets are implemented and executed above the TCP layer. The code in sundance.c will help you understand how to interact with the NIC. When talking at a kernel level, one seldom talks about sockets.

Looking closely at your question, LDD3 (Linux Device Driver ed. 3) might be of help to you. You can also read up on Netfilter Hooks. Google for them and you will find good links for both.
0
 
jainrahCommented:
Reading through the code of any of the network drivers should help you. One that I went through was sundance.c
0
 
-Thespian-Author Commented:
can u post here the source?
0
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
jainrahCommented:
Its a pretty big file. You can find it in the src directory of the kernel distribution. Or you can read the code here

http://lxr.linux.no/source/drivers/net/sundance.c
0
 
-Thespian-Author Commented:
Where do u see the socket functions there?
0
 
-Thespian-Author Commented:
I have already found the solvation, but in different sources. now I am trying to combine them. Already have made a char driver. And now trying to fill it with socket functionality...
0
 
-Thespian-Author Commented:
Now I only need the working sample of source code, where I can find the function which receives buffer and its size and form the message on this message and broadcast it.
0
 
leisnerCommented:
hmmm....maybe you should say what you want to accomplish...why is this a device driver instead of an application?

If you can find a way to map the solution into user space, it becomes much much simpler.
0
 
-Thespian-Author Commented:
I need it at my work...:( it is in TD.
0
 
NopiusConnect With a Mentor Commented:
As jainrah recommended, read Linux Device Drivers 3rd edition, it's available online (one PDF file per chapter): http://lwn.net/Kernel/LDD3/
It's extremely importent for device driver writers.

Next. Inside kernel sources (I have version 2.6.16-11) you may find code, that performs UDP packets sending and receiving via NIC.
This code is for IP autoconfiguration via BOOTP/DHCP when kernel is booting. Look inside this file: net/ipv4/ipconfig.c below kernel sources top level directory.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.