Skip to content

Commit

Permalink
[Net] Fixed incorrect endianness in GetOption optval
Browse files Browse the repository at this point in the history
  • Loading branch information
Gliniak authored and AdrianCassar committed Apr 30, 2024
1 parent fbdb1a6 commit 1f115b9
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/xenia/kernel/xsocket.cc
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,23 @@ X_STATUS XSocket::GetOption(uint32_t level, uint32_t optname, void* optval_ptr,
int* optlen) {
int ret =
getsockopt(native_handle_, level, optname, (char*)optval_ptr, optlen);

// Because values provided in optval_ptr are in LE we must to somehow save
// them in BE.
switch (*optlen) {
case 4:
xe::copy_and_swap<uint32_t>((uint32_t*)optval_ptr, (uint32_t*)optval_ptr,
(uint32_t)*optlen);
break;
case 8:
xe::copy_and_swap<uint64_t>((uint64_t*)optval_ptr, (uint64_t*)optval_ptr,
(uint32_t)*optlen);
break;
default:
XELOGE("XSocket::GetOption - Unhandled optlen: {}", *optlen);
break;
}

if (ret < 0) {
// TODO: WSAGetLastError()
return X_STATUS_UNSUCCESSFUL;
Expand Down

0 comments on commit 1f115b9

Please sign in to comment.