Rizin
unix-like reverse engineering framework and cli tools
iob_pipe.c File Reference
#include <fcntl.h>
#include <stdio.h>
#include <string.h>
#include <rz_types.h>
#include <rz_util.h>
#include "transport.h"
#include <errno.h>
#include <sys/socket.h>
#include <sys/select.h>
#include <sys/un.h>

Go to the source code of this file.

Functions

static void * iob_pipe_open (const char *path)
 
static bool iob_pipe_close (void *p)
 
static int iob_pipe_read (void *p, uint8_t *buf, const uint64_t count, const int timeout)
 
static int iob_pipe_write (void *p, const uint8_t *buf, const uint64_t count, const int timeout)
 

Variables

io_backend_t iob_pipe
 

Function Documentation

◆ iob_pipe_close()

static bool iob_pipe_close ( void *  p)
static

Definition at line 86 of file iob_pipe.c.

86  {
87  return close((int)(size_t)p) == 0;
88 }
static static fork const void static count close
Definition: sflib.h:33
void * p
Definition: libc.cpp:67

References close, and p.

◆ iob_pipe_open()

static void* iob_pipe_open ( const char *  path)
static

Definition at line 63 of file iob_pipe.c.

63  {
64  int sock;
65  struct sockaddr_un sa;
66 
67  sock = socket(AF_UNIX, SOCK_STREAM, 0);
68  if (sock == -1) {
69  perror("socket");
70  return 0;
71  }
72 
73  memset(&sa, 0, sizeof(struct sockaddr_un));
74 
75  sa.sun_family = AF_UNIX;
76  strncpy(sa.sun_path, path, sizeof(sa.sun_path) - 1);
77  sa.sun_path[sizeof(sa.sun_path) - 1] = 0;
78  if (connect(sock, (struct sockaddr *)&sa, sizeof(struct sockaddr_un)) == -1) {
79  perror("connect");
80  close(sock);
81  return 0;
82  }
83  return (void *)(size_t)sock;
84 }
static static fork const void static count static fd const char const char static newpath const char static path const char path
Definition: sflib.h:35
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 socket
Definition: sflib.h:79
return memset(p, 0, total)
#define AF_UNIX
Definition: sftypes.h:285
int size_t
Definition: sftypes.h:40
@ SOCK_STREAM
Definition: sftypes.h:224

References AF_UNIX, close, memset(), path, SOCK_STREAM, socket, and sockaddr_un::sun_path.

◆ iob_pipe_read()

static int iob_pipe_read ( void *  p,
uint8_t buf,
const uint64_t  count,
const int  timeout 
)
static

Definition at line 90 of file iob_pipe.c.

90  {
91  int result;
92  fd_set readset;
93  int fd = (int)(size_t)p;
94  struct timeval tv;
95  tv.tv_sec = 0;
96  // Convert from ms
97  tv.tv_usec = timeout * 1000;
98  for (;;) {
99  FD_ZERO(&readset);
100  FD_SET(fd, &readset);
101  result = select(fd + 1, &readset, NULL, NULL, &tv);
102  if (result < 1) {
103  if (errno == EINTR) {
104  continue;
105  }
106  if (result == 0) {
107  return 0;
108  }
109  return -1;
110  }
111  if (FD_ISSET(fd, &readset)) {
112  return recv((int)(size_t)p, buf, count, 0);
113  }
114  }
115  return EINTR;
116 }
#define NULL
Definition: cris-opc.c:27
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 tv
Definition: sflib.h:79
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 count
Definition: sflib.h:98
voidpf void * buf
Definition: ioapi.h:138
static static fork const void static count static fd const char const char static newpath char char char static envp time_t static t const char static mode static whence const char static dir time_t static t unsigned static seconds const char struct utimbuf static buf static inc static sig const char static mode static oldfd struct tms static buf static getgid static geteuid const char static filename static arg static mask struct ustat static ubuf static getppid static setsid static egid sigset_t static set struct timeval struct timezone static tz select
Definition: sflib.h:108
static int
Definition: sfsocketcall.h:114
#define FD_ZERO(set)
Definition: sftypes.h:204
#define FD_ISSET(d, set)
Definition: sftypes.h:214
#define FD_SET(d, set)
Definition: sftypes.h:212
#define EINTR
Definition: sftypes.h:114
uv_timer_t timeout
Definition: main.c:9
static const z80_opcode fd[]
Definition: z80_tab.h:997

References count, EINTR, fd, FD_ISSET, FD_SET, FD_ZERO, int, NULL, p, select, timeout, and tv.

◆ iob_pipe_write()

static int iob_pipe_write ( void *  p,
const uint8_t buf,
const uint64_t  count,
const int  timeout 
)
static

Definition at line 118 of file iob_pipe.c.

118  {
119  int ret = send((int)(size_t)p, buf, count, 0);
120  if (ret < 1) {
121  rz_sys_perror("iob_pipe_write, send");
122  if (errno == EPIPE) {
123  exit(1);
124  }
125  }
126  return ret;
127 }
#define rz_sys_perror(x)
Definition: rz_types.h:336
static struct sockaddr static addrlen static backlog send
Definition: sfsocketcall.h:119
#define EPIPE
Definition: sftypes.h:142

References count, EPIPE, test-lz4-list::exit, p, rz_sys_perror, and send.

Variable Documentation

◆ iob_pipe

io_backend_t iob_pipe
Initial value:
= {
.name = "pipe",
.type = KD_IO_PIPE,
.init = NULL,
.deinit = NULL,
.config = NULL,
.open = &iob_pipe_open,
.close = &iob_pipe_close,
.read = &iob_pipe_read,
.write = &iob_pipe_write,
}
static int iob_pipe_read(void *p, uint8_t *buf, const uint64_t count, const int timeout)
Definition: iob_pipe.c:90
static int iob_pipe_write(void *p, const uint8_t *buf, const uint64_t count, const int timeout)
Definition: iob_pipe.c:118
static bool iob_pipe_close(void *p)
Definition: iob_pipe.c:86
static void * iob_pipe_open(const char *path)
Definition: iob_pipe.c:63
#define KD_IO_PIPE
Definition: transport.h:17

Definition at line 130 of file iob_pipe.c.

Referenced by __open().