title: How to fix 'Cannot assign requested address?'
body: <p>Both the IP address and Port are confirmed not used by <code>netstat -a -n.</code> When I use gdb and break in the method calling bind I see that the correct IP address and Port are being used along with a reasonable socket address length of 16. This is for a UDP Listener. The remote IP is static and read from a configuration file.</p>
  
  <p>This is the code,</p>
  
  <pre><code>void CSocket::Bind(IpEndPoint&amp; endPoint)
  {
      int bindResult = bind( socketHandle, endPoint.GetSockAddrPtr(), 
          endPoint.GetAddrLength());
      if(bindResult &lt; 0)
      {
          TRACE_ERROR("Failed to bind to socket. %s. IpAddress %s Port %d AddrLength %d",
              strerror(errno), endPoint.GetIpAddressString(), 
              ntohs(endPoint.GetPort()), endPoint.GetAddrLength());
  </code></pre>
  
  <p>this is from gdb,</p>
  
  <blockquote>
    <p>Breakpoint 1, CSocket::Bind (this=0x819fa24, ipAddress="192.0.2.77",
    port=4185) at Socket.cpp:126</p>
  </blockquote>
  
  <p>and this is the TRACE_ERROR from the code above</p>
  
  <blockquote>
    <p>ERROR: Failed to bind to socket. errno 99 (Cannot assign requested address).
    IpAddress 192.0.2.77 Port 4185 AddrLength 16</p>
  </blockquote>
  
  <p>I've been re-reading <a href="http://www.beej.us/guide/bgnet/output/html/singlepage/bgnet.html" rel="nofollow">Beej's Guide to Network Programming</a> but not finding a clue. This is UDP so a connection should not be required to bind. The firewall is off. Where else should I be looking?</p>