Thread: [Plib-devel] Portability issue in plib 1.8.4 class netAddress
Brought to you by:
sjbaker
From: Miguel L. S. R. <mi...@an...> - 2008-03-27 18:43:37
|
Hi, Sorry for cross posting, but the plib-users mailing list seems to be mute. I've come across plib several times as it is used as a base for several other projects. In this case, I came across this problem when trying to get FlightGear to work on FreeBSD; whenever I tried to have it create a socket, it failed. I found out that it was failing with the following error: Address family not supported by protocol family. That's the message for EAFNOSUPPORT. So, I checked the file src/net/netSocket.h in the underlaying plib-1.8.4, and found out that a wrapper class is being used for sockaddr_in, the netAddress class (line 50 of the said file). I was a bit chocked by seeing that the layout of a structure which is supposed to be internal to the OS was being reproduced in the layout of netAddress. The code is as follows: class netAddress { /* DANGER!!! This MUST match 'struct sockaddr_in' exactly! */ short sin_family ; unsigned short sin_port ; unsigned int sin_addr ; char sin_zero [ 8 ] ; Well, I cannot guess what reason took plib's designers to choose this strategy, it would seem safer to me if a member variable of the type sockaddr_in existed inside the netAddress class. That way, the code would be protected from any differences in the layout of sockaddr_in of different OSes. All I can say is that in FreeBSD, the layout of sockaddr_in does not match that structure. On FreeBSD, we have: /* Socket address, internet style. */ struct sockaddr_in { uint8_t sin_len; sa_family_t sin_family; in_port_t sin_port; struct in_addr sin_addr; char sin_zero[8]; }; Of course, FreeBSD headers themselves are isolated from changes in the types sa_family_t, etc... In practice, the only thing that differs is that the two byte sin_family member is split into two members of one byte each, sin_len and sin_family. Because the i386 is a LSB first machine, filling the sin_family member of the netAddress class will end up filling the sin_len member of sockaddr_in instead of the sin_family member. Therefore, any operations involving plib-1.8.4, AF_INET sockets and FreeBSD 7 fail with EAFNOSUPPORT. QED. For my part, I would be happier if this would change, so I could play FlightGear right out-of-the-ports-collection. Anyway, I'm curious about the rationale behind this design issue. Could it be to avoid including OS specific headers? Greetings, Miguel Ramos Lisboa, Portugal |
From: Vikas N K. <vik...@us...> - 2008-03-27 19:32:25
|
On Thu, Mar 27, 2008 at 2:43 PM, Miguel Lopes Santos Ramos < mi...@an...> wrote: > > In this case, I came across this problem when trying to get FlightGear to > work on FreeBSD; > whenever I tried to have it create a socket, it failed. I found out that > it was failing with > the following error: Address family not supported by protocol family. > That's the message for EAFNOSUPPORT. > > So, I checked the file src/net/netSocket.h in the underlaying plib-1.8.4, > and found out > > Hi Miguel, If you are using CVS version of FlightGear then please use plib-1.8.5 for all purposes. It works fine with that. Regards Vikas. |
From: Miguel L. S. R. <mi...@an...> - 2008-03-30 10:31:11
|
> From wa...@gm... Thu Mar 27 19:32:34 2008 > From: "Vikas N Kumar" <vik...@us...> > Subject: Re: [Plib-devel] Portability issue in plib 1.8.4 class netAddress > > On Thu, Mar 27, 2008 at 2:43 PM, Miguel Lopes Santos Ramos < > mi...@an...> wrote: > > > > > In this case, I came across this problem when trying to get FlightGear to > > work on FreeBSD; > > whenever I tried to have it create a socket, it failed. I found out that > > it was failing with > > the following error: Address family not supported by protocol family. > > That's the message for EAFNOSUPPORT. > > > > So, I checked the file src/net/netSocket.h in the underlaying plib-1.8.4, > > and found out > > > > > Hi Miguel, > > If you are using CVS version of FlightGear then please use plib-1.8.5 for > all purposes. It works fine with that. > > Regards > Vikas. Hi, Sorry for the time taken to answer, I only have time on weekends. Actually, plib-1.8.5 has the same problem, please confirm net/netSocket.h. I don't know what you mean by "works fine"; I can get FlightGear to work as long as I don't activate the UDP interfaces (which are used for connecting to Atlas and terrasync). If those are activated, then it won't run. Anyway, that would be a matter for the FlightGear mailing list. I'm posting here because I have several different sugestions to make the netSocket class portable. How can I contact plib's developers? Greetings, Miguel |
From: Vikas N K. <vik...@us...> - 2008-03-30 16:32:59
|
On Sun, Mar 30, 2008 at 5:17 AM, Miguel Lopes Santos Ramos < mi...@an...> wrote: > Actually, plib-1.8.5 has the same problem, please confirm net/netSocket.h. > I don't know what you mean by "works fine"; I can get FlightGear to work > as long as I don't activate the UDP interfaces (which are used for > connecting > > I apologize. I have not tested the UDP part with terrasync or Atlas to have made a statement of "works fine" :) |