patacongo commented on issue #370: net: socket: Introduce net_clear_sinzero()
URL: https://github.com/apache/incubator-nuttx/pull/370#issuecomment-590889683
 
 
   But the memset of the whole structure would be wasteful for IPv6 addresses.
   
   > accept/getsockname/getpeername/recvfrom are general functions, shouldn't 
assume addr must be IPv4 and then contain sin_zero.
   
   The distinction between IPv4 and IPv6 is made at a lower level than 
accept/getsockname/getpeername/recvfrom.  At that lower level, the IPv4 
specific code and always assume that sin_zero is present.  If sin_port and 
sin_addr are set then you know that sin_zero can be set too.. always.
   
   For example:
   
   accept->psock_accept->inet_accept->tcp_psock_accept
   
   then the address is initialized like:
   
       106 #ifdef CONFIG_NET_IPv4
       114         {
       115           FAR struct sockaddr_in *inaddr = (FAR struct sockaddr_in 
*)addr;
       116
       117           inaddr->sin_family = AF_INET;
       118           inaddr->sin_port   = conn->rport;
       119           net_ipv4addr_copy(inaddr->sin_addr.s_addr, 
conn->u.ipv4.raddr);
       120
       121           *addrlen = sizeof(struct sockaddr_in);
       122         }
       123 #endif /* CONFIG_NET_IPv4 */
   
   The memset of sin_zero belongs between lines 119 and 120.  Easy and perfect!
   
   sin_zero should be initialized at the very, very lowest level at the same 
time that sin_port and sin_addr are initialize.  That is the simplest and can 
never fail.  I have not looked at every case, but I believe that all reduce to 
this simplest, most straight-forward, monst maintainable, most understanable 
solution.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

Reply via email to