@@ -933,7 +933,7 @@ int send_packet(const Networking_Core *net, const IP_Port *ip_port, Packet packe
933933{
934934    IP_Port  ipp_copy  =  * ip_port ;
935935
936-     if  (net_family_is_unspec (ip_port -> ip .family )) {
936+     if  (net_family_is_unspec (ipp_copy . ip .family )) {
937937        // TODO(iphydf): Make this an error. Currently this fails sometimes when 
938938        // called from DHT.c:do_ping_and_sendnode_requests. 
939939        return  -1 ;
@@ -996,7 +996,7 @@ int send_packet(const Networking_Core *net, const IP_Port *ip_port, Packet packe
996996    }
997997
998998    const  long  res  =  net_sendto (net -> ns , net -> sock , packet .data , packet .length , & addr , & ipp_copy );
999-     loglogdata (net -> log , "O=>" , packet .data , packet .length , ip_port , res );
999+     loglogdata (net -> log , "O=>" , packet .data , packet .length , & ipp_copy , res );
10001000
10011001    assert (res  <= INT_MAX );
10021002    return  (int )res ;
@@ -1021,7 +1021,8 @@ int sendpacket(const Networking_Core *net, const IP_Port *ip_port, const uint8_t
10211021non_null ()
10221022static  int  receivepacket (const  Network  * ns , const  Memory  * mem , const  Logger  * log , Socket  sock , IP_Port  * ip_port , uint8_t  * data , uint32_t  * length )
10231023{
1024-     memset (ip_port , 0 , sizeof (IP_Port ));
1024+     ipport_reset (ip_port );
1025+ 
10251026    Network_Addr  addr  =  {{0 }};
10261027    addr .size  =  sizeof (addr .addr );
10271028    * length  =  0 ;
@@ -1514,13 +1515,25 @@ void ip_reset(IP *ip)
15141515static  const  IP_Port  empty_ip_port  =  {{{0 }}};
15151516
15161517/** nulls out ip_port */ 
1517- void  ipport_reset (IP_Port  * ipport )
1518+ void  ipport_reset (IP_Port  * ip_port )
15181519{
1519-     if  (ipport  ==  nullptr ) {
1520+     if  (ip_port  ==  nullptr ) {
15201521        return ;
15211522    }
15221523
1523-     * ipport  =  empty_ip_port ;
1524+ #ifdef  RANDOM_PADDING 
1525+     // Leave padding bytes as uninitialized data. This should not matter, because we 
1526+     // then set all the actual fields to 0. 
1527+     IP_Port  empty ;
1528+     empty .ip .family .value  =  0 ;
1529+     empty .ip .ip .v6 .uint64 [0 ] =  0 ;
1530+     empty .ip .ip .v6 .uint64 [1 ] =  0 ;
1531+     empty .port  =  0 ;
1532+ 
1533+     * ip_port  =  empty ;
1534+ #else 
1535+     * ip_port  =  empty_ip_port ;
1536+ #endif  /* RANDOM_PADDING */ 
15241537}
15251538
15261539/** nulls out ip, sets family according to flag */ 
@@ -1630,7 +1643,7 @@ bool bin_pack_ip_port(Bin_Pack *bp, const Logger *logger, const IP_Port *ip_port
16301643        Ip_Ntoa  ip_str ;
16311644        // TODO(iphydf): Find out why we're trying to pack invalid IPs, stop 
16321645        // doing that, and turn this into an error. 
1633-         LOGGER_TRACE (logger , "cannot pack invalid IP: %s" , net_ip_ntoa (& ip_port -> ip , & ip_str ));
1646+         LOGGER_DEBUG (logger , "cannot pack invalid IP: %s" , net_ip_ntoa (& ip_port -> ip , & ip_str ));
16341647        return  false;
16351648    }
16361649
@@ -1651,6 +1664,7 @@ int pack_ip_port(const Logger *logger, uint8_t *data, uint16_t length, const IP_
16511664    const  uint32_t  size  =  bin_pack_obj_size (bin_pack_ip_port_handler , ip_port , logger );
16521665
16531666    if  (size  >  length ) {
1667+         LOGGER_ERROR (logger , "not enough space for packed IP: %u but need %u" , length , size );
16541668        return  -1 ;
16551669    }
16561670
0 commit comments