diff --git a/404.html b/404.html deleted file mode 100644 index b626427..0000000 --- a/404.html +++ /dev/null @@ -1,2 +0,0 @@ -404 Page not found -

404

\ No newline at end of file diff --git a/css/style.min.a2300dd0fbcbc91eb70c91148888ea7322a595ed0c5630ccc28d6beb44e8665d.css b/css/style.min.a2300dd0fbcbc91eb70c91148888ea7322a595ed0c5630ccc28d6beb44e8665d.css deleted file mode 100644 index 516c75f..0000000 --- a/css/style.min.a2300dd0fbcbc91eb70c91148888ea7322a595ed0c5630ccc28d6beb44e8665d.css +++ /dev/null @@ -1 +0,0 @@ -html{font-family:open sans,sans-serif;font-size:18px}body{background:#000;color:#fff}.container{margin:auto;padding:.5em 1em;min-width:300px;max-width:800px}.header{font-size:1.4em;user-select:none}.header ul{list-style-type:none;overflow:hidden;margin:0;padding:.5em 0}.header li{margin-left:.8em;float:right}.header li.home{margin-left:0;float:left;font-weight:600}.header a{color:inherit}ul.list{list-style:none;padding:0}ul.list li{padding:.5em 0}ul.list li span{float:right;padding-left:.5em}a{text-decoration:none;color:#fff}blockquote{border-left:5px solid;padding-left:1em;margin-left:0}code{font-family:source code pro,Consolas,ubuntu mono,Menlo,dejavu sans mono,monospace,monospace!important;font-size:.85em;padding:.2em .3em;border-radius:4px}pre code{padding:0;border-radius:0;background:0 0}pre{padding:1em;overflow:auto;border-radius:4px}table{margin:1em 0;display:block;overflow:auto;border-collapse:collapse}table td,table th{border:2px solid;padding:.5em}img{max-width:100%}figure{margin:1em 0;border-radius:4px}figure img{width:100%}figcaption h4{margin:.2em;text-align:center}.content a{text-decoration:underline} \ No newline at end of file diff --git a/index.html b/index.html deleted file mode 100644 index 8ffd7f0..0000000 --- a/index.html +++ /dev/null @@ -1,2 +0,0 @@ -rottenblog -

RSS feed here.

Latest Posts

\ No newline at end of file diff --git a/index.xml b/index.xml index bbfa823..ca8ec5f 100644 --- a/index.xml +++ b/index.xml @@ -1,2 +1,2 @@ rottenbloghttps://blog.rottenwheel.com/Recent content on rottenblogHugoen-usFri, 28 Jan 2022 03:00:00 +0300Example posthttps://blog.rottenwheel.com/posts/post-1/Fri, 28 Jan 2022 03:00:00 +0300https://blog.rottenwheel.com/posts/post-1/What you need to do is: -Create the sockets. Add the sockets to the set (FD_SET). Find the socket with the highest file descriptor for calls to select(). Above also works with different type sockets (e.g. AF_INET, AF_INET6). It even works if you have different type sockets (e.g. one IPv4 and one IPv6) listening on the same port number. Dual stack sockets are a thing but this approach is more flexible. \ No newline at end of file +Create the sockets. Add the sockets to the set (FD_SET). Find the socket with the highest file descriptor for calls to select(). Above also works with different type sockets (e.g. AF_INET, AF_INET6). It even works if you have different type sockets (e.g. one IPv4 and one IPv6) listening on the same port number. Dual stack sockets are a thing but this approach is more flexible. \ No newline at end of file diff --git a/posts/index.html b/posts/index.html deleted file mode 100644 index e513d5e..0000000 --- a/posts/index.html +++ /dev/null @@ -1,3 +0,0 @@ -Posts -
\ No newline at end of file diff --git a/posts/index.xml b/posts/index.xml index 55ab46c..291d4fd 100644 --- a/posts/index.xml +++ b/posts/index.xml @@ -1,2 +1,2 @@ Posts on rottenbloghttps://blog.rottenwheel.com/posts/Recent content in Posts on rottenblogHugoen-usFri, 28 Jan 2022 03:00:00 +0300Example posthttps://blog.rottenwheel.com/posts/post-1/Fri, 28 Jan 2022 03:00:00 +0300https://blog.rottenwheel.com/posts/post-1/What you need to do is: -Create the sockets. Add the sockets to the set (FD_SET). Find the socket with the highest file descriptor for calls to select(). Above also works with different type sockets (e.g. AF_INET, AF_INET6). It even works if you have different type sockets (e.g. one IPv4 and one IPv6) listening on the same port number. Dual stack sockets are a thing but this approach is more flexible. \ No newline at end of file +Create the sockets. Add the sockets to the set (FD_SET). Find the socket with the highest file descriptor for calls to select(). Above also works with different type sockets (e.g. AF_INET, AF_INET6). It even works if you have different type sockets (e.g. one IPv4 and one IPv6) listening on the same port number. Dual stack sockets are a thing but this approach is more flexible. \ No newline at end of file diff --git a/posts/post-1/index.html b/posts/post-1/index.html deleted file mode 100644 index 1c5f604..0000000 --- a/posts/post-1/index.html +++ /dev/null @@ -1,73 +0,0 @@ -Example post -

Example post

What you need to do is:

  1. Create the sockets.
  2. Add the sockets to the set (FD_SET).
  3. Find the socket with the highest file descriptor for calls to select().

Above also works with different type sockets (e.g. AF_INET, AF_INET6). It even works if you have different type sockets (e.g. one IPv4 and one IPv6) listening on the same port number. Dual stack sockets are a thing but this approach is more flexible.

Create sockets

For this example I will be creating two sockets. One of them will have an IPv4 address and the other IPv6. Nothing out of the ordinary here.

	/* Create IPv4 socket */
-	struct sockaddr_in serv_addr4, cli_addr4;
-	int addrlen4 = sizeof(cli_addr4);
-
-	if ((sockfd_v4 = socket(AF_INET, SOCK_STREAM, 0)) == -1) {
-		perror("socket");
-		return 1;
-	}
-
-	setsockopt(sockfd_v4, SOL_SOCKET, SO_REUSEADDR, &option, sizeof(int));
-
-	serv_addr4.sin_family = AF_INET;
-	serv_addr4.sin_addr.s_addr = inet_addr(IPV4_ADDR);
-	serv_addr4.sin_port = htons(IPV4_PORT);
-
-	if (bind(sockfd_v4, (struct sockaddr *)&serv_addr4, sizeof(serv_addr4)) < 0) {
-		perror("bind");
-		return 1;
-	}
-
-	if (listen(sockfd_v4, BACKLOG) < 0) {
-		perror("listen");
-		return 1;
-	}
-
-	/* Create IPv6 socket */
-	struct sockaddr_in6 serv_addr6, cli_addr6;
-	int addrlen6 = sizeof(cli_addr6);
-
-	if ((sockfd_v6 = socket(AF_INET6, SOCK_STREAM, 0)) == -1) {
-		perror("socket");
-		return 1;
-	}
-
-	setsockopt(sockfd_v6, SOL_SOCKET, SO_REUSEADDR, &option, sizeof(int));
-	serv_addr6.sin6_family = AF_INET6;
-	inet_pton(AF_INET6, IPV6_ADDR, &serv_addr6.sin6_addr);
-	serv_addr6.sin6_port = htons(IPV6_PORT);
-
-	if (bind(sockfd_v6, (struct sockaddr *)&serv_addr6, sizeof(serv_addr6)) < 0) {
-		perror("bind");
-		return 1;
-	}
-
-	if (listen(sockfd_v6, BACKLOG) < 0) {
-		perror("listen");
-		return 1;
-	}
-

Adding sockets to the set and calling select()

FD_SET() is called on each socket. Later on we compare the two sockets to see which one has the highest file descriptor (stored in maxfd). Additionally, there’s an array of structures that also contain sockets (clients), their values are also checked to find the highest descriptor. Finally we can call select() with maxfd + 1.

	for (;;) {
-		FD_ZERO(&descriptors);
-		FD_SET(sockfd_v4, &descriptors);
-		FD_SET(sockfd_v6, &descriptors);
-		if (sockfd_v6 > sockfd_v4)
-			maxfd = sockfd_v6;
-		else
-			maxfd = sockfd_v4;
-		/* Add all socket descriptors to the read list. */
-		for (id = 0; id < maxclients; id++) {
-			if (clients[id] != NULL) {
-				FD_SET(clients[id]->connfd, &descriptors);
-				/* Find highest file descriptor, needed for the select function. */
-				if (clients[id]->connfd > maxfd)
-					maxfd = clients[id]->connfd;
-			}
-		}
-
-		if (select(maxfd + 1 ,&descriptors, NULL, NULL, NULL) == -1)
-			perror("select");
-...
-

Full server example

The snippets in this post are taken from kernal-chat and simplified. You can find the full source code here.

Leave us a message on

$ nc 2a02:c207:2043:4492:: 1337 # or
-$ nc chat.kernal.eu 1337
-
\ No newline at end of file