the inheriting of linux sock type

0.0.1. Data Structure

Every xsock has parent sock as its first filed.

  1. sock_common
1
2
3
157 struct sock_common {
...
}
  1. sock
1
2
3
4
5
6
7
 288 struct sock {
289 /*
290 * Now struct inet_timewait_sock also uses sock_common, so please just
291 * don't add nothing before this first member (__sk_common) --acme
292 */
293 struct sock_common __sk_common;
...
  1. inet_sock
1
2
3
4
37 struct inet_sock {
138 /* sk and pinet6 has to be the first two members of inet_sock */
139 struct sock sk;
...
  1. inet_connection_sock
1
2
3
4
 87 struct inet_connection_sock {
88 /* inet_sock has to be the first member! */
89 struct inet_sock icsk_inet;
...
  1. tcp_sock
1
2
3
4
133 struct tcp_sock {
134 /* inet_connection_sock has to be the first member of tcp_sock */
135 struct inet_connection_sock inet_conn;
...

0.0.1.1. 转换函数:

0.0.1.1.1. sk to inet_sock
1
2
3
4
213 static inline struct inet_sock *inet_sk(const struct sock *sk)
214 {
215 return (struct inet_sock *)sk;
216 }
0.0.1.1.2. sk to inet_connection_sock
1
2
3
4
145 static inline struct inet_connection_sock *inet_csk(const struct sock *sk)
146 {
147 return (struct inet_connection_sock *)sk;
148 }
0.0.1.1.3. sk to tcp_sk
1
2
3
4
351 static inline struct tcp_sock *tcp_sk(const struct sock *sk)
352 {
353 return (struct tcp_sock *)sk;
354 }

Inherit


the inheriting of linux sock type
https://martinbj2008.github.io/2013/11/22/2013-11-22-the-inheriting-of-linux-sock-type/
Author
Martinbj2008
Posted on
November 22, 2013
Licensed under