Hands-On-Network-Programming-with-C icon indicating copy to clipboard operation
Hands-On-Network-Programming-with-C copied to clipboard

Check result of getaddrinfo() calls consistently

Open Filkolev opened this issue 11 months ago • 0 comments

The getaddrinfo() function returns 0 on success or a non-zero error code on failure. For reference:

  • https://man7.org/linux/man-pages/man3/getaddrinfo.3.html
  • https://learn.microsoft.com/en-us/windows/win32/api/ws2tcpip/nf-ws2tcpip-getaddrinfo

On Unix systems, errno is only set in the case where the return code is EAI_SYSTEM, therefore showing the errno code in all other cases would not provide meaningful information.

Print the return code of the function call along with errno to provide all the information needed to determine the cause of the error.

Add checks for the return code where they are missing.

Filkolev avatar Nov 28 '24 17:11 Filkolev