| 48 |
#define MAXSTATION 26 * 2 |
#define MAXSTATION 26 * 2 |
| 49 |
#define STATION_PER_LINE 4 |
#define STATION_PER_LINE 4 |
| 50 |
|
|
| 51 |
|
#define BBS_NET_DEFAULT_CHARSET "UTF-8" |
| 52 |
|
|
| 53 |
struct _bbsnet_conf |
struct _bbsnet_conf |
| 54 |
{ |
{ |
| 55 |
char host1[20]; |
char host1[20]; |
| 215 |
{ |
{ |
| 216 |
if (errno == EINVAL) // Incomplete |
if (errno == EINVAL) // Incomplete |
| 217 |
{ |
{ |
| 218 |
|
#ifdef _DEBUG |
| 219 |
|
log_error("iconv(inbytes=%d, outbytes=%d) error: EINVAL\n", in_bytes, out_bytes); |
| 220 |
|
#endif |
| 221 |
*p_buf_len = (int)(p_buf + *p_buf_len - in_buf); |
*p_buf_len = (int)(p_buf + *p_buf_len - in_buf); |
| 222 |
*p_buf_offset = 0; |
*p_buf_offset = 0; |
| 223 |
*p_conv_len = (int)(conv_size - out_bytes); |
*p_conv_len = (int)(conv_size - out_bytes); |
| 234 |
{ |
{ |
| 235 |
if (in_bytes > out_bytes || out_bytes <= 0) |
if (in_bytes > out_bytes || out_bytes <= 0) |
| 236 |
{ |
{ |
| 237 |
errno = E2BIG; |
log_error("iconv(inbytes=%d, outbytes=%d) error: EILSEQ and E2BIG\n", in_bytes, out_bytes); |
| 238 |
return -1; |
return -2; |
| 239 |
} |
} |
| 240 |
|
|
| 241 |
*out_buf++ = *in_buf++; |
*out_buf = *in_buf; |
| 242 |
|
in_buf++; |
| 243 |
|
out_buf++; |
| 244 |
in_bytes--; |
in_bytes--; |
| 245 |
out_bytes--; |
out_bytes--; |
| 246 |
|
|
| 293 |
int tos; |
int tos; |
| 294 |
char remote_addr[IP_ADDR_LEN]; |
char remote_addr[IP_ADDR_LEN]; |
| 295 |
int remote_port; |
int remote_port; |
| 296 |
|
char local_addr[IP_ADDR_LEN]; |
| 297 |
|
int local_port; |
| 298 |
|
socklen_t sock_len; |
| 299 |
time_t t_used = time(NULL); |
time_t t_used = time(NULL); |
| 300 |
struct tm *tm_used; |
struct tm *tm_used; |
| 301 |
int ch; |
int ch; |
| 475 |
log_error("setsockopt IP_TOS=%d error (%d)\n", tos, errno); |
log_error("setsockopt IP_TOS=%d error (%d)\n", tos, errno); |
| 476 |
} |
} |
| 477 |
|
|
| 478 |
|
sock_len = sizeof(sin); |
| 479 |
|
if (getsockname(sock, (struct sockaddr *)&sin, &sock_len) < 0) |
| 480 |
|
{ |
| 481 |
|
log_error("getsockname() error: %d", errno); |
| 482 |
|
goto cleanup; |
| 483 |
|
} |
| 484 |
|
|
| 485 |
|
strncpy(local_addr, inet_ntoa(sin.sin_addr), sizeof(local_addr) - 1); |
| 486 |
|
local_addr[sizeof(local_addr) - 1] = '\0'; |
| 487 |
|
local_port = ntohs(sin.sin_port); |
| 488 |
|
|
| 489 |
prints("\033[1;31m连接成功!\033[m\r\n"); |
prints("\033[1;31m连接成功!\033[m\r\n"); |
| 490 |
iflush(); |
iflush(); |
| 491 |
log_common("BBSNET connect to %s:%d\n", remote_addr, remote_port); |
log_common("BBSNET connect to %s:%d from %s:%d by [%s]\n", |
| 492 |
|
remote_addr, remote_port, local_addr, local_port, BBS_username); |
| 493 |
|
|
| 494 |
input_cd = iconv_open(bbsnet_conf[n].charset, "UTF-8"); |
input_cd = iconv_open(bbsnet_conf[n].charset, BBS_NET_DEFAULT_CHARSET); |
| 495 |
if (input_cd == (iconv_t)(-1)) |
if (input_cd == (iconv_t)(-1)) |
| 496 |
{ |
{ |
| 497 |
log_error("iconv_open(UTF8->GBK) error: %d\n", errno); |
log_error("iconv_open(%s->%s) error: %d\n", BBS_NET_DEFAULT_CHARSET, bbsnet_conf[n].charset, errno); |
| 498 |
goto cleanup; |
goto cleanup; |
| 499 |
} |
} |
| 500 |
output_cd = iconv_open("UTF-8", bbsnet_conf[n].charset); |
output_cd = iconv_open(BBS_NET_DEFAULT_CHARSET, bbsnet_conf[n].charset); |
| 501 |
if (input_cd == (iconv_t)(-1)) |
if (input_cd == (iconv_t)(-1)) |
| 502 |
{ |
{ |
| 503 |
log_error("iconv_open(GBK->UTF-8) error: %d\n", errno); |
log_error("iconv_open(%s->%s) error: %d\n", bbsnet_conf[n].charset, BBS_NET_DEFAULT_CHARSET, errno); |
| 504 |
iconv_close(input_cd); |
iconv_close(input_cd); |
| 505 |
goto cleanup; |
goto cleanup; |
| 506 |
} |
} |