| 33 |
#include <sys/ioctl.h> |
#include <sys/ioctl.h> |
| 34 |
#include <sys/socket.h> |
#include <sys/socket.h> |
| 35 |
#include <netinet/in.h> |
#include <netinet/in.h> |
| 36 |
|
#include <netinet/ip.h> |
| 37 |
#include <arpa/inet.h> |
#include <arpa/inet.h> |
| 38 |
|
|
| 39 |
#define MENU_CONF_DELIM " \t\r\n" |
#define MENU_CONF_DELIM " \t\r\n" |
| 158 |
fd_set write_fds; |
fd_set write_fds; |
| 159 |
struct timeval timeout; |
struct timeval timeout; |
| 160 |
struct hostent *p_host = NULL; |
struct hostent *p_host = NULL; |
| 161 |
int tos = 020, i; |
int tos; |
| 162 |
|
int i; |
| 163 |
char remote_addr[IP_ADDR_LEN]; |
char remote_addr[IP_ADDR_LEN]; |
| 164 |
int remote_port; |
int remote_port; |
| 165 |
time_t t_used; |
time_t t_used; |
| 192 |
} |
} |
| 193 |
|
|
| 194 |
sin.sin_family = AF_INET; |
sin.sin_family = AF_INET; |
| 195 |
sin.sin_addr.s_addr = |
sin.sin_addr.s_addr = (hostaddr_server[0] != '\0' ? inet_addr(hostaddr_server) : INADDR_ANY); |
|
(strnlen(hostaddr_server, sizeof(hostaddr_server)) > 0 ? inet_addr(hostaddr_server) : INADDR_ANY); |
|
| 196 |
sin.sin_port = 0; |
sin.sin_port = 0; |
| 197 |
|
|
| 198 |
if (bind(sock, (struct sockaddr *)&sin, sizeof(sin)) < 0) |
if (bind(sock, (struct sockaddr *)&sin, sizeof(sin)) < 0) |
| 199 |
{ |
{ |
| 200 |
log_error("Bind address %s:%u failed\n", |
log_error("Bind address %s:%u failed (%d)\n", |
| 201 |
inet_ntoa(sin.sin_addr), ntohs(sin.sin_port)); |
inet_ntoa(sin.sin_addr), ntohs(sin.sin_port), errno); |
| 202 |
return -2; |
return -2; |
| 203 |
} |
} |
| 204 |
|
|
| 280 |
} |
} |
| 281 |
|
|
| 282 |
fcntl(sock, F_SETFL, flags); /* restore file status flags */ |
fcntl(sock, F_SETFL, flags); /* restore file status flags */ |
| 283 |
setsockopt(sock, IPPROTO_IP, IP_TOS, &tos, sizeof(int)); |
|
| 284 |
|
tos = IPTOS_LOWDELAY; |
| 285 |
|
if (setsockopt(sock, IPPROTO_IP, IP_TOS, &tos, sizeof(tos)) < 0) |
| 286 |
|
{ |
| 287 |
|
log_error("setsockopt IP_TOS=%d error (%d)\n", tos, errno); |
| 288 |
|
} |
| 289 |
|
|
| 290 |
prints("\033[1;31m连接成功!\033[m\r\n"); |
prints("\033[1;31m连接成功!\033[m\r\n"); |
| 291 |
log_std("BBSNET connect to %s:%d\n", remote_addr, remote_port); |
log_std("BBSNET connect to %s:%d\n", remote_addr, remote_port); |
| 303 |
timeout.tv_sec = 0; |
timeout.tv_sec = 0; |
| 304 |
timeout.tv_usec = 100 * 1000; // 0.1 second |
timeout.tv_usec = 100 * 1000; // 0.1 second |
| 305 |
|
|
| 306 |
ret = select(FD_SETSIZE, &read_fds, NULL, NULL, &timeout); |
ret = select(sock + 1, &read_fds, NULL, NULL, &timeout); |
| 307 |
|
|
| 308 |
if (ret == 0) // timeout |
if (ret == 0) // timeout |
| 309 |
{ |
{ |