11 #define NETWORK_DISABLED 1
13 #define NETWORK_DISABLED 0
97 WSACleanup: closes
all network connections
99 #define BUFFER_SIZE 4096
106 int ret = recv(
s->
fd, (
char *)&
buf, 1, MSG_PEEK);
117 perror(
"getsockopt");
134 strncpy(
addr.sun_path,
file,
sizeof(
addr.sun_path) - 1);
153 unix_name.sun_family =
AF_UNIX;
154 strncpy(unix_name.sun_path,
file,
sizeof(unix_name.sun_path) - 1);
157 unlink(unix_name.sun_path);
159 if (
bind(sock, (
struct sockaddr *)&unix_name,
sizeof(unix_name)) < 0) {
166 if (
chmod(unix_name.sun_path, 0777) != 0) {
196 #if OPENSSL_VERSION_NUMBER < 0x1010000fL
197 if (!SSL_library_init()) {
201 SSL_load_error_strings();
214 int res =
rz_sys_cmdf(
"rz-run system=\"%s\" listen=%d",
a, port);
220 "listen=%d\n",
cmd, port);
227 eprintf(
"rz_socket_spawn: rz-run failed\n");
230 eprintf(
"rz_socket_spawn: %s is dead\n",
cmd);
248 int ret = waitpid(childPid, &
status, WNOHANG);
260 #define gai_strerror gai_strerrorA
263 if (WSAStartup(MAKEWORD(1, 1), &wsadata) == SOCKET_ERROR) {
264 eprintf(
"Error creating socket.");
269 struct addrinfo hints = { 0 };
270 struct addrinfo *res, *
rp;
279 if (!__connect_unix(
s, host)) {
285 hints.ai_protocol = proto;
286 int gai = getaddrinfo(host, port, &hints, &res);
288 eprintf(
"rz_socket_connect: Error in getaddrinfo: %s (%s:%s)\n",
289 gai_strerror(gai), host, port);
303 ret = setsockopt(
s->
fd, IPPROTO_TCP, TCP_NODELAY, (
char *)&flag,
sizeof(flag));
305 perror(
"setsockopt");
311 ret = connect(
s->
fd,
rp->ai_addr,
rp->ai_addrlen);
331 ret = connect(
s->
fd,
rp->ai_addr,
rp->ai_addrlen);
335 ret = connect(
s->
fd,
rp->ai_addr,
rp->ai_addrlen);
362 eprintf(
"Could not resolve address '%s' or failed to connect\n", host);
369 s->ctx = SSL_CTX_new(SSLv23_client_method());
374 s->sfd = SSL_new(
s->ctx);
375 SSL_set_fd(
s->sfd,
s->
fd);
376 int ret = SSL_connect(
s->sfd);
378 int error = SSL_get_error(
s->sfd, ret);
380 while (tries && ret && (
error == SSL_ERROR_WANT_READ ||
error == SSL_ERROR_WANT_WRITE)) {
385 if (
error == SSL_ERROR_WANT_READ) {
394 ret = SSL_connect(
s->sfd);
398 error = SSL_get_error(
s->sfd, ret);
412 return s->
fd != INVALID_SOCKET ? closesocket(
s->
fd) :
false;
426 shutdown(
s->
fd, SHUT_RDWR);
434 ret = recv(
s->
fd, &
buf, 1, 0);
435 }
while (ret != 0 && ret != SOCKET_ERROR);
437 ret = closesocket(
s->
fd);
461 SSL_CTX_free(
s->ctx);
470 struct servent *
p = getservbyname(
name,
"tcp");
477 struct linger linger = { 0 };
481 return __listen_unix(
s, port);
488 if (WSAStartup(MAKEWORD(1, 1), &wsadata) == SOCKET_ERROR) {
489 eprintf(
"Error creating socket.");
508 eprintf(
"Invalid protocol for socket\n");
563 s->ctx = SSL_CTX_new(SSLv23_method());
568 if (!SSL_CTX_use_certificate_chain_file(
s->ctx, certfile)) {
572 if (!SSL_CTX_use_PrivateKey_file(
s->ctx, certfile, SSL_FILETYPE_PEM)) {
576 SSL_CTX_set_verify_depth(
s->ctx, 1);
595 if (errno != EWOULDBLOCK) {
608 BIO *sbio = BIO_new_socket(sock->
fd, BIO_NOCLOSE);
609 sock->sfd = SSL_new(
s->ctx);
610 SSL_set_bio(sock->sfd, sbio, sbio);
611 if (SSL_accept(sock->sfd) <= 0) {
615 sock->bio = BIO_new(BIO_f_buffer());
616 sbio = BIO_new(BIO_f_ssl());
617 BIO_set_ssl(sbio, sock->sfd, BIO_CLOSE);
618 BIO_push(sock->bio, sbio);
668 if (sec > 0 || usec > 0) {
680 return BIO_flush(
s->bio);
706 memset(&sa, 0,
sizeof(sa));
707 if (!getpeername(
s->
fd, &sa, &sl)) {
715 eprintf(
"getperrname: failed\n");
729 for (
i = 0;
i <
len;
i++) {
765 return (ret == -1) ? -1 :
delta;
790 return BIO_read(
s->bio,
buf,
len);
792 return SSL_read(
s->sfd,
buf,
len);
800 for (
i = 0;
i <
len;
i++) {
810 for (ret = 0; ret <
len;) {
814 if (
s->
is_ssl && SSL_get_error(
s->sfd,
r) == SSL_ERROR_WANT_READ) {
847 return i == 0 ? -1 :
i;
849 if (
buf[
i] ==
'\r' ||
buf[
i] ==
'\n') {
869 int blockSize = 4096;
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
static static fork const void static count close
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
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 cmd
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 fcntl
static static fork const void static count static fd const char const char static newpath const char static path chmod
RZ_API void Ht_() free(HtName_(Ht) *ht)
return memset(p, 0, total)
void * realloc(void *ptr, size_t size)
void * malloc(size_t size)
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
return strdup("=SP r13\n" "=LR r14\n" "=PC r15\n" "=A0 r0\n" "=A1 r1\n" "=A2 r2\n" "=A3 r3\n" "=ZF zf\n" "=SF nf\n" "=OF vf\n" "=CF cf\n" "=SN or0\n" "gpr lr .32 56 0\n" "gpr pc .32 60 0\n" "gpr cpsr .32 64 0 ____tfiae_________________qvczn\n" "gpr or0 .32 68 0\n" "gpr tf .1 64.5 0 thumb\n" "gpr ef .1 64.9 0 endian\n" "gpr jf .1 64.24 0 java\n" "gpr qf .1 64.27 0 sticky_overflow\n" "gpr vf .1 64.28 0 overflow\n" "gpr cf .1 64.29 0 carry\n" "gpr zf .1 64.30 0 zero\n" "gpr nf .1 64.31 0 negative\n" "gpr itc .4 64.10 0 if_then_count\n" "gpr gef .4 64.16 0 great_or_equal\n" "gpr r0 .32 0 0\n" "gpr r1 .32 4 0\n" "gpr r2 .32 8 0\n" "gpr r3 .32 12 0\n" "gpr r4 .32 16 0\n" "gpr r5 .32 20 0\n" "gpr r6 .32 24 0\n" "gpr r7 .32 28 0\n" "gpr r8 .32 32 0\n" "gpr r9 .32 36 0\n" "gpr r10 .32 40 0\n" "gpr r11 .32 44 0\n" "gpr r12 .32 48 0\n" "gpr r13 .32 52 0\n" "gpr r14 .32 56 0\n" "gpr r15 .32 60 0\n" "gpr r16 .32 64 0\n" "gpr r17 .32 68 0\n")
static static fork const void static count static fd const char static mode unlink
static const char struct stat static buf struct stat static buf static vhangup int status
static const void static count static fd struct stat static buf struct pollfd unsigned static timeout void static offset void static length char static len const struct iovec static count unsigned long static filedes static sched_yield static flags static oldfd static pause unsigned static seconds static protocol accept
#define rz_return_val_if_fail(expr, val)
RZ_API ut64 rz_num_get(RzNum *num, const char *str)
RZ_API int rz_num_rand(int max)
#define RZ_SOCKET_PROTO_NONE
RZ_API void rz_run_free(RzRunProfile *r)
RZ_API RzRunProfile * rz_run_new(const char *str)
#define RZ_SOCKET_PROTO_UNIX
#define RZ_SOCKET_PROTO_UDP
RZ_API int rz_run_start(RzRunProfile *p)
#define RZ_SOCKET_PROTO_TCP
#define RZ_INVALID_SOCKET
#define RZ_SOCKET_PROTO_DEFAULT
RZ_API char * rz_str_newf(const char *fmt,...) RZ_PRINTF_CHECK(1
RZ_API char * rz_str_replace(char *str, const char *key, const char *val, int g)
RZ_API int rz_sys_cmdf(const char *fmt,...) RZ_PRINTF_CHECK(1
RZ_API int rz_sys_fork(void)
RZ_API int rz_sys_usleep(int usecs)
Sleep for usecs microseconds.
RZ_API int rz_sys_signal(int sig, void(*handler)(int))
RZ_API int rz_sys_sleep(int secs)
Sleep for secs seconds.
static struct sockaddr static addrlen static backlog send
static struct sockaddr static addrlen listen
static struct sockaddr static addrlen static backlog const void static flags void flags
RZ_API bool rz_socket_is_connected(RzSocket *s)
RZ_API int rz_socket_close(RzSocket *s)
RZ_API int rz_socket_read_block(RzSocket *s, ut8 *buf, int len)
RZ_API int rz_socket_puts(RzSocket *s, char *buf)
RZ_API int rz_socket_read(RzSocket *s, unsigned char *buf, int len)
RZ_API int rz_socket_close_fd(RzSocket *s)
RZ_API int rz_socket_ready(RzSocket *s, int secs, int usecs)
RZ_API int rz_socket_port_by_name(const char *name)
RZ_API RzSocket * rz_socket_accept(RzSocket *s)
RZ_API bool rz_socket_spawn(RzSocket *s, const char *cmd, unsigned int timeout)
RZ_API bool rz_socket_listen(RzSocket *s, const char *port, const char *certfile)
RZ_API int rz_socket_flush(RzSocket *s)
RZ_API bool rz_socket_block_time(RzSocket *s, bool block, int sec, int usec)
RZ_API char * rz_socket_to_string(RzSocket *s)
RZ_API int rz_socket_gets(RzSocket *s, char *buf, int size)
RZ_API bool rz_socket_connect(RzSocket *s, const char *host, const char *port, int proto, unsigned int timeout)
RZ_API RzSocket * rz_socket_accept_timeout(RzSocket *s, unsigned int timeout)
RZ_LIB_VERSION(rz_socket)
RZ_API RzSocket * rz_socket_new(bool is_ssl)
RZ_API ut8 * rz_socket_slurp(RzSocket *s, int *len)
RZ_API void rz_socket_printf(RzSocket *s, const char *fmt,...)
RZ_API RzSocket * rz_socket_new_from_fd(int fd)
RZ_API int rz_socket_free(RzSocket *s)
RZ_API int rz_socket_write(RzSocket *s, void *buf, int len)
void error(const char *msg)
static const z80_opcode fd[]