Bug#564232: bind behaviour different between linux and freebsd?
----------------original message-----------------
De: "Jan-Benedict Glaw" jbglaw@lug-owl.de
A: "Xavier Grave" grave@ipno.in2p3.fr, 564232@bugs.debian.org
Date: Sat, 9 Jan 2010 15:36:09 +0100
-------------------------------------------------
> Did you test errno? Please try this:
Yes and I get an ada exception with a errno 22 Invalid argument
In parallel of testing your code I have found the difference between the
default behaviour in linux and freebsd using a simple server example I found
on the net.
Here is the Ada modification I have done to the test in the bug related to
polyorb package :
see bug #561156, Message #24 for the original code
--- bind_socket.adb 2010-01-09 15:37:37.000000000 +0100
+++ bind_socket.adb.ok 2010-01-09 15:37:28.000000000 +0100
@@ -6,6 +6,7 @@
with GNAT.Sockets.Thin_Common;
with GNAT.Sockets.Constants;
with GNAT.Sockets.Thin;
+with System.OS_Constants;
pragma Warnings (on);
use GNAT.Sockets;
@@ -13,12 +14,16 @@
procedure Bind_Socket is
package C renames Interfaces.C;
use type C.int;
+ use type C.unsigned_char;
Socket : C.int;
Res : C.int;
Sin : aliased Thin_Common.Sockaddr_In;
Len : constant C.int := Sin'Size / 8;
begin
+ Sin.Sin_Family := (Has_Sockaddr_Len => True,
+ Length => Sin'Size / 8,
+ Char_Family => System.OS_Constants.AF_INET);
Sin.Sin_Addr := Thin_Common.Inaddr_Any;
Sin.Sin_Port := 5786;
> #include
> #include
> #include
> #include
> #include
>
> int
> main (int argc, char *argv[])
> {
> int socket_fd;
> struct sockaddr_in sin;
> int len, res;
>
> len = sizeof (struct sockaddr_in);
> memset (&sin, 0, len);
> sin.sin_port = htons (5786);
> sin.sin_family = AF_INET;
> sin.sin_addr.s_addr = INADDR_ANY;
>
> printf ("sin len %d\n",len);
> socket_fd = socket (AF_INET,SOCK_STREAM,0);
>
> res = bind (socket_fd, (struct sockaddr *) &sin, len);
> printf ("res = %d, errno = %s\n", res, strerror (res? errno: 0));
>
> return 0;
> }
Your code run like a charm, no errno. The important line in it is :
sin.sin_family = AF_INET; No setting in linux doesn't seem to be a problem.
Now, we need to include it in the top level binding of gnat.sockets.
Reply to: