GetAcceptExSockaddrs

Tech-Archive recommends: Fix windows errors by optimizing your registry

From: Daryn Kiely (DarynKiely_at_discussions.microsoft.com)
Date: 09/30/04


Date: Wed, 29 Sep 2004 18:25:04 -0700

Hi,

We have written an application on XP that uses completion ports and
asynchronous IO. When a new socket connects we were able to get the remote
address using getpeername. Unfortunately our library need to run on Windows
2000 as well, so we have attempted to retreive the remote address using
GetAcceptExSockaddrs. However when we use this method the data is completely
invalid. HELP!!! Here is the code that is getting the remote address.

Thanks
Daryn

bool WinSocket::getAddressesFromAsyncCall (ErrorStatus error_status)
{
   bool return_value = true;

   if (0 == m_GetAcceptExSockaddrs) // TODO: Make this a valid error code
   {
      GUID guid = WSAID_GETACCEPTEXSOCKADDRS;
      DWORD bytes;
      int io_error;
      ErrorDefs::ErrorCode error_code;
      string error_message;

      io_error = WSAIoctl (m_socket, SIO_GET_EXTENSION_FUNCTION_POINTER,
(LPVOID) &guid, sizeof (GUID), (LPVOID) &m_GetAcceptExSockaddrs, sizeof
(LPFN_GETACCEPTEXSOCKADDRS), &bytes, NULL, NULL);

      if (SOCKET_ERROR == io_error)
      {
         error_code = WindowsSockets::getWSAErrorInfo (error_message);
         socketError (error_status, error_code, error_message.c_str ());
         return_value = false;
      }
   }
   if (return_value)
   {
      sockaddr_in* local_addr = 0;
      sockaddr_in* remote_addr = 0;
      int local_addr_length = 0;
      int remote_addr_length = 0;

      m_GetAcceptExSockaddrs (m_address_info, (sizeof(sockaddr_in) + 16) *
2, sizeof(sockaddr_in) + 16, sizeof(sockaddr_in) + 16,
                           (sockaddr**) &local_addr, &local_addr_length,
(sockaddr**) &remote_addr, &remote_addr_length);
      m_local_ip_address = local_addr->sin_addr.s_addr;
      m_local_port_number = ntohs (local_addr->sin_port);
      m_remote_ip_address = remote_addr->sin_addr.s_addr;
      m_remote_port_number = ntohs (remote_addr->sin_port);
   }

   return return_value;
}



Relevant Pages

  • Re: Bandwidth - Your experience?
    ... Fast and securely accessing all of remote data sources anywhere with ... > I have been considering a raw socket implementation but if the Remoting ... > connecting to the remote server. ... > BinaryServerFormatterSinkProvider(); ...
    (microsoft.public.dotnet.framework.remoting)
  • Network pipes
    ... user to create a pipeline over the network using a socket as its ... has tar sending each block through a pipe to a local ssh process, ... communicating with sshd through a pipe again. ... local and the remote host with the standard output of tar and the ...
    (freebsd-hackers)
  • Re: please help in socket_send function in php
    ... i want to send some unix commands to remote unix machine in france ... socket communication program so that it connects to the remote ... now i want to send username and password to that remote machine.i am ... Jerry Stuckle ...
    (comp.lang.php)
  • Re: Socket errors and errno.
    ... > (and attempt a recovery if possible). ... > the socket is ready to read/write. ... > re-establish the connection with the remote host. ... Perhaps detecting the EPIPE error condition and trying to reconnect ...
    (comp.unix.programmer)
  • Re: please help in socket_send function in php
    ... i want to send some unix commands to remote unix machine in france ... socket communication program so that it connects to the remote ...
    (comp.lang.php)