| 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 |
|
|
| 297 |
log_error ("Close socket failed\n"); |
log_error ("Close socket failed\n"); |
| 298 |
} |
} |
| 299 |
|
|
| 300 |
|
t_used = time (0) - t_used; |
| 301 |
|
tm_used = gmtime (&t_used); |
| 302 |
|
|
| 303 |
|
log_std ("BBSNET disconnect, %d days %d hours %d minutes %d seconds used\n", |
| 304 |
|
tm_used->tm_mday - 1, tm_used->tm_hour, tm_used->tm_min, |
| 305 |
|
tm_used->tm_sec); |
| 306 |
|
|
| 307 |
return 0; |
return 0; |
| 308 |
} |
} |
| 309 |
|
|