81
81
int Posix_Printf(ConstUnicode format, ...);
82
82
int Posix_Fprintf(FILE *stream, ConstUnicode format, ...);
84
#if !defined(N_PLAT_NLM)
85
84
int Posix_Mkdir(ConstUnicode pathName, mode_t mode);
86
85
int Posix_Chdir(ConstUnicode pathName);
87
86
Unicode Posix_Getenv(ConstUnicode name);
88
87
long Posix_Pathconf(ConstUnicode pathName, int name);
89
88
int Posix_Lstat(ConstUnicode pathName, struct stat *statbuf);
92
90
#if !defined(_WIN32)
99
97
#define Posix_GetHostByName gethostbyname
101
99
#define Posix_GetAddrInfo getaddrinfo
100
#define Posix_FreeAddrInfo freeaddrinfo
102
101
#define Posix_GetNameInfo getnameinfo
104
103
void *Posix_Dlopen(ConstUnicode pathName, int flags);
106
105
int Posix_Utime(ConstUnicode pathName, const struct utimbuf *times);
108
#if !defined(N_PLAT_NLM)
109
107
int Posix_Mknod(ConstUnicode pathName, mode_t mode, dev_t dev);
110
108
int Posix_Chown(ConstUnicode pathName, uid_t owner, gid_t group);
111
109
int Posix_Lchown(ConstUnicode pathName, uid_t owner, gid_t group);
428
425
#ifdef _WS2TCPIP_H_
429
426
typedef int (WINAPI *GetAddrInfoWFnType)(PCWSTR pNodeName, PCWSTR pServiceName,
430
427
const struct addrinfo *pHints,
431
struct addrinfo **ppResult);
428
struct addrinfoW **ppResult);
429
typedef void (WINAPI *FreeAddrInfoWFnType)(struct addrinfoW *ai);
432
430
typedef int (WINAPI *GetNameInfoWFnType)(const SOCKADDR *pSockaddr,
433
431
socklen_t SockAddrLength,
434
432
PWCHAR pNodeBuffer,
461
459
const struct addrinfo *hints, // IN
462
460
struct addrinfo **res) // OUT
462
HMODULE hWs2_32 = GetModuleHandleW(L"ws2_32");
463
GetAddrInfoWFnType GetAddrInfoWFn = NULL;
464
FreeAddrInfoWFnType FreeAddrInfoWFn = NULL;
466
466
char *nodenameMBCS;
467
467
char *servnameMBCS;
468
GetAddrInfoWFnType GetAddrInfoWFn;
468
struct addrinfo *resA;
470
470
ASSERT(nodename || servname);
473
hWs2_32 = LoadLibraryW(L"ws2_32");
477
* If the unicode version of getaddrinfo exists, use it. The string
478
* conversion required is between UTF-8 and UTF-16 encodings. Note
479
* that struct addrinfo and ADDRINFOW are identical except for the
480
* fields ai_canonname (char * vs. PWSTR) and ai_next (obviously).
483
475
GetAddrInfoWFn = (GetAddrInfoWFnType)GetProcAddress(hWs2_32,
486
if (GetAddrInfoWFn) {
487
utf16_t *nodenameW = Unicode_GetAllocUTF16(nodename);
488
utf16_t *servnameW = Unicode_GetAllocUTF16(servname);
490
retval = (*GetAddrInfoWFn)(nodenameW, servnameW, hints, res);
493
struct addrinfo *cur;
496
for (cur = *res; cur != NULL; cur = cur->ai_next) {
497
if (cur->ai_canonname) {
498
tempW = (utf16_t *)cur->ai_canonname;
499
cur->ai_canonname = Unicode_AllocWithUTF16(tempW);
477
FreeAddrInfoWFn = (FreeAddrInfoWFnType)GetProcAddress(hWs2_32,
482
* If the unicode version of getaddrinfo exists, use it. The string
483
* conversion required is between UTF-8 and UTF-16 encodings. Note
484
* that struct addrinfo and ADDRINFOW are identical except for the
485
* fields ai_canonname (char * vs. PWSTR) and ai_next (obviously).
488
if (GetAddrInfoWFn && FreeAddrInfoWFn) {
489
utf16_t *nodenameW = Unicode_GetAllocUTF16(nodename);
490
utf16_t *servnameW = Unicode_GetAllocUTF16(servname);
491
struct addrinfoW *resW;
493
retval = (*GetAddrInfoWFn)(nodenameW, servnameW, hints, &resW);
496
struct addrinfoW *cur;
497
struct addrinfo **pres = res;
499
for (cur = resW; cur != NULL; cur = cur->ai_next) {
500
*pres = (struct addrinfo *)Util_SafeMalloc(sizeof **pres);
501
(*pres)->ai_flags = cur->ai_flags;
502
(*pres)->ai_family = cur->ai_family;
503
(*pres)->ai_socktype = cur->ai_socktype;
504
(*pres)->ai_protocol = cur->ai_protocol;
505
(*pres)->ai_addrlen = cur->ai_addrlen;
506
if (cur->ai_canonname) {
507
(*pres)->ai_canonname = Unicode_AllocWithUTF16(cur->ai_canonname);
509
(*pres)->ai_canonname = NULL;
511
(*pres)->ai_addr = (struct sockaddr *)
512
Util_SafeMalloc((*pres)->ai_addrlen);
513
memcpy((*pres)->ai_addr, cur->ai_addr, (*pres)->ai_addrlen);
514
pres = &((*pres)->ai_next);
517
FreeAddrInfoWFn(resW);
519
533
servnameMBCS = (char *)Unicode_GetAllocBytes(servname,
520
534
STRING_ENCODING_DEFAULT);
522
retval = getaddrinfo(nodenameMBCS, servnameMBCS, hints, res);
536
retval = getaddrinfo(nodenameMBCS, servnameMBCS, hints, &resA);
524
538
if (retval == 0) {
539
struct addrinfo **pres = res;
525
540
struct addrinfo *cur;
528
for (cur = *res; cur != NULL; cur = cur->ai_next) {
542
for (cur = resA; cur != NULL; cur = cur->ai_next) {
543
*pres = (struct addrinfo *)Util_SafeMalloc(sizeof **pres);
544
(*pres)->ai_flags = cur->ai_flags;
545
(*pres)->ai_family = cur->ai_family;
546
(*pres)->ai_socktype = cur->ai_socktype;
547
(*pres)->ai_protocol = cur->ai_protocol;
548
(*pres)->ai_addrlen = cur->ai_addrlen;
529
549
if (cur->ai_canonname) {
530
temp = cur->ai_canonname;
531
cur->ai_canonname = Unicode_Alloc(temp, STRING_ENCODING_DEFAULT);
550
(*pres)->ai_canonname = Unicode_Alloc(cur->ai_canonname,
551
STRING_ENCODING_DEFAULT);
553
(*pres)->ai_canonname = NULL;
555
(*pres)->ai_addr = (struct sockaddr *)
556
Util_SafeMalloc((*pres)->ai_addrlen);
557
memcpy((*pres)->ai_addr, cur->ai_addr, (*pres)->ai_addrlen);
558
pres = &((*pres)->ai_next);
537
564
free(nodenameMBCS);
538
565
free(servnameMBCS);
542
FreeLibrary(hWs2_32);
573
*----------------------------------------------------------------------------
575
* Posix_FreeAddrInfo --
577
* Free the addrinfo structure allocated by Posix_GetAddrInfo.
585
*----------------------------------------------------------------------------
589
Posix_FreeAddrInfo(struct addrinfo *ai)
591
struct addrinfo *temp;
596
free(temp->ai_canonname);
688
742
#if (defined(VMX86_SERVER) || defined(__APPLE__)) && \
689
743
!defined(UNICODE_BUILDING_POSIX_WRAPPERS)
691
* ESX and MacOS X are UTF-8 environments so these functions can be
745
* ESX and Mac OS are UTF-8 environments so these functions can be
692
746
* "defined away" - the POSIX wrapper call can be directly mapped to the
693
747
* POSIX function avoiding unneccesary (call and handling) overhead.