--- lbbs/src/bbs_net.c 2005/03/22 08:19:11 1.7 +++ lbbs/src/bbs_net.c 2005/03/22 08:59:31 1.8 @@ -109,79 +109,6 @@ load_bbsnet_conf (const char *file_confi return 0; } -// from Maple-hightman -// added by flyriver, 2001.3.3 -int -telnetopt (int fd, char *buf, int max) -{ - unsigned char c, d, e; - int pp = 0; - unsigned char tmp[30]; - - while (pp < max) - { - c = buf[pp++]; - if (c == 255) - { - d = buf[pp++]; - e = buf[pp++]; - iflush (); - if ((d == 253) && (e == 3 || e == 24)) - { - tmp[0] = 255; - tmp[1] = 251; - tmp[2] = e; - write (fd, tmp, 3); - continue; - } - if ((d == 251 || d == 252) && (e == 1 || e == 3 || e == 24)) - { - tmp[0] = 255; - tmp[1] = 253; - tmp[2] = e; - write (fd, tmp, 3); - continue; - } - if (d == 251 || d == 252) - { - tmp[0] = 255; - tmp[1] = 254; - tmp[2] = e; - write (fd, tmp, 3); - continue; - } - if (d == 253 || d == 254) - { - tmp[0] = 255; - tmp[1] = 252; - tmp[2] = e; - write (fd, tmp, 3); - continue; - } - if (d == 250) - { - while (e != 240 && pp < max) - e = buf[pp++]; - tmp[0] = 255; - tmp[1] = 250; - tmp[2] = 24; - tmp[3] = 0; - tmp[4] = 65; - tmp[5] = 78; - tmp[6] = 83; - tmp[7] = 73; - tmp[8] = 255; - tmp[9] = 240; - write (fd, tmp, 10); - } - } - else - outc (c); - } - iflush (); - return 0; -} - static void process_bar (int n, int len) { @@ -221,6 +148,10 @@ bbsnet_connect (int n) struct timeval timeout; struct hostent *pHost = NULL; int rc, rv, tos = 020, i; + char remote_addr[256]; + int remote_port; + time_t t_used; + struct tm * tm_used; prints ("\033[1;32m正在测试往 %s (%s) 的连接,请稍候... \033[m\n", bbsnet_conf[n].host1, bbsnet_conf[n].ip); @@ -256,12 +187,14 @@ bbsnet_connect (int n) inet_ntoa (sin.sin_addr), ntohs (sin.sin_port)); return -2; } - + bzero (&sin, sizeof (sin)); sin.sin_family = AF_INET; - sin.sin_port = htons (bbsnet_conf[n].port); sin.sin_addr = *(struct in_addr *) pHost->h_addr_list[0]; + sin.sin_port = htons (bbsnet_conf[n].port); + strcpy (remote_addr, inet_ntoa (sin.sin_addr)); + remote_port = ntohs (sin.sin_port); prints ("\033[1;32m穿梭进度条提示您当前已使用的时间。\033[m\n"); process_bar (0, MAX_PROCESS_BAR_LEN); @@ -296,13 +229,16 @@ bbsnet_connect (int n) return -1; } setsockopt (sock, IPPROTO_IP, IP_TOS, &tos, sizeof (int)); + prints ("\033[1;31m连接成功!\033[m\n"); + log_std ("BBSNET connect to %s:%d\n", + remote_addr, remote_port); FD_ZERO (&inputs); FD_SET (0, &inputs); FD_SET (sock, &inputs); - BBS_last_access_tm = time (0); + BBS_last_access_tm = t_used = time (0); loop = 1; @@ -357,6 +293,12 @@ bbsnet_connect (int n) log_error ("Close socket failed\n"); } + t_used = time (0) - t_used; + tm_used = gmtime (&t_used); + + log_std ("BBSNET disconnect, %d days %d hours %d minutes %d seconds used\n", + tm_used->tm_mday - 1, tm_used->tm_hour, tm_used->tm_min, tm_used->tm_sec); + return 0; }