Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/typepayload #200

Merged
merged 19 commits into from
Apr 6, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
utils.h: hex dump
  • Loading branch information
angelskieglazki committed Mar 31, 2021
commit 85d79fde06148115a316650fe83dc4011636441f
16 changes: 12 additions & 4 deletions src/commands_creator.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,22 @@
#pragma pack(push)
#pragma pack(1)
typedef struct connect_r_packet {
uint32_t port;
uint8_t ip_counts;
char type[64];
char ips[];
uint32_t port;
uint8_t ip_counts;
char type[64];
char ips[];
} connect_r_packet_t;

typedef struct connect_packet {
uint32_t port; ///< Peer port
char *name; ///< Peer name
char *addr; ///< Peer IP address
} connect_packet_t;

#pragma pack(pop)

uint8_t* createCmdConnectRPacketUdp(ksnetEvMgrClass *event_manager, size_t *size_out);
uint8_t* createCmdConnectRPacketTcp(ksnetEvMgrClass *event_manager, size_t *size_out);
uint8_t* createCmdConnectPacket(ksnetEvMgrClass *event_manager, size_t *size_out);

#endif
2 changes: 2 additions & 0 deletions src/ev_mgr.c
Original file line number Diff line number Diff line change
Expand Up @@ -735,11 +735,13 @@ void connect_r_host_cb(ksnetEvMgrClass *ke) {
// Send data to r-host
ksnCoreSendto(ke->kc, ke->teo_cfg.r_host_addr, ke->teo_cfg.r_port,
CMD_CONNECT_R, data, packet_size);

#ifdef DEBUG_KSNET
ksn_printf(ke, MODULE, DEBUG_VV, "send CMD_CONNECT_R = %u to r-host peer by address %s:%d.\n",
CMD_CONNECT_R, ke->teo_cfg.r_host_addr, ke->teo_cfg.r_port);
#endif

printHexDump(data, packet_size);
free(data);
}
}
Expand Down
39 changes: 39 additions & 0 deletions src/utils/utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -766,6 +766,45 @@ int ip_to_array(char* ip, uint8_t *arr) {
return i;
}

void printHexDump(void *addr, size_t len) {
unsigned char buf[17];
unsigned char *pc = addr;
size_t i = 0;
for (i = 0; i < len; i++) {
if ((i % 16) == 0) {
if (i != 0) {
printf(" %s\n", buf);
}

// print offset.
printf(" %04lx ", i);
}

// Now the hex code for the specific character.
printf(" %02x", pc[i]);
if ((i % 8) == 0) {
printf(" ");
}

// And store a printable ASCII character for later.
if ((pc[i] < 0x20) || (pc[i] > 0x7e)) {
buf[i % 16] = '.';
} else {
buf[i % 16] = pc[i];
}

buf[(i % 16) + 1] = '\0';
}


while ((i % 16) != 0) {
printf(" ");
i++;
}

printf(" %s\n", buf);
}

/**
* Detect if input IP address is private
*
Expand Down
2 changes: 2 additions & 0 deletions src/utils/utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,8 @@ unsigned char *ksn_base64_decode(const char *data,

void dump_bytes(char *buffer, int buffer_len, uint8_t* data, int data_len);

void printHexDump(void *addr, size_t len);

#ifdef __cplusplus
}
#endif
Expand Down