@@ -924,7 +924,7 @@ int send_packet(const Networking_Core *net, const IP_Port *ip_port, Packet packe
924924{
925925 IP_Port ipp_copy = * ip_port ;
926926
927- if (net_family_is_unspec (ip_port -> ip .family )) {
927+ if (net_family_is_unspec (ipp_copy . ip .family )) {
928928 // TODO(iphydf): Make this an error. Currently this fails sometimes when
929929 // called from DHT.c:do_ping_and_sendnode_requests.
930930 return -1 ;
@@ -987,7 +987,7 @@ int send_packet(const Networking_Core *net, const IP_Port *ip_port, Packet packe
987987 }
988988
989989 const long res = net_sendto (net -> ns , net -> sock , packet .data , packet .length , & addr , & ipp_copy );
990- loglogdata (net -> log , "O=>" , packet .data , packet .length , ip_port , res );
990+ loglogdata (net -> log , "O=>" , packet .data , packet .length , & ipp_copy , res );
991991
992992 assert (res <= INT_MAX );
993993 return (int )res ;
@@ -1012,7 +1012,8 @@ int sendpacket(const Networking_Core *net, const IP_Port *ip_port, const uint8_t
10121012non_null ()
10131013static int receivepacket (const Network * ns , const Memory * mem , const Logger * log , Socket sock , IP_Port * ip_port , uint8_t * data , uint32_t * length )
10141014{
1015- memset (ip_port , 0 , sizeof (IP_Port ));
1015+ ipport_reset (ip_port );
1016+
10161017 Network_Addr addr = {{0 }};
10171018 addr .size = sizeof (addr .addr );
10181019 * length = 0 ;
@@ -1502,14 +1503,21 @@ void ip_reset(IP *ip)
15021503}
15031504
15041505/** nulls out ip_port */
1505- void ipport_reset (IP_Port * ipport )
1506+ void ipport_reset (IP_Port * ip_port )
15061507{
1507- if (ipport == nullptr ) {
1508+ if (ip_port == nullptr ) {
15081509 return ;
15091510 }
15101511
1511- const IP_Port empty_ip_port = {{{0 }}};
1512- * ipport = empty_ip_port ;
1512+ // Leave padding bytes as uninitialized data. This should not matter, because we
1513+ // then set all the actual fields to 0.
1514+ IP_Port empty ;
1515+ empty .ip .family .value = 0 ;
1516+ empty .ip .ip .v6 .uint64 [0 ] = 0 ;
1517+ empty .ip .ip .v6 .uint64 [1 ] = 0 ;
1518+ empty .port = 0 ;
1519+
1520+ * ip_port = empty ;
15131521}
15141522
15151523/** nulls out ip, sets family according to flag */
@@ -1619,7 +1627,7 @@ bool bin_pack_ip_port(Bin_Pack *bp, const Logger *logger, const IP_Port *ip_port
16191627 Ip_Ntoa ip_str ;
16201628 // TODO(iphydf): Find out why we're trying to pack invalid IPs, stop
16211629 // doing that, and turn this into an error.
1622- LOGGER_TRACE (logger , "cannot pack invalid IP: %s" , net_ip_ntoa (& ip_port -> ip , & ip_str ));
1630+ LOGGER_DEBUG (logger , "cannot pack invalid IP: %s" , net_ip_ntoa (& ip_port -> ip , & ip_str ));
16231631 return false;
16241632 }
16251633
@@ -1640,6 +1648,7 @@ int pack_ip_port(const Logger *logger, uint8_t *data, uint16_t length, const IP_
16401648 const uint32_t size = bin_pack_obj_size (bin_pack_ip_port_handler , ip_port , logger );
16411649
16421650 if (size > length ) {
1651+ LOGGER_ERROR (logger , "not enough space for packed IP: %u but need %u" , length , size );
16431652 return -1 ;
16441653 }
16451654
0 commit comments