differences betwee socket and sock
I'm writing a protocol to go on top of TCP within a kernel module and defined the (create) callback.
static const struct net_proto_family my_family_ops = {
.family = PF_MYPROTO,
.create = my_create,
.owner = THIS_MODULE,
};
When I create a socket from userspace ...
sockfd = socket(PF_MYPROTO, SOCK_STREAM, NEW_PROTO);
... the (create) callback in the net_proto_family struct is invoked. And within this callback is where I'm assuming I'd make a call like the following in order to create the socket for which I will then later call a connect function to a remote host (from the proto_ops callback).
sock_create(PF_INT, SOCK_STREAM, IPPROTO_TCP, &s)
What's confusing me is the (create) callback function has a signature like ...
static int my_create(struct net *net, struct socket *sock, int protocol, int kern);
My book doesn't say much other than that memory for *sock has been reserved and creates a new instance of a kernel-internal sock socket, intializes it as far as possible, and inserts it in the kernel data structures. I'm not sure if the socket has been created, or if I need to call that sock_create function. I'm not sure what this socket is that's being passed in.
Can someone talk about the differences between sock and socket structures and help with which one I should use and store for other socket calls down the road such as connect, bind, accept, listen, etc...
Last edited by rrlangly; 02-05-2011 at 01:18 PM.
|