Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>When <code>accept()</code> returns <code>-1</code>, <code>errno</code> will be set to indicate what specific error occurred. Please call <code>perror("accept")</code> for an easy way to see what the error was, and update your question with the results.</p> <p>Also, please note that <code>accept()</code> must be called on a socket that has been:</p> <ul> <li>Created using the <code>socket()</code> call. (you should pass <code>PF_INET6</code> for the first argument of your socket to create an IPv6 protocol family socket)</li> <li>Bound, using <code>bind()</code> using a <code>struct sockaddr_in6</code> parameter as the 2nd parameter (with its <code>sin6_family</code> set to <code>AF_INET6</code> for IPv6 to indicate you will be binding to an IPv6 address). Remember to zero out the <code>sin6_zero</code> field first. One strategy would be to zero the entire sockaddr structure, which would set the IPv6 address to IN6ADDR_ANY, which means you would just have to set the port and the address family.</li> <li>Listening, by means of calling <code>listen()</code></li> </ul> <p>If you are still having trouble, post the code you have so far.</p> <p>If I had to guess (since you haven't posted any code), I think if it works with IPv4 and gets to the point where it can <code>accept()</code> a connection, but IPv6 connection <code>accept()</code> calls return <code>-1</code>, I think it's likely that you aren't passing <code>accept()</code> a large enough <code>struct sockaddr</code> for it to work.</p> <p>For example, the following code:</p> <pre><code>printf("sizeof(struct sockaddr_in) = %ld\n", sizeof(struct sockaddr_in)); printf("sizeof(struct sockaddr_in6) = %ld\n", sizeof(struct sockaddr_in6)); </code></pre> <p>Prints (on my system):</p> <pre><code>sizeof(struct sockaddr_in) = 16 sizeof(struct sockaddr_in6) = 28 </code></pre> <p>If you are only giving <code>accept()</code> enough room to write out an IPv4 address, it will fail when it accepts an IPv6 connection. Make sure you allocate either a <code>struct sockaddr_in6</code> or a <code>struct sockaddr storage</code>, and ensure the size argument is correct.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload