Re: can anyone tell me the differences between "struct sock" and "struct socket" that are data structures of network protocol stack ?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



I think "struct socket" is a socket which operates a transport layer. It allows the flexibility to add your own protocol stack (where you can defined your own protocol specific handlers  like bind, connect,  send, revc etc..). "struct sock" is operating at network layer. It holds all the connection specific information at kernel layer. It does not interact with user added protocol.

For example, when you want to add a protocol to linux, you will have to specify its type (STREAM or DGRAM) and its family. Depending upon that you will have to implement its protocol operations (like bind, connect, listen, send, recv etc..). So then when you call a socket related sys calls from user space, they all get redirected to your protocol. In this process, you will also implement the socket creation method, which will be invoked when socket() syscall is issued from user app. This syscall() will not directly come to your protocol, but it will pass through kernel first. Here kernel, will create a "struct socket" for you. Once "struct socket" is created, you will have to fill the proto_ops structure specific to your protocol in your socket creat() implementation. Here, its your job to create a "struct sock" and associate with your protocol's socket.

If you want to take a look on how to implement a user defined protocol in kernel, download ofed-1.4 package from here "http://www.openfabrics.org/downloads/OFED/". And look for "sdp" in that package. In sdp_main.c file, you will see how struct socket, and struct sk is being used. You can also go to "linux/net/socket.c" file and trace "sys_socket()" call to see how everything happens.

Vishal



Irfan Ahmed wrote:
can anyone tell me the differences between "struct sock" and "struct socket" that are data structures of network protocol stack ?


New Email names for you!
Get the Email name you've always wanted on the new @ymail and @rocketmail.
Hurry before someone else does!

-- To unsubscribe from this list: send an email with "unsubscribe kernelnewbies" to ecartis@xxxxxxxxxxxx Please read the FAQ at http://kernelnewbies.org/FAQ

[Index of Archives]     [Newbies FAQ]     [Linux Kernel Mentors]     [Linux Kernel Development]     [IETF Annouce]     [Git]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux SCSI]     [Linux ACPI]
  Powered by Linux