|
25 | 25 |
|
26 | 26 | #define BUFSIZE 1024
|
27 | 27 |
|
| 28 | +struct timeval now; |
| 29 | +struct tm *timeinfo; |
| 30 | + |
| 31 | +char new_line = true; |
| 32 | + |
28 | 33 | /* This is called with buf[-2:0] being IAC SB COM_PORT_OPTION */
|
29 | 34 | static int do_com_port_option(struct ios_ops *ios, unsigned char *buf, int len)
|
30 | 35 | {
|
@@ -210,14 +215,35 @@ static int do_subneg(struct ios_ops *ios, unsigned char *buf, int len)
|
210 | 215 | static int logfd = -1;
|
211 | 216 | char *answerback;
|
212 | 217 |
|
213 |
| -static void write_receive_buf(const unsigned char *buf, int len) |
214 |
| -{ |
215 |
| - if (!len) |
216 |
| - return; |
| 218 | +static void write_receive_buf(const unsigned char *buf, int len) { |
| 219 | + if (!len) return; |
| 220 | + if (timestamps) { |
| 221 | + if (buf[0] == '\n' || buf[0] == '\r') { |
| 222 | + new_line = true; |
| 223 | + write(STDOUT_FILENO, buf, len); |
| 224 | + } else { |
| 225 | + if (new_line) { |
| 226 | + new_line = false; |
| 227 | + char tbuf[30]; |
| 228 | + memset(tbuf, 0, sizeof(tbuf)); |
| 229 | + gettimeofday(&now, NULL); |
| 230 | + timeinfo = gmtime(&now.tv_sec); |
| 231 | + snprintf(tbuf, sizeof(tbuf), |
| 232 | + "[%02d-%02d-%02d %02d:%02d:%02d:%03d] ", |
| 233 | + timeinfo->tm_mday, timeinfo->tm_mon + 1, |
| 234 | + timeinfo->tm_year + 1900, timeinfo->tm_hour, |
| 235 | + timeinfo->tm_min, timeinfo->tm_sec, now.tv_usec / 1000); |
| 236 | + write(STDOUT_FILENO, tbuf, strlen(tbuf)); |
| 237 | + write(STDOUT_FILENO, buf, len); |
| 238 | + } else { |
| 239 | + write(STDOUT_FILENO, buf, len); |
| 240 | + } |
| 241 | + } |
| 242 | + } else { |
| 243 | + write(STDOUT_FILENO, buf, len); |
| 244 | + } |
217 | 245 |
|
218 |
| - write(STDOUT_FILENO, buf, len); |
219 |
| - if (logfd >= 0) |
220 |
| - write(logfd, buf, len); |
| 246 | + if (logfd >= 0) write(logfd, buf, len); |
221 | 247 | }
|
222 | 248 |
|
223 | 249 | static int ios_printf(struct ios_ops *ios, const char *format, ...)
|
|
0 commit comments