Commit 9aff533ce66ca3eceb367975342ef34d6ed2491e
1 parent
49a55f90
Exists in
master
and in
3 other branches
Iniciando implementação de trace da comunicação de rede
Showing
3 changed files
with
71 additions
and
45 deletions
Show diff stats
telnet.c
... | ... | @@ -102,6 +102,7 @@ |
102 | 102 | #include "screen.h" |
103 | 103 | |
104 | 104 | #include <lib3270/internals.h> |
105 | +#include <lib3270/trace.h> | |
105 | 106 | |
106 | 107 | #if !defined(TELOPT_NAWS) /*[*/ |
107 | 108 | #define TELOPT_NAWS 31 |
... | ... | @@ -1202,33 +1203,6 @@ void net_input(H3270 *hSession) |
1202 | 1203 | |
1203 | 1204 | lib3270_data_recv(hSession, nr, buffer); |
1204 | 1205 | |
1205 | -/* | |
1206 | - trace_netdata('<', session->netrbuf, nr); | |
1207 | - | |
1208 | - session->ns_brcvd += nr; | |
1209 | - for (cp = session->netrbuf; cp < (session->netrbuf + nr); cp++) | |
1210 | - { | |
1211 | - if (telnet_fsm(session,*cp)) | |
1212 | - { | |
1213 | - (void) ctlr_dbcs_postprocess(hSession); | |
1214 | - host_disconnect(session,True); | |
1215 | - return; | |
1216 | - } | |
1217 | - } | |
1218 | - | |
1219 | -#if defined(X3270_ANSI) | |
1220 | - if (IN_ANSI) | |
1221 | - { | |
1222 | - (void) ctlr_dbcs_postprocess(hSession); | |
1223 | - } | |
1224 | - | |
1225 | - if (session->ansi_data) | |
1226 | - { | |
1227 | - trace_dsn(session,"\n"); | |
1228 | - session->ansi_data = 0; | |
1229 | - } | |
1230 | -#endif // X3270_ANSI | |
1231 | -*/ | |
1232 | 1206 | } |
1233 | 1207 | |
1234 | 1208 | } |
... | ... | @@ -2736,29 +2710,68 @@ opt(unsigned char c) |
2736 | 2710 | |
2737 | 2711 | void trace_netdata(H3270 *hSession, char direction, unsigned const char *buf, int len) |
2738 | 2712 | { |
2739 | - int offset; | |
2740 | - struct timeval ts; | |
2741 | - double tdiff; | |
2742 | - | |
2743 | - if (!lib3270_get_toggle(hSession,LIB3270_TOGGLE_DS_TRACE)) | |
2744 | - return; | |
2745 | 2713 | |
2746 | - (void) gettimeofday(&ts, (struct timezone *)NULL); | |
2747 | - if (IN_3270) | |
2714 | + // IS DS trace ON? | |
2715 | + if (lib3270_get_toggle(hSession,LIB3270_TOGGLE_DS_TRACE)) | |
2748 | 2716 | { |
2749 | - tdiff = ((1.0e6 * (double)(ts.tv_sec - hSession->ds_ts.tv_sec)) + | |
2750 | - (double)(ts.tv_usec - hSession->ds_ts.tv_usec)) / 1.0e6; | |
2751 | - trace_dsn(hSession,"%c +%gs\n", direction, tdiff); | |
2717 | + int offset; | |
2718 | + struct timeval ts; | |
2719 | + double tdiff; | |
2720 | + | |
2721 | + (void) gettimeofday(&ts, (struct timezone *)NULL); | |
2722 | + if (IN_3270) | |
2723 | + { | |
2724 | + tdiff = ((1.0e6 * (double)(ts.tv_sec - hSession->ds_ts.tv_sec)) + | |
2725 | + (double)(ts.tv_usec - hSession->ds_ts.tv_usec)) / 1.0e6; | |
2726 | + trace_dsn(hSession,"%c +%gs\n", direction, tdiff); | |
2727 | + } | |
2728 | + | |
2729 | + hSession->ds_ts = ts; | |
2730 | + for (offset = 0; offset < len; offset++) | |
2731 | + { | |
2732 | + if (!(offset % LINEDUMP_MAX)) | |
2733 | + trace_dsn(hSession,"%s%c 0x%-3x ",(offset ? "\n" : ""), direction, offset); | |
2734 | + trace_dsn(hSession,"%02x", buf[offset]); | |
2735 | + } | |
2736 | + trace_dsn(hSession,"\n"); | |
2752 | 2737 | } |
2753 | 2738 | |
2754 | - hSession->ds_ts = ts; | |
2755 | - for (offset = 0; offset < len; offset++) | |
2739 | + if (lib3270_get_toggle(hSession,LIB3270_TOGGLE_NETWORK_TRACE)) | |
2756 | 2740 | { |
2757 | - if (!(offset % LINEDUMP_MAX)) | |
2758 | - trace_dsn(hSession,"%s%c 0x%-3x ",(offset ? "\n" : ""), direction, offset); | |
2759 | - trace_dsn(hSession,"%02x", buf[offset]); | |
2741 | + char l1[82]; | |
2742 | + char l2[82]; | |
2743 | + char l3[82]; | |
2744 | + | |
2745 | + int offset; | |
2746 | + int col = 0; | |
2747 | + | |
2748 | + for (offset = 0; offset < len; offset++) | |
2749 | + { | |
2750 | + unsigned char text[4]; | |
2751 | + | |
2752 | + text[0] = hSession->charset.ebc2asc[buf[offset]]; | |
2753 | + l1[col] = (text[0] >= ' ' ? text[0] : '.'); | |
2754 | + | |
2755 | + snprintf((char *) text,4,"%02x",buf[offset]); | |
2756 | + l2[col] = text[0]; | |
2757 | + l3[col] = text[1]; | |
2758 | + | |
2759 | + if(++col >= 80) | |
2760 | + { | |
2761 | + l1[col] = l2[col] = l3[col] = 0; | |
2762 | + lib3270_write_nettrace(hSession,"%c\t%s\n\t%s\n\t%s\n",direction,l1,l2,l3); | |
2763 | + col = 0; | |
2764 | + } | |
2765 | + } | |
2766 | + | |
2767 | + if(col) | |
2768 | + { | |
2769 | + l1[col] = l2[col] = l3[col] = 0; | |
2770 | + lib3270_write_nettrace(hSession,"%c\t%s\n\t%s\n\t%s\n",direction,l1,l2,l3); | |
2771 | + } | |
2772 | + | |
2760 | 2773 | } |
2761 | - trace_dsn(hSession,"\n"); | |
2774 | + | |
2762 | 2775 | } |
2763 | 2776 | #endif // X3270_TRACE |
2764 | 2777 | ... | ... |
toggles.c
... | ... | @@ -82,7 +82,7 @@ static const char *toggle_names[LIB3270_TOGGLE_COUNT] = |
82 | 82 | "fieldattr", /**< View Field attribute */ |
83 | 83 | "altscreen", /**< auto resize on altscreen */ |
84 | 84 | "keepalive", /**< Enable network keep-alive with SO_KEEPALIVE */ |
85 | - | |
85 | + "nettrace", /**< Enable network in/out trace */ | |
86 | 86 | |
87 | 87 | }; |
88 | 88 | ... | ... |
trace_ds.c
... | ... | @@ -214,6 +214,19 @@ LIB3270_EXPORT void lib3270_write_dstrace(H3270 *session, const char *fmt, ...) |
214 | 214 | va_end(args); |
215 | 215 | } |
216 | 216 | |
217 | +LIB3270_EXPORT void lib3270_write_nettrace(H3270 *session, const char *fmt, ...) | |
218 | +{ | |
219 | + va_list args; | |
220 | + | |
221 | + if(!lib3270_get_toggle(session,LIB3270_TOGGLE_NETWORK_TRACE)) | |
222 | + return; | |
223 | + | |
224 | + va_start(args, fmt); | |
225 | + vwtrace(session,fmt, args); | |
226 | + va_end(args); | |
227 | +} | |
228 | + | |
229 | + | |
217 | 230 | LIB3270_EXPORT void lib3270_trace_event(H3270 *session, const char *fmt, ...) |
218 | 231 | { |
219 | 232 | va_list args; | ... | ... |