Rizin
unix-like reverse engineering framework and cli tools
socket_proc.c File Reference
#include <rz_socket.h>
#include <rz_util.h>
#include <signal.h>

Go to the source code of this file.

Macros

#define BUFFER_SIZE   4096
 

Functions

RZ_API struct rz_socket_proc_trz_socket_proc_open (char *const argv[])
 
RZ_API int rz_socket_proc_close (struct rz_socket_proc_t *sp)
 
RZ_API int rz_socket_proc_read (RzSocketProc *sp, unsigned char *buf, int len)
 
RZ_API int rz_socket_proc_gets (RzSocketProc *sp, char *buf, int size)
 
RZ_API int rz_socket_proc_write (RzSocketProc *sp, void *buf, int len)
 
RZ_API void rz_socket_proc_printf (RzSocketProc *sp, const char *fmt,...)
 
RZ_API int rz_socket_proc_ready (RzSocketProc *sp, int secs, int usecs)
 

Macro Definition Documentation

◆ BUFFER_SIZE

#define BUFFER_SIZE   4096

Definition at line 15 of file socket_proc.c.

Function Documentation

◆ rz_socket_proc_close()

RZ_API int rz_socket_proc_close ( struct rz_socket_proc_t sp)

Definition at line 60 of file socket_proc.c.

60  {
61 #if __UNIX__
62  /* this is wrong */
63  kill(sp->pid, SIGKILL);
64  waitpid(sp->pid, NULL, 0); // WNOHANG);
65  close(sp->fd0[0]);
66  close(sp->fd0[1]);
67  // close(sp->fd1[0]);
68  close(sp->fd1[1]);
69  // sp->fd[0] = -1;
70  // sp->fd[1] = -1;
71 #endif
72  return 0;
73 }
#define SIGKILL
#define NULL
Definition: cris-opc.c:27
static static fork const void static count close
Definition: sflib.h:33
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 kill
Definition: sflib.h:64
static int sp
Definition: z80asm.c:91

References close, kill, NULL, SIGKILL, and sp.

Referenced by rz_socket_proc_open().

◆ rz_socket_proc_gets()

RZ_API int rz_socket_proc_gets ( RzSocketProc sp,
char *  buf,
int  size 
)

Definition at line 82 of file socket_proc.c.

82  {
83  RzSocket s;
84  s.is_ssl = false;
85  s.fd = sp->fd1[0];
86  return rz_socket_gets(&s, buf, size);
87 }
voidpf void uLong size
Definition: ioapi.h:138
voidpf void * buf
Definition: ioapi.h:138
static RzSocket * s
Definition: rtr.c:28
RZ_API int rz_socket_gets(RzSocket *s, char *buf, int size)
Definition: socket.c:830
bool is_ssl
Definition: rz_socket.h:68

References rz_socket_t::fd, rz_socket_t::is_ssl, rz_socket_gets(), s, and sp.

◆ rz_socket_proc_open()

RZ_API struct rz_socket_proc_t* rz_socket_proc_open ( char *const  argv[])

Definition at line 17 of file socket_proc.c.

17  {
18 #if __UNIX__ && HAVE_FORK
20 
21  if (!sp) {
22  return NULL;
23  }
24 
25  if (rz_sys_pipe(sp->fd0, true) == -1) {
26  perror("pipe");
27  goto error;
28  }
29 
30  if (rz_sys_pipe(sp->fd1, true) == -1) {
31  perror("pipe");
32  goto error;
33  }
34 
35  sp->pid = rz_sys_fork();
36  switch (sp->pid) {
37  case 0:
38  close(0);
39  dup2(sp->fd0[0], 0);
40  close(1);
41  dup2(sp->fd1[1], 1);
42  rz_sys_execv(argv[0], argv);
43  exit(1);
44  break;
45  case -1:
46  perror("fork");
48  goto error;
49  // rz_socket_block_time (sp, false, 0);
50  }
51  return sp;
52 error:
53  free(sp);
54  return NULL;
55 #else
56  return NULL;
57 #endif
58 }
RZ_API void Ht_() free(HtName_(Ht) *ht)
Definition: ht_inc.c:130
static static fork const void static count static fd const char const char static newpath char char argv
Definition: sflib.h:40
static static fork const void static count static fd const char static mode const char static pathname const char static path const char static dev const char static group static getpid static getuid void void static data static pause const char static mode static sync const char const char static newpath const char static pathname unsigned long static filedes void static end_data_segment static handler static getegid char static len static pgid const char static path dup2
Definition: sflib.h:94
RZ_API int rz_sys_execv(const char *pathname, char *const argv[])
Definition: sys.c:1483
RZ_API int rz_sys_pipe(int pipefd[2], bool close_on_exec)
Definition: sys.c:1458
RZ_API int rz_sys_fork(void)
Definition: sys.c:1679
#define RZ_NEW(x)
Definition: rz_types.h:285
RZ_API int rz_socket_proc_close(struct rz_socket_proc_t *sp)
Definition: socket_proc.c:60
void error(const char *msg)
Definition: untgz.c:593

References argv, close, dup2, error(), test-lz4-list::exit, free(), NULL, RZ_NEW, rz_socket_proc_close(), rz_sys_execv(), rz_sys_fork(), rz_sys_pipe(), and sp.

◆ rz_socket_proc_printf()

RZ_API void rz_socket_proc_printf ( RzSocketProc sp,
const char *  fmt,
  ... 
)

Definition at line 96 of file socket_proc.c.

96  {
97  RzSocket s;
98  char buf[BUFFER_SIZE];
99  va_list ap;
100  s.is_ssl = false;
101  s.fd = sp->fd0[1];
102  if (s.fd != RZ_INVALID_SOCKET) {
103  va_start(ap, fmt);
104  vsnprintf(buf, BUFFER_SIZE, fmt, ap);
105  rz_socket_write(&s, buf, strlen(buf));
106  va_end(ap);
107  }
108 }
vsnprintf
Definition: kernel.h:366
#define RZ_INVALID_SOCKET
Definition: rz_socket.h:48
RZ_API int rz_socket_write(RzSocket *s, void *buf, int len)
Definition: socket.c:724
#define BUFFER_SIZE
Definition: socket_proc.c:15

References BUFFER_SIZE, rz_socket_t::fd, rz_socket_t::is_ssl, RZ_INVALID_SOCKET, rz_socket_write(), s, sp, and vsnprintf.

◆ rz_socket_proc_read()

RZ_API int rz_socket_proc_read ( RzSocketProc sp,
unsigned char *  buf,
int  len 
)

Definition at line 75 of file socket_proc.c.

75  {
76  RzSocket s;
77  s.is_ssl = false;
78  s.fd = sp->fd1[0];
79  return rz_socket_read(&s, buf, len);
80 }
size_t len
Definition: 6502dis.c:15
RZ_API void RZ_API int rz_socket_read(RzSocket *s, ut8 *read, int len)
Definition: socket.c:783

References rz_socket_t::fd, rz_socket_t::is_ssl, len, rz_socket_read(), s, and sp.

◆ rz_socket_proc_ready()

RZ_API int rz_socket_proc_ready ( RzSocketProc sp,
int  secs,
int  usecs 
)

Definition at line 110 of file socket_proc.c.

110  {
111  RzSocket s;
112  s.is_ssl = false;
113  s.fd = sp->fd1[0];
114  return rz_socket_ready(&s, secs, usecs);
115 }
RZ_API int rz_socket_ready(RzSocket *s, int secs, int usecs)
Definition: socket.c:688

References rz_socket_t::fd, rz_socket_t::is_ssl, rz_socket_ready(), s, and sp.

◆ rz_socket_proc_write()

RZ_API int rz_socket_proc_write ( RzSocketProc sp,
void *  buf,
int  len 
)

Definition at line 89 of file socket_proc.c.

89  {
90  RzSocket s;
91  s.is_ssl = false;
92  s.fd = sp->fd0[1];
93  return rz_socket_write(&s, buf, len);
94 }

References rz_socket_t::fd, rz_socket_t::is_ssl, len, rz_socket_write(), s, and sp.