Added dump packets to file

This commit is contained in:
vysheng 2013-12-18 19:21:49 +04:00
parent d39a4e43c6
commit 28dd0f0e46
5 changed files with 43 additions and 2 deletions

View File

@ -1369,6 +1369,10 @@ void print_message (struct message *M) {
print_service_message (M);
return;
}
if (!get_peer_type (M->to_id)) {
logprintf ("Bad msg\n");
return;
}
last_from_id = M->from_id;
last_to_id = M->to_id;

1
loop.c
View File

@ -104,6 +104,7 @@ size_t *_l;
int got_it_ok;
void got_it (char *line, int len) {
assert (len > 0);
line[-- len] = 0; // delete end of line
*_s = line;
*_l = len;

17
main.c
View File

@ -324,10 +324,14 @@ extern char *rsa_public_key_name;
extern int verbosity;
extern int default_dc_num;
char *log_net_file;
FILE *log_net_f;
int register_mode;
int disable_auto_accept;
void args_parse (int argc, char **argv) {
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) {
case 'u':
set_default_username (optarg);
@ -360,6 +364,17 @@ void args_parse (int argc, char **argv) {
case 'B':
binlog_enabled = 1;
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':
default:
usage ();

View File

@ -60,6 +60,7 @@ char nonce[256];
char new_nonce[256];
char server_nonce[256];
extern int binlog_enabled;
extern int disable_auto_accept;
int total_packets_sent;
@ -1148,7 +1149,7 @@ void work_update (struct connection *c UU, long long msg_id UU) {
}
pop_color ();
print_end ();
if (E->state == sc_request) {
if (E->state == sc_request && !disable_auto_accept) {
do_accept_encr_chat_request (E);
}
fetch_int (); // date

20
net.c
View File

@ -45,6 +45,7 @@ DEFINE_TREE(int,int,int_cmp,0)
int verbosity;
extern struct connection_methods auth_methods;
extern FILE *log_net_f;
void fail_connection (struct connection *c);
@ -348,6 +349,7 @@ void fail_connection (struct connection *c) {
restart_connection (c);
}
extern FILE *log_net_f;
void try_write (struct connection *c) {
if (verbosity) {
logprintf ( "try write: fd = %d\n", c->fd);
@ -355,6 +357,15 @@ void try_write (struct connection *c) {
int x = 0;
while (c->out_head) {
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) {
x += r;
c->out_head->rptr += r;
@ -457,6 +468,15 @@ void try_read (struct connection *c) {
int x = 0;
while (1) {
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) {
c->last_receive_time = get_double_time ();
stop_ping_timer (c);