Conversation
There was a problem hiding this comment.
Pull request overview
This PR refactors curl’s local curlx_inet_ntop() API to return platform socket errors via an explicit out-parameter instead of using errno, removing a Windows-specific exception and making error handling more consistent across platforms.
Changes:
- Extend
curlx_inet_ntop()to acceptint *sockerrand propagateSOCKEAFNOSUPPORT/SOCKEINVALthrough it (rather thanerrno/ENOSPC). - Stop setting
errnoincurlx_inet_pton()(callers don’t use it). - Update call sites (notably
sockaddr2string()and its unit tests) to pass/handle the new parameter.
Reviewed changes
Copilot reviewed 13 out of 13 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| tests/unit/unit1961.c | Updates curlx_inet_ntop() unit test calls for the new sockerr parameter. |
| tests/unit/unit1609.c | Updates sockaddr2string() unit test call to pass a sockerr out-parameter. |
| tests/unit/unit1607.c | Updates sockaddr2string() unit test call to pass a sockerr out-parameter. |
| tests/server/dnsd.c | Updates server-side logging conversions to pass NULL for sockerr. |
| lib/urlapi.c | Updates IPv6 formatting call site to pass NULL for sockerr. |
| lib/if2ip.c | Updates interface-to-IP formatting call sites to pass NULL for sockerr. |
| lib/httpsrr.c | Updates address printing helper to pass NULL for sockerr. |
| lib/hostip.c | Updates printable-address helper to pass NULL for sockerr. |
| lib/ftp.c | Updates FTP PORT host formatting to pass NULL for sockerr. |
| lib/curlx/inet_pton.c | Removes errno assignment and updates related comments. |
| lib/curlx/inet_ntop.h | Updates curlx_inet_ntop() declaration with int *sockerr. |
| lib/curlx/inet_ntop.c | Implements sockerr propagation and replaces prior errno behavior. |
| lib/cf-socket.c | Plumbs sockerr through sockaddr2string() and related connection logging/error paths. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| switch(sa->sa_family) { | ||
| case AF_INET: | ||
| si = (struct sockaddr_in *)(void *)sa; | ||
| if(curlx_inet_ntop(sa->sa_family, &si->sin_addr, addr, MAX_IPADR_LEN)) { | ||
| if(curlx_inet_ntop(sa->sa_family, &si->sin_addr, addr, MAX_IPADR_LEN, | ||
| sockerr)) { |
There was a problem hiding this comment.
Oh, does this mean that the only code using these errnos, was only
ever returning SOCKEAFNOSUPPORT after all? If so, and nobody
noticed and it didn't cause issues, maybe this dance with sockerrs is
superfluous and this could be simplified by dropping it completely?
The store a fixed code in ctx→sockerr in case of any error.
Any second look / opinion on this?
|
I propose going one step further and make it as we would make a proper curl function and skip the errno. Return zero on success or an error code. |
I started out from ~there (with CURLcode 2af660f), then went back That said we can use dedicated error codes (or CURLcode) and |
|
I'm not following. If we completely drop the errno handling and don't even pass back any extra value in an argument, what breaks? |
8ca1cc8 to
b9bee70
Compare
|
Indeed, since in practice the returned sockerr wasn't used, I went In the single call where that return value was used previously, but (sorry for the delay with this.) |
errno, it was unused
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 3 out of 3 changed files in this pull request and generated no new comments.
Suppressed comments (3)
lib/cf-socket.c:1120
- This error path now reports only "inet_ntop() failed" and always sets ctx->sockerr to SOCKEAFNOSUPPORT, which makes the failure hard to diagnose. Even if you want to keep a fixed sockerr value, the message should at least include the address family and the chosen sockerr value so logs remain actionable.
ctx->sockerr = SOCKEAFNOSUPPORT;
/* malformed address or bug in inet_ntop, try next address */
failf(data, "curl_sa_addr inet_ntop() failed");
return CURLE_FAILED_INIT;
lib/cf-socket.c:2167
- This message was simplified to omit errno/strerror, but it is now too generic and attributes the failure specifically to inet_ntop(). Since the failure comes from sockaddr2string(), include at least the address family so debugging logs can distinguish unsupported families from other conversion failures.
failf(data, "ssrem inet_ntop() failed");
lib/cf-socket.c:1099
- The new log line loses context (errno/strerror) and also hard-codes the failure as an inet_ntop() problem, but the failure actually comes from sockaddr2string() (which can fail for reasons other than inet_ntop). Including the address family makes this actionable when debugging.
This issue also appears on line 2167 of the same file.
infof(data, "ssloc inet_ntop() failed");
|
Copilot (low-confidence) reports that after this patch there is one infof() |
|
I'm still in favor of "just return CURLcode" (and avoid errno). |
b9bee70 to
49f7c58
Compare
a5b9d2e to
74d8d72
Compare
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 12 out of 12 changed files in this pull request and generated no new comments.
Suppressed comments (1)
lib/curlx/inet_ntop.c:188
- The comment still says this function returns the destination pointer, but the new signature returns only a
CURLcode. Remove the pointer-return sentence so the documented contract is unambiguous.
* Returns pointer to presentation format address ('buf').
* Returns CURLcode.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 11 out of 11 changed files in this pull request and generated no new comments.
Suppressed comments (4)
lib/cf-socket.c:1129
- This user-facing failure now reports only an unlabeled numeric
CURLcode, losing the explanation previously supplied bycurlx_strerror(). Includecurl_easy_strerror(result)(and label the number as aCURLcode) so users can identify the actual conversion failure.
failf(data, "curl_sa_addr inet_ntop() failed with %d", (int)result);
lib/cf-socket.c:2179
- The revised message emits only an unlabeled integer for the
CURLcode, unlike the previous diagnostic which included readable error text. Addcurl_easy_strerror(result)and identify the numeric value as aCURLcode.
failf(data, "ssrem inet_ntop() failed with %d", (int)result);
lib/if2ip.c:158
- The return value is ignored even though
ipstris uninitialized until conversion succeeds. If an unsupported address family reaches this path,curlx_inet_ntop()returns an error without writingipstr, and the following%sreads indeterminate data while the function reportsIF2IP_FOUND. Handle the error before formatting the result.
(void)curlx_inet_ntop(af, addr, ipstr, sizeof(ipstr));
curl_msnprintf(buf, buf_size, "%s%s", ipstr, scope);
lib/cf-socket.c:1107
- This updated diagnostic replaces the prior descriptive socket error with an unlabeled numeric
CURLcode, producing messages such asfailed with 100. Include the code type andcurl_easy_strerror(result)so the failure remains actionable.
This issue also appears in the following locations of the same file:
- line 1129
- line 2179
if(result)
infof(data, "ssloc inet_ntop() failed with %d", (int)result);
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 11 out of 11 changed files in this pull request and generated no new comments.
Suppressed comments (1)
lib/if2ip.c:159
- On conversion failure this still sets
restoIF2IP_FOUND, even though the contract says that result means an address was stored inbuf; the buffer instead receives onlyscope(or an empty string). The ioctl implementation below returnsIF2IP_NOT_FOUNDfor the same failure. SetIF2IP_FOUNDand format the address only after a successful conversion.
res = IF2IP_FOUND;
result = curlx_inet_ntop(af, addr, ipstr, sizeof(ipstr));
curl_msnprintf(buf, buf_size, "%s%s", result ? "" : ipstr, scope);
|
Reworked to return CURLcode, and ready from my end. |
To simplify and to remove an exception where
errnowas reused toreturn a socket error codes on Windows.
The error was used by one call site (
sockaddr2string()incf-socket.c), but it was in practice always propagated asSOCKEAFNOSUPPORTto callers.Also:
CURLcodeaccordingly.curlx_inet_ntop()error inCurl_if2ip().CURLcodeon two errors.Follow-up to 39dec13 #22170
https://github.com/curl/curl/pull/22229/files?w=1
sockaddr2string()was overwriting the result with the same errorSOCKEAFNOSUPPORT, prior to this patch.It means the code never actually saw the values
WSAEINVAL/ENOSPC.errno. Separate PR. → curlx_inet_pton: drop settingerrnoon error #22607