RedArrow
RedArrow

Reputation: 638

Socket communication in char device driver

Is it feasible to open socket from kernel module of a char device driver in linux? I am trying to emulate the output / input stream of char devices over network. But as far as I searched opening a socket from char device is not possible? Any other option to access udp / tcp ports from char device drivers?

Upvotes: 1

Views: 1506

Answers (1)

fluter
fluter

Reputation: 13846

Yes, you can open socket and communicate with remote hosts in kernel code, a vivid example is the NFS module, which uses sunrpc for its protocols, and both of them are running in kernel module.

As a start, look at kernel_connect[1] to start a connection, and kernel_sock_shutdown to shutdown the connection. There are a full list of apis in socket.c.

[1]http://lxr.free-electrons.com/source/net/socket.c#L3212

[2]http://lxr.free-electrons.com/source/net/socket.c#L3298

[3]http://lxr.free-electrons.com/source/net/socket.c

Upvotes: 0

Related Questions