len_inet is simply sizeof(sockaddr)
The cast c=accept(s,(struct sockaddr *) &adr_client,
(socklen_t*)&len_inet);
solves the problem by why isn't this code
immediately
portable between the two platforms?
> I have some socket code that compiles without error
> with g++ under cygwin but on Linux it gives an
> error. I have looked at sys/socket.h on both
> platforms and they seem to take the same arguments.
The type of the last parameter is 'socklen_t *' on both Linux and
Cygwin.
> This line:
> c=accept(s,(struct sockaddr *) &adr_client,&len_inet);
> compiles and runs fine on cygwin. Under linux I get
> this compile error:
> buffer_manager.cxx:148: error: invalid conversion
> from int* to socklen_t*
> buffer_manager.cxx:148: error:
> initializing argument 3 of int accept(int,
> sockaddr*, socklen_t*)
>
> len_inet is simply sizeof(sockaddr)
Right, but what type is it?
> The cast c=accept(s,(struct sockaddr *) &adr_client,
> (socklen_t*)&len_inet);
> solves the problem
No, it doesn't. It hides the problem. The correct solution to the
problem is to make 'len_inet' of type 'socklen_t'.
> by why isn't this code
> immediately
> portable between the two platforms?
It works by sheer luck on Linux. On Linux, 'socklen_t' and whatever
type 'len_inet' is just happen to be compatible. On Cygwin, they
happen not to be. (As it happens, the 'socklen_t' implementations
different in signedness.)
DS