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
src/net_com.c: some debug messages. #188
  • Loading branch information
angelskieglazki committed Apr 1, 2021
commit dde6c6bdc23dfc32c28798d6a64e1a5b69d63eac
2 changes: 1 addition & 1 deletion src/commands_creator.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ uint8_t* createCmdConnectRPacketUdp(ksnetEvMgrClass *event_manager, size_t *size

*size_out = sizeof(connect_r_packet_t) + len * MAX_IP_STR_LEN;
connect_r_packet_t *packet = malloc(*size_out);

memset(packet, '\0', *size_out);
packet->ip_counts = 0;
packet->port = event_manager->kc->port;

Expand Down
14 changes: 7 additions & 7 deletions src/net_com.c
Original file line number Diff line number Diff line change
Expand Up @@ -1135,11 +1135,11 @@ static int cmd_connect_r_cb(ksnCommandClass *kco, ksnCorePacketData *rd) {
ksnetEvMgrClass *ke = EVENT_MANAGER_OBJECT(kco);
ksnetArpClass *arp_obj = ARP_TABLE_OBJECT(kco);

#ifdef DEBUG_KSNET
ksn_printf(ke, MODULE, DEBUG_VV,
//#ifdef DEBUG_KSNET
ksn_printf(ke, MODULE, DEBUG,
"process CMD_CONNECT_R = %u command, from %s (%s:%d)\n",
rd->cmd, rd->from, rd->addr, rd->port);
#endif
//#endif

// Set flag isRhost
ke->is_rhost = true;
Expand All @@ -1152,7 +1152,7 @@ static int cmd_connect_r_cb(ksnCommandClass *kco, ksnCorePacketData *rd) {
CMD_NONE, rd->addr, rd->port);
#endif
connect_r_packet_t *packet = rd->data;

printHexDump(packet, rd->data_len);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Это, наверное, стоит либо убрать, либо под флаг отладочный унести

// For UDP connection resend received IPs to child
if(packet->ip_counts) {
// Send peer address to child
Expand Down Expand Up @@ -1249,10 +1249,10 @@ static int cmd_connect_cb(ksnCommandClass *kco, ksnCorePacketData *rd) {
pd.addr = rd->data + ptr; ptr += strlen(pd.addr) + 1;
pd.port = *((uint32_t *)(rd->data + ptr));

#ifdef DEBUG_KSNET
ksn_printf(ke, MODULE, DEBUG_VV, "process CMD_CONNECT = %u from %s (%s:%d). (Connect to %s (%s:%d))\n",
// #ifdef DEBUG_KSNET
ksn_printf(ke, MODULE, DEBUG, "process CMD_CONNECT = %u from %s (%s:%d). (Connect to %s (%s:%d))\n",
rd->cmd, rd->from, rd->addr, rd->port, pd.name, pd.addr, pd.port);
#endif
// #endif

// Check ARP
if(ksnetArpGet(arp_class, pd.name) == NULL) {
Expand Down
30 changes: 17 additions & 13 deletions src/utils/utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -543,17 +543,6 @@ char *getExecPath (char *path, size_t dest_len, char *argv0) {
#endif

#ifndef HAVE_MINGW
// Moved to teonet_lo_client.c
///**
// * Set socket or FD to non blocking mode
// */
//void set_nonblock(int fd) {
//
// int flags;
//
// flags = fcntl(fd, F_GETFL, 0);
// fcntl(fd, F_SETFL, flags | O_NONBLOCK);
//}

/**
* Make socket reusable
Expand Down Expand Up @@ -766,6 +755,21 @@ int ip_to_array(char* ip, uint8_t *arr) {
return i;
}


/*
Example of output printHexDump function for connect_r_packet_t struct

0000 8a 1b 00 00 04 22 74 65 6f 2d 76 70 6e 22 2c 20 ....."teo-vpn",
0010 22 74 65 6f 2d 6c 30 22 00 00 00 00 00 00 00 00 "teo-l0"........
0020 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
0030 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
0040 00 00 00 00 00 31 39 32 2e 31 36 38 2e 31 2e 36 .....192.168.1.6
0050 39 00 31 39 32 2e 31 36 38 2e 31 32 32 2e 31 00 9.192.168.122.1.
0060 31 37 32 2e 31 37 2e 30 2e 31 00 31 30 2e 31 33 172.17.0.1.10.13
0070 35 2e 31 34 32 2e 38 33 00 00 00 00 00 00 00 00 5.142.83........
0080 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
0090 00 00 00 00 00 .....
*/
void printHexDump(void *addr, size_t len) {
unsigned char buf[17];
unsigned char *pc = addr;
Expand All @@ -782,7 +786,7 @@ void printHexDump(void *addr, size_t len) {

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

Expand All @@ -802,7 +806,7 @@ void printHexDump(void *addr, size_t len) {
i++;
}

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

/**
Expand Down