mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-07-20 17:40:30 +00:00
Polyfill ENOTSOCK in getsockname() and getpeername()
This commit is contained in:
parent
eb84a25994
commit
925219bdf3
1 changed files with 14 additions and 14 deletions
|
@ -39,21 +39,21 @@ static int __getsockpeername(int fd, struct sockaddr *out_addr,
|
||||||
uint32_t size = sizeof(ss);
|
uint32_t size = sizeof(ss);
|
||||||
|
|
||||||
if (IsWindows()) {
|
if (IsWindows()) {
|
||||||
if (__isfdkind(fd, kFdSocket)) {
|
if (!__isfdopen(fd)) {
|
||||||
if ((rc = impl_win32(g_fds.p[fd].handle, &ss, &size))) {
|
|
||||||
if (impl_win32 == __sys_getsockname_nt &&
|
|
||||||
WSAGetLastError() == WSAEINVAL) {
|
|
||||||
// The socket has not been bound to an address with bind, or
|
|
||||||
// ADDR_ANY is specified in bind but connection has not yet
|
|
||||||
// occurred. -MSDN
|
|
||||||
ss.ss_family = ((struct SockFd *)g_fds.p[fd].extra)->family;
|
|
||||||
rc = 0;
|
|
||||||
} else {
|
|
||||||
rc = __winsockerr();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
rc = ebadf();
|
rc = ebadf();
|
||||||
|
} else if (!__isfdkind(fd, kFdSocket)) {
|
||||||
|
rc = enotsock();
|
||||||
|
} else if ((rc = impl_win32(g_fds.p[fd].handle, &ss, &size))) {
|
||||||
|
if (impl_win32 == __sys_getsockname_nt &&
|
||||||
|
WSAGetLastError() == WSAEINVAL) {
|
||||||
|
// The socket has not been bound to an address with bind, or
|
||||||
|
// ADDR_ANY is specified in bind but connection has not yet
|
||||||
|
// occurred. -MSDN
|
||||||
|
ss.ss_family = ((struct SockFd *)g_fds.p[fd].extra)->family;
|
||||||
|
rc = 0;
|
||||||
|
} else {
|
||||||
|
rc = __winsockerr();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
rc = impl_sysv(fd, &ss, &size);
|
rc = impl_sysv(fd, &ss, &size);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue