<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
  xmlns:content="http://purl.org/rss/1.0/modules/content/"
  xmlns:dc="http://purl.org/dc/elements/1.1/"
  xmlns:atom="http://www.w3.org/2005/Atom">
  <channel>
    <title>Cademuir</title>
    <atom:link href="https://www.cademuir.eu/blog/feed.xml" rel="self" type="application/rss+xml" />
    <link>https://www.cademuir.eu/blog/</link>
    <description>Al's blog</description>
    <lastBuildDate>Mon, 19 Oct 2026 20:37:30 GMT</lastBuildDate>
    <language>en-GB</language>
    <generator>Astro</generator>
    <item>
      <title>An interview question I hate: “Tell me about a time you dealt with conflict”</title>
      <link>https://www.cademuir.eu/blog/2026/05/19/an-interview-question-i-hate-tell-me-about-a-time-you-dealt-with-conflict/</link>
      <pubDate>Tue, 19 May 2026 13:51:52 GMT</pubDate>
      <dc:creator><![CDATA[albertw]]></dc:creator>
      <category><![CDATA[computing]]></category>
      <category><![CDATA[Management]]></category>
      <category domain="post_tag"><![CDATA[conflict]]></category>
      <guid isPermaLink="false">https://www.cademuir.eu/blog/2026/05/19/an-interview-question-i-hate-tell-me-about-a-time-you-dealt-with-conflict/</guid>
      <description><![CDATA[<p>I hate that interview question. Not because I don’t have examples to give, but because it pulls you toward a narrow answer focused on one particular type of conflict and the approach you used to resolve it. Every case is different, and thinking about why that is has made me a better manager and (hopefully!) a better interviewee. Recently I completed a leadership course with my local Education and Training Board. To be honest, there</p>]]></description>
      <content:encoded><![CDATA[<p>I hate that interview question. Not because I don’t have examples to give, but because it pulls you toward a narrow answer focused on one particular type of conflict and the approach you used to resolve it. Every case is different, and thinking about why that is has made me a better manager and (hopefully!) a better interviewee.</p>



<p>Recently I completed a leadership course with my local Education and Training Board. To be honest, there wasn’t anything really new in it that I hadn’t come across in other training or books over the years. But it did provide a timely opportunity to think more deliberately about the causes of conflict and the approaches to resolution, useful preparation for giving a better answer to that question.</p>



<p>So, when we see conflict arising, how do we deal with it? The answer, as usual, is – it depends. But as a broad guideline, the first step is to figure out the cause.</p>



<p>The textbook taxonomy is Christopher Moore’s <em>Circle of Conflict</em>, which identifies Relationship, Data, Structural, Value and Interest as the main conflict types. The course I attended broke this down slightly differently, in a way that matches my experience more closely:</p>



<ul class="wp-block-list">
<li>Poor communication</li>



<li>Clashes in personalities or working styles</li>



<li>Competing needs or interests</li>



<li>Different values</li>



<li>Ambiguity in the workplace</li>



<li>Performance issues</li>
</ul>



<p>Looking back on the conflicts I’ve dealt with, they fit more naturally into those categories than into Moore’s original five. Performance issues and poor communication, for instance, both deserve their own category in modern workplaces.</p>



<p>As a manager dealing with conflict, your role is mostly that of a mediator. Imposing solutions rarely works; it may resolve the immediate situation but tends to store up bigger problems for later.</p>



<p>My approach depends on the severity and the situation, but broadly:</p>



<ul class="wp-block-list">
<li>I meet with people individually to understand their perspective first. What’s actually causing the conflict for them?, how do they feel?, what do they want?</li>



<li>then bring both parties together to facilitate a calm exchange of views. Sometimes we may set some simple ground rules – don’t interrupt, don’t criticise the person rather than the behaviour</li>



<li>From there it’s about exploring possible solutions and aiming for an outcome both sides can live with. Sometimes this involves finding a compromise or trade off, sometimes it involves setting boundaries, it’s about finding something that both people are happy with.</li>
</ul>



<p>When working through conflict with people, and indeed when you find yourself in one, it’s worth being mindful of the different approaches people take. Most people don’t like conflict, so avoidance is often the default. Sometimes that’s fine: if the matter is trivial or genuinely doesn’t need immediate attention, letting it pass isn’t always wrong. But if we avoid dealing with conflict, we risk it growing into something harder to address later.</p>



<p>The main conflict styles taught in leadership courses trace back to the Thomas-Kilmann Conflict Mode Instrument (1974), which identifies five approaches:</p>



<ul class="wp-block-list">
<li><strong>Avoid</strong> – sidestep the issue entirely</li>



<li><strong>Accommodate</strong> – give ground to preserve the relationship</li>



<li><strong>Compete</strong> – assert your position regardless of the other party</li>



<li><strong>Compromise</strong> – both sides give something to get something</li>



<li><strong>Collaborate</strong> – work together toward a genuine win-win</li>
</ul>



<p>There are situations where all five are valid. As a mediator, your job is partly to recognise which mode the parties are operating in and adjust accordingly. You can’t force people to change their style, but you can create conditions where they engage more productively. As a general principle, the goal should be to move toward compromise or collaboration wherever possible.</p>



<p>So how do I answer the interview question now, without disappearing into conflict theory? I say that the cause and the right response depend on the type of conflict, its severity, and the people involved. Then I give a specific example where I facilitated a resolution, one where both parties came out with something they could accept. If pushed, I have a couple of more difficult scenarios ready too.</p>



<p>It’s not a perfect answer. But it’s one I can give without waffling.</p>]]></content:encoded>
    </item>
    <item>
      <title>Why can’t I connect to localhost? Another Dirt MUD Mystery!</title>
      <link>https://www.cademuir.eu/blog/2026/04/13/why-cant-i-connect-to-localhost-another-dirt-mud-mystery/</link>
      <pubDate>Mon, 13 Apr 2026 07:30:48 GMT</pubDate>
      <dc:creator><![CDATA[albertw]]></dc:creator>
      <category><![CDATA[computing]]></category>
      <category domain="post_tag"><![CDATA[MUD]]></category>
      <guid isPermaLink="false">https://www.cademuir.eu/blog/2026/04/13/why-cant-i-connect-to-localhost-another-dirt-mud-mystery/</guid>
      <description><![CDATA[<p>Time for another look at the Dirt code. When I got the MUD running, I noticed something odd: I could only connect using the system hostname or its IP address. Connections to localhost, 127.0.0.1, or even the host’s IPv6 address all failed: So it works, but seems not to be accepting connections on all interfaces. Check what we’re actually listening on First stop netstat (or ss): So the process is bound specifically to 192.168.0.76. It</p>]]></description>
      <content:encoded><![CDATA[<p>Time for another look at the Dirt code.</p>



<p>When I got the MUD running, I noticed something odd: I could only connect using the system hostname or its IP address. Connections to <code>localhost</code>, <code>127.0.0.1</code>, or even the host’s IPv6 address all failed:</p>



<div class="wp-block-kevinbatdorf-code-block-pro" data-code-block-pro-font-family="Code-Pro-JetBrains-Mono" style="font-size:clamp(16px, 1rem, 24px);font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:clamp(20px, 1.25rem, 30px);--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)"><span role="button" tabindex="0" style="color:#d8dee9ff;display:none" aria-label="Copy" class="code-block-pro-copy-button"><pre class="code-block-pro-copy-button-pre" aria-hidden="true"><textarea class="code-block-pro-copy-button-textarea" tabindex="-1" aria-hidden="true" readonly="">$  telnet 192.168.0.76 6715
Trying 192.168.0.76...
Connected to 192.168.0.76.
Escape character is '^]'.
                A B E R M U D 
                
Game Time Elapsed: 6 minutes, 52 seconds

By what name shall I call you? ^]
telnet&gt; q
Connection closed.
$ telnet localhost 6715
Trying ::1...
telnet: connect to address ::1: Connection refused
Trying 127.0.0.1...
telnet: connect to address 127.0.0.1: Connection refused
$ </textarea></pre><svg xmlns="http://www.w3.org/2000/svg" style="width:24px;height:24px" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2"><path class="with-check" stroke-linecap="round" stroke-linejoin="round" d="M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4"></path><path class="without-check" stroke-linecap="round" stroke-linejoin="round" d="M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2"></path></svg></span><pre class="shiki nord" style="background-color: #2e3440ff" tabindex="0"><code><span class="line"><span style="color: #D8DEE9">$</span><span style="color: #D8DEE9FF">  </span><span style="color: #D8DEE9">telnet</span><span style="color: #D8DEE9FF"> </span><span style="color: #B48EAD">192.168</span><span style="color: #ECEFF4">.</span><span style="color: #B48EAD">0.76</span><span style="color: #D8DEE9FF"> </span><span style="color: #B48EAD">6715</span></span>
<span class="line"><span style="color: #D8DEE9">Trying</span><span style="color: #D8DEE9FF"> </span><span style="color: #B48EAD">192.168</span><span style="color: #ECEFF4">.</span><span style="color: #B48EAD">0.76</span><span style="color: #81A1C1">...</span></span>
<span class="line"><span style="color: #D8DEE9">Connected</span><span style="color: #D8DEE9FF"> </span><span style="color: #D8DEE9">to</span><span style="color: #D8DEE9FF"> </span><span style="color: #B48EAD">192.168</span><span style="color: #ECEFF4">.</span><span style="color: #B48EAD">0.76</span><span style="color: #ECEFF4">.</span></span>
<span class="line"><span style="color: #D8DEE9">Escape</span><span style="color: #D8DEE9FF"> </span><span style="color: #D8DEE9">character</span><span style="color: #D8DEE9FF"> </span><span style="color: #D8DEE9">is</span><span style="color: #D8DEE9FF"> </span><span style="color: #ECEFF4">'</span><span style="color: #A3BE8C">^]</span><span style="color: #ECEFF4">'</span><span style="color: #ECEFF4">.</span></span>
<span class="line"><span style="color: #D8DEE9FF">                </span><span style="color: #D8DEE9">A</span><span style="color: #D8DEE9FF"> </span><span style="color: #D8DEE9">B</span><span style="color: #D8DEE9FF"> </span><span style="color: #D8DEE9">E</span><span style="color: #D8DEE9FF"> </span><span style="color: #D8DEE9">R</span><span style="color: #D8DEE9FF"> </span><span style="color: #D8DEE9">M</span><span style="color: #D8DEE9FF"> </span><span style="color: #D8DEE9">U</span><span style="color: #D8DEE9FF"> </span><span style="color: #D8DEE9">D</span><span style="color: #D8DEE9FF"> </span></span>
<span class="line"><span style="color: #D8DEE9FF">                </span></span>
<span class="line"><span style="color: #D8DEE9">Game</span><span style="color: #D8DEE9FF"> </span><span style="color: #D8DEE9">Time</span><span style="color: #D8DEE9FF"> Elapsed</span><span style="color: #ECEFF4">:</span><span style="color: #D8DEE9FF"> </span><span style="color: #B48EAD">6</span><span style="color: #D8DEE9FF"> </span><span style="color: #D8DEE9">minutes</span><span style="color: #ECEFF4">,</span><span style="color: #D8DEE9FF"> </span><span style="color: #B48EAD">52</span><span style="color: #D8DEE9FF"> </span><span style="color: #D8DEE9">seconds</span></span>
<span class="line"></span>
<span class="line"><span style="color: #D8DEE9">By</span><span style="color: #D8DEE9FF"> </span><span style="color: #D8DEE9">what</span><span style="color: #D8DEE9FF"> </span><span style="color: #D8DEE9">name</span><span style="color: #D8DEE9FF"> </span><span style="color: #D8DEE9">shall</span><span style="color: #D8DEE9FF"> </span><span style="color: #D8DEE9">I</span><span style="color: #D8DEE9FF"> </span><span style="color: #D8DEE9">call</span><span style="color: #D8DEE9FF"> </span><span style="color: #D8DEE9">you</span><span style="color: #81A1C1">?</span><span style="color: #D8DEE9FF"> </span><span style="color: #81A1C1">^</span><span style="color: #D8DEE9FF">]</span></span>
<span class="line"><span style="color: #D8DEE9">telnet</span><span style="color: #81A1C1">&gt;</span><span style="color: #D8DEE9FF"> </span><span style="color: #D8DEE9">q</span></span>
<span class="line"><span style="color: #D8DEE9">Connection</span><span style="color: #D8DEE9FF"> </span><span style="color: #D8DEE9">closed</span><span style="color: #ECEFF4">.</span></span>
<span class="line"><span style="color: #D8DEE9">$</span><span style="color: #D8DEE9FF"> </span><span style="color: #D8DEE9">telnet</span><span style="color: #D8DEE9FF"> </span><span style="color: #D8DEE9">localhost</span><span style="color: #D8DEE9FF"> </span><span style="color: #B48EAD">6715</span></span>
<span class="line"><span style="color: #D8DEE9">Trying</span><span style="color: #D8DEE9FF"> </span><span style="color: #81A1C1">:</span><span style="color: #D8DEE9FF">:</span><span style="color: #B48EAD">1.</span><span style="color: #ECEFF4">..</span></span>
<span class="line"><span style="color: #D8DEE9FF">telnet</span><span style="color: #ECEFF4">:</span><span style="color: #D8DEE9FF"> </span><span style="color: #D8DEE9">connect</span><span style="color: #D8DEE9FF"> </span><span style="color: #D8DEE9">to</span><span style="color: #D8DEE9FF"> address </span><span style="color: #ECEFF4">:</span><span style="color: #D8DEE9FF">:</span><span style="color: #B48EAD">1</span><span style="color: #D8DEE9FF">: </span><span style="color: #D8DEE9">Connection</span><span style="color: #D8DEE9FF"> </span><span style="color: #D8DEE9">refused</span></span>
<span class="line"><span style="color: #D8DEE9">Trying</span><span style="color: #D8DEE9FF"> </span><span style="color: #B48EAD">127.0</span><span style="color: #ECEFF4">.</span><span style="color: #B48EAD">0.1</span><span style="color: #81A1C1">...</span></span>
<span class="line"><span style="color: #D8DEE9FF">telnet</span><span style="color: #ECEFF4">:</span><span style="color: #D8DEE9FF"> </span><span style="color: #D8DEE9">connect</span><span style="color: #D8DEE9FF"> </span><span style="color: #D8DEE9">to</span><span style="color: #D8DEE9FF"> </span><span style="color: #D8DEE9">address</span><span style="color: #D8DEE9FF"> </span><span style="color: #B48EAD">127.0</span><span style="color: #ECEFF4">.</span><span style="color: #B48EAD">0.1</span><span style="color: #D8DEE9FF">: </span><span style="color: #D8DEE9">Connection</span><span style="color: #D8DEE9FF"> </span><span style="color: #D8DEE9">refused</span></span>
<span class="line"><span style="color: #D8DEE9">$</span><span style="color: #D8DEE9FF"> </span></span></code></pre></div>



<p>So it works, but seems not to be accepting connections on all interfaces.</p>



<h2 class="wp-block-heading">Check what we’re actually listening on</h2>



<p>First stop netstat (or ss):</p>



<div class="wp-block-kevinbatdorf-code-block-pro" data-code-block-pro-font-family="Code-Pro-JetBrains-Mono" style="font-size:clamp(16px, 1rem, 24px);font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:clamp(20px, 1.25rem, 30px);--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)"><span role="button" tabindex="0" style="color:#d8dee9ff;display:none" aria-label="Copy" class="code-block-pro-copy-button"><pre class="code-block-pro-copy-button-pre" aria-hidden="true"><textarea class="code-block-pro-copy-button-textarea" tabindex="-1" aria-hidden="true" readonly="">$ netstat -lntp|grep 6715
tcp        0      0 192.168.0.76:6715       0.0.0.0:*               LISTEN      1312388/../bin/aber 
$ ss -lntp|grep 6715
LISTEN 0      5       192.168.0.76:6715       0.0.0.0:*    users:(("aberd",pid=1312388,fd=0))           
$ </textarea></pre><svg xmlns="http://www.w3.org/2000/svg" style="width:24px;height:24px" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2"><path class="with-check" stroke-linecap="round" stroke-linejoin="round" d="M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4"></path><path class="without-check" stroke-linecap="round" stroke-linejoin="round" d="M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2"></path></svg></span><pre class="shiki nord" style="background-color: #2e3440ff" tabindex="0"><code><span class="line"><span style="color: #D8DEE9">$</span><span style="color: #D8DEE9FF"> </span><span style="color: #D8DEE9">netstat</span><span style="color: #D8DEE9FF"> </span><span style="color: #81A1C1">-</span><span style="color: #D8DEE9">lntp</span><span style="color: #81A1C1">|</span><span style="color: #D8DEE9">grep</span><span style="color: #D8DEE9FF"> </span><span style="color: #B48EAD">6715</span></span>
<span class="line"><span style="color: #D8DEE9">tcp</span><span style="color: #D8DEE9FF">        </span><span style="color: #B48EAD">0</span><span style="color: #D8DEE9FF">      </span><span style="color: #B48EAD">0</span><span style="color: #D8DEE9FF"> </span><span style="color: #B48EAD">192.168</span><span style="color: #ECEFF4">.</span><span style="color: #B48EAD">0.76</span><span style="color: #D8DEE9FF">:</span><span style="color: #B48EAD">6715</span><span style="color: #D8DEE9FF">       </span><span style="color: #B48EAD">0.0</span><span style="color: #ECEFF4">.</span><span style="color: #B48EAD">0.0</span><span style="color: #D8DEE9FF">:</span><span style="color: #81A1C1">*</span><span style="color: #D8DEE9FF">               </span><span style="color: #D8DEE9">LISTEN</span><span style="color: #D8DEE9FF">      </span><span style="color: #B48EAD">1312388</span><span style="color: #81A1C1">/</span><span style="color: #ECEFF4">..</span><span style="color: #81A1C1">/</span><span style="color: #D8DEE9">bin</span><span style="color: #81A1C1">/</span><span style="color: #D8DEE9">aber</span><span style="color: #D8DEE9FF"> </span></span>
<span class="line"><span style="color: #D8DEE9">$</span><span style="color: #D8DEE9FF"> </span><span style="color: #D8DEE9">ss</span><span style="color: #D8DEE9FF"> </span><span style="color: #81A1C1">-</span><span style="color: #D8DEE9">lntp</span><span style="color: #81A1C1">|</span><span style="color: #D8DEE9">grep</span><span style="color: #D8DEE9FF"> </span><span style="color: #B48EAD">6715</span></span>
<span class="line"><span style="color: #D8DEE9">LISTEN</span><span style="color: #D8DEE9FF"> </span><span style="color: #B48EAD">0</span><span style="color: #D8DEE9FF">      </span><span style="color: #B48EAD">5</span><span style="color: #D8DEE9FF">       </span><span style="color: #B48EAD">192.168</span><span style="color: #ECEFF4">.</span><span style="color: #B48EAD">0.76</span><span style="color: #D8DEE9FF">:</span><span style="color: #B48EAD">6715</span><span style="color: #D8DEE9FF">       </span><span style="color: #B48EAD">0.0</span><span style="color: #ECEFF4">.</span><span style="color: #B48EAD">0.0</span><span style="color: #D8DEE9FF">:</span><span style="color: #81A1C1">*</span><span style="color: #D8DEE9FF">    users</span><span style="color: #ECEFF4">:</span><span style="color: #D8DEE9FF">((</span><span style="color: #ECEFF4">"</span><span style="color: #A3BE8C">aberd</span><span style="color: #ECEFF4">"</span><span style="color: #ECEFF4">,</span><span style="color: #D8DEE9">pid</span><span style="color: #81A1C1">=</span><span style="color: #B48EAD">1312388</span><span style="color: #ECEFF4">,</span><span style="color: #D8DEE9">fd</span><span style="color: #81A1C1">=</span><span style="color: #B48EAD">0</span><span style="color: #D8DEE9FF">))           </span></span>
<span class="line"><span style="color: #D8DEE9">$</span><span style="color: #D8DEE9FF"> </span></span></code></pre></div>



<ul class="wp-block-list">
<li><code>192.168.0.76:6715</code> – the <strong>local address and port</strong> we’re bound to</li>



<li><code>0.0.0.0:*</code> – <strong>any remote address and port</strong></li>
</ul>



<p>So the process is bound specifically to <code>192.168.0.76</code>. It won’t accept connections addressed to <code>127.0.0.1</code> or <code>::1</code>. We’ll accept connections _from_ anywhere, but only if they connect to <code>192.168.0.76</code></p>



<h2 class="wp-block-heading">Confirming with strace</h2>



<p>A quick strace confirms what’s happening – we’re binding specifically to 192.168.0.76</p>



<div class="wp-block-kevinbatdorf-code-block-pro" data-code-block-pro-font-family="Code-Pro-JetBrains-Mono" style="font-size:clamp(16px, 1rem, 24px);font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:clamp(20px, 1.25rem, 30px);--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)"><span role="button" tabindex="0" style="color:#d8dee9ff;display:none" aria-label="Copy" class="code-block-pro-copy-button"><pre class="code-block-pro-copy-button-pre" aria-hidden="true"><textarea class="code-block-pro-copy-button-textarea" tabindex="-1" aria-hidden="true" readonly="">$ strace ../bin/aberd -f 2&gt;&amp;1|grep bind
bind(4, {sa_family=AF_INET, sin_port=htons(6715), sin_addr=inet_addr("192.168.0.76")}, 16) = 0</textarea></pre><svg xmlns="http://www.w3.org/2000/svg" style="width:24px;height:24px" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2"><path class="with-check" stroke-linecap="round" stroke-linejoin="round" d="M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4"></path><path class="without-check" stroke-linecap="round" stroke-linejoin="round" d="M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2"></path></svg></span><pre class="shiki nord" style="background-color: #2e3440ff" tabindex="0"><code><span class="line"><span style="color: #D8DEE9">$</span><span style="color: #D8DEE9FF"> </span><span style="color: #D8DEE9">strace</span><span style="color: #D8DEE9FF"> </span><span style="color: #ECEFF4">..</span><span style="color: #81A1C1">/</span><span style="color: #D8DEE9">bin</span><span style="color: #81A1C1">/</span><span style="color: #D8DEE9">aberd</span><span style="color: #D8DEE9FF"> </span><span style="color: #81A1C1">-</span><span style="color: #D8DEE9">f</span><span style="color: #D8DEE9FF"> </span><span style="color: #B48EAD">2</span><span style="color: #81A1C1">&gt;&amp;</span><span style="color: #B48EAD">1</span><span style="color: #81A1C1">|</span><span style="color: #D8DEE9">grep</span><span style="color: #D8DEE9FF"> </span><span style="color: #D8DEE9">bind</span></span>
<span class="line"><span style="color: #88C0D0">bind</span><span style="color: #D8DEE9FF">(</span><span style="color: #B48EAD">4</span><span style="color: #ECEFF4">,</span><span style="color: #D8DEE9FF"> </span><span style="color: #ECEFF4">{</span><span style="color: #D8DEE9">sa_family</span><span style="color: #81A1C1">=</span><span style="color: #D8DEE9">AF_INET</span><span style="color: #ECEFF4">,</span><span style="color: #D8DEE9FF"> </span><span style="color: #D8DEE9">sin_port</span><span style="color: #81A1C1">=</span><span style="color: #88C0D0">htons</span><span style="color: #D8DEE9FF">(</span><span style="color: #B48EAD">6715</span><span style="color: #D8DEE9FF">)</span><span style="color: #ECEFF4">,</span><span style="color: #D8DEE9FF"> </span><span style="color: #D8DEE9">sin_addr</span><span style="color: #81A1C1">=</span><span style="color: #88C0D0">inet_addr</span><span style="color: #D8DEE9FF">(</span><span style="color: #ECEFF4">"</span><span style="color: #A3BE8C">192.168.0.76</span><span style="color: #ECEFF4">"</span><span style="color: #D8DEE9FF">)</span><span style="color: #ECEFF4">},</span><span style="color: #D8DEE9FF"> </span><span style="color: #B48EAD">16</span><span style="color: #D8DEE9FF">) </span><span style="color: #81A1C1">=</span><span style="color: #D8DEE9FF"> </span><span style="color: #B48EAD">0</span></span></code></pre></div>



<h2 class="wp-block-heading">The Simple fix – just bind to all interfaces</h2>



<p>A quick grep for ‘bind’ &amp; ‘listen’ in the code points us to s_socket.c. This has the standard socket operations you’d expect for sockets.</p>



<div class="wp-block-kevinbatdorf-code-block-pro" data-code-block-pro-font-family="Code-Pro-JetBrains-Mono" style="font-size:clamp(16px, 1rem, 24px);font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:clamp(20px, 1.25rem, 30px);--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)"><span role="button" tabindex="0" style="color:#d8dee9ff;display:none" aria-label="Copy" class="code-block-pro-copy-button"><pre class="code-block-pro-copy-button-pre" aria-hidden="true"><textarea class="code-block-pro-copy-button-textarea" tabindex="-1" aria-hidden="true" readonly="">int make_service(short unsigned int port,
		 char               *my_hostname,
		 int                my_hostnamelen,
		 struct hostent     **hp,
		 struct sockaddr_in *sin)
{
  int s, i;
  struct hostent *h;

  if (gethostname(my_hostname,my_hostnamelen) &lt; 0) {
    return -1; /* Error in hostname? */
  }
  if ((*hp = h = gethostbyname(my_hostname)) == NULL) {
    return -2; /* Error in gethostbyname */
  }
  bzero(sin,sizeof(struct sockaddr_in));
  sin-&gt;sin_family = AF_INET;
  sin-&gt;sin_port = htons(port);
  bcopy(h-&gt;h_addr_list[0],&amp;(sin-&gt;sin_addr),h-&gt;h_length);

  if ((s = socket(AF_INET,SOCK_STREAM,0)) &lt; 0) {
    return -3; /* Error in socket call */
  }

  /* Bug fix for hanging sockets. Socket options need to be set before
   * the bind takes place or they dont do ANY good.
   */
  i = 2;
  if (setsockopt(s, SOL_SOCKET, SO_REUSEADDR, &amp;i, sizeof(i)) == -1) {
	  progerror("setsockopt(reuseaddr)");
  }

  if (bind(s,(struct sockaddr *)sin,sizeof(*sin)) &lt; 0) {
    close(s);
    return -4; /* Error in bind. */
  }
  if (listen(s,5) != 0) {
    close(s);
    return -5; /* Error in listen */
  }</textarea></pre><svg xmlns="http://www.w3.org/2000/svg" style="width:24px;height:24px" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2"><path class="with-check" stroke-linecap="round" stroke-linejoin="round" d="M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4"></path><path class="without-check" stroke-linecap="round" stroke-linejoin="round" d="M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2"></path></svg></span><pre class="shiki nord" style="background-color: #2e3440ff" tabindex="0"><code><span class="line"><span style="color: #D8DEE9">int</span><span style="color: #D8DEE9FF"> </span><span style="color: #88C0D0">make_service</span><span style="color: #D8DEE9FF">(</span><span style="color: #D8DEE9">short</span><span style="color: #D8DEE9FF"> </span><span style="color: #D8DEE9">unsigned</span><span style="color: #D8DEE9FF"> </span><span style="color: #D8DEE9">int</span><span style="color: #D8DEE9FF"> </span><span style="color: #D8DEE9">port</span><span style="color: #ECEFF4">,</span></span>
<span class="line"><span style="color: #D8DEE9FF">		 </span><span style="color: #D8DEE9">char</span><span style="color: #D8DEE9FF">               </span><span style="color: #81A1C1">*</span><span style="color: #D8DEE9">my_hostname</span><span style="color: #ECEFF4">,</span></span>
<span class="line"><span style="color: #D8DEE9FF">		 </span><span style="color: #D8DEE9">int</span><span style="color: #D8DEE9FF">                </span><span style="color: #D8DEE9">my_hostnamelen</span><span style="color: #ECEFF4">,</span></span>
<span class="line"><span style="color: #D8DEE9FF">		 </span><span style="color: #D8DEE9">struct</span><span style="color: #D8DEE9FF"> </span><span style="color: #D8DEE9">hostent</span><span style="color: #D8DEE9FF">     </span><span style="color: #81A1C1">**</span><span style="color: #D8DEE9">hp</span><span style="color: #ECEFF4">,</span></span>
<span class="line"><span style="color: #D8DEE9FF">		 </span><span style="color: #D8DEE9">struct</span><span style="color: #D8DEE9FF"> </span><span style="color: #D8DEE9">sockaddr_in</span><span style="color: #D8DEE9FF"> </span><span style="color: #81A1C1">*</span><span style="color: #D8DEE9">sin</span><span style="color: #D8DEE9FF">)</span></span>
<span class="line"><span style="color: #ECEFF4">{</span></span>
<span class="line"><span style="color: #D8DEE9FF">  </span><span style="color: #D8DEE9">int</span><span style="color: #D8DEE9FF"> </span><span style="color: #D8DEE9">s</span><span style="color: #ECEFF4">,</span><span style="color: #D8DEE9FF"> </span><span style="color: #D8DEE9">i</span><span style="color: #81A1C1">;</span></span>
<span class="line"><span style="color: #D8DEE9FF">  </span><span style="color: #D8DEE9">struct</span><span style="color: #D8DEE9FF"> </span><span style="color: #D8DEE9">hostent</span><span style="color: #D8DEE9FF"> </span><span style="color: #81A1C1">*</span><span style="color: #D8DEE9">h</span><span style="color: #81A1C1">;</span></span>
<span class="line"></span>
<span class="line"><span style="color: #D8DEE9FF">  </span><span style="color: #81A1C1">if</span><span style="color: #D8DEE9FF"> (</span><span style="color: #88C0D0">gethostname</span><span style="color: #D8DEE9FF">(</span><span style="color: #D8DEE9">my_hostname</span><span style="color: #ECEFF4">,</span><span style="color: #D8DEE9">my_hostnamelen</span><span style="color: #D8DEE9FF">) </span><span style="color: #81A1C1">&lt;</span><span style="color: #D8DEE9FF"> </span><span style="color: #B48EAD">0</span><span style="color: #D8DEE9FF">) </span><span style="color: #ECEFF4">{</span></span>
<span class="line"><span style="color: #D8DEE9FF">    </span><span style="color: #81A1C1">return</span><span style="color: #D8DEE9FF"> </span><span style="color: #81A1C1">-</span><span style="color: #B48EAD">1</span><span style="color: #81A1C1">;</span><span style="color: #D8DEE9FF"> </span><span style="color: #616E88">/* Error in hostname? */</span></span>
<span class="line"><span style="color: #D8DEE9FF">  </span><span style="color: #ECEFF4">}</span></span>
<span class="line"><span style="color: #D8DEE9FF">  </span><span style="color: #81A1C1">if</span><span style="color: #D8DEE9FF"> ((</span><span style="color: #81A1C1">*</span><span style="color: #D8DEE9">hp</span><span style="color: #D8DEE9FF"> </span><span style="color: #81A1C1">=</span><span style="color: #D8DEE9FF"> </span><span style="color: #D8DEE9">h</span><span style="color: #D8DEE9FF"> </span><span style="color: #81A1C1">=</span><span style="color: #D8DEE9FF"> </span><span style="color: #88C0D0">gethostbyname</span><span style="color: #D8DEE9FF">(</span><span style="color: #D8DEE9">my_hostname</span><span style="color: #D8DEE9FF">)) </span><span style="color: #81A1C1">==</span><span style="color: #D8DEE9FF"> </span><span style="color: #D8DEE9">NULL</span><span style="color: #D8DEE9FF">) </span><span style="color: #ECEFF4">{</span></span>
<span class="line"><span style="color: #D8DEE9FF">    </span><span style="color: #81A1C1">return</span><span style="color: #D8DEE9FF"> </span><span style="color: #81A1C1">-</span><span style="color: #B48EAD">2</span><span style="color: #81A1C1">;</span><span style="color: #D8DEE9FF"> </span><span style="color: #616E88">/* Error in gethostbyname */</span></span>
<span class="line"><span style="color: #D8DEE9FF">  </span><span style="color: #ECEFF4">}</span></span>
<span class="line"><span style="color: #D8DEE9FF">  </span><span style="color: #88C0D0">bzero</span><span style="color: #D8DEE9FF">(</span><span style="color: #D8DEE9">sin</span><span style="color: #ECEFF4">,</span><span style="color: #88C0D0">sizeof</span><span style="color: #D8DEE9FF">(</span><span style="color: #D8DEE9">struct</span><span style="color: #D8DEE9FF"> </span><span style="color: #D8DEE9">sockaddr_in</span><span style="color: #D8DEE9FF">))</span><span style="color: #81A1C1">;</span></span>
<span class="line"><span style="color: #D8DEE9FF">  </span><span style="color: #D8DEE9">sin</span><span style="color: #81A1C1">-&gt;</span><span style="color: #D8DEE9">sin_family</span><span style="color: #D8DEE9FF"> </span><span style="color: #81A1C1">=</span><span style="color: #D8DEE9FF"> </span><span style="color: #D8DEE9">AF_INET</span><span style="color: #81A1C1">;</span></span>
<span class="line"><span style="color: #D8DEE9FF">  </span><span style="color: #D8DEE9">sin</span><span style="color: #81A1C1">-&gt;</span><span style="color: #D8DEE9">sin_port</span><span style="color: #D8DEE9FF"> </span><span style="color: #81A1C1">=</span><span style="color: #D8DEE9FF"> </span><span style="color: #88C0D0">htons</span><span style="color: #D8DEE9FF">(</span><span style="color: #D8DEE9">port</span><span style="color: #D8DEE9FF">)</span><span style="color: #81A1C1">;</span></span>
<span class="line"><span style="color: #D8DEE9FF">  </span><span style="color: #88C0D0">bcopy</span><span style="color: #D8DEE9FF">(</span><span style="color: #D8DEE9">h</span><span style="color: #81A1C1">-&gt;</span><span style="color: #D8DEE9">h_addr_list</span><span style="color: #D8DEE9FF">[</span><span style="color: #B48EAD">0</span><span style="color: #D8DEE9FF">]</span><span style="color: #ECEFF4">,</span><span style="color: #81A1C1">&amp;</span><span style="color: #D8DEE9FF">(</span><span style="color: #D8DEE9">sin</span><span style="color: #81A1C1">-&gt;</span><span style="color: #D8DEE9">sin_addr</span><span style="color: #D8DEE9FF">)</span><span style="color: #ECEFF4">,</span><span style="color: #D8DEE9">h</span><span style="color: #81A1C1">-&gt;</span><span style="color: #D8DEE9">h_length</span><span style="color: #D8DEE9FF">)</span><span style="color: #81A1C1">;</span></span>
<span class="line"></span>
<span class="line"><span style="color: #D8DEE9FF">  </span><span style="color: #81A1C1">if</span><span style="color: #D8DEE9FF"> ((</span><span style="color: #D8DEE9">s</span><span style="color: #D8DEE9FF"> </span><span style="color: #81A1C1">=</span><span style="color: #D8DEE9FF"> </span><span style="color: #88C0D0">socket</span><span style="color: #D8DEE9FF">(</span><span style="color: #D8DEE9">AF_INET</span><span style="color: #ECEFF4">,</span><span style="color: #D8DEE9">SOCK_STREAM</span><span style="color: #ECEFF4">,</span><span style="color: #B48EAD">0</span><span style="color: #D8DEE9FF">)) </span><span style="color: #81A1C1">&lt;</span><span style="color: #D8DEE9FF"> </span><span style="color: #B48EAD">0</span><span style="color: #D8DEE9FF">) </span><span style="color: #ECEFF4">{</span></span>
<span class="line"><span style="color: #D8DEE9FF">    </span><span style="color: #81A1C1">return</span><span style="color: #D8DEE9FF"> </span><span style="color: #81A1C1">-</span><span style="color: #B48EAD">3</span><span style="color: #81A1C1">;</span><span style="color: #D8DEE9FF"> </span><span style="color: #616E88">/* Error in socket call */</span></span>
<span class="line"><span style="color: #D8DEE9FF">  </span><span style="color: #ECEFF4">}</span></span>
<span class="line"></span>
<span class="line"><span style="color: #D8DEE9FF">  </span><span style="color: #616E88">/* Bug fix for hanging sockets. Socket options need to be set before</span></span>
<span class="line"><span style="color: #616E88">   * the bind takes place or they dont do ANY good.</span></span>
<span class="line"><span style="color: #616E88">   */</span></span>
<span class="line"><span style="color: #D8DEE9FF">  </span><span style="color: #D8DEE9">i</span><span style="color: #D8DEE9FF"> </span><span style="color: #81A1C1">=</span><span style="color: #D8DEE9FF"> </span><span style="color: #B48EAD">2</span><span style="color: #81A1C1">;</span></span>
<span class="line"><span style="color: #D8DEE9FF">  </span><span style="color: #81A1C1">if</span><span style="color: #D8DEE9FF"> (</span><span style="color: #88C0D0">setsockopt</span><span style="color: #D8DEE9FF">(</span><span style="color: #D8DEE9">s</span><span style="color: #ECEFF4">,</span><span style="color: #D8DEE9FF"> </span><span style="color: #D8DEE9">SOL_SOCKET</span><span style="color: #ECEFF4">,</span><span style="color: #D8DEE9FF"> </span><span style="color: #D8DEE9">SO_REUSEADDR</span><span style="color: #ECEFF4">,</span><span style="color: #D8DEE9FF"> </span><span style="color: #81A1C1">&amp;</span><span style="color: #D8DEE9">i</span><span style="color: #ECEFF4">,</span><span style="color: #D8DEE9FF"> </span><span style="color: #88C0D0">sizeof</span><span style="color: #D8DEE9FF">(</span><span style="color: #D8DEE9">i</span><span style="color: #D8DEE9FF">)) </span><span style="color: #81A1C1">==</span><span style="color: #D8DEE9FF"> </span><span style="color: #81A1C1">-</span><span style="color: #B48EAD">1</span><span style="color: #D8DEE9FF">) </span><span style="color: #ECEFF4">{</span></span>
<span class="line"><span style="color: #D8DEE9FF">	  </span><span style="color: #88C0D0">progerror</span><span style="color: #D8DEE9FF">(</span><span style="color: #ECEFF4">"</span><span style="color: #A3BE8C">setsockopt(reuseaddr)</span><span style="color: #ECEFF4">"</span><span style="color: #D8DEE9FF">)</span><span style="color: #81A1C1">;</span></span>
<span class="line"><span style="color: #D8DEE9FF">  </span><span style="color: #ECEFF4">}</span></span>
<span class="line"></span>
<span class="line"><span style="color: #D8DEE9FF">  </span><span style="color: #81A1C1">if</span><span style="color: #D8DEE9FF"> (</span><span style="color: #88C0D0">bind</span><span style="color: #D8DEE9FF">(</span><span style="color: #D8DEE9">s</span><span style="color: #ECEFF4">,</span><span style="color: #D8DEE9FF">(</span><span style="color: #D8DEE9">struct</span><span style="color: #D8DEE9FF"> </span><span style="color: #D8DEE9">sockaddr</span><span style="color: #D8DEE9FF"> </span><span style="color: #81A1C1">*</span><span style="color: #D8DEE9FF">)</span><span style="color: #D8DEE9">sin</span><span style="color: #ECEFF4">,</span><span style="color: #88C0D0">sizeof</span><span style="color: #D8DEE9FF">(</span><span style="color: #81A1C1">*</span><span style="color: #D8DEE9">sin</span><span style="color: #D8DEE9FF">)) </span><span style="color: #81A1C1">&lt;</span><span style="color: #D8DEE9FF"> </span><span style="color: #B48EAD">0</span><span style="color: #D8DEE9FF">) </span><span style="color: #ECEFF4">{</span></span>
<span class="line"><span style="color: #D8DEE9FF">    </span><span style="color: #88C0D0">close</span><span style="color: #D8DEE9FF">(</span><span style="color: #D8DEE9">s</span><span style="color: #D8DEE9FF">)</span><span style="color: #81A1C1">;</span></span>
<span class="line"><span style="color: #D8DEE9FF">    </span><span style="color: #81A1C1">return</span><span style="color: #D8DEE9FF"> </span><span style="color: #81A1C1">-</span><span style="color: #B48EAD">4</span><span style="color: #81A1C1">;</span><span style="color: #D8DEE9FF"> </span><span style="color: #616E88">/* Error in bind. */</span></span>
<span class="line"><span style="color: #D8DEE9FF">  </span><span style="color: #ECEFF4">}</span></span>
<span class="line"><span style="color: #D8DEE9FF">  </span><span style="color: #81A1C1">if</span><span style="color: #D8DEE9FF"> (</span><span style="color: #88C0D0">listen</span><span style="color: #D8DEE9FF">(</span><span style="color: #D8DEE9">s</span><span style="color: #ECEFF4">,</span><span style="color: #B48EAD">5</span><span style="color: #D8DEE9FF">) </span><span style="color: #81A1C1">!=</span><span style="color: #D8DEE9FF"> </span><span style="color: #B48EAD">0</span><span style="color: #D8DEE9FF">) </span><span style="color: #ECEFF4">{</span></span>
<span class="line"><span style="color: #D8DEE9FF">    </span><span style="color: #88C0D0">close</span><span style="color: #D8DEE9FF">(</span><span style="color: #D8DEE9">s</span><span style="color: #D8DEE9FF">)</span><span style="color: #81A1C1">;</span></span>
<span class="line"><span style="color: #D8DEE9FF">    </span><span style="color: #81A1C1">return</span><span style="color: #D8DEE9FF"> </span><span style="color: #81A1C1">-</span><span style="color: #B48EAD">5</span><span style="color: #81A1C1">;</span><span style="color: #D8DEE9FF"> </span><span style="color: #616E88">/* Error in listen */</span></span>
<span class="line"><span style="color: #D8DEE9FF">  </span><span style="color: #ECEFF4">}</span></span></code></pre></div>



<p>We call socket(2), then bind(2) to it and finally listen(2). The simplest fix here would be to simply listen on all interfaces, and that was my first fix here – just add this before we bind()</p>



<div class="wp-block-kevinbatdorf-code-block-pro" data-code-block-pro-font-family="Code-Pro-JetBrains-Mono" style="font-size:clamp(16px, 1rem, 24px);font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:clamp(20px, 1.25rem, 30px);--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)"><span role="button" tabindex="0" style="color:#d8dee9ff;display:none" aria-label="Copy" class="code-block-pro-copy-button"><pre class="code-block-pro-copy-button-pre" aria-hidden="true"><textarea class="code-block-pro-copy-button-textarea" tabindex="-1" aria-hidden="true" readonly="">sin-&gt;sin_addr.s_addr = htonl(INADDR_ANY);</textarea></pre><svg xmlns="http://www.w3.org/2000/svg" style="width:24px;height:24px" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2"><path class="with-check" stroke-linecap="round" stroke-linejoin="round" d="M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4"></path><path class="without-check" stroke-linecap="round" stroke-linejoin="round" d="M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2"></path></svg></span><pre class="shiki nord" style="background-color: #2e3440ff" tabindex="0"><code><span class="line"><span style="color: #D8DEE9">sin</span><span style="color: #81A1C1">-&gt;</span><span style="color: #D8DEE9">sin_addr</span><span style="color: #ECEFF4">.</span><span style="color: #D8DEE9">s_addr</span><span style="color: #D8DEE9FF"> </span><span style="color: #81A1C1">=</span><span style="color: #D8DEE9FF"> </span><span style="color: #88C0D0">htonl</span><span style="color: #D8DEE9FF">(</span><span style="color: #D8DEE9">INADDR_ANY</span><span style="color: #D8DEE9FF">)</span><span style="color: #81A1C1">;</span></span></code></pre></div>



<p>strace now shows we’re listening everywhere:</p>



<div class="wp-block-kevinbatdorf-code-block-pro" data-code-block-pro-font-family="Code-Pro-JetBrains-Mono" style="font-size:clamp(16px, 1rem, 24px);font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:clamp(20px, 1.25rem, 30px);--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)"><span role="button" tabindex="0" style="color:#d8dee9ff;display:none" aria-label="Copy" class="code-block-pro-copy-button"><pre class="code-block-pro-copy-button-pre" aria-hidden="true"><textarea class="code-block-pro-copy-button-textarea" tabindex="-1" aria-hidden="true" readonly="">$ strace ../bin/aberd -f 2&gt;&amp;1 | grep bind
bind(4, {sa_family=AF_INET, sin_port=htons(6715), sin_addr=inet_addr("0.0.0.0")}, 16) = 0</textarea></pre><svg xmlns="http://www.w3.org/2000/svg" style="width:24px;height:24px" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2"><path class="with-check" stroke-linecap="round" stroke-linejoin="round" d="M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4"></path><path class="without-check" stroke-linecap="round" stroke-linejoin="round" d="M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2"></path></svg></span><pre class="shiki nord" style="background-color: #2e3440ff" tabindex="0"><code><span class="line"><span style="color: #D8DEE9">$</span><span style="color: #D8DEE9FF"> </span><span style="color: #D8DEE9">strace</span><span style="color: #D8DEE9FF"> </span><span style="color: #ECEFF4">..</span><span style="color: #81A1C1">/</span><span style="color: #D8DEE9">bin</span><span style="color: #81A1C1">/</span><span style="color: #D8DEE9">aberd</span><span style="color: #D8DEE9FF"> </span><span style="color: #81A1C1">-</span><span style="color: #D8DEE9">f</span><span style="color: #D8DEE9FF"> </span><span style="color: #B48EAD">2</span><span style="color: #81A1C1">&gt;&amp;</span><span style="color: #B48EAD">1</span><span style="color: #D8DEE9FF"> </span><span style="color: #81A1C1">|</span><span style="color: #D8DEE9FF"> </span><span style="color: #D8DEE9">grep</span><span style="color: #D8DEE9FF"> </span><span style="color: #D8DEE9">bind</span></span>
<span class="line"><span style="color: #88C0D0">bind</span><span style="color: #D8DEE9FF">(</span><span style="color: #B48EAD">4</span><span style="color: #ECEFF4">,</span><span style="color: #D8DEE9FF"> </span><span style="color: #ECEFF4">{</span><span style="color: #D8DEE9">sa_family</span><span style="color: #81A1C1">=</span><span style="color: #D8DEE9">AF_INET</span><span style="color: #ECEFF4">,</span><span style="color: #D8DEE9FF"> </span><span style="color: #D8DEE9">sin_port</span><span style="color: #81A1C1">=</span><span style="color: #88C0D0">htons</span><span style="color: #D8DEE9FF">(</span><span style="color: #B48EAD">6715</span><span style="color: #D8DEE9FF">)</span><span style="color: #ECEFF4">,</span><span style="color: #D8DEE9FF"> </span><span style="color: #D8DEE9">sin_addr</span><span style="color: #81A1C1">=</span><span style="color: #88C0D0">inet_addr</span><span style="color: #D8DEE9FF">(</span><span style="color: #ECEFF4">"</span><span style="color: #A3BE8C">0.0.0.0</span><span style="color: #ECEFF4">"</span><span style="color: #D8DEE9FF">)</span><span style="color: #ECEFF4">},</span><span style="color: #D8DEE9FF"> </span><span style="color: #B48EAD">16</span><span style="color: #D8DEE9FF">) </span><span style="color: #81A1C1">=</span><span style="color: #D8DEE9FF"> </span><span style="color: #B48EAD">0</span></span></code></pre></div>



<p>After that chage we can connect via localhost, the hosts IP, hostname etc.</p>



<h2 class="wp-block-heading">Why Was It Written This Way?</h2>



<p>INADDR_ANY was around when this was written so why did MUDs want to bind to a specific hostname? I guess it was simply a different era and different ‘patterns’ were used. These days it seems logical to bind to all interfaces and implement restrictions with iptables. Back then perhaps it was more like listen on the interface that this system is known as. </p>



<p>You might have had a system called sionnach and that would be the hostname and assigned to a particular interface. But another interface might be assigned say sionnach-private so we wouldn’t listen on that, just the interface that corresponded to the hostname.</p>



<h2 class="wp-block-heading">Time to modernise</h2>



<p>The above code uses bcopy() which I don’t recall seeing before. Even my copy of Stevens(1993) uses memcpy. So this could could do with an update from these depreciated calls. Also it’s not accepting connections on IPv6 addresses.</p>



<p>A bit of reading later and the standard approach to this seems to be to use a duak-stack socket. It basically does:</p>



<ul class="wp-block-list">
<li>try IPv6 first </li>



<li>allow it to accept IPv4 connections (<code>IPV6_V6ONLY = 0</code>) </li>



<li>fall back to IPv4 if needed</li>
</ul>



<p>and while we’re at it we can get rid of my_hostent and s_in which are unused.</p>



<h2 class="wp-block-heading">Updated function:</h2>



<div class="wp-block-kevinbatdorf-code-block-pro" data-code-block-pro-font-family="Code-Pro-JetBrains-Mono" style="font-size:clamp(16px, 1rem, 24px);font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:clamp(20px, 1.25rem, 30px);--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)"><span role="button" tabindex="0" style="color:#d8dee9ff;display:none" aria-label="Copy" class="code-block-pro-copy-button"><pre class="code-block-pro-copy-button-pre" aria-hidden="true"><textarea class="code-block-pro-copy-button-textarea" tabindex="-1" aria-hidden="true" readonly="">int make_service(short unsigned int port, char *my_hostname, size_t my_hostnamelen)
{
  int s, i;
  struct sockaddr_in6 sin6;
  int ipv6_only = 0; /* 0 = allow both IPv4 and IPv6 (dual-stack) */

  if (gethostname(my_hostname, my_hostnamelen) &lt; 0) {
    return -1; /* Error in hostname? */
  }

  /* Try to create an IPv6 socket that also accepts IPv4 connections (dual-stack) */
  memset(&amp;sin6, 0, sizeof(sin6));
  sin6.sin6_family = AF_INET6;
  sin6.sin6_port = htons(port);
  sin6.sin6_addr = in6addr_any; /* Bind to all interfaces */

  if ((s = socket(AF_INET6, SOCK_STREAM, 0)) &lt; 0) {
    /* IPv6 not available, fall back to IPv4 */
    struct sockaddr_in sin4;
    memset(&amp;sin4, 0, sizeof(sin4));
    sin4.sin_family = AF_INET;
    sin4.sin_port = htons(port);
    sin4.sin_addr.s_addr = htonl(INADDR_ANY);

    if ((s = socket(AF_INET, SOCK_STREAM, 0)) &lt; 0) {
      return -3; /* Error in socket call */
    }

    /* Original SO_REUSEADDR code */
    i = 1;
    if (setsockopt(s, SOL_SOCKET, SO_REUSEADDR, &amp;i, sizeof(i)) == -1) {
      progerror("setsockopt(SO_REUSEADDR, v4)");
    }

    if (bind(s, (struct sockaddr *)&amp;sin4, sizeof(sin4)) &lt; 0) {
      close(s);
      return -4; /* Error in bind. */
    }
  } else {
    /* IPv6 socket created - set up dual-stack to also accept IPv4 */

    /* Original SO_REUSEADDR code */
    i = 1;
    if (setsockopt(s, SOL_SOCKET, SO_REUSEADDR, &amp;i, sizeof(i)) == -1) {
      progerror("setsockopt(SO_REUSEADDR, v6)");
    }

    /* Explicitly set IPV6_V6ONLY to 0 to allow both IPv4 and IPv6 connections */
    if (setsockopt(s, IPPROTO_IPV6, IPV6_V6ONLY, &amp;ipv6_only, sizeof(ipv6_only)) == -1) {
        /* If this fails, we can still bind but it will be IPv6 only, so just continue */
    }

    if (bind(s, (struct sockaddr *)&amp;sin6, sizeof(sin6)) &lt; 0) {
      close(s);
      return -4; /* Error in bind. */
    }
  }

  if (listen(s, 5) != 0) {
    close(s);
    return -5; /* Error in listen */
  }

  return s;
}</textarea></pre><svg xmlns="http://www.w3.org/2000/svg" style="width:24px;height:24px" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2"><path class="with-check" stroke-linecap="round" stroke-linejoin="round" d="M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4"></path><path class="without-check" stroke-linecap="round" stroke-linejoin="round" d="M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2"></path></svg></span><pre class="shiki nord" style="background-color: #2e3440ff" tabindex="0"><code><span class="line"><span style="color: #D8DEE9">int</span><span style="color: #D8DEE9FF"> </span><span style="color: #88C0D0">make_service</span><span style="color: #D8DEE9FF">(</span><span style="color: #D8DEE9">short</span><span style="color: #D8DEE9FF"> </span><span style="color: #D8DEE9">unsigned</span><span style="color: #D8DEE9FF"> </span><span style="color: #D8DEE9">int</span><span style="color: #D8DEE9FF"> </span><span style="color: #D8DEE9">port</span><span style="color: #ECEFF4">,</span><span style="color: #D8DEE9FF"> </span><span style="color: #D8DEE9">char</span><span style="color: #D8DEE9FF"> </span><span style="color: #81A1C1">*</span><span style="color: #D8DEE9">my_hostname</span><span style="color: #ECEFF4">,</span><span style="color: #D8DEE9FF"> </span><span style="color: #D8DEE9">size_t</span><span style="color: #D8DEE9FF"> </span><span style="color: #D8DEE9">my_hostnamelen</span><span style="color: #D8DEE9FF">)</span></span>
<span class="line"><span style="color: #ECEFF4">{</span></span>
<span class="line"><span style="color: #D8DEE9FF">  </span><span style="color: #D8DEE9">int</span><span style="color: #D8DEE9FF"> </span><span style="color: #D8DEE9">s</span><span style="color: #ECEFF4">,</span><span style="color: #D8DEE9FF"> </span><span style="color: #D8DEE9">i</span><span style="color: #81A1C1">;</span></span>
<span class="line"><span style="color: #D8DEE9FF">  </span><span style="color: #D8DEE9">struct</span><span style="color: #D8DEE9FF"> </span><span style="color: #D8DEE9">sockaddr_in6</span><span style="color: #D8DEE9FF"> </span><span style="color: #D8DEE9">sin6</span><span style="color: #81A1C1">;</span></span>
<span class="line"><span style="color: #D8DEE9FF">  </span><span style="color: #D8DEE9">int</span><span style="color: #D8DEE9FF"> </span><span style="color: #D8DEE9">ipv6_only</span><span style="color: #D8DEE9FF"> </span><span style="color: #81A1C1">=</span><span style="color: #D8DEE9FF"> </span><span style="color: #B48EAD">0</span><span style="color: #81A1C1">;</span><span style="color: #D8DEE9FF"> </span><span style="color: #616E88">/* 0 = allow both IPv4 and IPv6 (dual-stack) */</span></span>
<span class="line"></span>
<span class="line"><span style="color: #D8DEE9FF">  </span><span style="color: #81A1C1">if</span><span style="color: #D8DEE9FF"> (</span><span style="color: #88C0D0">gethostname</span><span style="color: #D8DEE9FF">(</span><span style="color: #D8DEE9">my_hostname</span><span style="color: #ECEFF4">,</span><span style="color: #D8DEE9FF"> </span><span style="color: #D8DEE9">my_hostnamelen</span><span style="color: #D8DEE9FF">) </span><span style="color: #81A1C1">&lt;</span><span style="color: #D8DEE9FF"> </span><span style="color: #B48EAD">0</span><span style="color: #D8DEE9FF">) </span><span style="color: #ECEFF4">{</span></span>
<span class="line"><span style="color: #D8DEE9FF">    </span><span style="color: #81A1C1">return</span><span style="color: #D8DEE9FF"> </span><span style="color: #81A1C1">-</span><span style="color: #B48EAD">1</span><span style="color: #81A1C1">;</span><span style="color: #D8DEE9FF"> </span><span style="color: #616E88">/* Error in hostname? */</span></span>
<span class="line"><span style="color: #D8DEE9FF">  </span><span style="color: #ECEFF4">}</span></span>
<span class="line"></span>
<span class="line"><span style="color: #D8DEE9FF">  </span><span style="color: #616E88">/* Try to create an IPv6 socket that also accepts IPv4 connections (dual-stack) */</span></span>
<span class="line"><span style="color: #D8DEE9FF">  </span><span style="color: #88C0D0">memset</span><span style="color: #D8DEE9FF">(</span><span style="color: #81A1C1">&amp;</span><span style="color: #D8DEE9">sin6</span><span style="color: #ECEFF4">,</span><span style="color: #D8DEE9FF"> </span><span style="color: #B48EAD">0</span><span style="color: #ECEFF4">,</span><span style="color: #D8DEE9FF"> </span><span style="color: #88C0D0">sizeof</span><span style="color: #D8DEE9FF">(</span><span style="color: #D8DEE9">sin6</span><span style="color: #D8DEE9FF">))</span><span style="color: #81A1C1">;</span></span>
<span class="line"><span style="color: #D8DEE9FF">  </span><span style="color: #D8DEE9">sin6</span><span style="color: #ECEFF4">.</span><span style="color: #D8DEE9">sin6_family</span><span style="color: #D8DEE9FF"> </span><span style="color: #81A1C1">=</span><span style="color: #D8DEE9FF"> </span><span style="color: #D8DEE9">AF_INET6</span><span style="color: #81A1C1">;</span></span>
<span class="line"><span style="color: #D8DEE9FF">  </span><span style="color: #D8DEE9">sin6</span><span style="color: #ECEFF4">.</span><span style="color: #D8DEE9">sin6_port</span><span style="color: #D8DEE9FF"> </span><span style="color: #81A1C1">=</span><span style="color: #D8DEE9FF"> </span><span style="color: #88C0D0">htons</span><span style="color: #D8DEE9FF">(</span><span style="color: #D8DEE9">port</span><span style="color: #D8DEE9FF">)</span><span style="color: #81A1C1">;</span></span>
<span class="line"><span style="color: #D8DEE9FF">  </span><span style="color: #D8DEE9">sin6</span><span style="color: #ECEFF4">.</span><span style="color: #D8DEE9">sin6_addr</span><span style="color: #D8DEE9FF"> </span><span style="color: #81A1C1">=</span><span style="color: #D8DEE9FF"> </span><span style="color: #D8DEE9">in6addr_any</span><span style="color: #81A1C1">;</span><span style="color: #D8DEE9FF"> </span><span style="color: #616E88">/* Bind to all interfaces */</span></span>
<span class="line"></span>
<span class="line"><span style="color: #D8DEE9FF">  </span><span style="color: #81A1C1">if</span><span style="color: #D8DEE9FF"> ((</span><span style="color: #D8DEE9">s</span><span style="color: #D8DEE9FF"> </span><span style="color: #81A1C1">=</span><span style="color: #D8DEE9FF"> </span><span style="color: #88C0D0">socket</span><span style="color: #D8DEE9FF">(</span><span style="color: #D8DEE9">AF_INET6</span><span style="color: #ECEFF4">,</span><span style="color: #D8DEE9FF"> </span><span style="color: #D8DEE9">SOCK_STREAM</span><span style="color: #ECEFF4">,</span><span style="color: #D8DEE9FF"> </span><span style="color: #B48EAD">0</span><span style="color: #D8DEE9FF">)) </span><span style="color: #81A1C1">&lt;</span><span style="color: #D8DEE9FF"> </span><span style="color: #B48EAD">0</span><span style="color: #D8DEE9FF">) </span><span style="color: #ECEFF4">{</span></span>
<span class="line"><span style="color: #D8DEE9FF">    </span><span style="color: #616E88">/* IPv6 not available, fall back to IPv4 */</span></span>
<span class="line"><span style="color: #D8DEE9FF">    </span><span style="color: #D8DEE9">struct</span><span style="color: #D8DEE9FF"> </span><span style="color: #D8DEE9">sockaddr_in</span><span style="color: #D8DEE9FF"> </span><span style="color: #D8DEE9">sin4</span><span style="color: #81A1C1">;</span></span>
<span class="line"><span style="color: #D8DEE9FF">    </span><span style="color: #88C0D0">memset</span><span style="color: #D8DEE9FF">(</span><span style="color: #81A1C1">&amp;</span><span style="color: #D8DEE9">sin4</span><span style="color: #ECEFF4">,</span><span style="color: #D8DEE9FF"> </span><span style="color: #B48EAD">0</span><span style="color: #ECEFF4">,</span><span style="color: #D8DEE9FF"> </span><span style="color: #88C0D0">sizeof</span><span style="color: #D8DEE9FF">(</span><span style="color: #D8DEE9">sin4</span><span style="color: #D8DEE9FF">))</span><span style="color: #81A1C1">;</span></span>
<span class="line"><span style="color: #D8DEE9FF">    </span><span style="color: #D8DEE9">sin4</span><span style="color: #ECEFF4">.</span><span style="color: #D8DEE9">sin_family</span><span style="color: #D8DEE9FF"> </span><span style="color: #81A1C1">=</span><span style="color: #D8DEE9FF"> </span><span style="color: #D8DEE9">AF_INET</span><span style="color: #81A1C1">;</span></span>
<span class="line"><span style="color: #D8DEE9FF">    </span><span style="color: #D8DEE9">sin4</span><span style="color: #ECEFF4">.</span><span style="color: #D8DEE9">sin_port</span><span style="color: #D8DEE9FF"> </span><span style="color: #81A1C1">=</span><span style="color: #D8DEE9FF"> </span><span style="color: #88C0D0">htons</span><span style="color: #D8DEE9FF">(</span><span style="color: #D8DEE9">port</span><span style="color: #D8DEE9FF">)</span><span style="color: #81A1C1">;</span></span>
<span class="line"><span style="color: #D8DEE9FF">    </span><span style="color: #D8DEE9">sin4</span><span style="color: #ECEFF4">.</span><span style="color: #D8DEE9">sin_addr</span><span style="color: #ECEFF4">.</span><span style="color: #D8DEE9">s_addr</span><span style="color: #D8DEE9FF"> </span><span style="color: #81A1C1">=</span><span style="color: #D8DEE9FF"> </span><span style="color: #88C0D0">htonl</span><span style="color: #D8DEE9FF">(</span><span style="color: #D8DEE9">INADDR_ANY</span><span style="color: #D8DEE9FF">)</span><span style="color: #81A1C1">;</span></span>
<span class="line"></span>
<span class="line"><span style="color: #D8DEE9FF">    </span><span style="color: #81A1C1">if</span><span style="color: #D8DEE9FF"> ((</span><span style="color: #D8DEE9">s</span><span style="color: #D8DEE9FF"> </span><span style="color: #81A1C1">=</span><span style="color: #D8DEE9FF"> </span><span style="color: #88C0D0">socket</span><span style="color: #D8DEE9FF">(</span><span style="color: #D8DEE9">AF_INET</span><span style="color: #ECEFF4">,</span><span style="color: #D8DEE9FF"> </span><span style="color: #D8DEE9">SOCK_STREAM</span><span style="color: #ECEFF4">,</span><span style="color: #D8DEE9FF"> </span><span style="color: #B48EAD">0</span><span style="color: #D8DEE9FF">)) </span><span style="color: #81A1C1">&lt;</span><span style="color: #D8DEE9FF"> </span><span style="color: #B48EAD">0</span><span style="color: #D8DEE9FF">) </span><span style="color: #ECEFF4">{</span></span>
<span class="line"><span style="color: #D8DEE9FF">      </span><span style="color: #81A1C1">return</span><span style="color: #D8DEE9FF"> </span><span style="color: #81A1C1">-</span><span style="color: #B48EAD">3</span><span style="color: #81A1C1">;</span><span style="color: #D8DEE9FF"> </span><span style="color: #616E88">/* Error in socket call */</span></span>
<span class="line"><span style="color: #D8DEE9FF">    </span><span style="color: #ECEFF4">}</span></span>
<span class="line"></span>
<span class="line"><span style="color: #D8DEE9FF">    </span><span style="color: #616E88">/* Original SO_REUSEADDR code */</span></span>
<span class="line"><span style="color: #D8DEE9FF">    </span><span style="color: #D8DEE9">i</span><span style="color: #D8DEE9FF"> </span><span style="color: #81A1C1">=</span><span style="color: #D8DEE9FF"> </span><span style="color: #B48EAD">1</span><span style="color: #81A1C1">;</span></span>
<span class="line"><span style="color: #D8DEE9FF">    </span><span style="color: #81A1C1">if</span><span style="color: #D8DEE9FF"> (</span><span style="color: #88C0D0">setsockopt</span><span style="color: #D8DEE9FF">(</span><span style="color: #D8DEE9">s</span><span style="color: #ECEFF4">,</span><span style="color: #D8DEE9FF"> </span><span style="color: #D8DEE9">SOL_SOCKET</span><span style="color: #ECEFF4">,</span><span style="color: #D8DEE9FF"> </span><span style="color: #D8DEE9">SO_REUSEADDR</span><span style="color: #ECEFF4">,</span><span style="color: #D8DEE9FF"> </span><span style="color: #81A1C1">&amp;</span><span style="color: #D8DEE9">i</span><span style="color: #ECEFF4">,</span><span style="color: #D8DEE9FF"> </span><span style="color: #88C0D0">sizeof</span><span style="color: #D8DEE9FF">(</span><span style="color: #D8DEE9">i</span><span style="color: #D8DEE9FF">)) </span><span style="color: #81A1C1">==</span><span style="color: #D8DEE9FF"> </span><span style="color: #81A1C1">-</span><span style="color: #B48EAD">1</span><span style="color: #D8DEE9FF">) </span><span style="color: #ECEFF4">{</span></span>
<span class="line"><span style="color: #D8DEE9FF">      </span><span style="color: #88C0D0">progerror</span><span style="color: #D8DEE9FF">(</span><span style="color: #ECEFF4">"</span><span style="color: #A3BE8C">setsockopt(SO_REUSEADDR, v4)</span><span style="color: #ECEFF4">"</span><span style="color: #D8DEE9FF">)</span><span style="color: #81A1C1">;</span></span>
<span class="line"><span style="color: #D8DEE9FF">    </span><span style="color: #ECEFF4">}</span></span>
<span class="line"></span>
<span class="line"><span style="color: #D8DEE9FF">    </span><span style="color: #81A1C1">if</span><span style="color: #D8DEE9FF"> (</span><span style="color: #88C0D0">bind</span><span style="color: #D8DEE9FF">(</span><span style="color: #D8DEE9">s</span><span style="color: #ECEFF4">,</span><span style="color: #D8DEE9FF"> (</span><span style="color: #D8DEE9">struct</span><span style="color: #D8DEE9FF"> </span><span style="color: #D8DEE9">sockaddr</span><span style="color: #D8DEE9FF"> </span><span style="color: #81A1C1">*</span><span style="color: #D8DEE9FF">)</span><span style="color: #81A1C1">&amp;</span><span style="color: #D8DEE9">sin4</span><span style="color: #ECEFF4">,</span><span style="color: #D8DEE9FF"> </span><span style="color: #88C0D0">sizeof</span><span style="color: #D8DEE9FF">(</span><span style="color: #D8DEE9">sin4</span><span style="color: #D8DEE9FF">)) </span><span style="color: #81A1C1">&lt;</span><span style="color: #D8DEE9FF"> </span><span style="color: #B48EAD">0</span><span style="color: #D8DEE9FF">) </span><span style="color: #ECEFF4">{</span></span>
<span class="line"><span style="color: #D8DEE9FF">      </span><span style="color: #88C0D0">close</span><span style="color: #D8DEE9FF">(</span><span style="color: #D8DEE9">s</span><span style="color: #D8DEE9FF">)</span><span style="color: #81A1C1">;</span></span>
<span class="line"><span style="color: #D8DEE9FF">      </span><span style="color: #81A1C1">return</span><span style="color: #D8DEE9FF"> </span><span style="color: #81A1C1">-</span><span style="color: #B48EAD">4</span><span style="color: #81A1C1">;</span><span style="color: #D8DEE9FF"> </span><span style="color: #616E88">/* Error in bind. */</span></span>
<span class="line"><span style="color: #D8DEE9FF">    </span><span style="color: #ECEFF4">}</span></span>
<span class="line"><span style="color: #D8DEE9FF">  </span><span style="color: #ECEFF4">}</span><span style="color: #D8DEE9FF"> </span><span style="color: #81A1C1">else</span><span style="color: #D8DEE9FF"> </span><span style="color: #ECEFF4">{</span></span>
<span class="line"><span style="color: #D8DEE9FF">    </span><span style="color: #616E88">/* IPv6 socket created - set up dual-stack to also accept IPv4 */</span></span>
<span class="line"></span>
<span class="line"><span style="color: #D8DEE9FF">    </span><span style="color: #616E88">/* Original SO_REUSEADDR code */</span></span>
<span class="line"><span style="color: #D8DEE9FF">    </span><span style="color: #D8DEE9">i</span><span style="color: #D8DEE9FF"> </span><span style="color: #81A1C1">=</span><span style="color: #D8DEE9FF"> </span><span style="color: #B48EAD">1</span><span style="color: #81A1C1">;</span></span>
<span class="line"><span style="color: #D8DEE9FF">    </span><span style="color: #81A1C1">if</span><span style="color: #D8DEE9FF"> (</span><span style="color: #88C0D0">setsockopt</span><span style="color: #D8DEE9FF">(</span><span style="color: #D8DEE9">s</span><span style="color: #ECEFF4">,</span><span style="color: #D8DEE9FF"> </span><span style="color: #D8DEE9">SOL_SOCKET</span><span style="color: #ECEFF4">,</span><span style="color: #D8DEE9FF"> </span><span style="color: #D8DEE9">SO_REUSEADDR</span><span style="color: #ECEFF4">,</span><span style="color: #D8DEE9FF"> </span><span style="color: #81A1C1">&amp;</span><span style="color: #D8DEE9">i</span><span style="color: #ECEFF4">,</span><span style="color: #D8DEE9FF"> </span><span style="color: #88C0D0">sizeof</span><span style="color: #D8DEE9FF">(</span><span style="color: #D8DEE9">i</span><span style="color: #D8DEE9FF">)) </span><span style="color: #81A1C1">==</span><span style="color: #D8DEE9FF"> </span><span style="color: #81A1C1">-</span><span style="color: #B48EAD">1</span><span style="color: #D8DEE9FF">) </span><span style="color: #ECEFF4">{</span></span>
<span class="line"><span style="color: #D8DEE9FF">      </span><span style="color: #88C0D0">progerror</span><span style="color: #D8DEE9FF">(</span><span style="color: #ECEFF4">"</span><span style="color: #A3BE8C">setsockopt(SO_REUSEADDR, v6)</span><span style="color: #ECEFF4">"</span><span style="color: #D8DEE9FF">)</span><span style="color: #81A1C1">;</span></span>
<span class="line"><span style="color: #D8DEE9FF">    </span><span style="color: #ECEFF4">}</span></span>
<span class="line"></span>
<span class="line"><span style="color: #D8DEE9FF">    </span><span style="color: #616E88">/* Explicitly set IPV6_V6ONLY to 0 to allow both IPv4 and IPv6 connections */</span></span>
<span class="line"><span style="color: #D8DEE9FF">    </span><span style="color: #81A1C1">if</span><span style="color: #D8DEE9FF"> (</span><span style="color: #88C0D0">setsockopt</span><span style="color: #D8DEE9FF">(</span><span style="color: #D8DEE9">s</span><span style="color: #ECEFF4">,</span><span style="color: #D8DEE9FF"> </span><span style="color: #D8DEE9">IPPROTO_IPV6</span><span style="color: #ECEFF4">,</span><span style="color: #D8DEE9FF"> </span><span style="color: #D8DEE9">IPV6_V6ONLY</span><span style="color: #ECEFF4">,</span><span style="color: #D8DEE9FF"> </span><span style="color: #81A1C1">&amp;</span><span style="color: #D8DEE9">ipv6_only</span><span style="color: #ECEFF4">,</span><span style="color: #D8DEE9FF"> </span><span style="color: #88C0D0">sizeof</span><span style="color: #D8DEE9FF">(</span><span style="color: #D8DEE9">ipv6_only</span><span style="color: #D8DEE9FF">)) </span><span style="color: #81A1C1">==</span><span style="color: #D8DEE9FF"> </span><span style="color: #81A1C1">-</span><span style="color: #B48EAD">1</span><span style="color: #D8DEE9FF">) </span><span style="color: #ECEFF4">{</span></span>
<span class="line"><span style="color: #D8DEE9FF">        </span><span style="color: #616E88">/* If this fails, we can still bind but it will be IPv6 only, so just continue */</span></span>
<span class="line"><span style="color: #D8DEE9FF">    </span><span style="color: #ECEFF4">}</span></span>
<span class="line"></span>
<span class="line"><span style="color: #D8DEE9FF">    </span><span style="color: #81A1C1">if</span><span style="color: #D8DEE9FF"> (</span><span style="color: #88C0D0">bind</span><span style="color: #D8DEE9FF">(</span><span style="color: #D8DEE9">s</span><span style="color: #ECEFF4">,</span><span style="color: #D8DEE9FF"> (</span><span style="color: #D8DEE9">struct</span><span style="color: #D8DEE9FF"> </span><span style="color: #D8DEE9">sockaddr</span><span style="color: #D8DEE9FF"> </span><span style="color: #81A1C1">*</span><span style="color: #D8DEE9FF">)</span><span style="color: #81A1C1">&amp;</span><span style="color: #D8DEE9">sin6</span><span style="color: #ECEFF4">,</span><span style="color: #D8DEE9FF"> </span><span style="color: #88C0D0">sizeof</span><span style="color: #D8DEE9FF">(</span><span style="color: #D8DEE9">sin6</span><span style="color: #D8DEE9FF">)) </span><span style="color: #81A1C1">&lt;</span><span style="color: #D8DEE9FF"> </span><span style="color: #B48EAD">0</span><span style="color: #D8DEE9FF">) </span><span style="color: #ECEFF4">{</span></span>
<span class="line"><span style="color: #D8DEE9FF">      </span><span style="color: #88C0D0">close</span><span style="color: #D8DEE9FF">(</span><span style="color: #D8DEE9">s</span><span style="color: #D8DEE9FF">)</span><span style="color: #81A1C1">;</span></span>
<span class="line"><span style="color: #D8DEE9FF">      </span><span style="color: #81A1C1">return</span><span style="color: #D8DEE9FF"> </span><span style="color: #81A1C1">-</span><span style="color: #B48EAD">4</span><span style="color: #81A1C1">;</span><span style="color: #D8DEE9FF"> </span><span style="color: #616E88">/* Error in bind. */</span></span>
<span class="line"><span style="color: #D8DEE9FF">    </span><span style="color: #ECEFF4">}</span></span>
<span class="line"><span style="color: #D8DEE9FF">  </span><span style="color: #ECEFF4">}</span></span>
<span class="line"></span>
<span class="line"><span style="color: #D8DEE9FF">  </span><span style="color: #81A1C1">if</span><span style="color: #D8DEE9FF"> (</span><span style="color: #88C0D0">listen</span><span style="color: #D8DEE9FF">(</span><span style="color: #D8DEE9">s</span><span style="color: #ECEFF4">,</span><span style="color: #D8DEE9FF"> </span><span style="color: #B48EAD">5</span><span style="color: #D8DEE9FF">) </span><span style="color: #81A1C1">!=</span><span style="color: #D8DEE9FF"> </span><span style="color: #B48EAD">0</span><span style="color: #D8DEE9FF">) </span><span style="color: #ECEFF4">{</span></span>
<span class="line"><span style="color: #D8DEE9FF">    </span><span style="color: #88C0D0">close</span><span style="color: #D8DEE9FF">(</span><span style="color: #D8DEE9">s</span><span style="color: #D8DEE9FF">)</span><span style="color: #81A1C1">;</span></span>
<span class="line"><span style="color: #D8DEE9FF">    </span><span style="color: #81A1C1">return</span><span style="color: #D8DEE9FF"> </span><span style="color: #81A1C1">-</span><span style="color: #B48EAD">5</span><span style="color: #81A1C1">;</span><span style="color: #D8DEE9FF"> </span><span style="color: #616E88">/* Error in listen */</span></span>
<span class="line"><span style="color: #D8DEE9FF">  </span><span style="color: #ECEFF4">}</span></span>
<span class="line"></span>
<span class="line"><span style="color: #D8DEE9FF">  </span><span style="color: #81A1C1">return</span><span style="color: #D8DEE9FF"> </span><span style="color: #D8DEE9">s</span><span style="color: #81A1C1">;</span></span>
<span class="line"><span style="color: #ECEFF4">}</span></span></code></pre></div>



<p>That’s my first proper dive into IPv6. A couple of hours of RFCs, compiler errors, and man pages later… 🙂 Beej’s Guide to Network Programming was the best resource I found for this <a href="https://beej.us/guide/bgnet/html/#jumping-from-ipv4-to-ipv6">https://beej.us/guide/bgnet/html/#jumping-from-ipv4-to-ipv6</a> but <a href="https://www.rfc-editor.org/rfc/rfc3493.html">https://www.rfc-editor.org/rfc/rfc3493.html</a> is also worth a scan</p>



<p>The full changeset is at <a href="https://github.com/albertw/dirt/commit/7fcf310e4588b7eb1212161cefb2a5ef4767c5e4">https://github.com/albertw/dirt/commit/7fcf310e4588b7eb1212161cefb2a5ef4767c5e4</a></p>



<p>I think this is portable, but if anyone runs into a problem on non-linux post an issue on github please!</p>



<p></p>]]></content:encoded>
    </item>
    <item>
      <title>Debugging a 64-bit Segfault in an Old MUD Codebase – more detail!</title>
      <link>https://www.cademuir.eu/blog/2026/04/08/debugging-a-64-bit-segfault-in-an-old-mud-codebase-more-detail/</link>
      <pubDate>Wed, 08 Apr 2026 14:34:43 GMT</pubDate>
      <dc:creator><![CDATA[albertw]]></dc:creator>
      <category><![CDATA[computing]]></category>
      
      <guid isPermaLink="false">https://www.cademuir.eu/blog/2026/04/08/debugging-a-64-bit-segfault-in-an-old-mud-codebase-more-detail/</guid>
      <description><![CDATA[<p>I want to look at the problem in the previous blog post about using gdb to figure out a segfault in a bit more detail. As a refresher this is what gdb showed us as the problem: I said that the address didn’t look right, and that’s probably one of the most frustrating things about learning this kind of debugging. I have sat down many times with experienced engineers to work through crash dumps, and</p>]]></description>
      <content:encoded><![CDATA[<p>I want to look at the problem in the previous blog post about using gdb to figure out a segfault in a bit more detail.</p>



<p>As a refresher this is what gdb showed us as the problem:</p>



<div class="wp-block-kevinbatdorf-code-block-pro" data-code-block-pro-font-family="Code-Pro-JetBrains-Mono" style="font-size:clamp(14px, .875rem, 21px);font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:clamp(20px, 1.25rem, 30px);--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)"><span role="button" tabindex="0" style="color:#d8dee9ff;display:none" aria-label="Copy" class="code-block-pro-copy-button"><pre class="code-block-pro-copy-button-pre" aria-hidden="true"><textarea class="code-block-pro-copy-button-textarea" tabindex="-1" aria-hidden="true" readonly="">Program received signal SIGSEGV, Segmentation fault.
check_send_msg (plx=plx@entry=111, a=a@entry=-13872, t=t@entry=0x7fffffffd1f0 "The Thief has gone west.\n") at sendsys.c:172
172 if (test_rcv(plx,b-&gt;mode,b-&gt;min,b-&gt;max,b-&gt;x1,b-&gt;x2)) return t;
(gdb)</textarea></pre><svg xmlns="http://www.w3.org/2000/svg" style="width:24px;height:24px" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2"><path class="with-check" stroke-linecap="round" stroke-linejoin="round" d="M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4"></path><path class="without-check" stroke-linecap="round" stroke-linejoin="round" d="M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2"></path></svg></span><pre class="shiki nord" style="background-color: #2e3440ff" tabindex="0"><code><span class="line"><span style="color: #D8DEE9">Program</span><span style="color: #D8DEE9FF"> </span><span style="color: #D8DEE9">received</span><span style="color: #D8DEE9FF"> </span><span style="color: #D8DEE9">signal</span><span style="color: #D8DEE9FF"> </span><span style="color: #D8DEE9">SIGSEGV</span><span style="color: #ECEFF4">,</span><span style="color: #D8DEE9FF"> </span><span style="color: #D8DEE9">Segmentation</span><span style="color: #D8DEE9FF"> </span><span style="color: #D8DEE9">fault</span><span style="color: #ECEFF4">.</span></span>
<span class="line"><span style="color: #88C0D0">check_send_msg</span><span style="color: #D8DEE9FF"> (</span><span style="color: #D8DEE9">plx</span><span style="color: #81A1C1">=</span><span style="color: #D8DEE9">plx</span><span style="color: #D8DEE9FF">@</span><span style="color: #D8DEE9">entry</span><span style="color: #81A1C1">=</span><span style="color: #B48EAD">111</span><span style="color: #ECEFF4">,</span><span style="color: #D8DEE9FF"> </span><span style="color: #D8DEE9">a</span><span style="color: #81A1C1">=</span><span style="color: #D8DEE9">a</span><span style="color: #D8DEE9FF">@</span><span style="color: #D8DEE9">entry</span><span style="color: #81A1C1">=-</span><span style="color: #B48EAD">13872</span><span style="color: #ECEFF4">,</span><span style="color: #D8DEE9FF"> </span><span style="color: #D8DEE9">t</span><span style="color: #81A1C1">=</span><span style="color: #D8DEE9">t</span><span style="color: #D8DEE9FF">@</span><span style="color: #D8DEE9">entry</span><span style="color: #81A1C1">=</span><span style="color: #B48EAD">0x7fffffffd1f0</span><span style="color: #D8DEE9FF"> </span><span style="color: #ECEFF4">"</span><span style="color: #A3BE8C">The Thief has gone west.</span><span style="color: #EBCB8B">\n</span><span style="color: #ECEFF4">"</span><span style="color: #D8DEE9FF">) </span><span style="color: #D8DEE9">at</span><span style="color: #D8DEE9FF"> </span><span style="color: #D8DEE9">sendsys</span><span style="color: #ECEFF4">.</span><span style="color: #D8DEE9">c</span><span style="color: #D8DEE9FF">:</span><span style="color: #B48EAD">172</span></span>
<span class="line"><span style="color: #B48EAD">172</span><span style="color: #D8DEE9FF"> </span><span style="color: #81A1C1">if</span><span style="color: #D8DEE9FF"> (</span><span style="color: #88C0D0">test_rcv</span><span style="color: #D8DEE9FF">(</span><span style="color: #D8DEE9">plx</span><span style="color: #ECEFF4">,</span><span style="color: #D8DEE9">b</span><span style="color: #81A1C1">-&gt;</span><span style="color: #D8DEE9">mode</span><span style="color: #ECEFF4">,</span><span style="color: #D8DEE9">b</span><span style="color: #81A1C1">-&gt;</span><span style="color: #D8DEE9">min</span><span style="color: #ECEFF4">,</span><span style="color: #D8DEE9">b</span><span style="color: #81A1C1">-&gt;</span><span style="color: #D8DEE9">max</span><span style="color: #ECEFF4">,</span><span style="color: #D8DEE9">b</span><span style="color: #81A1C1">-&gt;</span><span style="color: #D8DEE9">x1</span><span style="color: #ECEFF4">,</span><span style="color: #D8DEE9">b</span><span style="color: #81A1C1">-&gt;</span><span style="color: #D8DEE9">x2</span><span style="color: #D8DEE9FF">)) </span><span style="color: #81A1C1">return</span><span style="color: #D8DEE9FF"> </span><span style="color: #D8DEE9">t</span><span style="color: #81A1C1">;</span></span>
<span class="line"><span style="color: #D8DEE9FF">(</span><span style="color: #D8DEE9">gdb</span><span style="color: #D8DEE9FF">)</span></span></code></pre></div>



<p>I said that the address didn’t look right, and that’s probably one of the most frustrating things about learning this kind of debugging.</p>



<p>I have sat down <em>many</em> times with experienced engineers to work through crash dumps, and at some point they inevitably say that “something looks wrong.” That comes from experience, and it’s difficult to explain to someone unfamiliar with the code <em>why</em> it looks wrong.</p>



<p>So here’s how we can dig down and see exactly what the problem was caused by.</p>



<p>This is also often where you find yourself looking up assembly instructions and registers. Unless you’re doing this regularly, you forget it, the goal is to have some idea of what to look for, rather than retaining detailed knowledge of x86 assembly.</p>



<h2 class="wp-block-heading">Looking at the instruction that caused the segfault</h2>



<p>On x64, we can look at the instruction pointer to see exactly what line of assembly the CPU is currently executing:</p>



<div class="wp-block-kevinbatdorf-code-block-pro" data-code-block-pro-font-family="Code-Pro-JetBrains-Mono" style="font-size:clamp(16px, 1rem, 24px);font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:clamp(20px, 1.25rem, 30px);--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)"><span role="button" tabindex="0" style="color:#d8dee9ff;display:none" aria-label="Copy" class="code-block-pro-copy-button"><pre class="code-block-pro-copy-button-pre" aria-hidden="true"><textarea class="code-block-pro-copy-button-textarea" tabindex="-1" aria-hidden="true" readonly="">(gdb) x/i $rip
=&gt; 0x426e72 : cmp %edi,0xc(%rsi)
(gdb)</textarea></pre><svg xmlns="http://www.w3.org/2000/svg" style="width:24px;height:24px" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2"><path class="with-check" stroke-linecap="round" stroke-linejoin="round" d="M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4"></path><path class="without-check" stroke-linecap="round" stroke-linejoin="round" d="M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2"></path></svg></span><pre class="shiki nord" style="background-color: #2e3440ff" tabindex="0"><code><span class="line"><span style="color: #D8DEE9FF">(</span><span style="color: #D8DEE9">gdb</span><span style="color: #D8DEE9FF">) </span><span style="color: #D8DEE9">x</span><span style="color: #81A1C1">/</span><span style="color: #D8DEE9">i</span><span style="color: #D8DEE9FF"> </span><span style="color: #D8DEE9">$rip</span></span>
<span class="line"><span style="color: #81A1C1">=&gt;</span><span style="color: #D8DEE9FF"> </span><span style="color: #B48EAD">0x426e72</span><span style="color: #D8DEE9FF"> : </span><span style="color: #D8DEE9">cmp</span><span style="color: #D8DEE9FF"> </span><span style="color: #81A1C1">%</span><span style="color: #D8DEE9">edi</span><span style="color: #ECEFF4">,</span><span style="color: #B48EAD">0xc</span><span style="color: #D8DEE9FF">(</span><span style="color: #81A1C1">%</span><span style="color: #D8DEE9">rsi</span><span style="color: #D8DEE9FF">)</span></span>
<span class="line"><span style="color: #D8DEE9FF">(</span><span style="color: #D8DEE9">gdb</span><span style="color: #D8DEE9FF">)</span></span></code></pre></div>



<p>This is comparing %edi with 0xc(%rsi), specifically, the value in the register %edi with the value at the memory address stored in %rsi + 12 (0xc in hex).</p>



<p>This corresponds to part of the C call </p>



<div class="wp-block-kevinbatdorf-code-block-pro" data-code-block-pro-font-family="Code-Pro-JetBrains-Mono" style="font-size:clamp(16px, 1rem, 24px);font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:clamp(20px, 1.25rem, 30px);--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)"><span role="button" tabindex="0" style="color:#d8dee9ff;display:none" aria-label="Copy" class="code-block-pro-copy-button"><pre class="code-block-pro-copy-button-pre" aria-hidden="true"><textarea class="code-block-pro-copy-button-textarea" tabindex="-1" aria-hidden="true" readonly="">test_rcv(plx,b-&gt;mode,b-&gt;min,b-&gt;max,b-&gt;x1,b-&gt;x2)</textarea></pre><svg xmlns="http://www.w3.org/2000/svg" style="width:24px;height:24px" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2"><path class="with-check" stroke-linecap="round" stroke-linejoin="round" d="M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4"></path><path class="without-check" stroke-linecap="round" stroke-linejoin="round" d="M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2"></path></svg></span><pre class="shiki nord" style="background-color: #2e3440ff" tabindex="0"><code><span class="line"><span style="color: #88C0D0">test_rcv</span><span style="color: #D8DEE9FF">(</span><span style="color: #D8DEE9">plx</span><span style="color: #ECEFF4">,</span><span style="color: #D8DEE9">b</span><span style="color: #81A1C1">-&gt;</span><span style="color: #D8DEE9">mode</span><span style="color: #ECEFF4">,</span><span style="color: #D8DEE9">b</span><span style="color: #81A1C1">-&gt;</span><span style="color: #D8DEE9">min</span><span style="color: #ECEFF4">,</span><span style="color: #D8DEE9">b</span><span style="color: #81A1C1">-&gt;</span><span style="color: #D8DEE9">max</span><span style="color: #ECEFF4">,</span><span style="color: #D8DEE9">b</span><span style="color: #81A1C1">-&gt;</span><span style="color: #D8DEE9">x1</span><span style="color: #ECEFF4">,</span><span style="color: #D8DEE9">b</span><span style="color: #81A1C1">-&gt;</span><span style="color: #D8DEE9">x2</span><span style="color: #D8DEE9FF">)</span></span></code></pre></div>



<h3 class="wp-block-heading">A quick note on registers</h3>



<p>On x64, when we call a function, arguments are passed in registers:</p>



<figure class="wp-block-table"><table class="has-fixed-layout"><thead><tr><th>Argument</th><th>Register</th></tr></thead><tbody><tr><td>1st</td><td>rdi</td></tr><tr><td>2nd</td><td>rsi</td></tr><tr><td>3rd</td><td>rdx</td></tr><tr><td>4th</td><td>rcx</td></tr></tbody></table></figure>



<p>You can dump all registers with:</p>



<div class="wp-block-kevinbatdorf-code-block-pro" data-code-block-pro-font-family="Code-Pro-JetBrains-Mono" style="font-size:clamp(16px, 1rem, 24px);font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:clamp(20px, 1.25rem, 30px);--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)"><span role="button" tabindex="0" style="color:#d8dee9ff;display:none" aria-label="Copy" class="code-block-pro-copy-button"><pre class="code-block-pro-copy-button-pre" aria-hidden="true"><textarea class="code-block-pro-copy-button-textarea" tabindex="-1" aria-hidden="true" readonly="">(gdb) info registers
...
rsi 0xffffffffffffc9d0 -13872
rdi 0x6f 111
...</textarea></pre><svg xmlns="http://www.w3.org/2000/svg" style="width:24px;height:24px" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2"><path class="with-check" stroke-linecap="round" stroke-linejoin="round" d="M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4"></path><path class="without-check" stroke-linecap="round" stroke-linejoin="round" d="M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2"></path></svg></span><pre class="shiki nord" style="background-color: #2e3440ff" tabindex="0"><code><span class="line"><span style="color: #D8DEE9FF">(</span><span style="color: #D8DEE9">gdb</span><span style="color: #D8DEE9FF">) </span><span style="color: #D8DEE9">info</span><span style="color: #D8DEE9FF"> </span><span style="color: #D8DEE9">registers</span></span>
<span class="line"><span style="color: #81A1C1">...</span></span>
<span class="line"><span style="color: #D8DEE9">rsi</span><span style="color: #D8DEE9FF"> </span><span style="color: #B48EAD">0xffffffffffffc9d0</span><span style="color: #D8DEE9FF"> </span><span style="color: #81A1C1">-</span><span style="color: #B48EAD">13872</span></span>
<span class="line"><span style="color: #D8DEE9">rdi</span><span style="color: #D8DEE9FF"> </span><span style="color: #B48EAD">0x6f</span><span style="color: #D8DEE9FF"> </span><span style="color: #B48EAD">111</span></span>
<span class="line"><span style="color: #81A1C1">...</span></span></code></pre></div>



<h3 class="wp-block-heading">Register sizes</h3>



<p>On a 64-bit system, rdi is a 64-bit register. The instruction above uses edi, which is the lower 32 bits. </p>



<p>In this case, they contain the same value:</p>



<div class="wp-block-kevinbatdorf-code-block-pro" data-code-block-pro-font-family="Code-Pro-JetBrains-Mono" style="font-size:clamp(16px, 1rem, 24px);font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:clamp(20px, 1.25rem, 30px);--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)"><span role="button" tabindex="0" style="color:#d8dee9ff;display:none" aria-label="Copy" class="code-block-pro-copy-button"><pre class="code-block-pro-copy-button-pre" aria-hidden="true"><textarea class="code-block-pro-copy-button-textarea" tabindex="-1" aria-hidden="true" readonly="">(gdb) print $rdi
$5 = 111
(gdb) print $edi
$6 = 111</textarea></pre><svg xmlns="http://www.w3.org/2000/svg" style="width:24px;height:24px" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2"><path class="with-check" stroke-linecap="round" stroke-linejoin="round" d="M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4"></path><path class="without-check" stroke-linecap="round" stroke-linejoin="round" d="M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2"></path></svg></span><pre class="shiki nord" style="background-color: #2e3440ff" tabindex="0"><code><span class="line"><span style="color: #D8DEE9FF">(</span><span style="color: #D8DEE9">gdb</span><span style="color: #D8DEE9FF">) </span><span style="color: #D8DEE9">print</span><span style="color: #D8DEE9FF"> </span><span style="color: #D8DEE9">$rdi</span></span>
<span class="line"><span style="color: #D8DEE9">$5</span><span style="color: #D8DEE9FF"> </span><span style="color: #81A1C1">=</span><span style="color: #D8DEE9FF"> </span><span style="color: #B48EAD">111</span></span>
<span class="line"><span style="color: #D8DEE9FF">(</span><span style="color: #D8DEE9">gdb</span><span style="color: #D8DEE9FF">) </span><span style="color: #D8DEE9">print</span><span style="color: #D8DEE9FF"> </span><span style="color: #D8DEE9">$edi</span></span>
<span class="line"><span style="color: #D8DEE9">$6</span><span style="color: #D8DEE9FF"> </span><span style="color: #81A1C1">=</span><span style="color: #D8DEE9FF"> </span><span style="color: #B48EAD">111</span></span></code></pre></div>



<p>GDB already told us that the first argument (plx) is 111, so this lines up.</p>



<h2 class="wp-block-heading">Mapping back to the C code</h2>



<p>The second argument is a:</p>



<div class="wp-block-kevinbatdorf-code-block-pro" data-code-block-pro-font-family="Code-Pro-JetBrains-Mono" style="font-size:clamp(16px, 1rem, 24px);font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:clamp(20px, 1.25rem, 30px);--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)"><span role="button" tabindex="0" style="color:#d8dee9ff;display:none" aria-label="Copy" class="code-block-pro-copy-button"><pre class="code-block-pro-copy-button-pre" aria-hidden="true"><textarea class="code-block-pro-copy-button-textarea" tabindex="-1" aria-hidden="true" readonly="">(gdb) list
167
168 char *check_send_msg(int plx, int a, char *t)
169 {
170 struct _send_msg_box *b = (struct _send_msg_box *)a;
171
172 if (test_rcv(plx,b-&gt;mode,b-&gt;min,b-&gt;max,b-&gt;x1,b-&gt;x2)) return t;
173 return NULL;
174 }</textarea></pre><svg xmlns="http://www.w3.org/2000/svg" style="width:24px;height:24px" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2"><path class="with-check" stroke-linecap="round" stroke-linejoin="round" d="M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4"></path><path class="without-check" stroke-linecap="round" stroke-linejoin="round" d="M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2"></path></svg></span><pre class="shiki nord" style="background-color: #2e3440ff" tabindex="0"><code><span class="line"><span style="color: #D8DEE9FF">(</span><span style="color: #D8DEE9">gdb</span><span style="color: #D8DEE9FF">) </span><span style="color: #D8DEE9">list</span></span>
<span class="line"><span style="color: #B48EAD">167</span></span>
<span class="line"><span style="color: #B48EAD">168</span><span style="color: #D8DEE9FF"> </span><span style="color: #D8DEE9">char</span><span style="color: #D8DEE9FF"> </span><span style="color: #81A1C1">*</span><span style="color: #88C0D0">check_send_msg</span><span style="color: #D8DEE9FF">(</span><span style="color: #D8DEE9">int</span><span style="color: #D8DEE9FF"> </span><span style="color: #D8DEE9">plx</span><span style="color: #ECEFF4">,</span><span style="color: #D8DEE9FF"> </span><span style="color: #D8DEE9">int</span><span style="color: #D8DEE9FF"> </span><span style="color: #D8DEE9">a</span><span style="color: #ECEFF4">,</span><span style="color: #D8DEE9FF"> </span><span style="color: #D8DEE9">char</span><span style="color: #D8DEE9FF"> </span><span style="color: #81A1C1">*</span><span style="color: #D8DEE9">t</span><span style="color: #D8DEE9FF">)</span></span>
<span class="line"><span style="color: #B48EAD">169</span><span style="color: #D8DEE9FF"> </span><span style="color: #ECEFF4">{</span></span>
<span class="line"><span style="color: #B48EAD">170</span><span style="color: #D8DEE9FF"> </span><span style="color: #D8DEE9">struct</span><span style="color: #D8DEE9FF"> </span><span style="color: #D8DEE9">_send_msg_box</span><span style="color: #D8DEE9FF"> </span><span style="color: #81A1C1">*</span><span style="color: #D8DEE9">b</span><span style="color: #D8DEE9FF"> </span><span style="color: #81A1C1">=</span><span style="color: #D8DEE9FF"> (</span><span style="color: #D8DEE9">struct</span><span style="color: #D8DEE9FF"> </span><span style="color: #D8DEE9">_send_msg_box</span><span style="color: #D8DEE9FF"> </span><span style="color: #81A1C1">*</span><span style="color: #D8DEE9FF">)</span><span style="color: #D8DEE9">a</span><span style="color: #81A1C1">;</span></span>
<span class="line"><span style="color: #B48EAD">171</span></span>
<span class="line"><span style="color: #B48EAD">172</span><span style="color: #D8DEE9FF"> </span><span style="color: #81A1C1">if</span><span style="color: #D8DEE9FF"> (</span><span style="color: #88C0D0">test_rcv</span><span style="color: #D8DEE9FF">(</span><span style="color: #D8DEE9">plx</span><span style="color: #ECEFF4">,</span><span style="color: #D8DEE9">b</span><span style="color: #81A1C1">-&gt;</span><span style="color: #D8DEE9">mode</span><span style="color: #ECEFF4">,</span><span style="color: #D8DEE9">b</span><span style="color: #81A1C1">-&gt;</span><span style="color: #D8DEE9">min</span><span style="color: #ECEFF4">,</span><span style="color: #D8DEE9">b</span><span style="color: #81A1C1">-&gt;</span><span style="color: #D8DEE9">max</span><span style="color: #ECEFF4">,</span><span style="color: #D8DEE9">b</span><span style="color: #81A1C1">-&gt;</span><span style="color: #D8DEE9">x1</span><span style="color: #ECEFF4">,</span><span style="color: #D8DEE9">b</span><span style="color: #81A1C1">-&gt;</span><span style="color: #D8DEE9">x2</span><span style="color: #D8DEE9FF">)) </span><span style="color: #81A1C1">return</span><span style="color: #D8DEE9FF"> </span><span style="color: #D8DEE9">t</span><span style="color: #81A1C1">;</span></span>
<span class="line"><span style="color: #B48EAD">173</span><span style="color: #D8DEE9FF"> </span><span style="color: #81A1C1">return</span><span style="color: #D8DEE9FF"> </span><span style="color: #D8DEE9">NULL</span><span style="color: #81A1C1">;</span></span>
<span class="line"><span style="color: #B48EAD">174</span><span style="color: #D8DEE9FF"> </span><span style="color: #ECEFF4">}</span></span></code></pre></div>



<p>The assembly is comparing that 111 with the contents of the address at rsi + 12.</p>



<p>Why <code>+12</code>?</p>



<p>Let’s look at the struct:</p>



<div class="wp-block-kevinbatdorf-code-block-pro" data-code-block-pro-font-family="Code-Pro-JetBrains-Mono" style="font-size:clamp(16px, 1rem, 24px);font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:clamp(20px, 1.25rem, 30px);--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)"><span role="button" tabindex="0" style="color:#d8dee9ff;display:none" aria-label="Copy" class="code-block-pro-copy-button"><pre class="code-block-pro-copy-button-pre" aria-hidden="true"><textarea class="code-block-pro-copy-button-textarea" tabindex="-1" aria-hidden="true" readonly="">(gdb) ptype struct _send_msg_box
type = struct _send_msg_box {
    int mode;
    int min;
    int max;
    int x1;
    int x2;
}</textarea></pre><svg xmlns="http://www.w3.org/2000/svg" style="width:24px;height:24px" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2"><path class="with-check" stroke-linecap="round" stroke-linejoin="round" d="M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4"></path><path class="without-check" stroke-linecap="round" stroke-linejoin="round" d="M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2"></path></svg></span><pre class="shiki nord" style="background-color: #2e3440ff" tabindex="0"><code><span class="line"><span style="color: #D8DEE9FF">(</span><span style="color: #D8DEE9">gdb</span><span style="color: #D8DEE9FF">) </span><span style="color: #D8DEE9">ptype</span><span style="color: #D8DEE9FF"> </span><span style="color: #D8DEE9">struct</span><span style="color: #D8DEE9FF"> </span><span style="color: #D8DEE9">_send_msg_box</span></span>
<span class="line"><span style="color: #D8DEE9">type</span><span style="color: #D8DEE9FF"> </span><span style="color: #81A1C1">=</span><span style="color: #D8DEE9FF"> </span><span style="color: #D8DEE9">struct</span><span style="color: #D8DEE9FF"> </span><span style="color: #D8DEE9">_send_msg_box</span><span style="color: #D8DEE9FF"> </span><span style="color: #ECEFF4">{</span></span>
<span class="line"><span style="color: #D8DEE9FF">    </span><span style="color: #D8DEE9">int</span><span style="color: #D8DEE9FF"> </span><span style="color: #D8DEE9">mode</span><span style="color: #81A1C1">;</span></span>
<span class="line"><span style="color: #D8DEE9FF">    </span><span style="color: #D8DEE9">int</span><span style="color: #D8DEE9FF"> </span><span style="color: #D8DEE9">min</span><span style="color: #81A1C1">;</span></span>
<span class="line"><span style="color: #D8DEE9FF">    </span><span style="color: #D8DEE9">int</span><span style="color: #D8DEE9FF"> </span><span style="color: #D8DEE9">max</span><span style="color: #81A1C1">;</span></span>
<span class="line"><span style="color: #D8DEE9FF">    </span><span style="color: #D8DEE9">int</span><span style="color: #D8DEE9FF"> </span><span style="color: #D8DEE9">x1</span><span style="color: #81A1C1">;</span></span>
<span class="line"><span style="color: #D8DEE9FF">    </span><span style="color: #D8DEE9">int</span><span style="color: #D8DEE9FF"> </span><span style="color: #D8DEE9">x2</span><span style="color: #81A1C1">;</span></span>
<span class="line"><span style="color: #ECEFF4">}</span></span></code></pre></div>



<p>It’s just five integers:</p>



<ul class="wp-block-list">
<li><code>mode</code> → offset 0</li>



<li><code>min</code> → offset 4</li>



<li><code>max</code> → offset 8</li>



<li><code>x1</code> → offset 12</li>



<li><code>x2</code> → offset 16</li>
</ul>



<p>So <code>rsi + 12</code> corresponds to <code>b-&gt;x1</code>.</p>



<p>The compiler has generated assembly that accesses that field first.</p>



<h2 class="wp-block-heading">The real problem</h2>



<p>However, we don’t actually need to go that far to find the issue.</p>



<p>Just look at rsi:</p>



<div class="wp-block-kevinbatdorf-code-block-pro" data-code-block-pro-font-family="Code-Pro-JetBrains-Mono" style="font-size:clamp(16px, 1rem, 24px);font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:clamp(20px, 1.25rem, 30px);--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)"><span role="button" tabindex="0" style="color:#d8dee9ff;display:none" aria-label="Copy" class="code-block-pro-copy-button"><pre class="code-block-pro-copy-button-pre" aria-hidden="true"><textarea class="code-block-pro-copy-button-textarea" tabindex="-1" aria-hidden="true" readonly="">gdb) print $rsi
$9 = -13872
(gdb) print/x $rsi
$10 = 0xffffffffffffc9d0
(gdb) x/x $rsi
0xffffffffffffc9d0:	Cannot access memory at address 0xffffffffffffc9d0
</textarea></pre><svg xmlns="http://www.w3.org/2000/svg" style="width:24px;height:24px" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2"><path class="with-check" stroke-linecap="round" stroke-linejoin="round" d="M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4"></path><path class="without-check" stroke-linecap="round" stroke-linejoin="round" d="M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2"></path></svg></span><pre class="shiki nord" style="background-color: #2e3440ff" tabindex="0"><code><span class="line"><span style="color: #D8DEE9">gdb</span><span style="color: #D8DEE9FF">) </span><span style="color: #D8DEE9">print</span><span style="color: #D8DEE9FF"> </span><span style="color: #D8DEE9">$rsi</span></span>
<span class="line"><span style="color: #D8DEE9">$9</span><span style="color: #D8DEE9FF"> </span><span style="color: #81A1C1">=</span><span style="color: #D8DEE9FF"> </span><span style="color: #81A1C1">-</span><span style="color: #B48EAD">13872</span></span>
<span class="line"><span style="color: #D8DEE9FF">(</span><span style="color: #D8DEE9">gdb</span><span style="color: #D8DEE9FF">) </span><span style="color: #D8DEE9">print</span><span style="color: #81A1C1">/</span><span style="color: #D8DEE9">x</span><span style="color: #D8DEE9FF"> </span><span style="color: #D8DEE9">$rsi</span></span>
<span class="line"><span style="color: #D8DEE9">$10</span><span style="color: #D8DEE9FF"> </span><span style="color: #81A1C1">=</span><span style="color: #D8DEE9FF"> </span><span style="color: #B48EAD">0xffffffffffffc9d0</span></span>
<span class="line"><span style="color: #D8DEE9FF">(</span><span style="color: #D8DEE9">gdb</span><span style="color: #D8DEE9FF">) </span><span style="color: #D8DEE9">x</span><span style="color: #81A1C1">/</span><span style="color: #D8DEE9">x</span><span style="color: #D8DEE9FF"> </span><span style="color: #D8DEE9">$rsi</span></span>
<span class="line"><span style="color: #B48EAD">0xffffffffffffc9d0</span><span style="color: #D8DEE9FF">:	</span><span style="color: #D8DEE9">Cannot</span><span style="color: #D8DEE9FF"> </span><span style="color: #D8DEE9">access</span><span style="color: #D8DEE9FF"> </span><span style="color: #D8DEE9">memory</span><span style="color: #D8DEE9FF"> </span><span style="color: #D8DEE9">at</span><span style="color: #D8DEE9FF"> </span><span style="color: #D8DEE9">address</span><span style="color: #D8DEE9FF"> </span><span style="color: #B48EAD">0xffffffffffffc9d0</span></span>
<span class="line"></span></code></pre></div>



<p>We know this is supposed to be a memory address, when we try to examine it we get told we can’t access it.</p>



<p>At that point, we can go back through the code and see how that value ended up there.</p>



<h2 class="wp-block-heading">Conclusion</h2>



<p>Do you need to know all of this? Not really.</p>



<p>With practice, you do get a feel for what looks wrong. In reality, you’d probably only need to go as far as I did in the last blog post where we got the ‘Cannot access memory at address’ message. But it’s handy to know how to poke around a bit more.</p>]]></content:encoded>
    </item>
    <item>
      <title>Debugging a 64-bit Segfault in an Old MUD Codebase</title>
      <link>https://www.cademuir.eu/blog/2026/04/04/debugging-a-64-bit-segfault-in-an-old-mud-codebase/</link>
      <pubDate>Sat, 04 Apr 2026 17:20:36 GMT</pubDate>
      <dc:creator><![CDATA[albertw]]></dc:creator>
      <category><![CDATA[computing]]></category>
      
      <guid isPermaLink="false">https://www.cademuir.eu/blog/2026/04/04/debugging-a-64-bit-segfault-in-an-old-mud-codebase/</guid>
      <description><![CDATA[<p>Once I got the MUD built and running, it didn’t take long to hit problems. In fact, the very first time I connected: Good start. 1. Run it under GDB First step: run the server under GDB so we can see where it crashes. The –args lets us pass arguments (-f keeps the MUD in the foreground). Then: Pretty quickly we hit: I didn’t even need to connect this time, the NPC movement message alone</p>]]></description>
      <content:encoded><![CDATA[<p>Once I got the MUD built and running, it didn’t take long to hit problems. In fact, the very first time I connected:</p>



<div class="wp-block-kevinbatdorf-code-block-pro" data-code-block-pro-font-family="Code-Pro-JetBrains-Mono" style="font-size:clamp(16px, 1rem, 24px);font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:clamp(20px, 1.25rem, 30px);--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)"><span role="button" tabindex="0" style="color:#d8dee9ff;display:none" aria-label="Copy" class="code-block-pro-copy-button"><pre class="code-block-pro-copy-button-pre" aria-hidden="true"><textarea class="code-block-pro-copy-button-textarea" tabindex="-1" aria-hidden="true" readonly="">Connected to port 6715 on sionnach.
Segmentation fault (core dumped)</textarea></pre><svg xmlns="http://www.w3.org/2000/svg" style="width:24px;height:24px" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2"><path class="with-check" stroke-linecap="round" stroke-linejoin="round" d="M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4"></path><path class="without-check" stroke-linecap="round" stroke-linejoin="round" d="M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2"></path></svg></span><pre class="shiki nord" style="background-color: #2e3440ff" tabindex="0"><code><span class="line"><span style="color: #D8DEE9">Connected</span><span style="color: #D8DEE9FF"> </span><span style="color: #D8DEE9">to</span><span style="color: #D8DEE9FF"> </span><span style="color: #D8DEE9">port</span><span style="color: #D8DEE9FF"> </span><span style="color: #B48EAD">6715</span><span style="color: #D8DEE9FF"> </span><span style="color: #D8DEE9">on</span><span style="color: #D8DEE9FF"> </span><span style="color: #D8DEE9">sionnach</span><span style="color: #ECEFF4">.</span></span>
<span class="line"><span style="color: #D8DEE9">Segmentation</span><span style="color: #D8DEE9FF"> </span><span style="color: #88C0D0">fault</span><span style="color: #D8DEE9FF"> (</span><span style="color: #D8DEE9">core</span><span style="color: #D8DEE9FF"> </span><span style="color: #D8DEE9">dumped</span><span style="color: #D8DEE9FF">)</span></span></code></pre></div>



<p>Good start.</p>



<h2 class="wp-block-heading">1. Run it under GDB</h2>



<p>First step: run the server under GDB so we can see where it crashes.</p>



<div class="wp-block-kevinbatdorf-code-block-pro" data-code-block-pro-font-family="Code-Pro-JetBrains-Mono" style="font-size:clamp(16px, 1rem, 24px);font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:clamp(20px, 1.25rem, 30px);--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)"><span role="button" tabindex="0" style="color:#d8dee9ff;display:none" aria-label="Copy" class="code-block-pro-copy-button"><pre class="code-block-pro-copy-button-pre" aria-hidden="true"><textarea class="code-block-pro-copy-button-textarea" tabindex="-1" aria-hidden="true" readonly="">gdb --args ../bin/aberd -f</textarea></pre><svg xmlns="http://www.w3.org/2000/svg" style="width:24px;height:24px" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2"><path class="with-check" stroke-linecap="round" stroke-linejoin="round" d="M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4"></path><path class="without-check" stroke-linecap="round" stroke-linejoin="round" d="M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2"></path></svg></span><pre class="shiki nord" style="background-color: #2e3440ff" tabindex="0"><code><span class="line"><span style="color: #D8DEE9">gdb</span><span style="color: #D8DEE9FF"> </span><span style="color: #81A1C1">--</span><span style="color: #D8DEE9">args</span><span style="color: #D8DEE9FF"> </span><span style="color: #ECEFF4">..</span><span style="color: #81A1C1">/</span><span style="color: #D8DEE9">bin</span><span style="color: #81A1C1">/</span><span style="color: #D8DEE9">aberd</span><span style="color: #D8DEE9FF"> </span><span style="color: #81A1C1">-</span><span style="color: #D8DEE9">f</span></span></code></pre></div>



<p>The –args lets us pass arguments (-f keeps the MUD in the foreground).</p>



<p>Then:</p>



<div class="wp-block-kevinbatdorf-code-block-pro" data-code-block-pro-font-family="Code-Pro-JetBrains-Mono" style="font-size:clamp(14px, .875rem, 21px);font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:clamp(20px, 1.25rem, 30px);--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)"><span role="button" tabindex="0" style="color:#d8dee9ff;display:none" aria-label="Copy" class="code-block-pro-copy-button"><pre class="code-block-pro-copy-button-pre" aria-hidden="true"><textarea class="code-block-pro-copy-button-textarea" tabindex="-1" aria-hidden="true" readonly="">(gdb) run</textarea></pre><svg xmlns="http://www.w3.org/2000/svg" style="width:24px;height:24px" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2"><path class="with-check" stroke-linecap="round" stroke-linejoin="round" d="M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4"></path><path class="without-check" stroke-linecap="round" stroke-linejoin="round" d="M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2"></path></svg></span><pre class="shiki nord" style="background-color: #2e3440ff" tabindex="0"><code><span class="line"><span style="color: #D8DEE9FF">(</span><span style="color: #D8DEE9">gdb</span><span style="color: #D8DEE9FF">) </span><span style="color: #D8DEE9">run</span></span></code></pre></div>



<p>Pretty quickly we hit:</p>



<div class="wp-block-kevinbatdorf-code-block-pro" data-code-block-pro-font-family="Code-Pro-JetBrains-Mono" style="font-size:clamp(14px, .875rem, 21px);font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:clamp(20px, 1.25rem, 30px);--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)"><span role="button" tabindex="0" style="color:#d8dee9ff;display:none" aria-label="Copy" class="code-block-pro-copy-button"><pre class="code-block-pro-copy-button-pre" aria-hidden="true"><textarea class="code-block-pro-copy-button-textarea" tabindex="-1" aria-hidden="true" readonly="">Program received signal SIGSEGV, Segmentation fault.
check_send_msg (plx=111, a=-13872, t="The Thief has gone west.\n") at sendsys.c:172</textarea></pre><svg xmlns="http://www.w3.org/2000/svg" style="width:24px;height:24px" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2"><path class="with-check" stroke-linecap="round" stroke-linejoin="round" d="M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4"></path><path class="without-check" stroke-linecap="round" stroke-linejoin="round" d="M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2"></path></svg></span><pre class="shiki nord" style="background-color: #2e3440ff" tabindex="0"><code><span class="line"><span style="color: #D8DEE9">Program</span><span style="color: #D8DEE9FF"> </span><span style="color: #D8DEE9">received</span><span style="color: #D8DEE9FF"> </span><span style="color: #D8DEE9">signal</span><span style="color: #D8DEE9FF"> </span><span style="color: #D8DEE9">SIGSEGV</span><span style="color: #ECEFF4">,</span><span style="color: #D8DEE9FF"> </span><span style="color: #D8DEE9">Segmentation</span><span style="color: #D8DEE9FF"> </span><span style="color: #D8DEE9">fault</span><span style="color: #ECEFF4">.</span></span>
<span class="line"><span style="color: #88C0D0">check_send_msg</span><span style="color: #D8DEE9FF"> (</span><span style="color: #D8DEE9">plx</span><span style="color: #81A1C1">=</span><span style="color: #B48EAD">111</span><span style="color: #ECEFF4">,</span><span style="color: #D8DEE9FF"> </span><span style="color: #D8DEE9">a</span><span style="color: #81A1C1">=-</span><span style="color: #B48EAD">13872</span><span style="color: #ECEFF4">,</span><span style="color: #D8DEE9FF"> </span><span style="color: #D8DEE9">t</span><span style="color: #81A1C1">=</span><span style="color: #ECEFF4">"</span><span style="color: #A3BE8C">The Thief has gone west.</span><span style="color: #EBCB8B">\n</span><span style="color: #ECEFF4">"</span><span style="color: #D8DEE9FF">) </span><span style="color: #D8DEE9">at</span><span style="color: #D8DEE9FF"> </span><span style="color: #D8DEE9">sendsys</span><span style="color: #ECEFF4">.</span><span style="color: #D8DEE9">c</span><span style="color: #D8DEE9FF">:</span><span style="color: #B48EAD">172</span></span></code></pre></div>



<p>I didn’t even need to connect this time, the NPC movement message alone triggered the crash!</p>



<hr class="wp-block-separator has-alpha-channel-opacity">



<h2 class="wp-block-heading">2. Get the backtrace</h2>



<p>First thing to do it get a backtrace:</p>



<div class="wp-block-kevinbatdorf-code-block-pro" data-code-block-pro-font-family="Code-Pro-JetBrains-Mono" style="font-size:clamp(14px, .875rem, 21px);font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:clamp(20px, 1.25rem, 30px);--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)"><span role="button" tabindex="0" style="color:#d8dee9ff;display:none" aria-label="Copy" class="code-block-pro-copy-button"><pre class="code-block-pro-copy-button-pre" aria-hidden="true"><textarea class="code-block-pro-copy-button-textarea" tabindex="-1" aria-hidden="true" readonly="">(gdb) bt
#0  check_send_msg (plx=plx@entry=111, a=a@entry=-13872, t=t@entry=0x7fffffffd1f0 "The Thief has gone west.\n") at sendsys.c:172
#1  0x0000000000427318 in send_g_msg (destination=destination@entry=-613, func=func@entry=0x426e6b &lt;check_send_msg&gt;, arg=arg@entry=-13872, text=text@entry=0x7fffffffd1f0 "The Thief has gone west.\n")
    at sendsys.c:151
#2  0x0000000000427426 in send_msg (destination=-613, mode=mode@entry=0, min=&lt;optimized out&gt;, max=max@entry=100000, x1=x1@entry=111, x2=x2@entry=-32766, format=0x437c0b "%s has gone %s.\n") at sendsys.c:205
#3  0x000000000041a2ea in movemob (x=x@entry=111) at mobile.c:739
#4  0x000000000041a482 in consid_move (mon=mon@entry=111) at mobile.c:647
#5  0x000000000041a5af in move_mobiles () at mobile.c:527
#6  0x0000000000428462 in on_timer () at timing.c:538
#7  0x000000000041745a in main_loop (m_socket=m_socket@entry=0) at main.c:544
#8  0x0000000000418312 in xmain (fd=&lt;optimized out&gt;) at main.c:172
#9  main (argc=&lt;optimized out&gt;, argv=&lt;optimized out&gt;, ep=&lt;optimized out&gt;) at main.c:90
(gdb)</textarea></pre><svg xmlns="http://www.w3.org/2000/svg" style="width:24px;height:24px" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2"><path class="with-check" stroke-linecap="round" stroke-linejoin="round" d="M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4"></path><path class="without-check" stroke-linecap="round" stroke-linejoin="round" d="M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2"></path></svg></span><pre class="shiki nord" style="background-color: #2e3440ff" tabindex="0"><code><span class="line"><span style="color: #D8DEE9FF">(</span><span style="color: #D8DEE9">gdb</span><span style="color: #D8DEE9FF">) </span><span style="color: #D8DEE9">bt</span></span>
<span class="line"><span style="color: #D8DEE9FF">#</span><span style="color: #B48EAD">0</span><span style="color: #D8DEE9FF">  </span><span style="color: #88C0D0">check_send_msg</span><span style="color: #D8DEE9FF"> (</span><span style="color: #D8DEE9">plx</span><span style="color: #81A1C1">=</span><span style="color: #D8DEE9">plx</span><span style="color: #D8DEE9FF">@</span><span style="color: #D8DEE9">entry</span><span style="color: #81A1C1">=</span><span style="color: #B48EAD">111</span><span style="color: #ECEFF4">,</span><span style="color: #D8DEE9FF"> </span><span style="color: #D8DEE9">a</span><span style="color: #81A1C1">=</span><span style="color: #D8DEE9">a</span><span style="color: #D8DEE9FF">@</span><span style="color: #D8DEE9">entry</span><span style="color: #81A1C1">=-</span><span style="color: #B48EAD">13872</span><span style="color: #ECEFF4">,</span><span style="color: #D8DEE9FF"> </span><span style="color: #D8DEE9">t</span><span style="color: #81A1C1">=</span><span style="color: #D8DEE9">t</span><span style="color: #D8DEE9FF">@</span><span style="color: #D8DEE9">entry</span><span style="color: #81A1C1">=</span><span style="color: #B48EAD">0x7fffffffd1f0</span><span style="color: #D8DEE9FF"> </span><span style="color: #ECEFF4">"</span><span style="color: #A3BE8C">The Thief has gone west.</span><span style="color: #EBCB8B">\n</span><span style="color: #ECEFF4">"</span><span style="color: #D8DEE9FF">) </span><span style="color: #D8DEE9">at</span><span style="color: #D8DEE9FF"> </span><span style="color: #D8DEE9">sendsys</span><span style="color: #ECEFF4">.</span><span style="color: #D8DEE9">c</span><span style="color: #D8DEE9FF">:</span><span style="color: #B48EAD">172</span></span>
<span class="line"><span style="color: #D8DEE9FF">#</span><span style="color: #B48EAD">1</span><span style="color: #D8DEE9FF">  </span><span style="color: #B48EAD">0x0000000000427318</span><span style="color: #D8DEE9FF"> </span><span style="color: #81A1C1">in</span><span style="color: #D8DEE9FF"> </span><span style="color: #88C0D0">send_g_msg</span><span style="color: #D8DEE9FF"> (</span><span style="color: #D8DEE9">destination</span><span style="color: #81A1C1">=</span><span style="color: #D8DEE9">destination</span><span style="color: #D8DEE9FF">@</span><span style="color: #D8DEE9">entry</span><span style="color: #81A1C1">=-</span><span style="color: #B48EAD">613</span><span style="color: #ECEFF4">,</span><span style="color: #D8DEE9FF"> </span><span style="color: #D8DEE9">func</span><span style="color: #81A1C1">=</span><span style="color: #D8DEE9">func</span><span style="color: #D8DEE9FF">@</span><span style="color: #D8DEE9">entry</span><span style="color: #81A1C1">=</span><span style="color: #B48EAD">0x426e6b</span><span style="color: #D8DEE9FF"> </span><span style="color: #81A1C1">&lt;</span><span style="color: #D8DEE9">check_send_msg</span><span style="color: #81A1C1">&gt;</span><span style="color: #ECEFF4">,</span><span style="color: #D8DEE9FF"> </span><span style="color: #D8DEE9">arg</span><span style="color: #81A1C1">=</span><span style="color: #D8DEE9">arg</span><span style="color: #D8DEE9FF">@</span><span style="color: #D8DEE9">entry</span><span style="color: #81A1C1">=-</span><span style="color: #B48EAD">13872</span><span style="color: #ECEFF4">,</span><span style="color: #D8DEE9FF"> </span><span style="color: #D8DEE9">text</span><span style="color: #81A1C1">=</span><span style="color: #D8DEE9">text</span><span style="color: #D8DEE9FF">@</span><span style="color: #D8DEE9">entry</span><span style="color: #81A1C1">=</span><span style="color: #B48EAD">0x7fffffffd1f0</span><span style="color: #D8DEE9FF"> </span><span style="color: #ECEFF4">"</span><span style="color: #A3BE8C">The Thief has gone west.</span><span style="color: #EBCB8B">\n</span><span style="color: #ECEFF4">"</span><span style="color: #D8DEE9FF">)</span></span>
<span class="line"><span style="color: #D8DEE9FF">    </span><span style="color: #D8DEE9">at</span><span style="color: #D8DEE9FF"> </span><span style="color: #D8DEE9">sendsys</span><span style="color: #ECEFF4">.</span><span style="color: #D8DEE9">c</span><span style="color: #D8DEE9FF">:</span><span style="color: #B48EAD">151</span></span>
<span class="line"><span style="color: #D8DEE9FF">#</span><span style="color: #B48EAD">2</span><span style="color: #D8DEE9FF">  </span><span style="color: #B48EAD">0x0000000000427426</span><span style="color: #D8DEE9FF"> </span><span style="color: #81A1C1">in</span><span style="color: #D8DEE9FF"> </span><span style="color: #88C0D0">send_msg</span><span style="color: #D8DEE9FF"> (</span><span style="color: #D8DEE9">destination</span><span style="color: #81A1C1">=-</span><span style="color: #B48EAD">613</span><span style="color: #ECEFF4">,</span><span style="color: #D8DEE9FF"> </span><span style="color: #D8DEE9">mode</span><span style="color: #81A1C1">=</span><span style="color: #D8DEE9">mode</span><span style="color: #D8DEE9FF">@</span><span style="color: #D8DEE9">entry</span><span style="color: #81A1C1">=</span><span style="color: #B48EAD">0</span><span style="color: #ECEFF4">,</span><span style="color: #D8DEE9FF"> </span><span style="color: #D8DEE9">min</span><span style="color: #81A1C1">=&lt;optimized</span><span style="color: #D8DEE9FF"> </span><span style="color: #8FBCBB">out</span><span style="color: #81A1C1">&gt;</span><span style="color: #D8DEE9FF">, max=max@entry=100000, x1=x1@entry=111, x2=x2@entry=-32766, format=0x437c0b "%s has gone %s.\n") at sendsys.c:205</span></span>
<span class="line"><span style="color: #D8DEE9FF">#3  0x000000000041a2ea in movemob (x=x@entry=111) at mobile.c:739</span></span>
<span class="line"><span style="color: #D8DEE9FF">#4  0x000000000041a482 in consid_move (mon=mon@entry=111) at mobile.c:647</span></span>
<span class="line"><span style="color: #D8DEE9FF">#5  0x000000000041a5af in move_mobiles () at mobile.c:527</span></span>
<span class="line"><span style="color: #D8DEE9FF">#6  0x0000000000428462 in on_timer () at timing.c:538</span></span>
<span class="line"><span style="color: #D8DEE9FF">#7  0x000000000041745a in main_loop (m_socket=m_socket@entry=0) at main.c:544</span></span>
<span class="line"><span style="color: #D8DEE9FF">#8  0x0000000000418312 in xmain (fd=</span><span style="color: #81A1C1">&lt;optimized</span><span style="color: #D8DEE9FF"> </span><span style="color: #8FBCBB">out</span><span style="color: #81A1C1">&gt;</span><span style="color: #D8DEE9FF">) at main.c:172</span></span>
<span class="line"><span style="color: #D8DEE9FF">#9  main (argc=</span><span style="color: #81A1C1">&lt;optimized</span><span style="color: #D8DEE9FF"> </span><span style="color: #8FBCBB">out</span><span style="color: #81A1C1">&gt;</span><span style="color: #D8DEE9FF">, argv=</span><span style="color: #81A1C1">&lt;optimized</span><span style="color: #D8DEE9FF"> </span><span style="color: #8FBCBB">out</span><span style="color: #81A1C1">&gt;</span><span style="color: #D8DEE9FF">, ep=</span><span style="color: #81A1C1">&lt;optimized</span><span style="color: #D8DEE9FF"> </span><span style="color: #8FBCBB">out</span><span style="color: #81A1C1">&gt;</span><span style="color: #D8DEE9FF">) at main.c:90</span></span>
<span class="line"><span style="color: #D8DEE9FF">(gdb)</span></span></code></pre></div>



<p>How we can see that the flow of the program. We have a main loop and within that we move mobiles (NPCs) around and when they move a message gets printed. </p>



<h2 class="wp-block-heading">3. Look at the crashing function</h2>



<p>gdb can display code inline (list) but I prefer to use a separate terminal. So lets look at check_send_msg</p>



<div class="wp-block-kevinbatdorf-code-block-pro" data-code-block-pro-font-family="Code-Pro-JetBrains-Mono" style="font-size:clamp(14px, .875rem, 21px);font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:clamp(20px, 1.25rem, 30px);--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)"><span role="button" tabindex="0" style="color:#d8dee9ff;display:none" aria-label="Copy" class="code-block-pro-copy-button"><pre class="code-block-pro-copy-button-pre" aria-hidden="true"><textarea class="code-block-pro-copy-button-textarea" tabindex="-1" aria-hidden="true" readonly="">struct _send_msg_box {
  int mode;
  int min;
  int max;
  int x1;
  int x2;
};

char *check_send_msg(int plx, int a, char *t)
{
  struct _send_msg_box *b = (struct _send_msg_box *)a;
  
  if (test_rcv(plx,b-&gt;mode,b-&gt;min,b-&gt;max,b-&gt;x1,b-&gt;x2)) return t;
  return NULL;
}</textarea></pre><svg xmlns="http://www.w3.org/2000/svg" style="width:24px;height:24px" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2"><path class="with-check" stroke-linecap="round" stroke-linejoin="round" d="M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4"></path><path class="without-check" stroke-linecap="round" stroke-linejoin="round" d="M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2"></path></svg></span><pre class="shiki nord" style="background-color: #2e3440ff" tabindex="0"><code><span class="line"><span style="color: #D8DEE9">struct</span><span style="color: #D8DEE9FF"> </span><span style="color: #D8DEE9">_send_msg_box</span><span style="color: #D8DEE9FF"> </span><span style="color: #ECEFF4">{</span></span>
<span class="line"><span style="color: #D8DEE9FF">  </span><span style="color: #D8DEE9">int</span><span style="color: #D8DEE9FF"> </span><span style="color: #D8DEE9">mode</span><span style="color: #81A1C1">;</span></span>
<span class="line"><span style="color: #D8DEE9FF">  </span><span style="color: #D8DEE9">int</span><span style="color: #D8DEE9FF"> </span><span style="color: #D8DEE9">min</span><span style="color: #81A1C1">;</span></span>
<span class="line"><span style="color: #D8DEE9FF">  </span><span style="color: #D8DEE9">int</span><span style="color: #D8DEE9FF"> </span><span style="color: #D8DEE9">max</span><span style="color: #81A1C1">;</span></span>
<span class="line"><span style="color: #D8DEE9FF">  </span><span style="color: #D8DEE9">int</span><span style="color: #D8DEE9FF"> </span><span style="color: #D8DEE9">x1</span><span style="color: #81A1C1">;</span></span>
<span class="line"><span style="color: #D8DEE9FF">  </span><span style="color: #D8DEE9">int</span><span style="color: #D8DEE9FF"> </span><span style="color: #D8DEE9">x2</span><span style="color: #81A1C1">;</span></span>
<span class="line"><span style="color: #ECEFF4">}</span><span style="color: #81A1C1">;</span></span>
<span class="line"></span>
<span class="line"><span style="color: #D8DEE9">char</span><span style="color: #D8DEE9FF"> </span><span style="color: #81A1C1">*</span><span style="color: #88C0D0">check_send_msg</span><span style="color: #D8DEE9FF">(</span><span style="color: #D8DEE9">int</span><span style="color: #D8DEE9FF"> </span><span style="color: #D8DEE9">plx</span><span style="color: #ECEFF4">,</span><span style="color: #D8DEE9FF"> </span><span style="color: #D8DEE9">int</span><span style="color: #D8DEE9FF"> </span><span style="color: #D8DEE9">a</span><span style="color: #ECEFF4">,</span><span style="color: #D8DEE9FF"> </span><span style="color: #D8DEE9">char</span><span style="color: #D8DEE9FF"> </span><span style="color: #81A1C1">*</span><span style="color: #D8DEE9">t</span><span style="color: #D8DEE9FF">)</span></span>
<span class="line"><span style="color: #ECEFF4">{</span></span>
<span class="line"><span style="color: #D8DEE9FF">  </span><span style="color: #D8DEE9">struct</span><span style="color: #D8DEE9FF"> </span><span style="color: #D8DEE9">_send_msg_box</span><span style="color: #D8DEE9FF"> </span><span style="color: #81A1C1">*</span><span style="color: #D8DEE9">b</span><span style="color: #D8DEE9FF"> </span><span style="color: #81A1C1">=</span><span style="color: #D8DEE9FF"> (</span><span style="color: #D8DEE9">struct</span><span style="color: #D8DEE9FF"> </span><span style="color: #D8DEE9">_send_msg_box</span><span style="color: #D8DEE9FF"> </span><span style="color: #81A1C1">*</span><span style="color: #D8DEE9FF">)</span><span style="color: #D8DEE9">a</span><span style="color: #81A1C1">;</span></span>
<span class="line"><span style="color: #D8DEE9FF">  </span></span>
<span class="line"><span style="color: #D8DEE9FF">  </span><span style="color: #81A1C1">if</span><span style="color: #D8DEE9FF"> (</span><span style="color: #88C0D0">test_rcv</span><span style="color: #D8DEE9FF">(</span><span style="color: #D8DEE9">plx</span><span style="color: #ECEFF4">,</span><span style="color: #D8DEE9">b</span><span style="color: #81A1C1">-&gt;</span><span style="color: #D8DEE9">mode</span><span style="color: #ECEFF4">,</span><span style="color: #D8DEE9">b</span><span style="color: #81A1C1">-&gt;</span><span style="color: #D8DEE9">min</span><span style="color: #ECEFF4">,</span><span style="color: #D8DEE9">b</span><span style="color: #81A1C1">-&gt;</span><span style="color: #D8DEE9">max</span><span style="color: #ECEFF4">,</span><span style="color: #D8DEE9">b</span><span style="color: #81A1C1">-&gt;</span><span style="color: #D8DEE9">x1</span><span style="color: #ECEFF4">,</span><span style="color: #D8DEE9">b</span><span style="color: #81A1C1">-&gt;</span><span style="color: #D8DEE9">x2</span><span style="color: #D8DEE9FF">)) </span><span style="color: #81A1C1">return</span><span style="color: #D8DEE9FF"> </span><span style="color: #D8DEE9">t</span><span style="color: #81A1C1">;</span></span>
<span class="line"><span style="color: #D8DEE9FF">  </span><span style="color: #81A1C1">return</span><span style="color: #D8DEE9FF"> </span><span style="color: #D8DEE9">NULL</span><span style="color: #81A1C1">;</span></span>
<span class="line"><span style="color: #ECEFF4">}</span></span></code></pre></div>



<p>We segfault just on that test_rcv line.</p>



<h2 class="wp-block-heading">4. Inspect variables in GDB</h2>



<p>What I typically do at this point is just print the arguments and see if something jumps out. We could look at the instruction pointer and see exactly where were crashing if we needed to, perhaps in another post.</p>



<div class="wp-block-kevinbatdorf-code-block-pro" data-code-block-pro-font-family="Code-Pro-JetBrains-Mono" style="font-size:clamp(14px, .875rem, 21px);font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:clamp(20px, 1.25rem, 30px);--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)"><span role="button" tabindex="0" style="color:#d8dee9ff;display:none" aria-label="Copy" class="code-block-pro-copy-button"><pre class="code-block-pro-copy-button-pre" aria-hidden="true"><textarea class="code-block-pro-copy-button-textarea" tabindex="-1" aria-hidden="true" readonly="">(gdb) print plx
$3 = 111
(gdb) print b
$4 = (struct _send_msg_box *) 0xffffffffffffc9d0
(gdb) print b-&gt;mode
Cannot access memory at address 0xffffffffffffc9d0
(gdb) print b-&gt;min
Cannot access memory at address 0xffffffffffffc9d4
(gdb) print b-&gt;x2
Cannot access memory at address 0xffffffffffffc9e0
(gdb) </textarea></pre><svg xmlns="http://www.w3.org/2000/svg" style="width:24px;height:24px" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2"><path class="with-check" stroke-linecap="round" stroke-linejoin="round" d="M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4"></path><path class="without-check" stroke-linecap="round" stroke-linejoin="round" d="M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2"></path></svg></span><pre class="shiki nord" style="background-color: #2e3440ff" tabindex="0"><code><span class="line"><span style="color: #D8DEE9FF">(</span><span style="color: #D8DEE9">gdb</span><span style="color: #D8DEE9FF">) </span><span style="color: #D8DEE9">print</span><span style="color: #D8DEE9FF"> </span><span style="color: #D8DEE9">plx</span></span>
<span class="line"><span style="color: #D8DEE9">$3</span><span style="color: #D8DEE9FF"> </span><span style="color: #81A1C1">=</span><span style="color: #D8DEE9FF"> </span><span style="color: #B48EAD">111</span></span>
<span class="line"><span style="color: #D8DEE9FF">(</span><span style="color: #D8DEE9">gdb</span><span style="color: #D8DEE9FF">) </span><span style="color: #D8DEE9">print</span><span style="color: #D8DEE9FF"> </span><span style="color: #D8DEE9">b</span></span>
<span class="line"><span style="color: #D8DEE9">$4</span><span style="color: #D8DEE9FF"> </span><span style="color: #81A1C1">=</span><span style="color: #D8DEE9FF"> (</span><span style="color: #D8DEE9">struct</span><span style="color: #D8DEE9FF"> </span><span style="color: #D8DEE9">_send_msg_box</span><span style="color: #D8DEE9FF"> </span><span style="color: #81A1C1">*</span><span style="color: #D8DEE9FF">) </span><span style="color: #B48EAD">0xffffffffffffc9d0</span></span>
<span class="line"><span style="color: #D8DEE9FF">(</span><span style="color: #D8DEE9">gdb</span><span style="color: #D8DEE9FF">) </span><span style="color: #D8DEE9">print</span><span style="color: #D8DEE9FF"> </span><span style="color: #D8DEE9">b</span><span style="color: #81A1C1">-&gt;</span><span style="color: #D8DEE9">mode</span></span>
<span class="line"><span style="color: #D8DEE9">Cannot</span><span style="color: #D8DEE9FF"> </span><span style="color: #D8DEE9">access</span><span style="color: #D8DEE9FF"> </span><span style="color: #D8DEE9">memory</span><span style="color: #D8DEE9FF"> </span><span style="color: #D8DEE9">at</span><span style="color: #D8DEE9FF"> </span><span style="color: #D8DEE9">address</span><span style="color: #D8DEE9FF"> </span><span style="color: #B48EAD">0xffffffffffffc9d0</span></span>
<span class="line"><span style="color: #D8DEE9FF">(</span><span style="color: #D8DEE9">gdb</span><span style="color: #D8DEE9FF">) </span><span style="color: #D8DEE9">print</span><span style="color: #D8DEE9FF"> </span><span style="color: #D8DEE9">b</span><span style="color: #81A1C1">-&gt;</span><span style="color: #D8DEE9">min</span></span>
<span class="line"><span style="color: #D8DEE9">Cannot</span><span style="color: #D8DEE9FF"> </span><span style="color: #D8DEE9">access</span><span style="color: #D8DEE9FF"> </span><span style="color: #D8DEE9">memory</span><span style="color: #D8DEE9FF"> </span><span style="color: #D8DEE9">at</span><span style="color: #D8DEE9FF"> </span><span style="color: #D8DEE9">address</span><span style="color: #D8DEE9FF"> </span><span style="color: #B48EAD">0xffffffffffffc9d4</span></span>
<span class="line"><span style="color: #D8DEE9FF">(</span><span style="color: #D8DEE9">gdb</span><span style="color: #D8DEE9FF">) </span><span style="color: #D8DEE9">print</span><span style="color: #D8DEE9FF"> </span><span style="color: #D8DEE9">b</span><span style="color: #81A1C1">-&gt;</span><span style="color: #D8DEE9">x2</span></span>
<span class="line"><span style="color: #D8DEE9">Cannot</span><span style="color: #D8DEE9FF"> </span><span style="color: #D8DEE9">access</span><span style="color: #D8DEE9FF"> </span><span style="color: #D8DEE9">memory</span><span style="color: #D8DEE9FF"> </span><span style="color: #D8DEE9">at</span><span style="color: #D8DEE9FF"> </span><span style="color: #D8DEE9">address</span><span style="color: #D8DEE9FF"> </span><span style="color: #B48EAD">0xffffffffffffc9e0</span></span>
<span class="line"><span style="color: #D8DEE9FF">(</span><span style="color: #D8DEE9">gdb</span><span style="color: #D8DEE9FF">) </span></span></code></pre></div>



<p>plx is probably fine, but those memory addresses look wrong, that’s an invalid memory address. </p>



<h2 class="wp-block-heading">5. Where did <code>b</code> come from?</h2>



<p>Back tot he code and we see :</p>



<div class="wp-block-kevinbatdorf-code-block-pro" data-code-block-pro-font-family="Code-Pro-JetBrains-Mono" style="font-size:clamp(14px, .875rem, 21px);font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:clamp(20px, 1.25rem, 30px);--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)"><span role="button" tabindex="0" style="color:#d8dee9ff;display:none" aria-label="Copy" class="code-block-pro-copy-button"><pre class="code-block-pro-copy-button-pre" aria-hidden="true"><textarea class="code-block-pro-copy-button-textarea" tabindex="-1" aria-hidden="true" readonly="">struct _send_msg_box *b = (struct _send_msg_box *)a;</textarea></pre><svg xmlns="http://www.w3.org/2000/svg" style="width:24px;height:24px" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2"><path class="with-check" stroke-linecap="round" stroke-linejoin="round" d="M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4"></path><path class="without-check" stroke-linecap="round" stroke-linejoin="round" d="M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2"></path></svg></span><pre class="shiki nord" style="background-color: #2e3440ff" tabindex="0"><code><span class="line"><span style="color: #D8DEE9">struct</span><span style="color: #D8DEE9FF"> </span><span style="color: #D8DEE9">_send_msg_box</span><span style="color: #D8DEE9FF"> </span><span style="color: #81A1C1">*</span><span style="color: #D8DEE9">b</span><span style="color: #D8DEE9FF"> </span><span style="color: #81A1C1">=</span><span style="color: #D8DEE9FF"> (</span><span style="color: #D8DEE9">struct</span><span style="color: #D8DEE9FF"> </span><span style="color: #D8DEE9">_send_msg_box</span><span style="color: #D8DEE9FF"> </span><span style="color: #81A1C1">*</span><span style="color: #D8DEE9FF">)</span><span style="color: #D8DEE9">a</span><span style="color: #81A1C1">;</span></span></code></pre></div>



<p>b is just a reinterpreted as a pointer. so if a is a valid address b should be valid.</p>



<div class="wp-block-kevinbatdorf-code-block-pro" data-code-block-pro-font-family="Code-Pro-JetBrains-Mono" style="font-size:clamp(14px, .875rem, 21px);font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:clamp(20px, 1.25rem, 30px);--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)"><span role="button" tabindex="0" style="color:#d8dee9ff;display:none" aria-label="Copy" class="code-block-pro-copy-button"><pre class="code-block-pro-copy-button-pre" aria-hidden="true"><textarea class="code-block-pro-copy-button-textarea" tabindex="-1" aria-hidden="true" readonly="">(gdb) print a
$5 = -13872
(gdb)</textarea></pre><svg xmlns="http://www.w3.org/2000/svg" style="width:24px;height:24px" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2"><path class="with-check" stroke-linecap="round" stroke-linejoin="round" d="M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4"></path><path class="without-check" stroke-linecap="round" stroke-linejoin="round" d="M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2"></path></svg></span><pre class="shiki nord" style="background-color: #2e3440ff" tabindex="0"><code><span class="line"><span style="color: #D8DEE9FF">(</span><span style="color: #D8DEE9">gdb</span><span style="color: #D8DEE9FF">) </span><span style="color: #D8DEE9">print</span><span style="color: #D8DEE9FF"> </span><span style="color: #D8DEE9">a</span></span>
<span class="line"><span style="color: #D8DEE9">$5</span><span style="color: #D8DEE9FF"> </span><span style="color: #81A1C1">=</span><span style="color: #D8DEE9FF"> </span><span style="color: #81A1C1">-</span><span style="color: #B48EAD">13872</span></span>
<span class="line"><span style="color: #D8DEE9FF">(</span><span style="color: #D8DEE9">gdb</span><span style="color: #D8DEE9FF">)</span></span></code></pre></div>



<p>oh. Looking at the function declaration we see :</p>



<div class="wp-block-kevinbatdorf-code-block-pro" data-code-block-pro-font-family="Code-Pro-JetBrains-Mono" style="font-size:clamp(14px, .875rem, 21px);font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:clamp(20px, 1.25rem, 30px);--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)"><span role="button" tabindex="0" style="color:#d8dee9ff;display:none" aria-label="Copy" class="code-block-pro-copy-button"><pre class="code-block-pro-copy-button-pre" aria-hidden="true"><textarea class="code-block-pro-copy-button-textarea" tabindex="-1" aria-hidden="true" readonly="">char *check_send_msg(int plx, int a, char *t)</textarea></pre><svg xmlns="http://www.w3.org/2000/svg" style="width:24px;height:24px" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2"><path class="with-check" stroke-linecap="round" stroke-linejoin="round" d="M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4"></path><path class="without-check" stroke-linecap="round" stroke-linejoin="round" d="M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2"></path></svg></span><pre class="shiki nord" style="background-color: #2e3440ff" tabindex="0"><code><span class="line"><span style="color: #D8DEE9">char</span><span style="color: #D8DEE9FF"> </span><span style="color: #81A1C1">*</span><span style="color: #88C0D0">check_send_msg</span><span style="color: #D8DEE9FF">(</span><span style="color: #D8DEE9">int</span><span style="color: #D8DEE9FF"> </span><span style="color: #D8DEE9">plx</span><span style="color: #ECEFF4">,</span><span style="color: #D8DEE9FF"> </span><span style="color: #D8DEE9">int</span><span style="color: #D8DEE9FF"> </span><span style="color: #D8DEE9">a</span><span style="color: #ECEFF4">,</span><span style="color: #D8DEE9FF"> </span><span style="color: #D8DEE9">char</span><span style="color: #D8DEE9FF"> </span><span style="color: #81A1C1">*</span><span style="color: #D8DEE9">t</span><span style="color: #D8DEE9FF">)</span></span></code></pre></div>



<p>a is an integer. If it’s supposed to be a memory address it shouldn’t be an integer. You would get away with that on a 32 bit system but not modern 64 bit hardware. So it’s likely that somewhere we had a proper memory address but chopped it to an int somewhere.</p>



<h2 class="wp-block-heading">6. Follow the value backwards</h2>



<p>stepping back to where we call send_g_msg we see that we also have an address of -13872</p>



<div class="wp-block-kevinbatdorf-code-block-pro" data-code-block-pro-font-family="Code-Pro-JetBrains-Mono" style="font-size:clamp(14px, .875rem, 21px);font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:clamp(20px, 1.25rem, 30px);--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)"><span role="button" tabindex="0" style="color:#d8dee9ff;display:none" aria-label="Copy" class="code-block-pro-copy-button"><pre class="code-block-pro-copy-button-pre" aria-hidden="true"><textarea class="code-block-pro-copy-button-textarea" tabindex="-1" aria-hidden="true" readonly="">(gdb) frame 1
#1  0x0000000000427318 in send_g_msg (destination=destination@entry=-613, func=func@entry=0x426e6b &lt;check_send_msg&gt;, arg=arg@entry=-13872, text=text@entry=0x7fffffffd1f0 "The Thief has gone west.\n")
    at sendsys.c:151
151		  (t = (func == NULL ? text : func(p, arg, text))) != NULL &amp;&amp;
(gdb) print arg
$8 = -13872
(gdb) </textarea></pre><svg xmlns="http://www.w3.org/2000/svg" style="width:24px;height:24px" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2"><path class="with-check" stroke-linecap="round" stroke-linejoin="round" d="M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4"></path><path class="without-check" stroke-linecap="round" stroke-linejoin="round" d="M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2"></path></svg></span><pre class="shiki nord" style="background-color: #2e3440ff" tabindex="0"><code><span class="line"><span style="color: #D8DEE9FF">(</span><span style="color: #D8DEE9">gdb</span><span style="color: #D8DEE9FF">) </span><span style="color: #D8DEE9">frame</span><span style="color: #D8DEE9FF"> </span><span style="color: #B48EAD">1</span></span>
<span class="line"><span style="color: #D8DEE9FF">#</span><span style="color: #B48EAD">1</span><span style="color: #D8DEE9FF">  </span><span style="color: #B48EAD">0x0000000000427318</span><span style="color: #D8DEE9FF"> </span><span style="color: #81A1C1">in</span><span style="color: #D8DEE9FF"> </span><span style="color: #88C0D0">send_g_msg</span><span style="color: #D8DEE9FF"> (</span><span style="color: #D8DEE9">destination</span><span style="color: #81A1C1">=</span><span style="color: #D8DEE9">destination</span><span style="color: #D8DEE9FF">@</span><span style="color: #D8DEE9">entry</span><span style="color: #81A1C1">=-</span><span style="color: #B48EAD">613</span><span style="color: #ECEFF4">,</span><span style="color: #D8DEE9FF"> </span><span style="color: #D8DEE9">func</span><span style="color: #81A1C1">=</span><span style="color: #D8DEE9">func</span><span style="color: #D8DEE9FF">@</span><span style="color: #D8DEE9">entry</span><span style="color: #81A1C1">=</span><span style="color: #B48EAD">0x426e6b</span><span style="color: #D8DEE9FF"> </span><span style="color: #81A1C1">&lt;</span><span style="color: #D8DEE9">check_send_msg</span><span style="color: #81A1C1">&gt;</span><span style="color: #ECEFF4">,</span><span style="color: #D8DEE9FF"> </span><span style="color: #D8DEE9">arg</span><span style="color: #81A1C1">=</span><span style="color: #D8DEE9">arg</span><span style="color: #D8DEE9FF">@</span><span style="color: #D8DEE9">entry</span><span style="color: #81A1C1">=-</span><span style="color: #B48EAD">13872</span><span style="color: #ECEFF4">,</span><span style="color: #D8DEE9FF"> </span><span style="color: #D8DEE9">text</span><span style="color: #81A1C1">=</span><span style="color: #D8DEE9">text</span><span style="color: #D8DEE9FF">@</span><span style="color: #D8DEE9">entry</span><span style="color: #81A1C1">=</span><span style="color: #B48EAD">0x7fffffffd1f0</span><span style="color: #D8DEE9FF"> </span><span style="color: #ECEFF4">"</span><span style="color: #A3BE8C">The Thief has gone west.</span><span style="color: #EBCB8B">\n</span><span style="color: #ECEFF4">"</span><span style="color: #D8DEE9FF">)</span></span>
<span class="line"><span style="color: #D8DEE9FF">    </span><span style="color: #D8DEE9">at</span><span style="color: #D8DEE9FF"> </span><span style="color: #D8DEE9">sendsys</span><span style="color: #ECEFF4">.</span><span style="color: #D8DEE9">c</span><span style="color: #D8DEE9FF">:</span><span style="color: #B48EAD">151</span></span>
<span class="line"><span style="color: #B48EAD">151</span><span style="color: #D8DEE9FF">		  (</span><span style="color: #D8DEE9">t</span><span style="color: #D8DEE9FF"> </span><span style="color: #81A1C1">=</span><span style="color: #D8DEE9FF"> (</span><span style="color: #D8DEE9">func</span><span style="color: #D8DEE9FF"> </span><span style="color: #81A1C1">==</span><span style="color: #D8DEE9FF"> </span><span style="color: #D8DEE9">NULL</span><span style="color: #D8DEE9FF"> </span><span style="color: #81A1C1">?</span><span style="color: #D8DEE9FF"> </span><span style="color: #D8DEE9">text</span><span style="color: #D8DEE9FF"> </span><span style="color: #81A1C1">:</span><span style="color: #D8DEE9FF"> </span><span style="color: #88C0D0">func</span><span style="color: #D8DEE9FF">(</span><span style="color: #D8DEE9">p</span><span style="color: #ECEFF4">,</span><span style="color: #D8DEE9FF"> </span><span style="color: #D8DEE9">arg</span><span style="color: #ECEFF4">,</span><span style="color: #D8DEE9FF"> </span><span style="color: #D8DEE9">text</span><span style="color: #D8DEE9FF">))) </span><span style="color: #81A1C1">!=</span><span style="color: #D8DEE9FF"> </span><span style="color: #D8DEE9">NULL</span><span style="color: #D8DEE9FF"> </span><span style="color: #81A1C1">&amp;&amp;</span></span>
<span class="line"><span style="color: #D8DEE9FF">(</span><span style="color: #D8DEE9">gdb</span><span style="color: #D8DEE9FF">) </span><span style="color: #D8DEE9">print</span><span style="color: #D8DEE9FF"> </span><span style="color: #D8DEE9">arg</span></span>
<span class="line"><span style="color: #D8DEE9">$8</span><span style="color: #D8DEE9FF"> </span><span style="color: #81A1C1">=</span><span style="color: #D8DEE9FF"> </span><span style="color: #81A1C1">-</span><span style="color: #B48EAD">13872</span></span>
<span class="line"><span style="color: #D8DEE9FF">(</span><span style="color: #D8DEE9">gdb</span><span style="color: #D8DEE9FF">) </span></span></code></pre></div>



<p>and the function declaration says int again:</p>



<div class="wp-block-kevinbatdorf-code-block-pro" data-code-block-pro-font-family="Code-Pro-JetBrains-Mono" style="font-size:clamp(14px, .875rem, 21px);font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:clamp(20px, 1.25rem, 30px);--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)"><span role="button" tabindex="0" style="color:#d8dee9ff;display:none" aria-label="Copy" class="code-block-pro-copy-button"><pre class="code-block-pro-copy-button-pre" aria-hidden="true"><textarea class="code-block-pro-copy-button-textarea" tabindex="-1" aria-hidden="true" readonly="">void send_g_msg(int destination,                        /* Where to send to */
                char *func(int plx, int arg, char *t),  /* Test function */
                int arg,                             /* Argument to test */
                char *text)                          /* Text to send */
{ </textarea></pre><svg xmlns="http://www.w3.org/2000/svg" style="width:24px;height:24px" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2"><path class="with-check" stroke-linecap="round" stroke-linejoin="round" d="M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4"></path><path class="without-check" stroke-linecap="round" stroke-linejoin="round" d="M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2"></path></svg></span><pre class="shiki nord" style="background-color: #2e3440ff" tabindex="0"><code><span class="line"><span style="color: #81A1C1">void</span><span style="color: #D8DEE9FF"> </span><span style="color: #88C0D0">send_g_msg</span><span style="color: #D8DEE9FF">(</span><span style="color: #D8DEE9">int</span><span style="color: #D8DEE9FF"> </span><span style="color: #D8DEE9">destination</span><span style="color: #ECEFF4">,</span><span style="color: #D8DEE9FF">                        </span><span style="color: #616E88">/* Where to send to */</span></span>
<span class="line"><span style="color: #D8DEE9FF">                </span><span style="color: #D8DEE9">char</span><span style="color: #D8DEE9FF"> </span><span style="color: #81A1C1">*</span><span style="color: #88C0D0">func</span><span style="color: #D8DEE9FF">(</span><span style="color: #D8DEE9">int</span><span style="color: #D8DEE9FF"> </span><span style="color: #D8DEE9">plx</span><span style="color: #ECEFF4">,</span><span style="color: #D8DEE9FF"> </span><span style="color: #D8DEE9">int</span><span style="color: #D8DEE9FF"> </span><span style="color: #D8DEE9">arg</span><span style="color: #ECEFF4">,</span><span style="color: #D8DEE9FF"> </span><span style="color: #D8DEE9">char</span><span style="color: #D8DEE9FF"> </span><span style="color: #81A1C1">*</span><span style="color: #D8DEE9">t</span><span style="color: #D8DEE9FF">)</span><span style="color: #ECEFF4">,</span><span style="color: #D8DEE9FF">  </span><span style="color: #616E88">/* Test function */</span></span>
<span class="line"><span style="color: #D8DEE9FF">                </span><span style="color: #D8DEE9">int</span><span style="color: #D8DEE9FF"> </span><span style="color: #D8DEE9">arg</span><span style="color: #ECEFF4">,</span><span style="color: #D8DEE9FF">                             </span><span style="color: #616E88">/* Argument to test */</span></span>
<span class="line"><span style="color: #D8DEE9FF">                </span><span style="color: #D8DEE9">char</span><span style="color: #D8DEE9FF"> </span><span style="color: #81A1C1">*</span><span style="color: #D8DEE9">text</span><span style="color: #D8DEE9FF">)                          </span><span style="color: #616E88">/* Text to send */</span></span>
<span class="line"><span style="color: #ECEFF4">{</span><span style="color: #D8DEE9FF"> </span></span></code></pre></div>



<p>So lets step back again to send_msg:</p>



<div class="wp-block-kevinbatdorf-code-block-pro" data-code-block-pro-font-family="Code-Pro-JetBrains-Mono" style="font-size:clamp(14px, .875rem, 21px);font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:clamp(20px, 1.25rem, 30px);--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)"><span role="button" tabindex="0" style="color:#d8dee9ff;display:none" aria-label="Copy" class="code-block-pro-copy-button"><pre class="code-block-pro-copy-button-pre" aria-hidden="true"><textarea class="code-block-pro-copy-button-textarea" tabindex="-1" aria-hidden="true" readonly="">(gdb) frame 2
#2  0x0000000000427426 in send_msg (destination=-613, mode=mode@entry=0, min=&lt;optimized out&gt;, max=max@entry=100000, x1=x1@entry=111, x2=x2@entry=-32766, format=0x437c0b "%s has gone %s.\n") at sendsys.c:205
205	  send_g_msg(destination,check_send_msg,(int)&amp;b,bf);
(gdb) print b
$9 = {mode = 0, min = 0, max = 100000, x1 = 111, x2 = -32766}
(gdb) print (int)&amp;b
$10 = -13872
(gdb) print &amp;b
$11 = (struct _send_msg_box *) 0x7fffffffc9d0
</textarea></pre><svg xmlns="http://www.w3.org/2000/svg" style="width:24px;height:24px" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2"><path class="with-check" stroke-linecap="round" stroke-linejoin="round" d="M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4"></path><path class="without-check" stroke-linecap="round" stroke-linejoin="round" d="M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2"></path></svg></span><pre class="shiki nord" style="background-color: #2e3440ff" tabindex="0"><code><span class="line"><span style="color: #D8DEE9FF">(</span><span style="color: #D8DEE9">gdb</span><span style="color: #D8DEE9FF">) </span><span style="color: #D8DEE9">frame</span><span style="color: #D8DEE9FF"> </span><span style="color: #B48EAD">2</span></span>
<span class="line"><span style="color: #D8DEE9FF">#</span><span style="color: #B48EAD">2</span><span style="color: #D8DEE9FF">  </span><span style="color: #B48EAD">0x0000000000427426</span><span style="color: #D8DEE9FF"> </span><span style="color: #81A1C1">in</span><span style="color: #D8DEE9FF"> </span><span style="color: #88C0D0">send_msg</span><span style="color: #D8DEE9FF"> (</span><span style="color: #D8DEE9">destination</span><span style="color: #81A1C1">=-</span><span style="color: #B48EAD">613</span><span style="color: #ECEFF4">,</span><span style="color: #D8DEE9FF"> </span><span style="color: #D8DEE9">mode</span><span style="color: #81A1C1">=</span><span style="color: #D8DEE9">mode</span><span style="color: #D8DEE9FF">@</span><span style="color: #D8DEE9">entry</span><span style="color: #81A1C1">=</span><span style="color: #B48EAD">0</span><span style="color: #ECEFF4">,</span><span style="color: #D8DEE9FF"> </span><span style="color: #D8DEE9">min</span><span style="color: #81A1C1">=&lt;optimized</span><span style="color: #D8DEE9FF"> </span><span style="color: #8FBCBB">out</span><span style="color: #81A1C1">&gt;</span><span style="color: #D8DEE9FF">, max=max@entry=100000, x1=x1@entry=111, x2=x2@entry=-32766, format=0x437c0b "%s has gone %s.\n") at sendsys.c:205</span></span>
<span class="line"><span style="color: #D8DEE9FF">205	  send_g_msg(destination,check_send_msg,(int)&amp;b,bf);</span></span>
<span class="line"><span style="color: #D8DEE9FF">(gdb) print b</span></span>
<span class="line"><span style="color: #D8DEE9FF">$9 = </span><span style="color: #81A1C1">{</span><span style="color: #D8DEE9">mode</span><span style="color: #D8DEE9FF"> </span><span style="color: #81A1C1">=</span><span style="color: #D8DEE9FF"> </span><span style="color: #B48EAD">0</span><span style="color: #ECEFF4">,</span><span style="color: #D8DEE9FF"> </span><span style="color: #D8DEE9">min</span><span style="color: #D8DEE9FF"> </span><span style="color: #81A1C1">=</span><span style="color: #D8DEE9FF"> </span><span style="color: #B48EAD">0</span><span style="color: #ECEFF4">,</span><span style="color: #D8DEE9FF"> </span><span style="color: #D8DEE9">max</span><span style="color: #D8DEE9FF"> </span><span style="color: #81A1C1">=</span><span style="color: #D8DEE9FF"> </span><span style="color: #B48EAD">100000</span><span style="color: #ECEFF4">,</span><span style="color: #D8DEE9FF"> </span><span style="color: #D8DEE9">x1</span><span style="color: #D8DEE9FF"> </span><span style="color: #81A1C1">=</span><span style="color: #D8DEE9FF"> </span><span style="color: #B48EAD">111</span><span style="color: #ECEFF4">,</span><span style="color: #D8DEE9FF"> </span><span style="color: #D8DEE9">x2</span><span style="color: #D8DEE9FF"> </span><span style="color: #81A1C1">=</span><span style="color: #D8DEE9FF"> </span><span style="color: #81A1C1">-</span><span style="color: #B48EAD">32766</span><span style="color: #81A1C1">}</span></span>
<span class="line"><span style="color: #D8DEE9FF">(gdb) print (int)&amp;b</span></span>
<span class="line"><span style="color: #D8DEE9FF">$10 = -13872</span></span>
<span class="line"><span style="color: #D8DEE9FF">(gdb) print &amp;b</span></span>
<span class="line"><span style="color: #D8DEE9FF">$11 = (struct _send_msg_box *) 0x7fffffffc9d0</span></span>
<span class="line"></span></code></pre></div>



<h2 class="wp-block-heading">7. Root cause</h2>



<p>We took a valid pointer:</p>



<pre class="wp-block-code"><code>0x7fffffffc9d0</code></pre>



<p>and did this:</p>



<pre class="wp-block-code"><code>(int)&amp;b</code></pre>



<p>On a 64-bit system:</p>



<ul class="wp-block-list">
<li>pointers = 64 bits</li>



<li><code>int</code> = 32 bits</li>
</ul>



<p>So we truncate the pointer, keeping only the low 32 bits:</p>



<pre class="wp-block-code"><code>0x7fffffffc9d0 -&gt; 0x0000c9d0 -&gt; -13872</code></pre>



<p>Later, it gets cast back to a pointer:</p>



<pre class="wp-block-code"><code>(struct _send_msg_box *)a</code></pre>



<p>Which becomes:</p>



<pre class="wp-block-code"><code>0xffffffffffffc9d0   </code></pre>



<p>Then we dereference it:</p>



<pre class="wp-block-code"><code>b-&gt;mode</code></pre>



<p>Segmentation fault</p>



<h2 class="wp-block-heading">8. The Fix</h2>



<p>The correct solution is to use a type that can safely hold a pointer. After a bit of reading I found that the correct way to do this is with intptr_t:</p>



<div class="wp-block-kevinbatdorf-code-block-pro" data-code-block-pro-font-family="Code-Pro-JetBrains-Mono" style="font-size:clamp(14px, .875rem, 21px);font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:clamp(20px, 1.25rem, 30px);--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)"><span role="button" tabindex="0" style="color:#d8dee9ff;display:none" aria-label="Copy" class="code-block-pro-copy-button"><pre class="code-block-pro-copy-button-pre" aria-hidden="true"><textarea class="code-block-pro-copy-button-textarea" tabindex="-1" aria-hidden="true" readonly="">#include &lt;stdint.h&gt;
intptr_t arg;</textarea></pre><svg xmlns="http://www.w3.org/2000/svg" style="width:24px;height:24px" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2"><path class="with-check" stroke-linecap="round" stroke-linejoin="round" d="M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4"></path><path class="without-check" stroke-linecap="round" stroke-linejoin="round" d="M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2"></path></svg></span><pre class="shiki nord" style="background-color: #2e3440ff" tabindex="0"><code><span class="line"><span style="color: #D8DEE9FF">#</span><span style="color: #D8DEE9">include</span><span style="color: #D8DEE9FF"> </span><span style="color: #81A1C1">&lt;</span><span style="color: #D8DEE9">stdint</span><span style="color: #ECEFF4">.</span><span style="color: #D8DEE9">h</span><span style="color: #81A1C1">&gt;</span></span>
<span class="line"><span style="color: #D8DEE9">intptr_t</span><span style="color: #D8DEE9FF"> </span><span style="color: #D8DEE9">arg</span><span style="color: #81A1C1">;</span></span></code></pre></div>



<p>Update the function signatures:</p>



<div class="wp-block-kevinbatdorf-code-block-pro" data-code-block-pro-font-family="Code-Pro-JetBrains-Mono" style="font-size:clamp(14px, .875rem, 21px);font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:clamp(20px, 1.25rem, 30px);--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)"><span role="button" tabindex="0" style="color:#d8dee9ff;display:none" aria-label="Copy" class="code-block-pro-copy-button"><pre class="code-block-pro-copy-button-pre" aria-hidden="true"><textarea class="code-block-pro-copy-button-textarea" tabindex="-1" aria-hidden="true" readonly="">char *check_send_msg(int plx, intptr_t a, char *t)
{
  struct _send_msg_box *b = (struct _send_msg_box *)a;
  ...
}</textarea></pre><svg xmlns="http://www.w3.org/2000/svg" style="width:24px;height:24px" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2"><path class="with-check" stroke-linecap="round" stroke-linejoin="round" d="M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4"></path><path class="without-check" stroke-linecap="round" stroke-linejoin="round" d="M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2"></path></svg></span><pre class="shiki nord" style="background-color: #2e3440ff" tabindex="0"><code><span class="line"><span style="color: #D8DEE9">char</span><span style="color: #D8DEE9FF"> </span><span style="color: #81A1C1">*</span><span style="color: #88C0D0">check_send_msg</span><span style="color: #D8DEE9FF">(</span><span style="color: #D8DEE9">int</span><span style="color: #D8DEE9FF"> </span><span style="color: #D8DEE9">plx</span><span style="color: #ECEFF4">,</span><span style="color: #D8DEE9FF"> </span><span style="color: #D8DEE9">intptr_t</span><span style="color: #D8DEE9FF"> </span><span style="color: #D8DEE9">a</span><span style="color: #ECEFF4">,</span><span style="color: #D8DEE9FF"> </span><span style="color: #D8DEE9">char</span><span style="color: #D8DEE9FF"> </span><span style="color: #81A1C1">*</span><span style="color: #D8DEE9">t</span><span style="color: #D8DEE9FF">)</span></span>
<span class="line"><span style="color: #ECEFF4">{</span></span>
<span class="line"><span style="color: #D8DEE9FF">  </span><span style="color: #D8DEE9">struct</span><span style="color: #D8DEE9FF"> </span><span style="color: #D8DEE9">_send_msg_box</span><span style="color: #D8DEE9FF"> </span><span style="color: #81A1C1">*</span><span style="color: #D8DEE9">b</span><span style="color: #D8DEE9FF"> </span><span style="color: #81A1C1">=</span><span style="color: #D8DEE9FF"> (</span><span style="color: #D8DEE9">struct</span><span style="color: #D8DEE9FF"> </span><span style="color: #D8DEE9">_send_msg_box</span><span style="color: #D8DEE9FF"> </span><span style="color: #81A1C1">*</span><span style="color: #D8DEE9FF">)</span><span style="color: #D8DEE9">a</span><span style="color: #81A1C1">;</span></span>
<span class="line"><span style="color: #D8DEE9FF">  </span><span style="color: #81A1C1">...</span></span>
<span class="line"><span style="color: #ECEFF4">}</span></span></code></pre></div>



<div class="wp-block-kevinbatdorf-code-block-pro" data-code-block-pro-font-family="Code-Pro-JetBrains-Mono" style="font-size:clamp(14px, .875rem, 21px);font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:clamp(20px, 1.25rem, 30px);--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)"><span role="button" tabindex="0" style="color:#d8dee9ff;display:none" aria-label="Copy" class="code-block-pro-copy-button"><pre class="code-block-pro-copy-button-pre" aria-hidden="true"><textarea class="code-block-pro-copy-button-textarea" tabindex="-1" aria-hidden="true" readonly="">void send_g_msg(..., intptr_t arg, ...)</textarea></pre><svg xmlns="http://www.w3.org/2000/svg" style="width:24px;height:24px" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2"><path class="with-check" stroke-linecap="round" stroke-linejoin="round" d="M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4"></path><path class="without-check" stroke-linecap="round" stroke-linejoin="round" d="M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2"></path></svg></span><pre class="shiki nord" style="background-color: #2e3440ff" tabindex="0"><code><span class="line"><span style="color: #81A1C1">void</span><span style="color: #D8DEE9FF"> </span><span style="color: #88C0D0">send_g_msg</span><span style="color: #D8DEE9FF">(</span><span style="color: #81A1C1">...</span><span style="color: #ECEFF4">,</span><span style="color: #D8DEE9FF"> </span><span style="color: #D8DEE9">intptr_t</span><span style="color: #D8DEE9FF"> </span><span style="color: #D8DEE9">arg</span><span style="color: #ECEFF4">,</span><span style="color: #D8DEE9FF"> </span><span style="color: #81A1C1">...</span><span style="color: #D8DEE9FF">)</span></span></code></pre></div>



<p>And call it like:</p>



<div class="wp-block-kevinbatdorf-code-block-pro" data-code-block-pro-font-family="Code-Pro-JetBrains-Mono" style="font-size:clamp(14px, .875rem, 21px);font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:clamp(20px, 1.25rem, 30px);--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)"><span role="button" tabindex="0" style="color:#d8dee9ff;display:none" aria-label="Copy" class="code-block-pro-copy-button"><pre class="code-block-pro-copy-button-pre" aria-hidden="true"><textarea class="code-block-pro-copy-button-textarea" tabindex="-1" aria-hidden="true" readonly="">send_g_msg(destination, check_send_msg, (intptr_t)&amp;b, bf);</textarea></pre><svg xmlns="http://www.w3.org/2000/svg" style="width:24px;height:24px" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2"><path class="with-check" stroke-linecap="round" stroke-linejoin="round" d="M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4"></path><path class="without-check" stroke-linecap="round" stroke-linejoin="round" d="M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2"></path></svg></span><pre class="shiki nord" style="background-color: #2e3440ff" tabindex="0"><code><span class="line"><span style="color: #88C0D0">send_g_msg</span><span style="color: #D8DEE9FF">(</span><span style="color: #D8DEE9">destination</span><span style="color: #ECEFF4">,</span><span style="color: #D8DEE9FF"> </span><span style="color: #D8DEE9">check_send_msg</span><span style="color: #ECEFF4">,</span><span style="color: #D8DEE9FF"> (</span><span style="color: #D8DEE9">intptr_t</span><span style="color: #D8DEE9FF">)</span><span style="color: #81A1C1">&amp;</span><span style="color: #D8DEE9">b</span><span style="color: #ECEFF4">,</span><span style="color: #D8DEE9FF"> </span><span style="color: #D8DEE9">bf</span><span style="color: #D8DEE9FF">)</span><span style="color: #81A1C1">;</span></span></code></pre></div>



<p>My changeset for this is at <a href="https://github.com/albertw/dirt/commit/94ec62c63e144920a04ca2e7e4290e04d0ee0319">https://github.com/albertw/dirt/commit/94ec62c63e144920a04ca2e7e4290e04d0ee0319</a></p>



<h2 class="wp-block-heading">9. Verify the fix</h2>



<p>We can just run the mud and see that it doesn’t segfault, but a little better is to run it in gdb, set a breakpoint, and inspect that we have the right values now:</p>



<div class="wp-block-kevinbatdorf-code-block-pro" data-code-block-pro-font-family="Code-Pro-JetBrains-Mono" style="font-size:clamp(14px, .875rem, 21px);font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:clamp(20px, 1.25rem, 30px);--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)"><span role="button" tabindex="0" style="color:#d8dee9ff;display:none" aria-label="Copy" class="code-block-pro-copy-button"><pre class="code-block-pro-copy-button-pre" aria-hidden="true"><textarea class="code-block-pro-copy-button-textarea" tabindex="-1" aria-hidden="true" readonly="">gdb) break check_send_msg&lt;br&gt;Breakpoint 1 at 0x426e6b: file sendsys.c, line 170.
(gdb) run
.
.
.
Breakpoint 1, check_send_msg (plx=plx@entry=111, a=a@entry=140737488341456, t=t@entry=0x7fffffffd1f0 "The Thief has gone west.\n") at sendsys.c:170&lt;br&gt;170 {&lt;br&gt;
(gdb) p a
$1 = 140737488341456
(gdb) p/x a
$2 = 0x7fffffffc9d0
(gdb) p *(struct _send_msg_box *)a&lt;br&gt;$3 = {mode = 0, min = 0, max = 100000, x1 = 114, x2 = -32766}</textarea></pre><svg xmlns="http://www.w3.org/2000/svg" style="width:24px;height:24px" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2"><path class="with-check" stroke-linecap="round" stroke-linejoin="round" d="M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4"></path><path class="without-check" stroke-linecap="round" stroke-linejoin="round" d="M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2"></path></svg></span><pre class="shiki nord" style="background-color: #2e3440ff" tabindex="0"><code><span class="line"><span style="color: #D8DEE9">gdb</span><span style="color: #D8DEE9FF">) </span><span style="color: #81A1C1">break</span><span style="color: #D8DEE9FF"> check_send_msg</span><span style="color: #81A1C1">&lt;</span><span style="color: #D8DEE9">br</span><span style="color: #81A1C1">&gt;</span><span style="color: #D8DEE9">Breakpoint</span><span style="color: #D8DEE9FF"> </span><span style="color: #B48EAD">1</span><span style="color: #D8DEE9FF"> </span><span style="color: #D8DEE9">at</span><span style="color: #D8DEE9FF"> </span><span style="color: #B48EAD">0x426e6b</span><span style="color: #D8DEE9FF">: </span><span style="color: #D8DEE9">file</span><span style="color: #D8DEE9FF"> </span><span style="color: #D8DEE9">sendsys</span><span style="color: #ECEFF4">.</span><span style="color: #D8DEE9">c</span><span style="color: #ECEFF4">,</span><span style="color: #D8DEE9FF"> </span><span style="color: #D8DEE9">line</span><span style="color: #D8DEE9FF"> </span><span style="color: #B48EAD">170.</span></span>
<span class="line"><span style="color: #D8DEE9FF">(</span><span style="color: #D8DEE9">gdb</span><span style="color: #D8DEE9FF">) </span><span style="color: #D8DEE9">run</span></span>
<span class="line"><span style="color: #ECEFF4">.</span></span>
<span class="line"><span style="color: #ECEFF4">.</span></span>
<span class="line"><span style="color: #ECEFF4">.</span></span>
<span class="line"><span style="color: #D8DEE9">Breakpoint</span><span style="color: #D8DEE9FF"> </span><span style="color: #B48EAD">1</span><span style="color: #ECEFF4">,</span><span style="color: #D8DEE9FF"> </span><span style="color: #88C0D0">check_send_msg</span><span style="color: #D8DEE9FF"> (</span><span style="color: #D8DEE9">plx</span><span style="color: #81A1C1">=</span><span style="color: #D8DEE9">plx</span><span style="color: #D8DEE9FF">@</span><span style="color: #D8DEE9">entry</span><span style="color: #81A1C1">=</span><span style="color: #B48EAD">111</span><span style="color: #ECEFF4">,</span><span style="color: #D8DEE9FF"> </span><span style="color: #D8DEE9">a</span><span style="color: #81A1C1">=</span><span style="color: #D8DEE9">a</span><span style="color: #D8DEE9FF">@</span><span style="color: #D8DEE9">entry</span><span style="color: #81A1C1">=</span><span style="color: #B48EAD">140737488341456</span><span style="color: #ECEFF4">,</span><span style="color: #D8DEE9FF"> </span><span style="color: #D8DEE9">t</span><span style="color: #81A1C1">=</span><span style="color: #D8DEE9">t</span><span style="color: #D8DEE9FF">@</span><span style="color: #D8DEE9">entry</span><span style="color: #81A1C1">=</span><span style="color: #B48EAD">0x7fffffffd1f0</span><span style="color: #D8DEE9FF"> </span><span style="color: #ECEFF4">"</span><span style="color: #A3BE8C">The Thief has gone west.</span><span style="color: #EBCB8B">\n</span><span style="color: #ECEFF4">"</span><span style="color: #D8DEE9FF">) </span><span style="color: #D8DEE9">at</span><span style="color: #D8DEE9FF"> </span><span style="color: #D8DEE9">sendsys</span><span style="color: #ECEFF4">.</span><span style="color: #D8DEE9">c</span><span style="color: #D8DEE9FF">:</span><span style="color: #B48EAD">170</span><span style="color: #81A1C1">&lt;</span><span style="color: #D8DEE9">br</span><span style="color: #81A1C1">&gt;</span><span style="color: #B48EAD">170</span><span style="color: #D8DEE9FF"> </span><span style="color: #ECEFF4">{</span><span style="color: #81A1C1">&lt;br&gt;</span></span>
<span class="line"><span style="color: #D8DEE9FF">(gdb) p a</span></span>
<span class="line"><span style="color: #D8DEE9FF">$1 = 140737488341456</span></span>
<span class="line"><span style="color: #D8DEE9FF">(gdb) p/x a</span></span>
<span class="line"><span style="color: #D8DEE9FF">$2 = 0x7fffffffc9d0</span></span>
<span class="line"><span style="color: #D8DEE9FF">(gdb) p *(struct _send_msg_box *)a</span><span style="color: #81A1C1">&lt;br&gt;</span><span style="color: #D8DEE9FF">$3 = </span><span style="color: #81A1C1">{</span><span style="color: #D8DEE9">mode</span><span style="color: #D8DEE9FF"> </span><span style="color: #81A1C1">=</span><span style="color: #D8DEE9FF"> </span><span style="color: #B48EAD">0</span><span style="color: #ECEFF4">,</span><span style="color: #D8DEE9FF"> </span><span style="color: #D8DEE9">min</span><span style="color: #D8DEE9FF"> </span><span style="color: #81A1C1">=</span><span style="color: #D8DEE9FF"> </span><span style="color: #B48EAD">0</span><span style="color: #ECEFF4">,</span><span style="color: #D8DEE9FF"> </span><span style="color: #D8DEE9">max</span><span style="color: #D8DEE9FF"> </span><span style="color: #81A1C1">=</span><span style="color: #D8DEE9FF"> </span><span style="color: #B48EAD">100000</span><span style="color: #ECEFF4">,</span><span style="color: #D8DEE9FF"> </span><span style="color: #D8DEE9">x1</span><span style="color: #D8DEE9FF"> </span><span style="color: #81A1C1">=</span><span style="color: #D8DEE9FF"> </span><span style="color: #B48EAD">114</span><span style="color: #ECEFF4">,</span><span style="color: #D8DEE9FF"> </span><span style="color: #D8DEE9">x2</span><span style="color: #D8DEE9FF"> </span><span style="color: #81A1C1">=</span><span style="color: #D8DEE9FF"> </span><span style="color: #81A1C1">-</span><span style="color: #B48EAD">32766</span><span style="color: #81A1C1">}</span></span></code></pre></div>



<p>This is a classic example of why legacy C code that ‘worked fine’ on 32-bit systems can fail in subtle ways on modern architectures, and why types matter more than they seem.</p>



<p></p>]]></content:encoded>
    </item>
    <item>
      <title>We Had Online Multiplayer Gaming in the 1990s – And I’ve got one of those worlds working again!</title>
      <link>https://www.cademuir.eu/blog/2026/04/02/we-had-online-multiplayer-gaming-in-the-1990s-and-ive-got-one-of-those-worlds-working-again/</link>
      <pubDate>Thu, 02 Apr 2026 16:08:07 GMT</pubDate>
      <dc:creator><![CDATA[albertw]]></dc:creator>
      <category><![CDATA[computing]]></category>
      <category domain="post_tag"><![CDATA[C]]></category>
      <category domain="post_tag"><![CDATA[gaming]]></category>
      <category domain="post_tag"><![CDATA[MUD]]></category>
      <guid isPermaLink="false">https://www.cademuir.eu/blog/2026/04/02/we-had-online-multiplayer-gaming-in-the-1990s-and-ive-got-one-of-those-worlds-working-again/</guid>
      <description><![CDATA[<p>It may come as a surprise to some, but online multiplayer gaming didn’t begin with World of Warcraft or even EverQuest. Back in the 1990s, long before broadband and GPUs were household staples, we had Multi‑User Dungeons – MUDs. These were text‑based online worlds you connected to over telnet, and they came in all flavours: social hangouts, Dungeons &amp; Dragons–inspired adventures, exploration‑heavy quest worlds, and everything in between. One of the most beloved of these</p>]]></description>
      <content:encoded><![CDATA[<p>It may come as a surprise to some, but online multiplayer gaming didn’t begin with World of Warcraft or even EverQuest. Back in the 1990s, long before broadband and GPUs were household staples, we had <em>Multi‑User Dungeons</em> – MUDs. These were text‑based online worlds you connected to over telnet, and they came in all flavours: social hangouts, Dungeons &amp; Dragons–inspired adventures, exploration‑heavy quest worlds, and everything in between.</p>



<p>One of the most beloved of these for my uni group was Northern Lights, hosted originally at the Computer Society of Luleå University of Technology in Sweden (alber.ludd.luth.se 6715!). It later moved under the care of its founder, Anna “Vitastjern” Eklund. Sadly, a catastrophic server failure a few years ago destroyed the world and its source code. As Anna wrote in a recent facebook message:</p>



<blockquote class="wp-block-quote is-layout-flow wp-block-quote-is-layout-flow">
<p>I’m sorry, the source code is not available due to the catastrophic failure of the server. Furthermore I promised the authors of quite a few NL‑specific zones to never give them out, so I am against people reverse engineering them without the authors’ consent.</p>



<p>If you get hold of the base dirt3 source code that NL and other MUDs were built on, please have fun with it, but make it your own work and place.</p>



<p>NL existed for 31+ years. Let it rest now.</p>
</blockquote>



<p>For many of us, NL was a formative part of early online life. And for me, it also brought back memories of Eiru, a MUD based on the same codebase that I ran in UCD Netsoc in the late ’90s. That world, too, has long since vanished.</p>



<p>But the story doesn’t end there.</p>



<p>A few weeks ago, I got in touch with Amy Antonucci via Facebook. She was still in touch with Alf Salte, the original author of the Dirt MUD engine, itself descended from AberMUD (a rabbit hole for another day). Alf still had the original Dirt source code and gave permission for it to be made public again.</p>



<p>So after more than 30 years, the code that seeded Northern Lights, Eiru, and countless other MUDs is available on github.</p>



<p>This codebase hasn’t been touched since 1994, so getting it running again has been… educational. Let’s just say I’ve become reacquainted with <code>gdb</code>. I’ll write more about those adventures in future posts.</p>



<p>For now, though, I’m happy to share that the Dirt MUD engine, complete with zone files, is on GitHub: <a href="https://github.com/albertw/dirt">https://github.com/albertw/dirt</a></p>



<p>If you’re interested in retro gaming, game history, or just want to poke around a piece of online‑gaming archaeology, have a look. Bug reports, fixes, and pull requests are very welcome. And if anyone out there has old patches, zone files, or stories from the Dirt lineage, I’d love to include them.</p>



<p></p>



<p></p>



<p></p>



<p></p>



<p></p>]]></content:encoded>
    </item>
    <item>
      <title>Building with AI: Lessons from Devloping a Django App with Claude</title>
      <link>https://www.cademuir.eu/blog/2026/02/17/building-with-ai-lessons-from-developing-a-django-app-with-claude/</link>
      <pubDate>Tue, 17 Feb 2026 22:18:59 GMT</pubDate>
      <dc:creator><![CDATA[albertw]]></dc:creator>
      <category><![CDATA[computing]]></category>
      <category domain="post_tag"><![CDATA[AI]]></category>
      <category domain="post_tag"><![CDATA[Claude]]></category>
      <category domain="post_tag"><![CDATA[django]]></category>
      <category domain="post_tag"><![CDATA[python]]></category>
      <guid isPermaLink="false">https://www.cademuir.eu/blog/2026/02/17/building-with-ai-lessons-from-developing-a-django-app-with-claude/</guid>
      <description><![CDATA[<p>I’ve recently been exploring AI-assisted development, specifically using Claude to build a Django-based inventory management application for scout and youth groups. So how did it go? In a couple of weeks of part-time work, I built and deployed a functional MVP to production: www.armaria.club (app.armaria.club). Here are my key takeaways. These aren’t universal rules, just what worked well for me while developing a real application with AI assistance. I’m also very aware that with the</p>]]></description>
      <content:encoded><![CDATA[<p>I’ve recently been exploring AI-assisted development, specifically using Claude to build a Django-based inventory management application for scout and youth groups.</p>



<p>So how did it go? In a couple of weeks of part-time work, I built and deployed a functional MVP to production:<a href="http://www.armaria.club"> www.armaria.club</a> (app.armaria.club). Here are my key takeaways. These aren’t universal rules, just what worked well for me while developing a real application with AI assistance. I’m also very aware that with the current pace of AI assisted tools this will probably be out of date before I post it! 🙂</p>



<p>I’m late to this party – AI-assisted coding has been evolving rapidly over the past few years. But what I’m noticing is that many senior engineers are only starting to engage deeply with AI assistance recently. If that trend is representative across the industry, it means many architects, designers, QA engineers, and software leads are only beginning their AI journey. And we’re only beginning to see the impact of AI across the software development lifecycle.</p>



<p>I’ve experimented with ChatGPT and Claude before on programming tasks and learning exercises, but this was my first time building a production application with AI assistance. I chose Django because it’s a framework I used extensively at Oracle and know well. I assumed I’d be better positioned to review Claude’s design decisions and code changes if I deeply understood the framework. My expectation is that AI assistance works best with greenfield or well-understood codebases – I haven’t yet tried using it extensively with mature legacy code.</p>



<p>I used Claude via a z.ai subscription <a href="https://z.ai/subscribe?ic=HI1H8NMTBC">https://z.ai/subscribe?ic=HI1H8NMTBC</a> (referral link)</p>



<h2 class="wp-block-heading"><strong>1. Refine the Idea (Write a PRD)</strong></h2>



<p>This might seem old-school, but step away from the laptop, grab a coffee, and write down what your app needs to do. Create an initial Product Requirements Document (PRD). Ask yourself:</p>



<ul class="wp-block-list">
<li>What problem are you trying to solve?</li>



<li>Who are the target users?</li>



<li>What are the core concepts within the app?</li>



<li>What are the goals?</li>



<li>What’s the core functionality needed for version 1?</li>



<li>What’s out of scope now but planned for the future?</li>



<li>What are your security requirements?</li>



<li>What are your technical constraints?</li>



<li>Do you have any guiding principles?</li>
</ul>



<p><strong>Share this with your AI</strong>—it becomes your source of truth for requirements and informs your technical instructions (your claude.md file).</p>



<h2 class="wp-block-heading"><strong>2. Plan (Use Claude’s Planning Features)</strong></h2>



<p>Use Claude to discuss and develop a plan for each feature. I found it helpful to:</p>



<ul class="wp-block-list">
<li>Use multiple models as independent reviewers. This reduces blind spots and often surfaces alternative architectural approaches.</li>



<li>Discuss ideas with ChatGPT first to formulate detailed prompts for Claude.</li>



<li>Use this exploration phase to clarify what you actually want to achieve.</li>
</ul>



<p>I found ‘arguing’ with Claude useful here. Explain why you are taking this approach. What alternative approaches could we take? What could go wrong? What if a user did X?</p>



<p>AI output is non-deterministic. Saving prompts, architecture decisions, and generated code history becomes critical for reproducibility and traceability.</p>



<h2 class="wp-block-heading"><strong>3. Break Down Implementation</strong></h2>



<p>Once you know what you want to accomplish, have Claude break it down into implementation steps that you can understand and review. <strong>This is crucial</strong>—you need to be able to verify each step makes sense before code is written.</p>



<p>As with the broader planning stage, ask Claude why it’s suggesting particular approaches.</p>



<h2 class="wp-block-heading"><strong>4. Small, Frequent Commits</strong></h2>



<p>Once you’re happy with the plan and steps, <strong>commit each step</strong> rather than waiting to commit a massive changeset. This is for your benefit so you can understand the changes.</p>



<p>I had cases where a seemingly small change – like adding additional flags to a user model – resulted in Claude suggesting a total model rewrite. You can spot these overreaches when working with small changesets and roll back easily. But you need to actually look at the diff.</p>



<p>I use git and a private repo on GitHub. Give meaningful commit messages. I didn’t use branches but might in future.</p>



<h2 class="wp-block-heading"><strong>5. Test-Driven Development</strong></h2>



<p>I fell into the old trap of writing tests after finding bugs. <strong>Tell Claude (in your </strong><strong>claude.md</strong><strong>) to create tests before implementing plan stages</strong>. The tests won’t be perfect initially and will need fixing, but you’ll quickly build up a bank of regression tests.</p>



<p>You don’t need to implement Selenium or Playwright initially—regular unit and integration tests within your framework will do just fine.</p>



<p>For Django, start with model tests, then view/API tests. Ensure you have the key data and paths covered, full coverage and complex tests can come later.</p>



<p>Also, you may need to remind your AI assistant to run the tests from time to time!</p>



<h2 class="wp-block-heading"><strong>6. Protect Your Tests</strong></h2>



<p>When implementing a new feature, <strong>tell Claude not to “fix” existing tests during development</strong>. Claude will happily change a failing test to match its latest hallucination if you let it! Treat test changes as a red flag, you want to understand why a change is being made before accepting it.</p>



<h2 class="wp-block-heading"><strong>7. Use Your App</strong></h2>



<p>This sounds obvious, but <strong>actually use your application</strong> as outlined in your PRD. You’ll find many things that need tweaking, and it’s much easier to iterate during the implementation phase than to do big changes later.</p>



<p>Test on different browsers and devices. Have someone else try it. Make a list of bugs/features and iterate through them.</p>



<h2 class="wp-block-heading"><strong>What I Wish I’d Known</strong></h2>



<p><strong>The claude.md File Is Critical</strong></p>



<p>Create a claude.md file at the start with:</p>



<ul class="wp-block-list">
<li>Your tech stack and versions</li>



<li>Coding standards and preferences</li>



<li>What NOT to do (this is as important as what to do)</li>



<li>Testing requirements</li>



<li>Common patterns you want followed</li>
</ul>



<p>Update it as you learn what works and what doesn’t.</p>



<p><strong>Know When to Step In</strong></p>



<p>AI is a tool, not a replacement for engineering judgment. In particular, step in when:</p>



<ul class="wp-block-list">
<li>The solution seems overly complex</li>



<li>Security-sensitive code is being written</li>



<li>The AI keeps going in circles on a problem</li>
</ul>



<p>Sometimes the fastest path is to write it yourself and move on.</p>



<p><strong>Deploy Often</strong></p>



<p>Don’t wait for perfection. I deployed to production in a couple of days with basic functionality. This:</p>



<ul class="wp-block-list">
<li>Forced me to set up proper CI/CD early (which deserves its own future blog post)</li>



<li>Revealed deployment issues immediately</li>



<li>Gave me a real environment to test in</li>



<li>Provided motivation to keep iterating.</li>
</ul>



<p><strong>Common Pitfalls I Encountered</strong></p>



<ul class="wp-block-list">
<li><strong>Over-engineering</strong>: Claude loves to suggest complex or enterprise patterns for simple problems. AI models are rarely short on confidence – but they are not always correct. Push back.&nbsp;</li>



<li><strong>Inconsistent styling: </strong>Without clear direction, Claude will use different patterns across files. Your claude.md should enforce consistency. I originally told Claude not to use Django signals. Later, I approved one legitimate use case. Claude immediately generalised that decision and started proposing signals everywhere. AI models are extremely quick to promote exceptions into rules unless you restate your constraints.</li>



<li><strong>Security assumptions</strong>: Don’t assume Claude knows your security requirements or best practices, be explicit about authentication, authorization, data validation, especially if building a multi-tenant system.</li>



<li><strong>Documentation drift</strong>: Claude-generated docstrings can become outdated quickly. Similarly, any documentation you ask Claude to write can quickly become dated.</li>
</ul>



<h2 class="wp-block-heading"><strong>Am I Still in the “Old Engineering Mindset”?</strong></h2>



<p>Am I still in the old engineering mindset, or even – <em>shudder</em> – waterfall development? Yes, to some extent, but I think this oversight is still necessary and proportionate.</p>



<p>Of course, this is all iterative. Whatever functionality you implement in a sprint may cause you to adjust future work. But I think this level of oversight over the AI assistant is appropriate.</p>



<p><strong>It also helps future you.</strong> I’ve certainly discovered code I wrote 10+ years ago still running in production that I had to re-understand! The practices above will make that easier – whether it’s future me or a future AI trying to make sense of it. My colleagues at Oracle will remember my frequent code review reminders to think about how “future you” will read today’s changes.</p>



<h2 class="wp-block-heading"><strong>Closing thoughts</strong></h2>



<p><strong>AI assistance amplifies both good and bad practices</strong>. If you have strong software engineering fundamentals – testing, version control, incremental development, clear requirements – AI will accelerate your work. If you skip the basics, AI will help you build a mess faster.</p>



<p>Experienced engineers entering AI-assisted development now have an advantage: we know what good software and process looks like. The challenge is teaching the AI our standards and staying disciplined about engineering practices even when the AI can generate code faster than we can review it.</p>



<p>The future isn’t “AI replaces developers” – it’s “developers who effectively collaborate with AI replace those who don’t.”</p>



<p>On a personal note, I’m now the Quartermaster for our Scout Group so will be using this tool to solve our actual inventory and maintenance needs. Get in touch and give it a try if you think it might help your group or club!</p>



<p></p>]]></content:encoded>
    </item>
    <item>
      <title>17th Dalkey Scouts</title>
      <link>https://www.cademuir.eu/blog/2022/05/25/17th-dalkey-scouts/</link>
      <pubDate>Wed, 25 May 2022 12:14:04 GMT</pubDate>
      <dc:creator><![CDATA[albertw]]></dc:creator>
      <category><![CDATA[General]]></category>
      
      <guid isPermaLink="false">https://www.cademuir.eu/blog/2022/05/25/17th-dalkey-scouts/</guid>
      <description><![CDATA[<p>I’m helping getting the 17th Dalkey Scouts back up and running. Initially for Beavers and Cubs but we’ll get to Scouts as well in a year or two! Check out www.dalkeyscouts.ie and https://www.facebook.com/17thDalkey for more!</p>]]></description>
      <content:encoded><![CDATA[<p>I’m helping getting the 17th Dalkey Scouts back up and running. Initially for Beavers and Cubs but we’ll get to Scouts as well in a year or two!</p>



<p>Check out <a href="http://www.dalkeyscouts.ie">www.dalkeyscouts.ie</a> and <a href="https://www.facebook.com/17thDalkey">https://www.facebook.com/17thDalkey</a> for more!</p>



<p></p>]]></content:encoded>
    </item>
    <item>
      <title>Choosing a map for your adventures</title>
      <link>https://www.cademuir.eu/blog/2021/09/02/choosing-a-map/</link>
      <pubDate>Thu, 02 Sep 2021 22:39:00 GMT</pubDate>
      <dc:creator><![CDATA[albertw]]></dc:creator>
      <category><![CDATA[General]]></category>
      <category><![CDATA[Geocaching]]></category>
      <category><![CDATA[SOTA]]></category>
      <category domain="post_tag"><![CDATA[hiking]]></category>
      <category domain="post_tag"><![CDATA[maps]]></category>
      <guid isPermaLink="false">https://www.cademuir.eu/blog/2021/09/02/choosing-a-map/</guid>
      <description><![CDATA[<p>Choosing a map for an adventure is easy right? The standard map for hiking for many years has been the <a href="https://store.osi.ie/">Ordnance Survey</a> 1:50000 set of waterproof laminated maps which retail for about €25. More recently, though the company has apparently been inexistance for over 30 years, <a href="https://eastwestmapping.ie/">EastWest mapping</a> have produced €9.99 maps of specific areas of interest at a scale of 1:25000 and are water resistant. I am aware that the OS issue some 1:25000 maps but I don’t have one to compare with so here’s my thoughts on what map you should get out of the two I have.</p>]]></description>
      <content:encoded><![CDATA[<p>Choosing a map for an adventure is easy right? The standard map for hiking for many years has been the <a href="https://store.osi.ie/">Ordnance Survey</a> 1:50000 set of waterproof laminated maps which retail for about €25. More recently, though the company has apparently been inexistance for over 30 years, <a href="https://eastwestmapping.ie/">EastWest mapping</a> have produced €9.99 maps of specific areas of interest at a scale of 1:25000 and are water resistant. I am aware that the OS issue some 1:25000 maps but I don’t have one to compare with so here’s my thoughts on what map you should get out of the two I have.</p>



<span id="more-1660"></span>



<p>The most obvious difference is in the scale.  1:50000 gives you 1km in 2cm, whereas 1:25000 is double that at a kilometer for 4cm.  But what does EastWest do with the extra space and is it a useful use of space? Here’s a comparison of the two maps on a mountain in Mayo, both are dated 2015.</p>



<figure class="wp-block-image size-large"><img fetchpriority="high" decoding="async" width="1024" height="794" src="/blog/wp-content/uploads/mountain2-1024x794.png" alt="" class="wp-image-1662" srcset="/blog/wp-content/uploads/mountain2-1024x794.png 1024w, /blog/wp-content/uploads/mountain2-300x233.png 300w, /blog/wp-content/uploads/mountain2-768x595.png 768w, /blog/wp-content/uploads/mountain2-1536x1191.png 1536w, /blog/wp-content/uploads/mountain2-2048x1587.png 2048w" sizes="(max-width: 1024px) 100vw, 1024px"><figcaption>EastWest on the left; OS on the right (scaled to match the EW scale and relative size)</figcaption></figure>



<p>The contour lines are a good place to start with the similarities. They are almost identical as both maps use 10m differences with a thicker line every 50 and a change of base colour every 100.The lines are thinner on the OS map so you get the same number of lines, but the steep ground to the left of the 311 spot height is more pronounced on the OS map due to the scale.</p>



<p>But as you would expect the EastWest map does have more detail. We have names of specific points, locations of ‘intermittent streams’, cliffs explicitly marked, marshes and upland grazing indicated. The OS map does include spot heights but they aren’t really that useful. The spelling and lanuguage on the maps also differ; this may be down to the gaealtacht dialect or one using more local names for features; I’m not sure but I suspect EastWest have done more local research into placenames.</p>



<p>Taking a look at an town square kilometer we see similar differences:</p>



<figure class="wp-block-image size-large"><img decoding="async" width="852" height="426" src="/blog/wp-content/uploads/mul.png" alt="" class="wp-image-1663" srcset="/blog/wp-content/uploads/mul.png 852w, /blog/wp-content/uploads/mul-300x150.png 300w, /blog/wp-content/uploads/mul-768x384.png 768w" sizes="(max-width: 852px) 100vw, 852px"></figure>



<p>The EastWest Map can indicate smaller roads better and includes field boundaries along with more detail in general.</p>



<p>Which is better? I’ve always found the 1:50000 adequate for navigation, even on courses where I have to navigate by map and compass. Though the additional scale and information in the 1:25000 is nice. The scale wouldn’t be enough to push me either way.</p>



<p>The next point to consider is coverage. The EastWest map is two sided  with a map on each side. In the case of the Nephin maps that gives one side from mulranny up to ballycroy, and the other face from Ballycroy up to Bangor  Erris with a decent overlap. </p>



<figure class="wp-block-image size-large"><img decoding="async" width="400" height="463" src="/blog/wp-content/uploads/wild_nephin_regional-400x463-1.jpg" alt="" class="wp-image-1664" srcset="/blog/wp-content/uploads/wild_nephin_regional-400x463-1.jpg 400w, /blog/wp-content/uploads/wild_nephin_regional-400x463-1-259x300.jpg 259w" sizes="(max-width: 400px) 100vw, 400px"><figcaption>EastWest map coverage for Wild Nephin.</figcaption></figure>



<p>The OS maps on the other hand are divided up strictly along latitude and longitude and to cover the same area you need 4 maps! In some areas this works ok, you get most of Wicklow in Sheet 56 for example, but doesnt for the Wild Nephin National Park. The OS do cover more useful areas in their 1:25000 series but I don’t see one of those available for this national park yet. So which map will suit best depends on where you want to go; in the case of Wicklow you’ll need to get a couple of East west maps…</p>



<figure class="wp-block-image size-large"><img loading="lazy" decoding="async" width="360" height="366" src="/blog/wp-content/uploads/Screenshot-2021-08-31-at-23.20.24.png" alt="" class="wp-image-1665" srcset="/blog/wp-content/uploads/Screenshot-2021-08-31-at-23.20.24.png 360w, /blog/wp-content/uploads/Screenshot-2021-08-31-at-23.20.24-295x300.png 295w" sizes="auto, (max-width: 360px) 100vw, 360px"><figcaption>The OS map coverage</figcaption></figure>



<p>Lastly there’s the waterproofing. The OS maps come in either paper or fully laminated. The fully waterproof versions have never failed me, and they have been stuffed in bags, pockets, and been out in all weather. The East West maps however are printed on plastic and while this does give them some waterproofing they do not survive the abuse of being stuffed into pockets and bags. The EW web page does mention ‘fully encapsulated’ maps for some areas.</p>



<figure class="wp-block-image size-large"><img loading="lazy" decoding="async" width="420" height="450" src="/blog/wp-content/uploads/Screenshot-2021-08-31-at-23.26.12.png" alt="" class="wp-image-1666" srcset="/blog/wp-content/uploads/Screenshot-2021-08-31-at-23.26.12.png 420w, /blog/wp-content/uploads/Screenshot-2021-08-31-at-23.26.12-280x300.png 280w" sizes="auto, (max-width: 420px) 100vw, 420px"><figcaption>My EW map after being in my back pocket for 26km!</figcaption></figure>



<p>So when choosing a map which should you buy? It depends… Firstl figure out the are that you need a map or maps for obviously, then:</p>



<ol class="wp-block-list"><li>If you will be hiking or wild camping get a fully waterproof map. It’ll last longer and take more abuse.</li><li>If you can get fully waterproof maps from both then see how many maps you need. At up to €25 each you don’t want to have to buy too many of them!</li><li>Decide if the scale matters to you. This is related to point 2, but to me is an additional bonus rather than a requirement.</li></ol>



<p>For me then the next time I need a map I’d have no problem buying the fully waterproof maps from either EastWest mapping or the Ordnance Survey. What I buy will come down to the area covered. For Wicklow I think I’ll stick to the OS sheet 56 laminated edition, but for an extended trip in the Nephin Wilderness I’d get a fully waterproof EastWest mapping map if they have one available.</p>]]></content:encoded>
    </item>
    <item>
      <title>The simple things in Astrophotography</title>
      <link>https://www.cademuir.eu/blog/2021/09/01/taking-good-astronomy-photos/</link>
      <pubDate>Wed, 01 Sep 2021 18:31:00 GMT</pubDate>
      <dc:creator><![CDATA[albertw]]></dc:creator>
      <category><![CDATA[Astronomy]]></category>
      <category><![CDATA[Photography]]></category>
      <category domain="post_tag"><![CDATA[kerry]]></category>
      <category domain="post_tag"><![CDATA[light pollution]]></category>
      <guid isPermaLink="false">https://www.cademuir.eu/blog/2021/09/01/taking-good-astronomy-photos/</guid>
      <description><![CDATA[<p>How to take good astrophotography photos:</p>



<ol class="wp-block-list"><li> Go to <a href="https://www.kerrydarkskytourism.com/">Kerry International Dark Sky Reserve</a></li><li>Wander outside at night and take a photo with your camera.</li></ol>]]></description>
      <content:encoded><![CDATA[<p>How to take good astrophotography photos:</p>



<ol class="wp-block-list"><li> Go to <a href="https://www.kerrydarkskytourism.com/">Kerry International Dark Sky Reserve</a></li><li>Wander outside at night and take a photo with your camera.</li></ol>



<span id="more-1653"></span>



<p><br>This is a 30second exposure with my regular camera resting on a kitchen towel at the back door of the holiday home.<br><br>Sure, you can spend lots on filters and cameras and tracking mounts, and stack images and use noise reduciton in software etc. etc. But you really can’t beat a really dark sky.<br><br>And don’t believe that it’s all about cold dark winter nights either! This was at the end of july and the temperature outside was about 15 degrees!</p>



<figure class="wp-block-image size-large"><img fetchpriority="high" decoding="async" width="1024" height="683" src="/blog/wp-content/uploads/kerry-1024x683.jpg" alt="" class="wp-image-1654" srcset="/blog/wp-content/uploads/kerry-1024x683.jpg 1024w, /blog/wp-content/uploads/kerry-300x200.jpg 300w, /blog/wp-content/uploads/kerry-768x512.jpg 768w, /blog/wp-content/uploads/kerry-1536x1024.jpg 1536w, /blog/wp-content/uploads/kerry.jpg 1944w" sizes="(max-width: 1024px) 100vw, 1024px"></figure>



<p>(Fortuitous satellite btw, not a meteor!)</p>]]></content:encoded>
    </item>
    <item>
      <title>Slieve Carr</title>
      <link>https://www.cademuir.eu/blog/2021/08/31/reaching-slieve-carr-irelands-most-remote-mountain/</link>
      <pubDate>Tue, 31 Aug 2021 18:29:55 GMT</pubDate>
      <dc:creator><![CDATA[albertw]]></dc:creator>
      <category><![CDATA[General]]></category>
      <category><![CDATA[SOTA]]></category>
      <category domain="post_tag"><![CDATA[ireland]]></category>
      <category domain="post_tag"><![CDATA[Mayo]]></category>
      <category domain="post_tag"><![CDATA[slieve carr]]></category>
      <guid isPermaLink="false">https://www.cademuir.eu/blog/2021/08/31/reaching-slieve-carr-irelands-most-remote-mountain/</guid>
      <description><![CDATA[<p>Ever since I first got interested in <a href="https://www.sota.org.uk/">Summits On the Air</a>, one mountain in the west of Ireland has been calling me. In the Nephin range in Co. Mayo lies Slieve Carr. At 721m it is not even in the top 40 highest mountains in Ireland, but as it is often referred to as ‘the most remote mountain in Ireland’ it had remained un activated.</p>]]></description>
      <content:encoded><![CDATA[<p>Ever since I first got interested in <a href="https://www.sota.org.uk/">Summits On the Air</a>, one mountain in the west of Ireland has been calling me. In the Nephin range in Co. Mayo lies Slieve Carr. At 721m it is not even in the top 40 highest mountains in Ireland, but as it is often referred to as ‘the most remote mountain in Ireland’ it had remained un activated.</p>



<span id="more-1645"></span>



<p>Slieve Car along with Nephin Beg (activated for the first time only a few weeks ago by Shane G6WBS) are the two main summits in the Wild Nephin national park, an area that now comprises 11,000 hectares of blanket bog. The summits rise sharply from the bog and tower over 500m above the rest of the landscape.</p>



<p>Since the establishment of <a href="https://www.wildnephinnationalpark.ie/">Ballycroy National Park</a> in 1998 a lot of work has gone into making this remote landscape more accessible for visitors while still conserving it’s pristine dark skies, active blanket bog systems, and right flora and fauna. The area now has several marked trails, shelters and dark sky sites as part of the ‘<a href="https://www.mayodarkskypark.ie/">Mayo Dark Sky Park</a>’.</p>



<p>Yet Slieve Carr still manages to retain it’s remoteness. From the west a bóithrin off the N59 will give you access to the Bangor trail which you can follow to Tomashiffin Mountain and then approach Carr from the South. This is a 14km trip one way and was the route I was planning on taking a couple of years ago and doing the route over a couple of days, wild camping in the National Park. Covid ended that plan but I had some time on a family trip to try and make a quick day trip to the summit. A 28k round trip through a bog was too far, and a quick look at the map shows the North approach is mired by wet bogs with no apparent paths through them. If I was going to attempt this I would need to cheat as much as I could on the Eastern approach.</p>



<p>The east of the range is mainly covered in conifer forest, which does thankfully have some tracks running through it connecting&nbsp; the North East of the park, Altnabrocky bothy and Brogan Carroll Bothy with the road to Newport at Letterkeen. A quick check with some local guides confirmed that biking along these was possible and would take some time off my journey.</p>



<figure class="wp-block-image size-large"><img fetchpriority="high" decoding="async" width="1024" height="498" src="/blog/wp-content/uploads/spurs-1024x498.jpg" alt="" class="wp-image-1651" srcset="/blog/wp-content/uploads/spurs-1024x498.jpg 1024w, /blog/wp-content/uploads/spurs-300x146.jpg 300w, /blog/wp-content/uploads/spurs-768x373.jpg 768w, /blog/wp-content/uploads/spurs-1536x747.jpg 1536w, /blog/wp-content/uploads/spurs.jpg 2016w" sizes="(max-width: 1024px) 100vw, 1024px"><figcaption>Steep Spurs</figcaption></figure>



<p>So on Wednesday morning I got a lift to the park entrance near the farm at Altnabrocky Lodge. At the gate I was met with the expected covid warnings, along with ‘do not enter’ construction notices. I took these warning to be for the farm rather than the forest tracks, and ignored them, hopping on my bike and heading the 7km for the Altnabrocky shelter. At the shelter there is a steep track up another 1.5km or so to ‘the steps’ which gives you access from the forest to the mountain. From here your first task is to climb the knoll in front of you; it’s only 100m ascent but the lush grass, heather and moss makes it difficult. Walkers from other parts of the country may be familiar with seeing well-worn tracks into the mountains with obvious paths – there are none here, you find your own way. From that knoll you have a choice, you can head west, and south of the lake to ascend Corr na Binne, or take the route I choose to head northwest and take the spur north of Coire and nGarru lake. On paper this looks the less steep option, but there were times where I had to put the hiking poles away and climb up on all fours such was the steepness. The climb is worthwhile however as the views across the lakes to Nephin Beg are spectacular. After that the ascent to the main ridge and North to the summit felt easy! The summit itself is rocky with a large cairn, said to be the burial mound of Daithí a 5<sup>th</sup> century King of Connaught. The view from the summit is commanding. With the exception of Nehphin in the distance, Carr dominates the landscape and you feel yourself towering above the blanket bog below with the mountains of Achill island visible in the Atlantic and the summits of Donegal in the North. From the steps I’d travelled about 3.5k with about 500m elevation.</p>



<p>But it was time to get the radio out and I quickly set up the arrow antenna and connected it to my FT-65 handheld. Almost immediately I was chatting to Dermot EI7IX, with the best 2m DX being with Patsy EI9CUB 170km away in Cavan. Next up was Dave EI5IMB in Bundoran, and as I was starting to set up for HF I heard Padraic EI9JA in nearby Westport to get the 4 required QSO’s for the activation. For HF I used my trusty FT817 and linked dipole on 40m and 20m SSB. The bands seemed quiet but I got reports of strong QRM on both bands from European stations. 40m yielded 7 QSOs with the short skip getting mainly UK stations. 20m was better for DX getting over 1600km to stations in Sweden, but I didn’t quite manage to finish my QSO with a Bulgarian station which would have added another 1000km to the DX range.</p>



<p>However I did manage a summit-to-summit contact with Daniel, HB9IIO, who was on the summit of Mont Pèlerin near Lusanne in Switzerland.</p>



<figure class="wp-block-image size-large"><img decoding="async" width="498" height="1024" src="/blog/wp-content/uploads/20210825_104921-498x1024.jpg" alt="" class="wp-image-1646" srcset="/blog/wp-content/uploads/20210825_104921-498x1024.jpg 498w, /blog/wp-content/uploads/20210825_104921-146x300.jpg 146w, /blog/wp-content/uploads/20210825_104921-768x1580.jpg 768w, /blog/wp-content/uploads/20210825_104921-747x1536.jpg 747w, /blog/wp-content/uploads/20210825_104921-996x2048.jpg 996w, /blog/wp-content/uploads/20210825_104921-scaled.jpg 1245w" sizes="(max-width: 498px) 100vw, 498px"><figcaption>The Steps</figcaption></figure>



<p>At the sumit I met Ged from Terra Firma Ireland who was leading a small group up to Slieve Carr also. Ged and Georgia from Terra Firma Ireland had given me some really useful advice when planning this adventure so it was good to see him again on the summit.</p>



<p>I spent over an hour on the summit, but after eating the bligatory sandwiches and having a couple of mugs of tea it was time to descend. The uphill work was done, but the longest part of the journey lay ahead.</p>



<figure class="wp-block-image size-large"><img decoding="async" width="1024" height="498" src="/blog/wp-content/uploads/20210825_144303-1024x498.jpg" alt="" class="wp-image-1648" srcset="/blog/wp-content/uploads/20210825_144303-1024x498.jpg 1024w, /blog/wp-content/uploads/20210825_144303-300x146.jpg 300w, /blog/wp-content/uploads/20210825_144303-768x373.jpg 768w, /blog/wp-content/uploads/20210825_144303-1536x747.jpg 1536w, /blog/wp-content/uploads/20210825_144303-2048x996.jpg 2048w" sizes="(max-width: 1024px) 100vw, 1024px"><figcaption>Antenna at the summit looking towards Achill</figcaption></figure>



<p>I followed the same route back to ‘the steps’. The steep ascents on the spur that caused me problems on the way up caused my knees plenty of problems on the way down too. By the time I reached Coire na nGaru I was out of water so made a detour to the lake to relax and filter some more to keep me going. Back at ‘the steps’ I was sorry that I’d abandoned the bike in a ditch near the shelter, so another 1.6km walk beckoned. But it was mostly downhill so it wasn’t long before I was back at my bike and on my way. This time, on Ged’s advice, I headed south towards the Leterkeen Bothy, and most importantly it’s car park where I could be picked up. It was a long tiring cycle, but as Ged had promised it was mostly downhill. That 10k cycle added another hour and I was shattered when I got to the bothy.</p>



<p>All in all it was a 26km route. Far longer than I’m used to for activations but despite the soreness in my legs a couple of days later, it was worth it and I’m glad I got to mark Slieve Carr off the list of unactivated summits!</p>



<figure class="wp-block-image size-large"><img loading="lazy" decoding="async" width="1024" height="821" src="/blog/wp-content/uploads/track-1024x821.jpg" alt="" class="wp-image-1650" srcset="/blog/wp-content/uploads/track-1024x821.jpg 1024w, /blog/wp-content/uploads/track-300x240.jpg 300w, /blog/wp-content/uploads/track-768x615.jpg 768w, /blog/wp-content/uploads/track.jpg 1520w" sizes="auto, (max-width: 1024px) 100vw, 1024px"><figcaption>Garmin Track</figcaption></figure>



<p>If you are thinking of tackling Slieve Carr my route is probably the quickest and shortest route. But do check with local guides, and for this I can thoroughly recommend <a href="https://terrafirmaireland.com/">Terra Firma Ireland</a>, who can give you up to date local advice on access as well as arrange transport and bespoke guided hikes and adventures to meet your needs.</p>]]></content:encoded>
    </item>
  </channel>
</rss>
