Added dump packets to file
This commit is contained in:
parent
d39a4e43c6
commit
28dd0f0e46
@ -1369,6 +1369,10 @@ void print_message (struct message *M) {
|
|||||||
print_service_message (M);
|
print_service_message (M);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
if (!get_peer_type (M->to_id)) {
|
||||||
|
logprintf ("Bad msg\n");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
last_from_id = M->from_id;
|
last_from_id = M->from_id;
|
||||||
last_to_id = M->to_id;
|
last_to_id = M->to_id;
|
||||||
|
1
loop.c
1
loop.c
@ -104,6 +104,7 @@ size_t *_l;
|
|||||||
int got_it_ok;
|
int got_it_ok;
|
||||||
|
|
||||||
void got_it (char *line, int len) {
|
void got_it (char *line, int len) {
|
||||||
|
assert (len > 0);
|
||||||
line[-- len] = 0; // delete end of line
|
line[-- len] = 0; // delete end of line
|
||||||
*_s = line;
|
*_s = line;
|
||||||
*_l = len;
|
*_l = len;
|
||||||
|
17
main.c
17
main.c
@ -324,10 +324,14 @@ extern char *rsa_public_key_name;
|
|||||||
extern int verbosity;
|
extern int verbosity;
|
||||||
extern int default_dc_num;
|
extern int default_dc_num;
|
||||||
|
|
||||||
|
char *log_net_file;
|
||||||
|
FILE *log_net_f;
|
||||||
|
|
||||||
int register_mode;
|
int register_mode;
|
||||||
|
int disable_auto_accept;
|
||||||
void args_parse (int argc, char **argv) {
|
void args_parse (int argc, char **argv) {
|
||||||
int opt = 0;
|
int opt = 0;
|
||||||
while ((opt = getopt (argc, argv, "u:hk:vn:Nc:p:l:Rf")) != -1) {
|
while ((opt = getopt (argc, argv, "u:hk:vn:Nc:p:l:RfBL:E")) != -1) {
|
||||||
switch (opt) {
|
switch (opt) {
|
||||||
case 'u':
|
case 'u':
|
||||||
set_default_username (optarg);
|
set_default_username (optarg);
|
||||||
@ -360,6 +364,17 @@ void args_parse (int argc, char **argv) {
|
|||||||
case 'B':
|
case 'B':
|
||||||
binlog_enabled = 1;
|
binlog_enabled = 1;
|
||||||
break;
|
break;
|
||||||
|
case 'L':
|
||||||
|
if (log_net_file) {
|
||||||
|
usage ();
|
||||||
|
}
|
||||||
|
log_net_file = strdup (optarg);
|
||||||
|
log_net_f = fopen (log_net_file, "a");
|
||||||
|
assert (log_net_f);
|
||||||
|
break;
|
||||||
|
case 'E':
|
||||||
|
disable_auto_accept = 1;
|
||||||
|
break;
|
||||||
case 'h':
|
case 'h':
|
||||||
default:
|
default:
|
||||||
usage ();
|
usage ();
|
||||||
|
@ -60,6 +60,7 @@ char nonce[256];
|
|||||||
char new_nonce[256];
|
char new_nonce[256];
|
||||||
char server_nonce[256];
|
char server_nonce[256];
|
||||||
extern int binlog_enabled;
|
extern int binlog_enabled;
|
||||||
|
extern int disable_auto_accept;
|
||||||
|
|
||||||
|
|
||||||
int total_packets_sent;
|
int total_packets_sent;
|
||||||
@ -1148,7 +1149,7 @@ void work_update (struct connection *c UU, long long msg_id UU) {
|
|||||||
}
|
}
|
||||||
pop_color ();
|
pop_color ();
|
||||||
print_end ();
|
print_end ();
|
||||||
if (E->state == sc_request) {
|
if (E->state == sc_request && !disable_auto_accept) {
|
||||||
do_accept_encr_chat_request (E);
|
do_accept_encr_chat_request (E);
|
||||||
}
|
}
|
||||||
fetch_int (); // date
|
fetch_int (); // date
|
||||||
|
20
net.c
20
net.c
@ -45,6 +45,7 @@ DEFINE_TREE(int,int,int_cmp,0)
|
|||||||
|
|
||||||
int verbosity;
|
int verbosity;
|
||||||
extern struct connection_methods auth_methods;
|
extern struct connection_methods auth_methods;
|
||||||
|
extern FILE *log_net_f;
|
||||||
|
|
||||||
void fail_connection (struct connection *c);
|
void fail_connection (struct connection *c);
|
||||||
|
|
||||||
@ -348,6 +349,7 @@ void fail_connection (struct connection *c) {
|
|||||||
restart_connection (c);
|
restart_connection (c);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
extern FILE *log_net_f;
|
||||||
void try_write (struct connection *c) {
|
void try_write (struct connection *c) {
|
||||||
if (verbosity) {
|
if (verbosity) {
|
||||||
logprintf ( "try write: fd = %d\n", c->fd);
|
logprintf ( "try write: fd = %d\n", c->fd);
|
||||||
@ -355,6 +357,15 @@ void try_write (struct connection *c) {
|
|||||||
int x = 0;
|
int x = 0;
|
||||||
while (c->out_head) {
|
while (c->out_head) {
|
||||||
int r = write (c->fd, c->out_head->rptr, c->out_head->wptr - c->out_head->rptr);
|
int r = write (c->fd, c->out_head->rptr, c->out_head->wptr - c->out_head->rptr);
|
||||||
|
if (r > 0 && log_net_f) {
|
||||||
|
fprintf (log_net_f, "OUT %s:%d", c->ip, c->port);
|
||||||
|
int i;
|
||||||
|
for (i = 0; i < r; i++) {
|
||||||
|
fprintf (log_net_f, " %02x", *(unsigned char *)(c->out_head->rptr + i));
|
||||||
|
}
|
||||||
|
fprintf (log_net_f, "\n");
|
||||||
|
fflush (log_net_f);
|
||||||
|
}
|
||||||
if (r >= 0) {
|
if (r >= 0) {
|
||||||
x += r;
|
x += r;
|
||||||
c->out_head->rptr += r;
|
c->out_head->rptr += r;
|
||||||
@ -457,6 +468,15 @@ void try_read (struct connection *c) {
|
|||||||
int x = 0;
|
int x = 0;
|
||||||
while (1) {
|
while (1) {
|
||||||
int r = read (c->fd, c->in_tail->wptr, c->in_tail->end - c->in_tail->wptr);
|
int r = read (c->fd, c->in_tail->wptr, c->in_tail->end - c->in_tail->wptr);
|
||||||
|
if (r > 0 && log_net_f) {
|
||||||
|
fprintf (log_net_f, "IN %s:%d", c->ip, c->port);
|
||||||
|
int i;
|
||||||
|
for (i = 0; i < r; i++) {
|
||||||
|
fprintf (log_net_f, " %02x", *(unsigned char *)(c->in_tail->wptr + i));
|
||||||
|
}
|
||||||
|
fprintf (log_net_f, "\n");
|
||||||
|
fflush (log_net_f);
|
||||||
|
}
|
||||||
if (r > 0) {
|
if (r > 0) {
|
||||||
c->last_receive_time = get_double_time ();
|
c->last_receive_time = get_double_time ();
|
||||||
stop_ping_timer (c);
|
stop_ping_timer (c);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user