@@ -395,18 +395,14 @@ parseAddress(const char *address, struct addrinfo **result) {
395395 return getAddrInfo (address , hostnameLen , port , & hints , result );
396396}
397397
398- /*
399- * Input is sockaddr just because all clients have it.
400- */
401- static void convertIPv4ToIPv6 (const struct sockaddr * addr4 , struct in6_addr * addr6 ) {
398+ static void convertIPv4ToIPv6 (const struct in_addr * addr4 , struct in6_addr * addr6 ) {
402399 // Implement in a platform-independent way.
403400 // Spec requires in_addr has s_addr member, in6_addr has s6_addr[16] member.
404- struct in_addr * a4 = & (((struct sockaddr_in * )addr4 )-> sin_addr );
405401 memset (addr6 , 0 , sizeof (* addr6 )); // for safety
406402
407403 // Mapped address contains 80 zero bits, then 16 "1" bits, then IPv4 address (4 bytes).
408404 addr6 -> s6_addr [10 ] = addr6 -> s6_addr [11 ] = 0xFF ;
409- memcpy (& (addr6 -> s6_addr [12 ]), & (a4 -> s_addr ), 4 );
405+ memcpy (& (addr6 -> s6_addr [12 ]), & (addr4 -> s_addr ), 4 );
410406}
411407
412408/*
@@ -415,37 +411,19 @@ static void convertIPv4ToIPv6(const struct sockaddr *addr4, struct in6_addr *add
415411 */
416412static jdwpTransportError
417413parseAllowedAddr (const char * buffer , struct in6_addr * result , int * isIPv4 ) {
418- struct addrinfo hints ;
419- struct addrinfo * addrInfo = NULL ;
420- jdwpTransportError err ;
421-
422- /*
423- * To parse both IPv4 and IPv6 need to specify AF_UNSPEC family
424- * (with AF_INET6 IPv4 addresses are not parsed even with AI_V4MAPPED and AI_ALL flags).
425- */
426- memset (& hints , 0 , sizeof (hints ));
427- hints .ai_family = AF_UNSPEC ; // IPv6 or mapped IPv4
428- hints .ai_socktype = SOCK_STREAM ;
429- hints .ai_protocol = IPPROTO_TCP ;
430- hints .ai_flags = AI_NUMERICHOST ; // only numeric addresses, no resolution
431-
432- err = getAddrInfo (buffer , strlen (buffer ), NULL , & hints , & addrInfo );
433-
434- if (err != JDWPTRANSPORT_ERROR_NONE ) {
435- return err ;
436- }
437-
438- if (addrInfo -> ai_family == AF_INET6 ) {
439- memcpy (result , & (((struct sockaddr_in6 * )(addrInfo -> ai_addr ))-> sin6_addr ), sizeof (* result ));
414+ struct in_addr addr ;
415+ struct in6_addr addr6 ;
416+ if (inet_pton (AF_INET6 , buffer , & addr6 ) == 1 ) {
440417 * isIPv4 = 0 ;
441- } else { // IPv4 address - convert to mapped IPv6
442- struct in6_addr addr6 ;
443- convertIPv4ToIPv6 (addrInfo -> ai_addr , & addr6 );
444- memcpy (result , & addr6 , sizeof (* result ));
418+ } else if (inet_pton (AF_INET , buffer , & addr ) == 1 ) {
419+ // IPv4 address - convert to mapped IPv6
420+ convertIPv4ToIPv6 (& addr , & addr6 );
445421 * isIPv4 = 1 ;
422+ } else {
423+ return JDWPTRANSPORT_ERROR_IO_ERROR ;
446424 }
447425
448- dbgsysFreeAddrInfo ( addrInfo );
426+ memcpy ( result , & addr6 , sizeof ( * result ) );
449427
450428 return JDWPTRANSPORT_ERROR_NONE ;
451429}
@@ -603,7 +581,8 @@ isPeerAllowed(struct sockaddr_storage *peer) {
603581 int i ;
604582 // _peers contains IPv6 subnet and mask (IPv4 is converted to mapped IPv6)
605583 if (peer -> ss_family == AF_INET ) {
606- convertIPv4ToIPv6 ((struct sockaddr * )peer , & tmp );
584+ struct in_addr * addr4 = & (((struct sockaddr_in * )peer )-> sin_addr );
585+ convertIPv4ToIPv6 (addr4 , & tmp );
607586 addr6 = & tmp ;
608587 } else {
609588 addr6 = & (((struct sockaddr_in6 * )peer )-> sin6_addr );
0 commit comments