EXPERIMENTAL attempt telnet ipv6 support
This commit is contained in:
parent
f8a3071e00
commit
402e406fbe
25
main.c
25
main.c
@ -863,12 +863,13 @@ void server(int port) {
|
|||||||
int client_sock, c;
|
int client_sock, c;
|
||||||
int pid;
|
int pid;
|
||||||
char *ip;
|
char *ip;
|
||||||
struct sockaddr_in server, client;
|
struct sockaddr_in6 server, client;
|
||||||
FILE *fptr;
|
FILE *fptr;
|
||||||
char buffer[1024];
|
char buffer[1024];
|
||||||
struct ip_address_guard *ip_guard;
|
struct ip_address_guard *ip_guard;
|
||||||
int i;
|
int i;
|
||||||
|
int on = 1;
|
||||||
|
char str[INET6_ADDRSTRLEN];
|
||||||
#if defined(ENABLE_WWW)
|
#if defined(ENABLE_WWW)
|
||||||
www_daemon = NULL;
|
www_daemon = NULL;
|
||||||
#endif
|
#endif
|
||||||
@ -972,7 +973,7 @@ void server(int port) {
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
server_socket = socket(AF_INET, SOCK_STREAM, 0);
|
server_socket = socket(AF_INET6, SOCK_STREAM, 0);
|
||||||
if (server_socket == -1) {
|
if (server_socket == -1) {
|
||||||
remove(conf.pid_file);
|
remove(conf.pid_file);
|
||||||
fprintf(stderr, "Couldn't create socket..\n");
|
fprintf(stderr, "Couldn't create socket..\n");
|
||||||
@ -980,9 +981,17 @@ void server(int port) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
server.sin_family = AF_INET;
|
if (setsockopt(server_socket, SOL_SOCKET, SO_REUSEADDR, (char *)&on, sizeof(on)) < 0) {
|
||||||
server.sin_addr.s_addr = INADDR_ANY;
|
remove(conf.pid_file);
|
||||||
server.sin_port = htons(port);
|
fprintf(stderr, "setsockopt(SO_REUSEADDR) failed");
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
memset(&server, 0, sizeof(server));
|
||||||
|
|
||||||
|
server.sin6_family = AF_INET6;
|
||||||
|
server.sin6_addr = in6addr_any;
|
||||||
|
server.sin6_port = htons(port);
|
||||||
|
|
||||||
if (bind(server_socket, (struct sockaddr *)&server, sizeof(server)) < 0) {
|
if (bind(server_socket, (struct sockaddr *)&server, sizeof(server)) < 0) {
|
||||||
perror("Bind Failed, Error\n");
|
perror("Bind Failed, Error\n");
|
||||||
@ -992,10 +1001,10 @@ void server(int port) {
|
|||||||
|
|
||||||
listen(server_socket, 3);
|
listen(server_socket, 3);
|
||||||
|
|
||||||
c = sizeof(struct sockaddr_in);
|
c = sizeof(struct sockaddr_in6);
|
||||||
|
|
||||||
while ((client_sock = accept(server_socket, (struct sockaddr *)&client, (socklen_t *)&c))) {
|
while ((client_sock = accept(server_socket, (struct sockaddr *)&client, (socklen_t *)&c))) {
|
||||||
ip = strdup(inet_ntoa(client.sin_addr));
|
ip = strdup(inet_ntop(AF_INET6, &client.sin6_addr, str, sizeof(str)));
|
||||||
if (client_sock == -1) {
|
if (client_sock == -1) {
|
||||||
if (errno == EINTR) {
|
if (errno == EINTR) {
|
||||||
continue;
|
continue;
|
||||||
|
Reference in New Issue
Block a user