fix: use errno instead of getsockopt return value for strerror

getsockopt() returns -1 on error, not an errno value. The actual error
code is stored in errno. Using strerror(retval) with retval=-1 gives
incorrect error messages.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
Isaac Connor
2026-02-02 20:56:04 -05:00
parent 2f14c6559a
commit 4e0476603a

View File

@@ -231,7 +231,7 @@ int RemoteCameraHttp::ReadData(Buffer &buffer, unsigned int bytes_expected) {
socklen_t len = sizeof(error);
int retval = getsockopt(sd, SOL_SOCKET, SO_ERROR, &error, &len);
if (retval != 0) {
Debug(1, "error getting socket error code %s", strerror(retval));
Debug(1, "error getting socket error code %s", strerror(errno));
}
if (error != 0) {
return -1;
@@ -263,7 +263,7 @@ int RemoteCameraHttp::ReadData(Buffer &buffer, unsigned int bytes_expected) {
socklen_t len = sizeof(error);
int retval = getsockopt(sd, SOL_SOCKET, SO_ERROR, &error, &len);
if (retval != 0) {
Debug(1, "error getting socket error code %s", strerror(retval));
Debug(1, "error getting socket error code %s", strerror(errno));
}
if (error != 0) {
return -1;