| 109 |
return 0; |
return 0; |
| 110 |
} |
} |
| 111 |
|
|
|
// 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; |
|
|
} |
|
|
|
|
| 112 |
static void |
static void |
| 113 |
process_bar (int n, int len) |
process_bar (int n, int len) |
| 114 |
{ |
{ |
| 119 |
char *ptr3; |
char *ptr3; |
| 120 |
|
|
| 121 |
moveto (4, 0); |
moveto (4, 0); |
| 122 |
prints ("┌───────────────┐\n"); |
prints ("┌───────────────┐\r\n"); |
| 123 |
sprintf (buf2, " %3d%% ", n * 100 / len); |
sprintf (buf2, " %3d%% ", n * 100 / len); |
| 124 |
ptr = buf; |
ptr = buf; |
| 125 |
ptr2 = buf2; |
ptr2 = buf2; |
| 134 |
while (*ptr2 != '\0') |
while (*ptr2 != '\0') |
| 135 |
*ptr++ = *ptr2++; |
*ptr++ = *ptr2++; |
| 136 |
*ptr++ = '\0'; |
*ptr++ = '\0'; |
| 137 |
prints ("│\033[46m%s\033[m│\n", buf); |
prints ("│\033[46m%s\033[m│\r\n", buf); |
| 138 |
prints ("└───────────────┘\n"); |
prints ("└───────────────┘\r\n"); |
| 139 |
|
iflush (); |
| 140 |
} |
} |
| 141 |
|
|
| 142 |
int |
int |
| 149 |
struct timeval timeout; |
struct timeval timeout; |
| 150 |
struct hostent *pHost = NULL; |
struct hostent *pHost = NULL; |
| 151 |
int rc, rv, tos = 020, i; |
int rc, rv, tos = 020, i; |
| 152 |
|
char remote_addr[256]; |
| 153 |
|
int remote_port; |
| 154 |
|
time_t t_used; |
| 155 |
|
struct tm *tm_used; |
| 156 |
|
|
| 157 |
prints ("\033[1;32m正在测试往 %s (%s) 的连接,请稍候... \033[m\n", |
clearscr (); |
| 158 |
|
|
| 159 |
|
moveto (0, 0); |
| 160 |
|
prints ("\033[1;32m正在测试往 %s (%s) 的连接,请稍候... \033[m\r\n", |
| 161 |
bbsnet_conf[n].host1, bbsnet_conf[n].ip); |
bbsnet_conf[n].host1, bbsnet_conf[n].ip); |
| 162 |
prints ("\033[1;32m如果在 %d 秒内无法连上,穿梭程序将放弃连接。\033[m\n", |
prints ("\033[1;32m如果在 %d 秒内无法连上,穿梭程序将放弃连接。\033[m\r\n", |
| 163 |
TIME_OUT); |
TIME_OUT); |
| 164 |
|
iflush (); |
| 165 |
|
|
| 166 |
pHost = gethostbyname (bbsnet_conf[n].ip); |
pHost = gethostbyname (bbsnet_conf[n].ip); |
| 167 |
|
|
| 168 |
if (pHost == NULL) |
if (pHost == NULL) |
| 169 |
{ |
{ |
| 170 |
prints ("\033[1;31m查找主机名失败!\033[m\n"); |
prints ("\033[1;31m查找主机名失败!\033[m\r\n"); |
| 171 |
press_any_key (); |
press_any_key (); |
| 172 |
return -1; |
return -1; |
| 173 |
} |
} |
| 176 |
|
|
| 177 |
if (sock < 0) |
if (sock < 0) |
| 178 |
{ |
{ |
| 179 |
prints ("\033[1;31m无法创建socket!\033[m\n"); |
prints ("\033[1;31m无法创建socket!\033[m\r\n"); |
| 180 |
press_any_key (); |
press_any_key (); |
| 181 |
return -1; |
return -1; |
| 182 |
} |
} |
| 195 |
|
|
| 196 |
bzero (&sin, sizeof (sin)); |
bzero (&sin, sizeof (sin)); |
| 197 |
sin.sin_family = AF_INET; |
sin.sin_family = AF_INET; |
|
sin.sin_port = htons (bbsnet_conf[n].port); |
|
| 198 |
sin.sin_addr = *(struct in_addr *) pHost->h_addr_list[0]; |
sin.sin_addr = *(struct in_addr *) pHost->h_addr_list[0]; |
| 199 |
|
sin.sin_port = htons (bbsnet_conf[n].port); |
| 200 |
|
|
| 201 |
|
strcpy (remote_addr, inet_ntoa (sin.sin_addr)); |
| 202 |
|
remote_port = ntohs (sin.sin_port); |
| 203 |
|
|
| 204 |
prints ("\033[1;32m穿梭进度条提示您当前已使用的时间。\033[m\n"); |
prints ("\033[1;32m穿梭进度条提示您当前已使用的时间。\033[m\r\n"); |
| 205 |
process_bar (0, MAX_PROCESS_BAR_LEN); |
process_bar (0, MAX_PROCESS_BAR_LEN); |
| 206 |
for (i = 0; i < MAX_PROCESS_BAR_LEN; i++) |
for (i = 0; i < MAX_PROCESS_BAR_LEN; i++) |
| 207 |
{ |
{ |
| 222 |
break; |
break; |
| 223 |
else |
else |
| 224 |
{ |
{ |
| 225 |
prints ("\033[1;31m连接失败!\033[m\n"); |
prints ("\033[1;31m连接失败!\033[m\r\n"); |
| 226 |
press_any_key (); |
press_any_key (); |
| 227 |
return -1; |
return -1; |
| 228 |
} |
} |
| 229 |
} |
} |
| 230 |
if (i == MAX_PROCESS_BAR_LEN) |
if (i == MAX_PROCESS_BAR_LEN) |
| 231 |
{ |
{ |
| 232 |
prints ("\033[1;31m连接超时!\033[m\n"); |
prints ("\033[1;31m连接超时!\033[m\r\n"); |
| 233 |
press_any_key (); |
press_any_key (); |
| 234 |
return -1; |
return -1; |
| 235 |
} |
} |
| 236 |
setsockopt (sock, IPPROTO_IP, IP_TOS, &tos, sizeof (int)); |
setsockopt (sock, IPPROTO_IP, IP_TOS, &tos, sizeof (int)); |
| 237 |
prints ("\033[1;31m连接成功!\033[m\n"); |
|
| 238 |
|
prints ("\033[1;31m连接成功!\033[m\r\n"); |
| 239 |
|
log_std ("BBSNET connect to %s:%d\n", remote_addr, remote_port); |
| 240 |
|
|
| 241 |
FD_ZERO (&inputs); |
FD_ZERO (&inputs); |
| 242 |
FD_SET (0, &inputs); |
FD_SET (0, &inputs); |
| 243 |
FD_SET (sock, &inputs); |
FD_SET (sock, &inputs); |
| 244 |
|
|
| 245 |
BBS_last_access_tm = time (0); |
BBS_last_access_tm = t_used = time (0); |
| 246 |
|
|
| 247 |
loop = 1; |
loop = 1; |
| 248 |
|
|
| 252 |
timeout.tv_sec = TIME_OUT; |
timeout.tv_sec = TIME_OUT; |
| 253 |
timeout.tv_usec = 0; |
timeout.tv_usec = 0; |
| 254 |
|
|
| 255 |
result = select (FD_SETSIZE, &testfds, (fd_set *) NULL, |
result = SignalSafeSelect (FD_SETSIZE, &testfds, (fd_set *) NULL, |
| 256 |
(fd_set *) NULL, &timeout); |
(fd_set *) NULL, &timeout); |
| 257 |
|
|
| 258 |
switch (result) |
if (result == 0) |
| 259 |
{ |
{ |
|
case 0: |
|
| 260 |
if (time (0) - BBS_last_access_tm >= MAX_DELAY_TIME) |
if (time (0) - BBS_last_access_tm >= MAX_DELAY_TIME) |
| 261 |
{ |
{ |
| 262 |
loop = 0; |
loop = 0; |
| 263 |
} |
} |
| 264 |
break; |
} |
| 265 |
case -1: |
if (result < 0) |
| 266 |
|
{ |
| 267 |
log_error ("select() error!\n"); |
log_error ("select() error!\n"); |
| 268 |
break; |
loop = 0; |
| 269 |
default: |
} |
| 270 |
|
if (result > 0) |
| 271 |
|
{ |
| 272 |
if (FD_ISSET (0, &testfds)) |
if (FD_ISSET (0, &testfds)) |
| 273 |
{ |
{ |
| 274 |
len = read (0, buf, 255); |
len = read (0, buf, 255); |
| 275 |
if (len == 0) |
if (len == 0) |
| 276 |
{ |
{ |
| 277 |
loop = 0; |
loop = 0; |
|
break; |
|
| 278 |
} |
} |
| 279 |
write (sock, buf, len); |
write (sock, buf, len); |
| 280 |
} |
} |
| 284 |
if (len == 0) |
if (len == 0) |
| 285 |
{ |
{ |
| 286 |
loop = 0; |
loop = 0; |
|
break; |
|
| 287 |
} |
} |
| 288 |
write (1, buf, len); |
write (1, buf, len); |
| 289 |
} |
} |
|
break; |
|
| 290 |
BBS_last_access_tm = time (0); |
BBS_last_access_tm = time (0); |
| 291 |
} |
} |
| 292 |
} |
} |
| 296 |
log_error ("Close socket failed\n"); |
log_error ("Close socket failed\n"); |
| 297 |
} |
} |
| 298 |
|
|
| 299 |
|
t_used = time (0) - t_used; |
| 300 |
|
tm_used = gmtime (&t_used); |
| 301 |
|
|
| 302 |
|
log_std ("BBSNET disconnect, %d days %d hours %d minutes %d seconds used\n", |
| 303 |
|
tm_used->tm_mday - 1, tm_used->tm_hour, tm_used->tm_min, |
| 304 |
|
tm_used->tm_sec); |
| 305 |
|
|
| 306 |
return 0; |
return 0; |
| 307 |
} |
} |
| 308 |
|
|
| 314 |
clearscr (); |
clearscr (); |
| 315 |
moveto (1, 0); |
moveto (1, 0); |
| 316 |
prints |
prints |
| 317 |
("╭══════════════════════════════════════╮"); |
("?q?T?T?T?T?T?T?T?T?T?T?T?T?T?T?T?T?T?T?T?T?T?T?T?T?T?T?T?T?T?T?T?T?T?T?T?T?T?T?r"); |
| 318 |
for (i = 2; i < 19; i++) |
for (i = 2; i < 19; i++) |
| 319 |
{ |
{ |
| 320 |
moveto (i, 0); |
moveto (i, 0); |
| 321 |
prints ("║"); |
prints ("?U"); |
| 322 |
moveto (i, 79); |
moveto (i, 79); |
| 323 |
prints ("║"); |
prints ("?U"); |
| 324 |
} |
} |
| 325 |
moveto (19, 0); |
moveto (19, 0); |
| 326 |
prints |
prints |
| 327 |
("║——————————————————————————————————————║"); |
("?U——————————————————————————————————————?U"); |
| 328 |
moveto (22, 0); |
moveto (22, 0); |
| 329 |
prints |
prints |
| 330 |
("╰══════════════════════════════════════╯"); |
("?t?T?T?T?T?T?T?T?T?T?T?T?T?T?T?T?T?T?T?T?T?T?T?T?T?T?T?T?T?T?T?T?T?T?T?T?T?T?T?s"); |
| 331 |
moveto (23, 0); |
moveto (23, 0); |
| 332 |
prints (" [\x1b[1;32mCtrl+C\x1b[m]退出"); |
prints (" [\x1b[1;32mCtrl+C\x1b[m]退出"); |
| 333 |
iflush (); |
iflush (); |
| 340 |
{ |
{ |
| 341 |
moveto (20, 0); |
moveto (20, 0); |
| 342 |
clrtoeol (); |
clrtoeol (); |
| 343 |
prints ("║\x1b[1m单位:\x1b[1;33m%-18s\x1b[m 站名:\x1b[1;33m%s\x1b[m", |
prints ("?U\x1b[1m单位:\x1b[1;33m%-18s\x1b[m 站名:\x1b[1;33m%s\x1b[m", |
| 344 |
bbsnet_conf[new_pos].host2, bbsnet_conf[new_pos].host1); |
bbsnet_conf[new_pos].host2, bbsnet_conf[new_pos].host1); |
| 345 |
moveto (20, 79); |
moveto (20, 79); |
| 346 |
prints ("║"); |
prints ("?U"); |
| 347 |
moveto (21, 0); |
moveto (21, 0); |
| 348 |
clrtoeol (); |
clrtoeol (); |
| 349 |
prints ("║\x1b[1m连往:\x1b[1;33m%-20s", bbsnet_conf[new_pos].ip); |
prints ("?U\x1b[1m连往:\x1b[1;33m%-20s", bbsnet_conf[new_pos].ip); |
| 350 |
if (bbsnet_conf[new_pos].port != 23) |
if (bbsnet_conf[new_pos].port != 23) |
| 351 |
prints (" %d", bbsnet_conf[new_pos].port); |
prints (" %d", bbsnet_conf[new_pos].port); |
| 352 |
prints ("\x1b[m"); |
prints ("\x1b[m"); |
| 353 |
moveto (21, 79); |
moveto (21, 79); |
| 354 |
prints ("║"); |
prints ("?U"); |
| 355 |
iflush (); |
iflush (); |
| 356 |
|
|
| 357 |
return 0; |
return 0; |