commit 721f59a177600212ef27765bc53ecff21c211e37 Author: rottenwheel Date: Mon Jul 15 07:27:01 2024 +0000 deploy: b83a65b9e1a0d92c2b4721ebf7b6c596779af8dd diff --git a/.nojekyll b/.nojekyll new file mode 100644 index 0000000..e69de29 diff --git a/404.html b/404.html new file mode 100644 index 0000000..ce60c0c --- /dev/null +++ b/404.html @@ -0,0 +1,2 @@ +404 Page not found +

404

\ No newline at end of file diff --git a/contact-signed.txt b/contact-signed.txt new file mode 100644 index 0000000..ec0eca2 --- /dev/null +++ b/contact-signed.txt @@ -0,0 +1,34 @@ +-----BEGIN PGP SIGNED MESSAGE----- +Hash: SHA256 + +E-mail: hi |at| rottenwheel |dot| com; +Lemmy: rottenwheel |at| monero |dot| town; +Matrix: |at| rottenwheel:kernal |dot| eu; +Nostr: rottenwheel |at| ok0 |dot| org; npub1tn8spk9zhxrctg2qym3gj8r7eq2wk6z3phrl8304wc54vt9qam4qvzw6jx; +PGP public key: https://rottenwheel.com/pgp.txt. Archive: https://archive.org/details/rottenwheel_pgp_public_key; GitHub: https://github.com/rottenwheel.gpg; PrivateBin: https://pb.envs.net/?f2171d903c8c39b2#ABKvcDPPMxwB3TACST583PJs1Tz8JtZ27cAWmEYqo35e; +Fingerprint: 080F330AD043CC0A449A27D71FAD78669DE85DE8; +SimpleX contact address: https://simplex.chat/contact#/?v=1-4&smp=smp%3A%2F%2Fhejn2gVIqNU6xjtGM3OwQeuk8ZEbDXVJXAlnSBJBWUA%3D%40smp16.simplex.im%2F4O2CIL0kxNTZbB9wwgWsPw9HB_Gp9Y38%23%2F%3Fv%3D1-2%26dh%3DMCowBQYDK2VuAyEACg4ttrfKTdLLCneB7Mzevbuh1Lo6s1Scfjhrz0e7emA%253D%26srv%3Dp3ktngodzi6qrf7w64mmde3syuzrv57y55hxabqcq3l5p6oi7yzze6qd.onion; +SoundCloud: |at| rottensox; +Threema: Y99DFWMR; +Wire: |at| rottenwheel; +XMPP: rottenwheel |at| jabbers |dot| one; +OMEMO: [1]: ed49f179a8f10ddc3365a123eda4a987a0dd303e0dc40143f2c9e118a3c92b63; +[2]: 5ab674ad81cc103fe448cbd80b2c13acf888a56c8892c93b0bb3afc0934ab621; +X: |at| rottenwheel1 // |at| rottenwheel. +-----BEGIN PGP SIGNATURE----- + +iQI+BAEBCAAoIRxyb3R0ZW53aGVlbCA8aGlAcm90dGVud2hlZWwuY29tPgUCZo9H +mQAKCRAfrXhmnehd6JVND/kBPULP2JHun78NOZh8RJVmpARmTytYPDz1pC3S6IR6 +EmbH9Oy+QToldFtellRg6qQC8v0lrQUmYEa8PGsx7JT6kcdAlr9JPQaC8JT4jrDO +wpVFrhjZupaFVS4Ni+QuKMRAWApQ/SDfLtWCc8SgyCKo3ihcJ4fgaUeCZBsYQLVL +PmsKLB+IW8RbnGCjMyj0IH/g3XkmjVHEwCwwfaDcNHUQ8bTpWxSPS8KTbcVIxYmr +heHE9xf083TEXU97Bt04TUcLhR2L+loT//JSiTGyM+72j4y/jYiw7h9ltrgrDiEN +4nXjKSwQo1h4cOEbCYVTW02YBp7p5GfDmBPjVD87x8oVm7H1f309kEcc21aALI4L +L7pvgVuLfAabu5Yo0YckfQ56siKKisrHmJAA5fsS0MNMguJJNzp0CtUTF7lveTZG +8dpZhAYpboqk2aByiaRURtLb/eAtTzTE8Fq8gGOFPWLOocGeWbIucesNis0aB3z1 +0CWjptmXTnZWnX1cXV8ABmB/uUMFCQuR9tFpL9figZblJZ9z96b91ngBqzoI6jzl +kQZOxvhcpZolI8jyVASwQbVJ+TcJ6WKMqsZBpTJJU3Dj5YL+dvQQNDx8Mhut4rXr +swSyVcieyfBZtWq2yF+EMYVOYgamaBU1bqmOf+Sju33cV87TBECxgzfZcWJcDef5 +Kg== +=Or8v +-----END PGP SIGNATURE----- diff --git a/css/style.min.a2300dd0fbcbc91eb70c91148888ea7322a595ed0c5630ccc28d6beb44e8665d.css b/css/style.min.a2300dd0fbcbc91eb70c91148888ea7322a595ed0c5630ccc28d6beb44e8665d.css new file mode 100644 index 0000000..516c75f --- /dev/null +++ b/css/style.min.a2300dd0fbcbc91eb70c91148888ea7322a595ed0c5630ccc28d6beb44e8665d.css @@ -0,0 +1 @@ +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/favicon.ico b/favicon.ico new file mode 100644 index 0000000..2907c17 Binary files /dev/null and b/favicon.ico differ diff --git a/index.html b/index.html new file mode 100644 index 0000000..ae511aa --- /dev/null +++ b/index.html @@ -0,0 +1,2 @@ +rottenblog +

RSS feed here.

Latest Posts

\ No newline at end of file diff --git a/index.xml b/index.xml new file mode 100644 index 0000000..ca8ec5f --- /dev/null +++ b/index.xml @@ -0,0 +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 diff --git a/posts/index.html b/posts/index.html new file mode 100644 index 0000000..215cc1a --- /dev/null +++ b/posts/index.html @@ -0,0 +1,3 @@ +Posts +
\ No newline at end of file diff --git a/posts/index.xml b/posts/index.xml new file mode 100644 index 0000000..291d4fd --- /dev/null +++ b/posts/index.xml @@ -0,0 +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 diff --git a/posts/post-1/index.html b/posts/post-1/index.html new file mode 100644 index 0000000..a297289 --- /dev/null +++ b/posts/post-1/index.html @@ -0,0 +1,73 @@ +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 diff --git a/robots.txt b/robots.txt new file mode 100644 index 0000000..5d7320b --- /dev/null +++ b/robots.txt @@ -0,0 +1,4 @@ +User-agent: * +Allow: / + +Sitemap: https://blog.rottenwheel.com/sitemap.xml diff --git a/sitemap.xml b/sitemap.xml new file mode 100644 index 0000000..02bb8e8 --- /dev/null +++ b/sitemap.xml @@ -0,0 +1 @@ +https://blog.rottenwheel.com/posts/post-1/2022-01-28T03:00:00+03:00https://blog.rottenwheel.com/posts/2022-01-28T03:00:00+03:00https://blog.rottenwheel.com/2022-01-28T03:00:00+03:00 \ No newline at end of file