Skip to content
/ server Public

MDEV-39169: Replace deprecated network functions with modern POSIX equivalents#4856

Draft
FaramosCZ wants to merge 1 commit intoMariaDB:mainfrom
FaramosCZ:resolveip_ipv6
Draft

MDEV-39169: Replace deprecated network functions with modern POSIX equivalents#4856
FaramosCZ wants to merge 1 commit intoMariaDB:mainfrom
FaramosCZ:resolveip_ipv6

Conversation

@FaramosCZ
Copy link
Copy Markdown
Contributor

resolveip: replace inet_aton/inet_addr, gethostbyname, gethostbyaddr, inet_ntoa with inet_pton, getaddrinfo, getnameinfo, inet_ntop.

These deprecated functions are IPv4-only and some are not thread-safe (gethostbyname, gethostbyaddr, and inet_ntoa use static internal buffers). The modernized code:

  • Adds IPv6 support for both forward and reverse lookups
  • Uses thread-safe APIs throughout
  • Eliminates the #ifdef WIN32 code path split (inet_pton works on both)
  • Removes the h_errno dependency (replaced by gai_strerror)
  • Uses AF_UNSPEC with getaddrinfo to return both IPv4 and IPv6 results
  • Preserves existing output format, exit codes, and special cases (Broadcast, Null-IP-Addr, Old-Bcast)

Bump version from 2.3 to 2.4 to reflect the API change.

Update Solaris library search in CMakeLists.txt from inet_aton to getaddrinfo since the old function is no longer referenced.

@gkodinov gkodinov added the External Contribution All PRs from entities outside of MariaDB Foundation, Corporation, Codership agreements. label Mar 25, 2026
@gkodinov gkodinov changed the title Replace deprecated network functions with modern POSIX equivalents MDEV-39169: Replace deprecated network functions with modern POSIX equivalents Mar 25, 2026
Copy link
Copy Markdown
Member

@gkodinov gkodinov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for your contribution! This is a preliminary review.

LGTM. I've taken the liberty of filing a jira for the task.

Please stand by for the final review.

I'd also be nice to have some sort of testing for this. Maybe resolve some IPv6 IP or something?

@FaramosCZ FaramosCZ force-pushed the resolveip_ipv6 branch 2 times, most recently from 70e52fc to 6333f1a Compare March 25, 2026 13:02
Copy link
Copy Markdown
Contributor

@raghunandanbhat raghunandanbhat left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@FaramosCZ , thanks for the contribution.

I have a few suggestion-

  • please squash two commits into a single commit
  • ensure that commit message starts with the MDEV number, something like MDEV-39169:...
  • plus, issues I found in test (comments below).

--echo # MDEV-39169: resolveip IPv6 support
--echo #

--source include/not_windows.inc
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please move the --source include.. to the top of the test file.

we write our mtr test in this format -

--source include/....inc 

--echo # 
--echo # MDEV-39169: resolveip IPv6 support
--echo # 

... <tests> ...

--echo # End of 13.x tests 

you have the header with MDEV, but footer is missing. please add the footer in your test with correct server version.

--echo #
--echo # IPv6 reverse lookup
--echo #
--exec $MYSQL_RESOLVEIP ::1 | sed 's/Host name of ::1 is .*/Host name of ::1 is HOSTNAME/'
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

these are some of the cases that were not resolved in my machine (Ubuntu 24) with resolveip, I believe these are valid IPv6 addresses

$ resolveip :: ::1 ::ffff:127.0.0.1 0000:0000:0000:0000:0000:0000:0000:0001
resolveip: Unable to find hostid for '::': host not found
resolveip: Unable to find hostid for '::1': host not found
resolveip: Unable to find hostid for '::ffff:127.0.0.1': host not found
resolveip: Unable to find hostid for '0000:0000:0000:0000:0000:0000:0000:0001': host not found

getent ahosts works but resolveip couldn't resolve them

$ getent ahosts :: ::1 ::ffff:127.0.0.1 0000:0000:0000:0000:0000:0000:0000:0001
::              STREAM ::
::              DGRAM  
::              RAW    
::1             STREAM ::1
::1             DGRAM  
::1             RAW    
::ffff:127.0.0.1 STREAM ::ffff:127.0.0.1
::ffff:127.0.0.1 DGRAM  
::ffff:127.0.0.1 RAW    
::1             STREAM 0000:0000:0000:0000:0000:0000:0000:0001
::1             DGRAM  
::1             RAW  

--exec $MYSQL_RESOLVEIP -s ::1 | sed 's/.*/HOSTNAME/'

--echo #
--echo # Error: invalid hostname
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for completeness, may be you can add few more tests- trying to resolve multiple addresses, invalid addresses, resolving multiple mixed args ( resolveip ipv4 ipv6, resolveip ipv4 hostname)

@FaramosCZ FaramosCZ marked this pull request as draft March 27, 2026 15:03
@FaramosCZ FaramosCZ force-pushed the resolveip_ipv6 branch 3 times, most recently from 096dd52 to e64c305 Compare March 27, 2026 15:51
Replace inet_aton/inet_addr/gethostbyname/gethostbyaddr with
their modern POSIX equivalents inet_pton/getaddrinfo/getnameinfo.
This adds IPv6 support to resolveip and removes dependency on the
deprecated h_errno global.

Handle IPv6 unspecified address (::) as Null-IP-Addr, consistent
with existing IPv4 INADDR_ANY handling for 0.0.0.0.

Add MTR test covering IPv4/IPv6 reverse lookups, special
addresses, multiple arguments, mixed address types, and
invalid hostname handling.

Co-Authored-By: Claude AI <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

External Contribution All PRs from entities outside of MariaDB Foundation, Corporation, Codership agreements.

Development

Successfully merging this pull request may close these issues.

3 participants