Rizin
unix-like reverse engineering framework and cli tools
getnameinfo.c File Reference
#include <assert.h>
#include <stdio.h>
#include "uv.h"
#include "internal.h"
#include "req-inl.h"

Go to the source code of this file.

Functions

int WSAAPI GetNameInfoW (const SOCKADDR *pSockaddr, socklen_t SockaddrLength, PWCHAR pNodeBuffer, DWORD NodeBufferSize, PWCHAR pServiceBuffer, DWORD ServiceBufferSize, INT Flags)
 
static void uv__getnameinfo_work (struct uv__work *w)
 
static void uv__getnameinfo_done (struct uv__work *w, int status)
 
int uv_getnameinfo (uv_loop_t *loop, uv_getnameinfo_t *req, uv_getnameinfo_cb getnameinfo_cb, const struct sockaddr *addr, int flags)
 

Function Documentation

◆ GetNameInfoW()

int WSAAPI GetNameInfoW ( const SOCKADDR *  pSockaddr,
socklen_t  SockaddrLength,
PWCHAR  pNodeBuffer,
DWORD  NodeBufferSize,
PWCHAR  pServiceBuffer,
DWORD  ServiceBufferSize,
INT  Flags 
)

Referenced by uv__getnameinfo_work().

◆ uv__getnameinfo_done()

static void uv__getnameinfo_done ( struct uv__work w,
int  status 
)
static

Definition at line 90 of file getnameinfo.c.

90  {
92  char* host;
93  char* service;
94 
95  req = container_of(w, uv_getnameinfo_t, work_req);
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 }
#define NULL
Definition: cris-opc.c:27
#define w
Definition: crypto_rc6.c:13
static static sync static getppid static getegid const char static filename char static len const char char static bufsiz static mask static vfork const void static prot static getpgrp const char static swapflags static arg static fd static protocol static who struct sockaddr static addrlen static backlog struct timeval struct timezone static tz const struct iovec static count static mode const void const struct sockaddr static tolen const char static pathname void static offset struct stat static buf void long static basep static whence static length const void static len static semflg const void static shmflg const struct timespec req
Definition: sflib.h:128
static const char struct stat static buf struct stat static buf static vhangup int status
Definition: sflib.h:145
assert(limit<=UINT32_MAX/2)
#define container_of(ptr, type, member)
Definition: rz_types.h:650
#define uv__req_unregister(loop, req)
Definition: uv-common.h:230

References assert(), container_of, NULL, req, status, uv__req_unregister, and w.

Referenced by uv_getnameinfo().

◆ uv__getnameinfo_work()

static void uv__getnameinfo_work ( struct uv__work w)
static

Definition at line 41 of file getnameinfo.c.

41  {
43  WCHAR host[NI_MAXHOST];
44  WCHAR service[NI_MAXSERV];
45  int ret;
46 
47  req = container_of(w, uv_getnameinfo_t, work_req);
48  if (GetNameInfoW((struct sockaddr*)&req->storage,
49  sizeof(req->storage),
50  host,
51  ARRAY_SIZE(host),
52  service,
53  ARRAY_SIZE(service),
54  req->flags)) {
55  ret = WSAGetLastError();
56  req->retcode = uv__getaddrinfo_translate_error(ret);
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 }
#define ARRAY_SIZE(a)
int uv__getaddrinfo_translate_error(int sys_err)
Definition: getaddrinfo.c:42
#define NI_MAXHOST
Definition: unix.h:77
#define NI_MAXSERV
Definition: unix.h:81
UV_EXTERN int uv_translate_sys_error(int sys_errno)
Definition: core.c:1249
int WSAAPI GetNameInfoW(const SOCKADDR *pSockaddr, socklen_t SockaddrLength, PWCHAR pNodeBuffer, DWORD NodeBufferSize, PWCHAR pServiceBuffer, DWORD ServiceBufferSize, INT Flags)

References ARRAY_SIZE, container_of, GetNameInfoW(), NI_MAXHOST, NI_MAXSERV, NULL, req, uv__getaddrinfo_translate_error(), uv_translate_sys_error(), and w.

Referenced by uv_getnameinfo().

◆ 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 at line 117 of file getnameinfo.c.

121  {
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 }
memcpy(mem, inblock.get(), min(CONTAINING_RECORD(inblock.get(), MEMBLOCK, data) ->size, size))
static struct sockaddr static addrlen static backlog const void static flags void flags
Definition: sfsocketcall.h:123
#define AF_INET
Definition: sftypes.h:287
#define AF_INET6
Definition: sftypes.h:295
uv_loop_t * loop
Definition: main.c:7
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
#define UV_REQ_INIT(req, typ)
Definition: uv-common.h:322
@ UV__WORK_SLOW_IO
Definition: uv-common.h:194
#define uv__req_register(loop, req)
Definition: uv-common.h:224
static void uv__getnameinfo_work(struct uv__work *w)
Definition: getnameinfo.c:41
static void uv__getnameinfo_done(struct uv__work *w, int status)
Definition: getnameinfo.c:90
static int addr
Definition: z80asm.c:58

References addr, AF_INET, AF_INET6, flags, loop, memcpy(), NULL, req, uv__getnameinfo_done(), uv__getnameinfo_work(), uv__req_init, uv__req_register, UV__WORK_SLOW_IO, uv__work_submit(), and UV_REQ_INIT.