Commit ae9e095a authored by Heiko Liermann's avatar Heiko Liermann
Browse files

updated discard and daytime server to make them protocol independent

parent b1b0d9e5
......@@ -8,21 +8,23 @@
int
main(int argc, char **argv)
{
int server_fd, client_fd, on = 1;
struct sockaddr_in server_addr;
int server_fd, client_fd, on = 1, off = 0;
struct sockaddr_in6 server_addr;
char buf[BUFFER_SIZE];
time_t ticks;
//(1)The creation of the TCP socket is identical to the client code
server_fd = socket_wrapper(AF_INET, SOCK_STREAM, IPPROTO_TCP);
memset(&server_addr, 0, sizeof(server_addr)); //socket address structure
server_addr.sin_family = AF_INET;
server_addr.sin_addr.s_addr = htonl(INADDR_ANY); //specify the IP address allows the server to accept a client //connection on any interface,
server_addr.sin_port = htons(strtol(argv[1], NULL, 10));
memset(&server_addr, 0, sizeof(server_addr));
server_fd = socket_wrapper(AF_INET6, SOCK_STREAM, IPPROTO_TCP);
server_addr.sin6_family = AF_INET6;
server_addr.sin6_addr = in6addr_any;
server_addr.sin6_port = htons(strtol(argv[1], NULL, 10));
setsockopt_wrap(server_fd, SOL_SOCKET, SO_REUSEADDR, &on, sizeof(int));
bind_wrapper(server_fd, (const struct sockaddr *)&server_addr, (socklen_t) sizeof(server_addr)); //(2)The bind() function shall assign a local socket address address to a socket identified by descriptor socket
//accept Ipv4 and Ipv6
setsockopt_wrap(server_fd, IPPROTO_IPV6, IPV6_V6ONLY, &off, sizeof(int));
bind_wrapper(server_fd, (const struct sockaddr *)&server_addr, (socklen_t) sizeof(server_addr)); //(2)The bind() function shall assign a local socket address address to a socket identified by descriptor socket
//(3)Socket converted in listening socket, incomming connections from clients will be accepted by kernel
//server_fd = listening descriptor
......
......@@ -5,19 +5,22 @@
#include "Socket.h"
int main(int argc, char **argv) {
int i, server_fd, client_fd, nfds, len;
struct sockaddr_in server_addr;
int i, server_fd, client_fd, nfds, len, on= 1, off = 0;
struct sockaddr_in6 server_addr;
int client_fds[30];
char buf[BUFFER_SIZE];
fd_set read_set, whole_set;
//(1)The creation of the TCP socket is identical to the client code
nfds = server_fd = socket_wrapper(AF_INET, SOCK_STREAM, 0);
server_fd = socket_wrapper(AF_INET6, SOCK_STREAM, IPPROTO_TCP);
memset(&server_addr, 0, sizeof(server_addr));
server_addr.sin6_family = AF_INET6;
server_addr.sin6_addr = in6addr_any;
server_addr.sin6_port = htons(strtol(argv[1], NULL, 10));
memset(&server_addr, 0, sizeof(server_addr)); //socket address structure
server_addr.sin_family = AF_INET; // inte
server_addr.sin_addr.s_addr = htonl(INADDR_ANY); //specify the IP address allows the server to accept a client //connection on any interface,
server_addr.sin_port = htons(strtol(argv[1], NULL, 10));
setsockopt_wrap(server_fd, SOL_SOCKET, SO_REUSEADDR, &on, sizeof(int));
//accept Ipv4 and Ipv6
setsockopt_wrap(server_fd, IPPROTO_IPV6, IPV6_V6ONLY, &off, sizeof(int));
bind_wrapper(server_fd, (const struct sockaddr *) &server_addr, (socklen_t) sizeof(server_addr)); //(1)The bind() function shall assign a local socket address address to a socket identified by descriptor socket
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment