Skip to content

Commit

Permalink
fix release
Browse files Browse the repository at this point in the history
  • Loading branch information
spacemeowx2 committed Oct 9, 2018
1 parent 3d0c455 commit 9cd8f5a
Show file tree
Hide file tree
Showing 10 changed files with 36 additions and 31 deletions.
3 changes: 3 additions & 0 deletions CMakeLists.txt
Expand Up @@ -54,6 +54,9 @@ else()
endif()

set(SOURCE_FILES
base/debug.c
base/llog.c

src/main.c
src/packet.c
src/arp.c
Expand Down
9 changes: 9 additions & 0 deletions base/debug.c
@@ -0,0 +1,9 @@
#include <base/llog.h>

void rt_assert(int val, const char *exp)
{
if (!val) {
LLOG(LLOG_ERROR, "assert failed: %s", exp);
exit(1);
}
}
4 changes: 2 additions & 2 deletions base/debug.h
Expand Up @@ -135,8 +135,8 @@
#define WARN_UNUSED
#endif

#define B_USE(expr) (void)(sizeof((expr)));
#define RT_ASSERT(exp) rt_assert(exp, #exp);

#define B_ASSERT_USE(expr) { ASSERT(expr) B_USE(expr) }
void rt_assert(int val, const char *exp);

#endif
15 changes: 15 additions & 0 deletions base/llog.c
@@ -1,2 +1,17 @@
#include <string.h>
#include "llog.h"

static char *llog_level_names[] = { NULL, "ERROR", "WARNING", "NOTICE", "INFO", "DEBUG" };
void LLog_log(int level, const char *fmt, ...)
{
va_list ap;
va_start(ap, fmt);

if (level <= LLOG_DISPLAY_LEVEL) {
fprintf(stderr, "[%s]: ", llog_level_names[level]);
vfprintf(stderr, fmt, ap);
fprintf(stderr, "\n");
}

va_end(ap);
}
15 changes: 1 addition & 14 deletions base/llog.h
Expand Up @@ -20,19 +20,6 @@
// #define LLOG(level, ...) ((level <= LLOG_DISPLAY_LEVEL) && fprintf(stderr, "[%s]%.0s: " FIRST(__VA_ARGS__) "\n", llog_level_names[level], __VA_ARGS__))
#define LLOG(level, ...) LLog_log(level, __VA_ARGS__)

static char *llog_level_names[] = { NULL, "ERROR", "WARNING", "NOTICE", "INFO", "DEBUG" };
static void LLog_log(int level, const char *fmt, ...)
{
va_list ap;
va_start(ap, fmt);

if (level <= LLOG_DISPLAY_LEVEL) {
fprintf(stderr, "[%s]: ", llog_level_names[level]);
vfprintf(stderr, fmt, ap);
fprintf(stderr, "\n");
}

va_end(ap);
}
void LLog_log(int level, const char *fmt, ...);

#endif // _LOG_H_
8 changes: 4 additions & 4 deletions src/gateway.c
Expand Up @@ -262,7 +262,7 @@ int gateway_uvl_output(uvl_t *handle, const uv_buf_t bufs[], unsigned int nbufs)
uint32_t len = 0;

for (int i = 0; i < nbufs; i++) {
ASSERT(len + bufs[i].len < sizeof(buffer))
RT_ASSERT(len + bufs[i].len < sizeof(buffer))
memcpy(buf, bufs[i].base, bufs[i].len);
buf += bufs[i].len;
len += bufs[i].len;
Expand All @@ -276,9 +276,9 @@ int gateway_init(struct gateway *gateway, struct packet_ctx *packet_ctx)
gateway->loop = packet_ctx->arg->loop;
gateway->packet_ctx = packet_ctx;

ASSERT(uvl_init(gateway->loop, &gateway->uvl) == 0);
ASSERT(uvl_bind(&gateway->uvl, gateway_uvl_output) == 0);
ASSERT(uvl_listen(&gateway->uvl, on_connect) == 0);
RT_ASSERT(uvl_init(gateway->loop, &gateway->uvl) == 0);
RT_ASSERT(uvl_bind(&gateway->uvl, gateway_uvl_output) == 0);
RT_ASSERT(uvl_listen(&gateway->uvl, on_connect) == 0);
gateway->uvl.data = gateway;
gateway->first_conn = NULL;

Expand Down
8 changes: 0 additions & 8 deletions src/helper.c
Expand Up @@ -303,14 +303,6 @@ int parse_addr(const char *str, struct sockaddr_in *addr)
return 0;
}

void rt_assert(int val, const char *exp)
{
if (!val) {
LLOG(LLOG_ERROR, "assert failed: %s", exp);
exit(1);
}
}

#if defined(_WIN32)
static void win32_init_winsocket() __attribute__((constructor));
static void win32_init_winsocket()
Expand Down
2 changes: 0 additions & 2 deletions src/helper.h
Expand Up @@ -26,13 +26,11 @@
#define IS_BROADCAST(ip, net, mask) ( ((*(uint32_t*)net) | ( ~ *(uint32_t*)mask)) == *(uint32_t*)ip )
#define PRINT_IP(ip) printf("%d.%d.%d.%d", *(uint8_t*)(ip), *(uint8_t*)((uint8_t*)ip + 1), *(uint8_t*)((uint8_t*)ip + 2), *(uint8_t*)((uint8_t*)ip + 3))
#define PRINT_MAC(mac) printf("%x:%x:%x:%x:%x:%x", *(uint8_t*)(mac), *(uint8_t*)((uint8_t*)mac + 1), *(uint8_t*)((uint8_t*)mac + 2), *(uint8_t*)((uint8_t*)mac + 3), *(uint8_t*)((uint8_t*)mac + 4), *(uint8_t*)((uint8_t*)mac + 5))
#define RT_ASSERT(exp) rt_assert(exp, #exp);

const char *ip2str(void *ip);
void *str2ip(const char *ip);
void print_hex(const void *buf, int len);
int set_immediate_mode(pcap_t *p);
int get_mac_address(pcap_if_t *d, pcap_t *p, u_char mac_addr[6]);
int parse_addr(const char *str, struct sockaddr_in *addr);
void rt_assert(int val, const char *exp);
#endif // _HELPER_H_
1 change: 1 addition & 0 deletions src/lan-play.h
Expand Up @@ -12,6 +12,7 @@
#include <errno.h>
#include <stdbool.h>
#include <base/llog.h>
#include <base/debug.h>
#include <uv.h>

struct lan_play;
Expand Down
2 changes: 1 addition & 1 deletion src/uv_lwip.c
Expand Up @@ -274,7 +274,7 @@ static err_t uvl_client_recv_func (void *arg, struct tcp_pcb *tpcb, struct pbuf
}

// LLOG(LLOG_DEBUG, "[+] recv_buf %d + %d / %d", buf->recv_used, p->tot_len, sizeof(buf->recv_buf));
ASSERT(pbuf_copy_partial(p, buf->recv_buf + buf->recv_used, p->tot_len, 0) == p->tot_len)
RT_ASSERT(pbuf_copy_partial(p, buf->recv_buf + buf->recv_used, p->tot_len, 0) == p->tot_len)
buf->recv_used += p->tot_len;

pbuf_free(p);
Expand Down

0 comments on commit 9cd8f5a

Please sign in to comment.