 <p>You have one serious problem here:</p> <pre><code>struct sockaddr_in *local = malloc(sizeof (struct sockaddr_in *)); </code></pre> <p>because you're just allocating the size of a pointer instead of the size of the struct itself.</p> <p>This should of course be:</p> <pre><code>struct sockaddr_in *local = malloc(sizeof (struct sockaddr_in)); </code></pre> <p><hr> Two more problems with the same variable in this line:</p> <pre><code> if (bind(s, (struct sockaddr *)&amp;local, sizeof(local)) &lt; 0) </code></pre> <p>This should be:</p> <pre><code> if (bind(s, (struct sockaddr *)local, sizeof(*local)) &lt; 0) </code></pre>