win/getnameinfo.c
Go to the documentation of this file.
1 /* Copyright Joyent, Inc. and other Node contributors. All rights reserved.
2 *
3 * Permission is hereby granted, free of charge, to any person obtaining a copy
4 * of this software and associated documentation files (the "Software"), to
5 * deal in the Software without restriction, including without limitation the
6 * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
7 * sell copies of the Software, and to permit persons to whom the Software is
8 * furnished to do so, subject to the following conditions:
9 *
10 * The above copyright notice and this permission notice shall be included in
11 * all copies or substantial portions of the Software.
12 *
13 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
18 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
19 * IN THE SOFTWARE.
20 */
21 
22 #include <assert.h>
23 #include <stdio.h>
24 
25 #include "uv.h"
26 #include "internal.h"
27 #include "req-inl.h"
28 
29 #ifndef GetNameInfo
30 int WSAAPI GetNameInfoW(
31  const SOCKADDR *pSockaddr,
32  socklen_t SockaddrLength,
33  PWCHAR pNodeBuffer,
34  DWORD NodeBufferSize,
35  PWCHAR pServiceBuffer,
36  DWORD ServiceBufferSize,
37  INT Flags
38 );
39 #endif
40 
41 static void uv__getnameinfo_work(struct uv__work* w) {
43  WCHAR host[NI_MAXHOST];
44  WCHAR service[NI_MAXSERV];
45  int ret;
46 
48  if (GetNameInfoW((struct sockaddr*)&req->storage,
49  sizeof(req->storage),
50  host,
51  ARRAY_SIZE(host),
52  service,
54  req->flags)) {
55  ret = WSAGetLastError();
57  return;
58  }
59 
60  ret = WideCharToMultiByte(CP_UTF8,
61  0,
62  host,
63  -1,
64  req->host,
65  sizeof(req->host),
66  NULL,
67  NULL);
68  if (ret == 0) {
69  req->retcode = uv_translate_sys_error(GetLastError());
70  return;
71  }
72 
73  ret = WideCharToMultiByte(CP_UTF8,
74  0,
75  service,
76  -1,
77  req->service,
78  sizeof(req->service),
79  NULL,
80  NULL);
81  if (ret == 0) {
82  req->retcode = uv_translate_sys_error(GetLastError());
83  }
84 }
85 
86 
87 /*
88 * Called from uv_run when complete.
89 */
90 static void uv__getnameinfo_done(struct uv__work* w, int status) {
92  char* host;
93  char* service;
94 
96  uv__req_unregister(req->loop, req);
97  host = service = NULL;
98 
99  if (status == UV_ECANCELED) {
100  assert(req->retcode == 0);
101  req->retcode = UV_EAI_CANCELED;
102  } else if (req->retcode == 0) {
103  host = req->host;
104  service = req->service;
105  }
106 
107  if (req->getnameinfo_cb)
108  req->getnameinfo_cb(req, req->retcode, host, service);
109 }
110 
111 
112 /*
113 * Entry point for getnameinfo
114 * return 0 if a callback will be made
115 * return error code if validation fails
116 */
120  const struct sockaddr* addr,
121  int flags) {
122  if (req == NULL || addr == NULL)
123  return UV_EINVAL;
124 
125  if (addr->sa_family == AF_INET) {
126  memcpy(&req->storage,
127  addr,
128  sizeof(struct sockaddr_in));
129  } else if (addr->sa_family == AF_INET6) {
130  memcpy(&req->storage,
131  addr,
132  sizeof(struct sockaddr_in6));
133  } else {
134  return UV_EINVAL;
135  }
136 
137  UV_REQ_INIT(req, UV_GETNAMEINFO);
139 
140  req->getnameinfo_cb = getnameinfo_cb;
141  req->flags = flags;
142  req->loop = loop;
143  req->retcode = 0;
144 
145  if (getnameinfo_cb) {
147  &req->work_req,
151  return 0;
152  } else {
153  uv__getnameinfo_work(&req->work_req);
154  uv__getnameinfo_done(&req->work_req, 0);
155  return req->retcode;
156  }
157 }
async_greeter_server_with_graceful_shutdown.loop
loop
Definition: async_greeter_server_with_graceful_shutdown.py:59
uv__work
Definition: third_party/libuv/include/uv/threadpool.h:30
ARRAY_SIZE
#define ARRAY_SIZE(array)
Definition: bloaty.cc:101
AF_INET6
#define AF_INET6
Definition: ares_setup.h:208
GetNameInfoW
int WSAAPI GetNameInfoW(const SOCKADDR *pSockaddr, socklen_t SockaddrLength, PWCHAR pNodeBuffer, DWORD NodeBufferSize, PWCHAR pServiceBuffer, DWORD ServiceBufferSize, INT Flags)
status
absl::Status status
Definition: rls.cc:251
uv_getnameinfo_s
Definition: uv.h:894
NI_MAXHOST
#define NI_MAXHOST
Definition: unix.h:75
container_of
#define container_of(ptr, type, member)
Definition: uv-common.h:57
req-inl.h
memcpy
memcpy(mem, inblock.get(), min(CONTAINING_RECORD(inblock.get(), MEMBLOCK, data) ->size, size))
sockaddr_in6
Definition: ares_ipv6.h:25
req
static uv_connect_t req
Definition: test-connection-fail.c:30
uv_translate_sys_error
UV_EXTERN int uv_translate_sys_error(int sys_errno)
Definition: unix/core.c:1244
getnameinfo_cb
static void getnameinfo_cb(uv_getnameinfo_t *handle, int status, const char *hostname, const char *service)
Definition: test-threadpool-cancel.c:106
uv_getnameinfo_cb
void(* uv_getnameinfo_cb)(uv_getnameinfo_t *req, int status, const char *hostname, const char *service)
Definition: uv.h:331
uv__getaddrinfo_translate_error
int uv__getaddrinfo_translate_error(int sys_err)
Definition: unix/getaddrinfo.c:42
absl::str_format_internal::Flags
Flags
Definition: abseil-cpp/absl/strings/internal/str_format/extension.h:134
uv.h
UV_REQ_INIT
#define UV_REQ_INIT(req, typ)
Definition: uv-common.h:305
UV__WORK_SLOW_IO
@ UV__WORK_SLOW_IO
Definition: uv-common.h:181
NI_MAXSERV
#define NI_MAXSERV
Definition: unix.h:79
absl::flags_internal
Definition: abseil-cpp/absl/flags/commandlineflag.h:40
uv__req_register
#define uv__req_register(loop, req)
Definition: uv-common.h:207
ret
UniquePtr< SSL_SESSION > ret
Definition: ssl_x509.cc:1029
uv_getnameinfo
int uv_getnameinfo(uv_loop_t *loop, uv_getnameinfo_t *req, uv_getnameinfo_cb getnameinfo_cb, const struct sockaddr *addr, int flags)
Definition: win/getnameinfo.c:117
uv__getnameinfo_work
static void uv__getnameinfo_work(struct uv__work *w)
Definition: win/getnameinfo.c:41
uv_loop_s
Definition: uv.h:1767
flags
uint32_t flags
Definition: retry_filter.cc:632
internal.h
service
__attribute__((deprecated("Please use GRPCProtoMethod."))) @interface ProtoMethod NSString * service
Definition: ProtoMethod.h:25
work_req
static uv_work_t work_req
Definition: test-loop-alive.c:32
uv__work_submit
void uv__work_submit(uv_loop_t *loop, struct uv__work *w, enum uv__work_kind kind, void(*work)(struct uv__work *w), void(*done)(struct uv__work *w, int status))
Definition: threadpool.c:256
uv__getnameinfo_done
static void uv__getnameinfo_done(struct uv__work *w, int status)
Definition: win/getnameinfo.c:90
addr
struct sockaddr_in addr
Definition: libuv/docs/code/tcp-echo-server/main.c:10
uv__req_unregister
#define uv__req_unregister(loop, req)
Definition: uv-common.h:213


grpc
Author(s):
autogenerated on Fri May 16 2025 02:58:28