comp.lang.ada
 help / color / mirror / Atom feed
* Winsock WSAEADDRNOTAVAIL exception raised...
@ 1999-05-04  0:00 Ronald Ali
  1999-05-04  0:00 ` David Botton
  1999-05-10  0:00 ` Ronald Ali
  0 siblings, 2 replies; 3+ messages in thread
From: Ronald Ali @ 1999-05-04  0:00 UTC (permalink / raw)


I'm getting the WSAEADDRNOTAVAIL (#10049) error on the Bind (...)
command.  I'm on NT 4.0 (SP3), using Gnat Ada compiler & win32-winsock
functions.

Could someone out there in the know suggest a fix ?
Could DHCP running on our network be a cause of the error?

Snippets of the source code follow.  I will send the full Package spec
& body and Test procedure upon request.

--=====================================================
with WinSock;     use WinSock;
with Ada.Text_IO; use Ada.Text_IO;
procedure Test_WinSock is
begin
   Put_Line ("Test_Winsock...");
   Startup_Sockets; -- WSASTARTUP works fine

   Put_Line ("The name    of this host is " & Get_Host_Name);
   Put_Line ("The address of this host is " & Get_Host_Address);

   Local := (Sin_Family => AF_INET,
             Sin_Port   => htons (5001),
             Sin_Addr   => To_U_32 (Host_Address.h_addr_list'Address),
             Sin_zero   => (others => '*')
            );

   Open_Listen_Socket;   -- WSASTARTUP works fine
   Set_Socket_Option;     -- WSASTARTUP works fine
   Bind_Listen_Socket;    -- raised WSAEADDRNOTAVAIL
    . . . 
end Test_WinSock;
--=====================================================

package body WinSock is
   . . .

--------------------------------------------------------------------
   procedure Open_Listen_Socket is
      Protocol_Used : Integer := IPPROTO_IP;
   begin
      Listen_Socket := socket_func (Addr_Family => AF_INET,
                                    Socket_Type => SOCK_STREAM,
                                    Protocol    => Protocol_Used);

      If Listen_Socket = INVALID_SOCKET then
         Put ("INVALID ""Listen_Socket""");
--         raise UNKNOWN_SOCKETS_ERROR;
      end if;
   end Open_Listen_Socket;


--------------------------------------------------------------------
   procedure Set_Socket_Option is
      Result : Integer;
      Optval : Char_Array := "SO_REUSEADDR";
   begin
      Result := setsockopt (The_Socket => Listen_Socket,
                            level      => SOL_SOCKET,
                            optname    => SO_REUSEADDR,
                            optval     => Optval,
                            optlen     => Optval'Size);
      Check_Result (WSAGetLastError);
   end Set_Socket_Option;


--------------------------------------------------------------------
   procedure Bind_Listen_Socket is
      Result : Integer;
   begin
      Result := Bind (The_Socket  => Listen_Socket,
                      The_Address => To_Sock_Addr (Local'Address),
                      Name_Length => Local'Size / 8);
      Check_Result (WSAGetLastError);
   end Bind_Listen_Socket;
   . . .
end WinSock;




^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Winsock WSAEADDRNOTAVAIL exception raised...
  1999-05-04  0:00 Winsock WSAEADDRNOTAVAIL exception raised Ronald Ali
@ 1999-05-04  0:00 ` David Botton
  1999-05-10  0:00 ` Ronald Ali
  1 sibling, 0 replies; 3+ messages in thread
From: David Botton @ 1999-05-04  0:00 UTC (permalink / raw)


WSAEADDRNOTAVAIL 

(10049) 

Cannot assign requested address. 

The requested address is not valid in its context. Normally results from
an attempt to bind to an address that is not valid for the local
machine, or connect/sendto an address or port that is not valid for a
remote machine (e.g. port 0). 


Ronald Ali wrote:
> 
> I'm getting the WSAEADDRNOTAVAIL (#10049) error on the Bind (...)
> command.  I'm on NT 4.0 (SP3), using Gnat Ada compiler & win32-winsock
> functions.
> 
> Could someone out there in the know suggest a fix ?
> Could DHCP running on our network be a cause of the error?
> 
> Snippets of the source code follow.  I will send the full Package spec
> & body and Test procedure upon request.
> 
> --=====================================================
> with WinSock;     use WinSock;
> with Ada.Text_IO; use Ada.Text_IO;
> procedure Test_WinSock is
> begin
>    Put_Line ("Test_Winsock...");
>    Startup_Sockets; -- WSASTARTUP works fine
> 
>    Put_Line ("The name    of this host is " & Get_Host_Name);
>    Put_Line ("The address of this host is " & Get_Host_Address);
> 
>    Local := (Sin_Family => AF_INET,
>              Sin_Port   => htons (5001),
>              Sin_Addr   => To_U_32 (Host_Address.h_addr_list'Address),
>              Sin_zero   => (others => '*')
>             );
> 
>    Open_Listen_Socket;   -- WSASTARTUP works fine
>    Set_Socket_Option;     -- WSASTARTUP works fine
>    Bind_Listen_Socket;    -- raised WSAEADDRNOTAVAIL
>     . . .
> end Test_WinSock;
> --=====================================================
> 
> package body WinSock is
>    . . .
> 
> --------------------------------------------------------------------
>    procedure Open_Listen_Socket is
>       Protocol_Used : Integer := IPPROTO_IP;
>    begin
>       Listen_Socket := socket_func (Addr_Family => AF_INET,
>                                     Socket_Type => SOCK_STREAM,
>                                     Protocol    => Protocol_Used);
> 
>       If Listen_Socket = INVALID_SOCKET then
>          Put ("INVALID ""Listen_Socket""");
> --         raise UNKNOWN_SOCKETS_ERROR;
>       end if;
>    end Open_Listen_Socket;
> 
> --------------------------------------------------------------------
>    procedure Set_Socket_Option is
>       Result : Integer;
>       Optval : Char_Array := "SO_REUSEADDR";
>    begin
>       Result := setsockopt (The_Socket => Listen_Socket,
>                             level      => SOL_SOCKET,
>                             optname    => SO_REUSEADDR,
>                             optval     => Optval,
>                             optlen     => Optval'Size);
>       Check_Result (WSAGetLastError);
>    end Set_Socket_Option;
> 
> --------------------------------------------------------------------
>    procedure Bind_Listen_Socket is
>       Result : Integer;
>    begin
>       Result := Bind (The_Socket  => Listen_Socket,
>                       The_Address => To_Sock_Addr (Local'Address),
>                       Name_Length => Local'Size / 8);
>       Check_Result (WSAGetLastError);
>    end Bind_Listen_Socket;
>    . . .
> end WinSock;




^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Winsock WSAEADDRNOTAVAIL exception raised...
  1999-05-04  0:00 Winsock WSAEADDRNOTAVAIL exception raised Ronald Ali
  1999-05-04  0:00 ` David Botton
@ 1999-05-10  0:00 ` Ronald Ali
  1 sibling, 0 replies; 3+ messages in thread
From: Ronald Ali @ 1999-05-10  0:00 UTC (permalink / raw)


The problem was resolved when I changed the assignment of the
LOCAL Socket Address from the results of the Get_Host_Address function
call to "INADDR_ANY", which equates to zero.

--         Sin_Addr   => To_U_32 (Host_Address.h_addr_list'Address),
           Sin_Addr   => IN_ADDR (INADDR_ANY),

Thank you David Botton for your insight.

Regards, Ron Ali




^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~1999-05-10  0:00 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1999-05-04  0:00 Winsock WSAEADDRNOTAVAIL exception raised Ronald Ali
1999-05-04  0:00 ` David Botton
1999-05-10  0:00 ` Ronald Ali

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox