@@ -926,7 +926,7 @@ int send_packet(const Networking_Core *net, const IP_Port *ip_port, Packet packe
926926{
927927 IP_Port ipp_copy = * ip_port ;
928928
929- if (net_family_is_unspec (ip_port -> ip .family )) {
929+ if (net_family_is_unspec (ipp_copy . ip .family )) {
930930 // TODO(iphydf): Make this an error. Currently this fails sometimes when
931931 // called from DHT.c:do_ping_and_sendnode_requests.
932932 return -1 ;
@@ -989,7 +989,7 @@ int send_packet(const Networking_Core *net, const IP_Port *ip_port, Packet packe
989989 }
990990
991991 const long res = net_sendto (net -> ns , net -> sock , packet .data , packet .length , & addr , & ipp_copy );
992- loglogdata (net -> log , "O=>" , packet .data , packet .length , ip_port , res );
992+ loglogdata (net -> log , "O=>" , packet .data , packet .length , & ipp_copy , res );
993993
994994 assert (res <= INT_MAX );
995995 return (int )res ;
@@ -1014,7 +1014,8 @@ int sendpacket(const Networking_Core *net, const IP_Port *ip_port, const uint8_t
10141014non_null ()
10151015static int receivepacket (const Network * ns , const Memory * mem , const Logger * log , Socket sock , IP_Port * ip_port , uint8_t * data , uint32_t * length )
10161016{
1017- memset (ip_port , 0 , sizeof (IP_Port ));
1017+ ipport_reset (ip_port );
1018+
10181019 Network_Addr addr = {{0 }};
10191020 addr .size = sizeof (addr .addr );
10201021 * length = 0 ;
@@ -1503,14 +1504,21 @@ void ip_reset(IP *ip)
15031504}
15041505
15051506/** nulls out ip_port */
1506- void ipport_reset (IP_Port * ipport )
1507+ void ipport_reset (IP_Port * ip_port )
15071508{
1508- if (ipport == nullptr ) {
1509+ if (ip_port == nullptr ) {
15091510 return ;
15101511 }
15111512
1512- const IP_Port empty_ip_port = {{{0 }}};
1513- * ipport = empty_ip_port ;
1513+ // Leave padding bytes as uninitialized data. This should not matter, because we
1514+ // then set all the actual fields to 0.
1515+ IP_Port empty ;
1516+ empty .ip .family .value = 0 ;
1517+ empty .ip .ip .v6 .uint64 [0 ] = 0 ;
1518+ empty .ip .ip .v6 .uint64 [1 ] = 0 ;
1519+ empty .port = 0 ;
1520+
1521+ * ip_port = empty ;
15141522}
15151523
15161524/** nulls out ip, sets family according to flag */
@@ -1620,7 +1628,7 @@ bool bin_pack_ip_port(Bin_Pack *bp, const Logger *logger, const IP_Port *ip_port
16201628 Ip_Ntoa ip_str ;
16211629 // TODO(iphydf): Find out why we're trying to pack invalid IPs, stop
16221630 // doing that, and turn this into an error.
1623- LOGGER_TRACE (logger , "cannot pack invalid IP: %s" , net_ip_ntoa (& ip_port -> ip , & ip_str ));
1631+ LOGGER_DEBUG (logger , "cannot pack invalid IP: %s" , net_ip_ntoa (& ip_port -> ip , & ip_str ));
16241632 return false;
16251633 }
16261634
@@ -1641,6 +1649,7 @@ int pack_ip_port(const Logger *logger, uint8_t *data, uint16_t length, const IP_
16411649 const uint32_t size = bin_pack_obj_size (bin_pack_ip_port_handler , ip_port , logger );
16421650
16431651 if (size > length ) {
1652+ LOGGER_ERROR (logger , "not enough space for packed IP: %u but need %u" , length , size );
16441653 return -1 ;
16451654 }
16461655
0 commit comments