Commit 9fbedf6a authored by Gero Hülsbusch's avatar Gero Hülsbusch
Browse files

Update echo_server_IPv6.c

parent 3e467f98
// Created by user on 17.11.21.
Erweitern Sie einen Server in tcp examples, so dass sowohl IPv4 und IPv6 unterstu ̈tzt wird.
#include "Socket.h"
......@@ -40,10 +43,13 @@ int main (int argc, char **argv) {
server_addr.sin6_addr = in6addr_any;
server_addr.sin6_port = htons(strtol(argv[1], NULL, 10));
//accept Ipv4 and Ipv6
int *option = 0;
setsockopt(server_fd, IPPROTO_IPV6, IPV6_V6ONLY, &option, sizeof(int));
//bind the socket
bind_wrapper(server_fd, (const struct sockaddr *)&server_addr, (socklen_t)sizeof(server_addr));
//wait for incumming connection
while(1) {
......@@ -57,11 +63,16 @@ int main (int argc, char **argv) {
*thread_fd = accept_wrapper(server_fd, NULL, NULL);
//create a thread for each client
//for each is handle_connection called
//(void *) thread_fd) argument for called funktion
pthread_create(&client_thread, NULL, &handle_connection, (void *) thread_fd);
//destroy thread after performance and free memmory
//close fd
if (close_wrapper(server_fd) < 0)
return (0);
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