This commit is contained in:
rottenwheel 2024-07-15 07:27:01 +00:00
commit 721f59a177
12 changed files with 124 additions and 0 deletions

0
.nojekyll Normal file
View File

2
404.html Normal file
View File

@ -0,0 +1,2 @@
<!doctype html><html class=dark lang=en-us><head><meta charset=UTF-8><title>404 Page not found</title>
<meta name=description content><meta name=viewport content="width=device-width,initial-scale=1"><meta name=generator content="Hugo 0.128.2"><link rel=stylesheet href=/css/style.min.a2300dd0fbcbc91eb70c91148888ea7322a595ed0c5630ccc28d6beb44e8665d.css></head><body><div class=container><div class=header><ul><li class=home><a href=https://blog.rottenwheel.com/>rottenblog</a></li><li><a href=https://rottenwheel.com>about</a></li><li><a href=/>blog</a></li></ul></div><div class=content><h1>404</h1></div></div></body></html>

34
contact-signed.txt Normal file
View File

@ -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-----

View File

@ -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}

BIN
favicon.ico Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 998 B

2
index.html Normal file
View File

@ -0,0 +1,2 @@
<!doctype html><html class=dark lang=en-us><head><meta charset=UTF-8><title>rottenblog</title>
<meta name=description content><meta name=viewport content="width=device-width,initial-scale=1"><meta name=generator content="Hugo 0.128.2"><link rel=stylesheet href=/css/style.min.a2300dd0fbcbc91eb70c91148888ea7322a595ed0c5630ccc28d6beb44e8665d.css></head><body><div class=container><div class=header><ul><li class=home><a href=https://blog.rottenwheel.com/>rottenblog</a></li><li><a href=https://rottenwheel.com>about</a></li><li><a href=/>blog</a></li></ul></div><div class=content><p>RSS feed <a href=/index.xml>here</a>.</p><h2>Latest Posts</h2><ul><li><a href=https://blog.rottenwheel.com/posts/post-1/>Example post</a> - 2022-01-28</li></ul></div></div></body></html>

2
index.xml Normal file
View File

@ -0,0 +1,2 @@
<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>rottenblog</title><link>https://blog.rottenwheel.com/</link><description>Recent content on rottenblog</description><generator>Hugo</generator><language>en-us</language><lastBuildDate>Fri, 28 Jan 2022 03:00:00 +0300</lastBuildDate><atom:link href="https://blog.rottenwheel.com/index.xml" rel="self" type="application/rss+xml"/><item><title>Example post</title><link>https://blog.rottenwheel.com/posts/post-1/</link><pubDate>Fri, 28 Jan 2022 03:00:00 +0300</pubDate><guid>https://blog.rottenwheel.com/posts/post-1/</guid><description>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.</description></item></channel></rss>

3
posts/index.html Normal file
View File

@ -0,0 +1,3 @@
<!doctype html><html class=dark lang=en-us><head><meta charset=UTF-8><title>Posts</title>
<meta name=description content><meta name=viewport content="width=device-width,initial-scale=1"><meta name=generator content="Hugo 0.128.2"><link rel=stylesheet href=/css/style.min.a2300dd0fbcbc91eb70c91148888ea7322a595ed0c5630ccc28d6beb44e8665d.css></head><body><div class=container><div class=header><ul><li class=home><a href=https://blog.rottenwheel.com/>rottenblog</a></li><li><a href=https://rottenwheel.com>about</a></li><li><a href=/>blog</a></li></ul></div><div class=content><ul class=list><li><span>2022-01-28</span>
<a href=/posts/post-1/>Example post</a></li></ul></div></div></body></html>

2
posts/index.xml Normal file
View File

@ -0,0 +1,2 @@
<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Posts on rottenblog</title><link>https://blog.rottenwheel.com/posts/</link><description>Recent content in Posts on rottenblog</description><generator>Hugo</generator><language>en-us</language><lastBuildDate>Fri, 28 Jan 2022 03:00:00 +0300</lastBuildDate><atom:link href="https://blog.rottenwheel.com/posts/index.xml" rel="self" type="application/rss+xml"/><item><title>Example post</title><link>https://blog.rottenwheel.com/posts/post-1/</link><pubDate>Fri, 28 Jan 2022 03:00:00 +0300</pubDate><guid>https://blog.rottenwheel.com/posts/post-1/</guid><description>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.</description></item></channel></rss>

73
posts/post-1/index.html Normal file
View File

@ -0,0 +1,73 @@
<!doctype html><html class=dark lang=en-us><head><meta charset=UTF-8><title>Example post</title>
<meta name=description content><meta name=viewport content="width=device-width,initial-scale=1"><meta name=generator content="Hugo 0.128.2"><link rel=stylesheet href=/css/style.min.a2300dd0fbcbc91eb70c91148888ea7322a595ed0c5630ccc28d6beb44e8665d.css></head><body><div class=container><div class=header><ul><li class=home><a href=https://blog.rottenwheel.com/>rottenblog</a></li><li><a href=https://rottenwheel.com>about</a></li><li><a href=/>blog</a></li></ul></div><div class=content><h1>Example post</h1><p>What you need to do is:</p><ol><li>Create the sockets.</li><li>Add the sockets to the set (<code>FD_SET</code>).</li><li>Find the socket with the highest file descriptor for calls to select().</li></ol><p>Above also works with different type sockets (e.g. <code>AF_INET</code>, <code>AF_INET6</code>). 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.</p><h2 id=create-sockets>Create sockets</h2><p>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.</p><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-C data-lang=C><span style=display:flex><span> <span style=color:#75715e>/* Create IPv4 socket */</span>
</span></span><span style=display:flex><span> <span style=color:#66d9ef>struct</span> sockaddr_in serv_addr4, cli_addr4;
</span></span><span style=display:flex><span> <span style=color:#66d9ef>int</span> addrlen4 <span style=color:#f92672>=</span> <span style=color:#66d9ef>sizeof</span>(cli_addr4);
</span></span><span style=display:flex><span>
</span></span><span style=display:flex><span> <span style=color:#66d9ef>if</span> ((sockfd_v4 <span style=color:#f92672>=</span> <span style=color:#a6e22e>socket</span>(AF_INET, SOCK_STREAM, <span style=color:#ae81ff>0</span>)) <span style=color:#f92672>==</span> <span style=color:#f92672>-</span><span style=color:#ae81ff>1</span>) {
</span></span><span style=display:flex><span> <span style=color:#a6e22e>perror</span>(<span style=color:#e6db74>&#34;socket&#34;</span>);
</span></span><span style=display:flex><span> <span style=color:#66d9ef>return</span> <span style=color:#ae81ff>1</span>;
</span></span><span style=display:flex><span> }
</span></span><span style=display:flex><span>
</span></span><span style=display:flex><span> <span style=color:#a6e22e>setsockopt</span>(sockfd_v4, SOL_SOCKET, SO_REUSEADDR, <span style=color:#f92672>&amp;</span>option, <span style=color:#66d9ef>sizeof</span>(<span style=color:#66d9ef>int</span>));
</span></span><span style=display:flex><span>
</span></span><span style=display:flex><span> serv_addr4.sin_family <span style=color:#f92672>=</span> AF_INET;
</span></span><span style=display:flex><span> serv_addr4.sin_addr.s_addr <span style=color:#f92672>=</span> <span style=color:#a6e22e>inet_addr</span>(IPV4_ADDR);
</span></span><span style=display:flex><span> serv_addr4.sin_port <span style=color:#f92672>=</span> <span style=color:#a6e22e>htons</span>(IPV4_PORT);
</span></span><span style=display:flex><span>
</span></span><span style=display:flex><span> <span style=color:#66d9ef>if</span> (<span style=color:#a6e22e>bind</span>(sockfd_v4, (<span style=color:#66d9ef>struct</span> sockaddr <span style=color:#f92672>*</span>)<span style=color:#f92672>&amp;</span>serv_addr4, <span style=color:#66d9ef>sizeof</span>(serv_addr4)) <span style=color:#f92672>&lt;</span> <span style=color:#ae81ff>0</span>) {
</span></span><span style=display:flex><span> <span style=color:#a6e22e>perror</span>(<span style=color:#e6db74>&#34;bind&#34;</span>);
</span></span><span style=display:flex><span> <span style=color:#66d9ef>return</span> <span style=color:#ae81ff>1</span>;
</span></span><span style=display:flex><span> }
</span></span><span style=display:flex><span>
</span></span><span style=display:flex><span> <span style=color:#66d9ef>if</span> (<span style=color:#a6e22e>listen</span>(sockfd_v4, BACKLOG) <span style=color:#f92672>&lt;</span> <span style=color:#ae81ff>0</span>) {
</span></span><span style=display:flex><span> <span style=color:#a6e22e>perror</span>(<span style=color:#e6db74>&#34;listen&#34;</span>);
</span></span><span style=display:flex><span> <span style=color:#66d9ef>return</span> <span style=color:#ae81ff>1</span>;
</span></span><span style=display:flex><span> }
</span></span><span style=display:flex><span>
</span></span><span style=display:flex><span> <span style=color:#75715e>/* Create IPv6 socket */</span>
</span></span><span style=display:flex><span> <span style=color:#66d9ef>struct</span> sockaddr_in6 serv_addr6, cli_addr6;
</span></span><span style=display:flex><span> <span style=color:#66d9ef>int</span> addrlen6 <span style=color:#f92672>=</span> <span style=color:#66d9ef>sizeof</span>(cli_addr6);
</span></span><span style=display:flex><span>
</span></span><span style=display:flex><span> <span style=color:#66d9ef>if</span> ((sockfd_v6 <span style=color:#f92672>=</span> <span style=color:#a6e22e>socket</span>(AF_INET6, SOCK_STREAM, <span style=color:#ae81ff>0</span>)) <span style=color:#f92672>==</span> <span style=color:#f92672>-</span><span style=color:#ae81ff>1</span>) {
</span></span><span style=display:flex><span> <span style=color:#a6e22e>perror</span>(<span style=color:#e6db74>&#34;socket&#34;</span>);
</span></span><span style=display:flex><span> <span style=color:#66d9ef>return</span> <span style=color:#ae81ff>1</span>;
</span></span><span style=display:flex><span> }
</span></span><span style=display:flex><span>
</span></span><span style=display:flex><span> <span style=color:#a6e22e>setsockopt</span>(sockfd_v6, SOL_SOCKET, SO_REUSEADDR, <span style=color:#f92672>&amp;</span>option, <span style=color:#66d9ef>sizeof</span>(<span style=color:#66d9ef>int</span>));
</span></span><span style=display:flex><span> serv_addr6.sin6_family <span style=color:#f92672>=</span> AF_INET6;
</span></span><span style=display:flex><span> <span style=color:#a6e22e>inet_pton</span>(AF_INET6, IPV6_ADDR, <span style=color:#f92672>&amp;</span>serv_addr6.sin6_addr);
</span></span><span style=display:flex><span> serv_addr6.sin6_port <span style=color:#f92672>=</span> <span style=color:#a6e22e>htons</span>(IPV6_PORT);
</span></span><span style=display:flex><span>
</span></span><span style=display:flex><span> <span style=color:#66d9ef>if</span> (<span style=color:#a6e22e>bind</span>(sockfd_v6, (<span style=color:#66d9ef>struct</span> sockaddr <span style=color:#f92672>*</span>)<span style=color:#f92672>&amp;</span>serv_addr6, <span style=color:#66d9ef>sizeof</span>(serv_addr6)) <span style=color:#f92672>&lt;</span> <span style=color:#ae81ff>0</span>) {
</span></span><span style=display:flex><span> <span style=color:#a6e22e>perror</span>(<span style=color:#e6db74>&#34;bind&#34;</span>);
</span></span><span style=display:flex><span> <span style=color:#66d9ef>return</span> <span style=color:#ae81ff>1</span>;
</span></span><span style=display:flex><span> }
</span></span><span style=display:flex><span>
</span></span><span style=display:flex><span> <span style=color:#66d9ef>if</span> (<span style=color:#a6e22e>listen</span>(sockfd_v6, BACKLOG) <span style=color:#f92672>&lt;</span> <span style=color:#ae81ff>0</span>) {
</span></span><span style=display:flex><span> <span style=color:#a6e22e>perror</span>(<span style=color:#e6db74>&#34;listen&#34;</span>);
</span></span><span style=display:flex><span> <span style=color:#66d9ef>return</span> <span style=color:#ae81ff>1</span>;
</span></span><span style=display:flex><span> }
</span></span></code></pre></div><h2 id=adding-sockets-to-the-set-and-calling-select>Adding sockets to the set and calling select()</h2><p><code>FD_SET()</code> is called on each socket. Later on we compare the two sockets to see which one has the highest file descriptor (stored in <code>maxfd</code>). Additionally, there&rsquo;s an array of structures that also contain sockets (<code>clients</code>), their values are also checked to find the highest descriptor. Finally we can call <code>select()</code> with <code>maxfd + 1</code>.</p><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-C data-lang=C><span style=display:flex><span> <span style=color:#66d9ef>for</span> (;;) {
</span></span><span style=display:flex><span> <span style=color:#a6e22e>FD_ZERO</span>(<span style=color:#f92672>&amp;</span>descriptors);
</span></span><span style=display:flex><span> <span style=color:#a6e22e>FD_SET</span>(sockfd_v4, <span style=color:#f92672>&amp;</span>descriptors);
</span></span><span style=display:flex><span> <span style=color:#a6e22e>FD_SET</span>(sockfd_v6, <span style=color:#f92672>&amp;</span>descriptors);
</span></span><span style=display:flex><span> <span style=color:#66d9ef>if</span> (sockfd_v6 <span style=color:#f92672>&gt;</span> sockfd_v4)
</span></span><span style=display:flex><span> maxfd <span style=color:#f92672>=</span> sockfd_v6;
</span></span><span style=display:flex><span> <span style=color:#66d9ef>else</span>
</span></span><span style=display:flex><span> maxfd <span style=color:#f92672>=</span> sockfd_v4;
</span></span><span style=display:flex><span> <span style=color:#75715e>/* Add all socket descriptors to the read list. */</span>
</span></span><span style=display:flex><span> <span style=color:#66d9ef>for</span> (id <span style=color:#f92672>=</span> <span style=color:#ae81ff>0</span>; id <span style=color:#f92672>&lt;</span> maxclients; id<span style=color:#f92672>++</span>) {
</span></span><span style=display:flex><span> <span style=color:#66d9ef>if</span> (clients[id] <span style=color:#f92672>!=</span> NULL) {
</span></span><span style=display:flex><span> <span style=color:#a6e22e>FD_SET</span>(clients[id]<span style=color:#f92672>-&gt;</span>connfd, <span style=color:#f92672>&amp;</span>descriptors);
</span></span><span style=display:flex><span> <span style=color:#75715e>/* Find highest file descriptor, needed for the select function. */</span>
</span></span><span style=display:flex><span> <span style=color:#66d9ef>if</span> (clients[id]<span style=color:#f92672>-&gt;</span>connfd <span style=color:#f92672>&gt;</span> maxfd)
</span></span><span style=display:flex><span> maxfd <span style=color:#f92672>=</span> clients[id]<span style=color:#f92672>-&gt;</span>connfd;
</span></span><span style=display:flex><span> }
</span></span><span style=display:flex><span> }
</span></span><span style=display:flex><span>
</span></span><span style=display:flex><span> <span style=color:#66d9ef>if</span> (<span style=color:#a6e22e>select</span>(maxfd <span style=color:#f92672>+</span> <span style=color:#ae81ff>1</span> ,<span style=color:#f92672>&amp;</span>descriptors, NULL, NULL, NULL) <span style=color:#f92672>==</span> <span style=color:#f92672>-</span><span style=color:#ae81ff>1</span>)
</span></span><span style=display:flex><span> <span style=color:#a6e22e>perror</span>(<span style=color:#e6db74>&#34;select&#34;</span>);
</span></span><span style=display:flex><span>...
</span></span></code></pre></div><h2 id=full-server-example>Full server example</h2><p>The snippets in this post are taken from kernal-chat and simplified. You can find the full source code <a href=https://gitlab.com/kernal/kchat/-/blob/master/src/kchat.c>here</a>.</p><p>Leave us a message on</p><pre tabindex=0><code>$ nc 2a02:c207:2043:4492:: 1337 # or
$ nc chat.kernal.eu 1337
</code></pre></div></div></body></html>

4
robots.txt Normal file
View File

@ -0,0 +1,4 @@
User-agent: *
Allow: /
Sitemap: https://blog.rottenwheel.com/sitemap.xml

1
sitemap.xml Normal file
View File

@ -0,0 +1 @@
<?xml version="1.0" encoding="utf-8" standalone="yes"?><urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:xhtml="http://www.w3.org/1999/xhtml"><url><loc>https://blog.rottenwheel.com/posts/post-1/</loc><lastmod>2022-01-28T03:00:00+03:00</lastmod></url><url><loc>https://blog.rottenwheel.com/posts/</loc><lastmod>2022-01-28T03:00:00+03:00</lastmod></url><url><loc>https://blog.rottenwheel.com/</loc><lastmod>2022-01-28T03:00:00+03:00</lastmod></url></urlset>