accept() always returns 204.204.204.204

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • TBass

    accept() always returns 204.204.204.204

    Hi,

    I wrote an app that accepts a client connection.

    [snip]
    SOCKADDR_IN sockAddrIn;
    unsigned int clientLen = sizeof( sockAddrIn );
    SOCKET conn = accept( m_Socket, (struct sockaddr *)&sockAddrIn,
    NULL );

    if ( conn == INVALID_SOCKET )
    {
    int errorno = WSAGetLastError ();
    if ( errorno != WSAEWOULDBLOCK )
    {
    return -1;
    }
    else
    {
    return false;
    }

    }
    else
    {

    CFusionSCK_Clie nt myclient(m_Conn Flags);

    myclient.Socket ( &conn );
    myclient.AddrIn ( &sockAddrIn );
    myclient.IPAddr ess( inet_ntoa( sockAddrIn.sin_ addr ) );
    myclient.Port( sockAddrIn.sin_ port );

    m_listClients.p ush_back( myclient );

    }

    return false;

    [/snip]

    The IP address pulled out of the SOCKADDRIN structure is always
    204.204.204.204 , no matter what machine I connect from. The connection
    is otherwise functional. Has anyone had this problem before?

    Thanks in advance,
    Tom
  • Mark Salsbery [MVP]

    #2
    Re: accept() always returns 204.204.204.204

    "TBass" <tbj@automatedd esign.comwrote in message
    news:4ab16c33-3ab0-4d14-bd92-8c42b5426faf@s1 9g2000prg.googl egroups.com...
    Hi,
    >
    I wrote an app that accepts a client connection.
    >
    [snip]
    SOCKADDR_IN sockAddrIn;
    unsigned int clientLen = sizeof( sockAddrIn );
    SOCKET conn = accept( m_Socket, (struct sockaddr *)&sockAddrIn,
    NULL );

    From the docs: "If addr and/or addrlen are equal to NULL, then no
    information about the remote address of the accepted socket is returned."

    Maybe try

    SOCKADDR_IN sockAddrIn;
    int clientLen = sizeof( sockAddrIn );
    SOCKET conn = accept( m_Socket, (struct sockaddr *)&sockAddrIn,
    &clientLen );

    Mark

    --
    Mark Salsbery
    Microsoft MVP - Visual C++

    >
    if ( conn == INVALID_SOCKET )
    {
    int errorno = WSAGetLastError ();
    if ( errorno != WSAEWOULDBLOCK )
    {
    return -1;
    }
    else
    {
    return false;
    }
    >
    }
    else
    {
    >
    CFusionSCK_Clie nt myclient(m_Conn Flags);
    >
    myclient.Socket ( &conn );
    myclient.AddrIn ( &sockAddrIn );
    myclient.IPAddr ess( inet_ntoa( sockAddrIn.sin_ addr ) );
    myclient.Port( sockAddrIn.sin_ port );
    >
    m_listClients.p ush_back( myclient );
    >
    }
    >
    return false;
    >
    [/snip]
    >
    The IP address pulled out of the SOCKADDRIN structure is always
    204.204.204.204 , no matter what machine I connect from. The connection
    is otherwise functional. Has anyone had this problem before?
    >
    Thanks in advance,
    Tom

    Comment

    • Nikolaos D. Bougalis

      #3
      Re: accept() always returns 204.204.204.204

      TBass wrote:
      SOCKADDR_IN sockAddrIn;
      unsigned int clientLen = sizeof( sockAddrIn );
      SOCKET conn = accept( m_Socket, (struct sockaddr *)&sockAddrIn,
      NULL );

      You're passing NULL to accept() for the length of the address field,
      which causes no information to be returned (sane behavior -- without
      knowing the number of bytes to the memory pointed, it could not possibly
      do anything reasonable)

      Try:

      SOCKET conn = accept(m_Socket ,
      (struct sockaddr *)&sockAddrIn,
      &clientLen);

      The IP address pulled out of the SOCKADDRIN structure is always
      204.204.204.204 , no matter what machine I connect from. The connection
      is otherwise functional. Has anyone had this problem before?
      204 is 0xCC, which is the value that the compiler uses for
      uninitialized stack variables in debug builds to help catch bad
      accesses. Since you passed NULL, nothing was returned, and sockAddrIn
      was uninitialized.

      -n

      Comment

      Working...