Socket program in kernel

Javier Martinez Canillas martinez.javier at gmail.com
Tue Feb 22 09:49:01 EST 2011


On Tue, Feb 22, 2011 at 10:43 AM, prabhu <prabhum at msys-tech.com> wrote:
> Hi All,
>
> I wrote socket program in user level but i want to write the same program in
> kernel. Like the driver(socket server) should receive all the incoming
> TCP or UDP pocket(may be say raw socket) and write into the file.
>
> Please provide your valuable idea to do this program ... Also please point
> out pitfalls.
>

Hello Prabhu,

Please can you told us more about what do you want to achieve? Do you
want to receive information sended by a userspace program using
sockets? In that case netlink sockets is the way to go I think.

But if what you want to capture all the TCP and UDP messages and log
it, maybe you can register a new protocol handler.

Look at the packet_type structure and dev_add_pack() registration function.

Either way, accesing files from inside the kernel is not a good idea,
you should export your data via netlink sockets, sysfs, etc and write
to files from userpace.

Look at this excelent article  written by Greg KH about "Things You
Should Never Do in the Kernel"

http://www.linuxjournal.com/article/8130

Hope it helps.

Best regards,

-- 
-----------------------------------------
Javier Martínez Canillas
(+34) 682 39 81 69
PhD Student in High Performance Computing
Computer Architecture and Operating System Department (CAOS)
Universitat Autònoma de Barcelona
Barcelona, Spain



More information about the Kernelnewbies mailing list