mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-08-06 01:40:28 +00:00
add __convert_sockaddr_un_to_nt
This commit is contained in:
parent
c2d5152958
commit
b6ff9e82d9
4 changed files with 19 additions and 12 deletions
|
@ -27,12 +27,9 @@
|
||||||
__msabi extern typeof(__sys_bind_nt) *const __imp_bind;
|
__msabi extern typeof(__sys_bind_nt) *const __imp_bind;
|
||||||
|
|
||||||
textwindows int sys_bind_nt(struct Fd *f, const void *addr, uint32_t addrsize) {
|
textwindows int sys_bind_nt(struct Fd *f, const void *addr, uint32_t addrsize) {
|
||||||
struct sockaddr_un *sun, nt_sun;
|
struct sockaddr_un nt_sun;
|
||||||
if (f->family == AF_UNIX && ((struct sockaddr *)addr)->sa_family == AF_UNIX &&
|
if (f->family == AF_UNIX) {
|
||||||
addrsize >= sizeof(struct sockaddr_un)) {
|
if (__convert_sockaddr_un_to_nt(&nt_sun, addr, addrsize) == -1) return -1;
|
||||||
sun = (struct sockaddr_un *)addr;
|
|
||||||
nt_sun.sun_family = AF_UNIX;
|
|
||||||
if (__mkntsunpath(sun->sun_path, nt_sun.sun_path) == -1) return -1;
|
|
||||||
addr = &nt_sun;
|
addr = &nt_sun;
|
||||||
}
|
}
|
||||||
if (__imp_bind(f->handle, addr, addrsize) != -1) {
|
if (__imp_bind(f->handle, addr, addrsize) != -1) {
|
||||||
|
|
|
@ -142,12 +142,9 @@ static textwindows int sys_connect_nt_impl(struct Fd *f, const void *addr,
|
||||||
|
|
||||||
textwindows int sys_connect_nt(struct Fd *f, const void *addr,
|
textwindows int sys_connect_nt(struct Fd *f, const void *addr,
|
||||||
uint32_t addrsize) {
|
uint32_t addrsize) {
|
||||||
struct sockaddr_un *sun, nt_sun;
|
struct sockaddr_un nt_sun;
|
||||||
if (f->family == AF_UNIX && ((struct sockaddr *)addr)->sa_family == AF_UNIX &&
|
if (f->family == AF_UNIX) {
|
||||||
addrsize >= sizeof(struct sockaddr_un)) {
|
if (__convert_sockaddr_un_to_nt(&nt_sun, addr, addrsize) == -1) return -1;
|
||||||
sun = (struct sockaddr_un *)addr;
|
|
||||||
nt_sun.sun_family = AF_UNIX;
|
|
||||||
if (__mkntsunpath(sun->sun_path, nt_sun.sun_path) == -1) return -1;
|
|
||||||
addr = &nt_sun;
|
addr = &nt_sun;
|
||||||
}
|
}
|
||||||
sigset_t mask = __sig_block();
|
sigset_t mask = __sig_block();
|
||||||
|
|
|
@ -17,6 +17,7 @@
|
||||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||||
#include "libc/sock/struct/sockaddr.h"
|
#include "libc/sock/struct/sockaddr.h"
|
||||||
|
#include "libc/calls/syscall_support-nt.internal.h"
|
||||||
#include "libc/macros.internal.h"
|
#include "libc/macros.internal.h"
|
||||||
#include "libc/sock/sock.h"
|
#include "libc/sock/sock.h"
|
||||||
#include "libc/sock/struct/sockaddr.h"
|
#include "libc/sock/struct/sockaddr.h"
|
||||||
|
@ -61,6 +62,17 @@ void __convert_sockaddr_to_bsd(struct sockaddr_storage *addr) {
|
||||||
pun->bsd.sa_len = len;
|
pun->bsd.sa_len = len;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// converts cosmo sockaddr_un abi to nt
|
||||||
|
int __convert_sockaddr_un_to_nt(struct sockaddr_un *out_addr, const void *addr,
|
||||||
|
uint32_t addrsize) {
|
||||||
|
const struct sockaddr_un *sun = addr;
|
||||||
|
if (sun->sun_family == AF_UNIX && addrsize >= sizeof(struct sockaddr_un)) {
|
||||||
|
out_addr->sun_family = AF_UNIX;
|
||||||
|
if (__mkntsunpath(sun->sun_path, out_addr->sun_path) == -1) return -1;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
// copies sockaddr from internal memory to user's buffer
|
// copies sockaddr from internal memory to user's buffer
|
||||||
void __write_sockaddr(const struct sockaddr_storage *addr, void *out_addr,
|
void __write_sockaddr(const struct sockaddr_storage *addr, void *out_addr,
|
||||||
uint32_t *inout_addrsize) {
|
uint32_t *inout_addrsize) {
|
||||||
|
|
|
@ -45,6 +45,7 @@ const char *DescribeSockaddr(char[128], const struct sockaddr *, size_t);
|
||||||
|
|
||||||
void __convert_bsd_to_sockaddr(struct sockaddr_storage *);
|
void __convert_bsd_to_sockaddr(struct sockaddr_storage *);
|
||||||
void __convert_sockaddr_to_bsd(struct sockaddr_storage *);
|
void __convert_sockaddr_to_bsd(struct sockaddr_storage *);
|
||||||
|
int __convert_sockaddr_un_to_nt(struct sockaddr_un *, const void *, uint32_t);
|
||||||
uint8_t __get_sockaddr_len(const struct sockaddr_storage *);
|
uint8_t __get_sockaddr_len(const struct sockaddr_storage *);
|
||||||
void __write_sockaddr(const struct sockaddr_storage *, void *, uint32_t *);
|
void __write_sockaddr(const struct sockaddr_storage *, void *, uint32_t *);
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue