When passing a socket address structure to a socket function, the structure is always passed as a reference, that is, a pointer to the struct is passed.
The length of the structure is also passed as a parameter, but the way it is passed depends on the direction of the structure: process--Kernel kernel--process
1) process-to-kernel pass socket address structure functions are 3: Bind, Connect, sendto
One parameter to these functions is a pointer to a socket address structure, and the other parameter is the integer size of the structure
2) The kernel-to-process pass socket address structure has 4 functions: Accept, Recvfrom, GetSockName, Getpeername
The 2 parameters of these 4 functions are pointers to a socket address structure and pointers to integer variables that represent the size of the structure
Change the size of the socket address structure from an integer to a pointer to an integer variable for the reason:
When a function is called, the size of the structure is a value (value), which tells the kernel the size of the structure so that the kernel does not cross over when writing the structure;
When the function returns, the size of the structure is another result, which tells the process kernel exactly how much information is stored in the struct.
This type of parameter is called: value-result parameter
Value-Result parameter