1. If the source port number is not specified before client connect, the system will automatically allocate and bind one.
/*
* Automatically bind an unbound socket.
*/
Static int inet_autobind (struct sock * SK)
{
/* We may need to bind the socket .*/
If (SK-> num = 0)
{
SK-> num = get_new_socknum (SK-> Prot, 0 );
If (SK-> num = 0)
Return (-eagain );
Put_sock (SK-> num, SK );
SK-> dummy_th.source = ntohs (SK-> num );
}
Return 0;
}
2. In function inet_create (), the congestion window size is 1, slow start
SK-> cong_window = 1;/* start with only sending one packet at a time .*/
3. In function inet_dup (),
The inet_dup function is called by the server. The socket used by the server for actual communication is different from the socket used for listening. When an application receives a client request using the accept function on the server side, a new socket is created for data communication with the client, the listening socket is still only responsible for listening to requests from other clients. After sock_accept (the BSD layer processing function called by the accept System) allocates a new socket structure, it calls the inet_dup function to initialize the new socket structure, the initialization information mainly comes from the listening socket. newsock in the input parameter of the inet_dup function indicates the new socket structure, while oldsock indicates the listening Socket socket structure. From the implementation of inet_dup, this function calls the inet_create function to complete the specific function: allocate the lower-layer sock structure corresponding to the new socket structure. Here, only the protocol field of the listening socket structure is used.
4. Using the same port number for different protocols will not cause any problems.
5. All sockets applicable to the same protocol are inserted into the sock_array array in the corresponding proto (such as tcp_prot) structure of the protocol.
6. About socket functions,
Before using a socket, an application must first have a socket. The system calls socket () to provide the application with the means to create a socket. The call format is as follows:
Socket Pascal far socket (int af, int type, int Protocol );
This call receives three parameters: AF, type, and protocol. The AF parameter specifies the region where communication occurs, such as af_unix, af_inet, and af_ns. in DOS and Windows, only af_inet is supported, which is the region of the Internet. Therefore, the address family is the same as the protocol family.
Reference: LINUX-2.4.0 kernel network stack implementation source code analysis