@@ -699,6 +699,9 @@ Networking_Core *new_networking_ex(IP ip, uint16_t port_from, uint16_t port_to,
699699/* Function to cleanup networking stuff. */
700700void kill_networking (Networking_Core * net )
701701{
702+ if (!net )
703+ return ;
704+
702705 if (net -> family != 0 ) /* Socket not initialized */
703706 kill_sock (net -> sock );
704707
@@ -823,7 +826,7 @@ void ipport_copy(IP_Port *target, const IP_Port *source)
823826 * writes error message into the buffer on error
824827 */
825828/* there would be INET6_ADDRSTRLEN, but it might be too short for the error message */
826- static char addresstext [96 ];
829+ static char addresstext [96 ]; // FIXME magic number. Why not INET6_ADDRSTRLEN ?
827830const char * ip_ntoa (const IP * ip )
828831{
829832 if (ip ) {
@@ -964,22 +967,22 @@ int addr_resolve(const char *address, IP *to, IP *extra)
964967 return 0 ;
965968 }
966969
967- IP4 ip4 ;
968- memset (& ip4 , 0 , sizeof ( ip4 ) );
969- IP6 ip6 ;
970- memset (& ip6 , 0 , sizeof ( ip6 ) );
970+ IP ip4 ;
971+ ip_init (& ip4 , /* ipv6? */ false );
972+ IP ip6 ;
973+ ip_init (& ip6 , /* ipv6? */ true );
971974
972975 for (walker = server ; (walker != NULL ) && (rc != 3 ); walker = walker -> ai_next ) {
973976 switch (walker -> ai_family ) {
974977 case AF_INET :
975978 if (walker -> ai_family == family ) { /* AF_INET requested, done */
976979 struct sockaddr_in * addr = (struct sockaddr_in * )walker -> ai_addr ;
977980 to -> ip4 .in_addr = addr -> sin_addr ;
978- rc = 3 ;
981+ rc = 3 ; // TODO do we really have to reuse variable instead of creating a new one?
979982 } else if (!(rc & 1 )) { /* AF_UNSPEC requested, store away */
980983 struct sockaddr_in * addr = (struct sockaddr_in * )walker -> ai_addr ;
981- ip4 .in_addr = addr -> sin_addr ;
982- rc |= 1 ;
984+ ip4 .ip4 . in_addr = addr -> sin_addr ;
985+ rc |= 1 ; // FIXME magic number
983986 }
984987
985988 break ; /* switch */
@@ -994,7 +997,7 @@ int addr_resolve(const char *address, IP *to, IP *extra)
994997 } else if (!(rc & 2 )) { /* AF_UNSPEC requested, store away */
995998 if (walker -> ai_addrlen == sizeof (struct sockaddr_in6 )) {
996999 struct sockaddr_in6 * addr = (struct sockaddr_in6 * )walker -> ai_addr ;
997- ip6 .in6_addr = addr -> sin6_addr ;
1000+ ip6 .ip6 . in6_addr = addr -> sin6_addr ;
9981001 rc |= 2 ;
9991002 }
10001003 }
@@ -1004,17 +1007,14 @@ int addr_resolve(const char *address, IP *to, IP *extra)
10041007 }
10051008
10061009 if (to -> family == AF_UNSPEC ) {
1007- if (rc & 2 ) {
1008- to -> family = AF_INET6 ;
1009- to -> ip6 = ip6 ;
1010+ if (rc & 2 ) { // FIXME magic number
1011+ ip_copy (to , & ip6 );
10101012
10111013 if ((rc & 1 ) && (extra != NULL )) {
1012- extra -> family = AF_INET ;
1013- extra -> ip4 = ip4 ;
1014+ ip_copy (extra , & ip4 );
10141015 }
10151016 } else if (rc & 1 ) {
1016- to -> family = AF_INET ;
1017- to -> ip4 = ip4 ;
1017+ ip_copy (to , & ip4 );
10181018 } else
10191019 rc = 0 ;
10201020 }
0 commit comments