Skip to contentSkip to conversation

Socket program in kernel

DISCUSSION prabhu 3 participants 3 messages Feb 22, 2011

lore
Share & tools
lore

prabhu

author
#0 lore raw

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.

Thanks,
Prabhu

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.kernelnewbies.org/pipermail/kernelnewbies/attachments/20110222/1465157a/attachment.html

#1 lore raw

http://www.linuxjournal.com/node/7356/

here is the link showing how u can add ur socket and define new protocol for netlink family ( if u wish) in kernel land.

Quoted 19 lines · prabhu

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.

Thanks,
Prabhu

_______________________________________________
Kernelnewbies mailing list
Kernelnewbies at kernelnewbies.org
http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies

Signature · 5 lines
........................
*MOHIT VERMA*
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.kernelnewbies.org/pipermail/kernelnewbies/attachments/20110222/f0868e42/attachment-0001.html 
#2 lore raw
In reply to prabhu
Quoted 9 lines · prabhu

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,

Signature · 7 lines
-----------------------------------------
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