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

Go to the source code of this file.

Functions

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

◆ uv__getnameinfo_done()

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

Definition at line 55 of file getnameinfo.c.

55  {
57  char* host;
58  char* service;
59 
60  req = container_of(w, uv_getnameinfo_t, work_req);
61  uv__req_unregister(req->loop, req);
62  host = service = NULL;
63 
64  if (status == UV_ECANCELED) {
65  assert(req->retcode == 0);
66  req->retcode = UV_EAI_CANCELED;
67  } else if (req->retcode == 0) {
68  host = req->host;
69  service = req->service;
70  }
71 
72  if (req->getnameinfo_cb)
73  req->getnameinfo_cb(req, req->retcode, host, service);
74 }
#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 31 of file getnameinfo.c.

31  {
33  int err;
34  socklen_t salen;
35 
36  req = container_of(w, uv_getnameinfo_t, work_req);
37 
38  if (req->storage.ss_family == AF_INET)
39  salen = sizeof(struct sockaddr_in);
40  else if (req->storage.ss_family == AF_INET6)
41  salen = sizeof(struct sockaddr_in6);
42  else
43  abort();
44 
45  err = getnameinfo((struct sockaddr*) &req->storage,
46  salen,
47  req->host,
48  sizeof(req->host),
49  req->service,
50  sizeof(req->service),
51  req->flags);
53 }
static bool err
Definition: armass.c:435
unsigned int socklen_t
Definition: sftypes.h:219
#define AF_INET
Definition: sftypes.h:287
#define AF_INET6
Definition: sftypes.h:295
int uv__getaddrinfo_translate_error(int sys_err)
Definition: getaddrinfo.c:42

References AF_INET, AF_INET6, container_of, err, req, uv__getaddrinfo_translate_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 81 of file getnameinfo.c.

85  {
86  if (req == NULL || addr == NULL)
87  return UV_EINVAL;
88 
89  if (addr->sa_family == AF_INET) {
90  memcpy(&req->storage,
91  addr,
92  sizeof(struct sockaddr_in));
93  } else if (addr->sa_family == AF_INET6) {
94  memcpy(&req->storage,
95  addr,
96  sizeof(struct sockaddr_in6));
97  } else {
98  return UV_EINVAL;
99  }
100 
101  uv__req_init(loop, (uv_req_t*)req, UV_GETNAMEINFO);
102 
103  req->getnameinfo_cb = getnameinfo_cb;
104  req->flags = flags;
105  req->type = UV_GETNAMEINFO;
106  req->loop = loop;
107  req->retcode = 0;
108 
109  if (getnameinfo_cb) {
111  &req->work_req,
115  return 0;
116  } else {
117  uv__getnameinfo_work(&req->work_req);
118  uv__getnameinfo_done(&req->work_req, 0);
119  return req->retcode;
120  }
121 }
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
Definition: uv.h:407
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
static void uv__getnameinfo_work(struct uv__work *w)
Definition: getnameinfo.c:31
static void uv__getnameinfo_done(struct uv__work *w, int status)
Definition: getnameinfo.c:55
@ UV__WORK_SLOW_IO
Definition: uv-common.h:194
#define uv__req_init(loop, req, typ)
Definition: uv-common.h:329
static int addr
Definition: z80asm.c:58