Re: Building NSPR with mods that depend on winsock2.h, mswsock.h, and ws2tcpip.h

Jon Leighton <[email protected]> Fri, 13 Feb 2009 12:25:21 -0500
Newsgroups gmane.comp.mozilla.devel.nspr
Organization University of Delaware
Message-ID <[email protected]>
Wan-Teh Chang wrote:
> On Thu, Jan 22, 2009 at 5:52 PM, Jon Leighton <[email protected]> wrote:
>> Please let me know if this should be posted in a different newsgroup.
>> (moz.dev.builds?)  I'm working on modifying NSPR to support SCTP and I'm
>> running into some problems trying to build NSPR (WIN95 target) on Windows XP
>> (with which I'm not very familiar).  The problem I'm running into is that
>> I've made some modifications to prio.h that use several structures defined
>> in the SCTP header file.  I've included the SCTP header file in my prio.h,
>> but that's not sufficient.  As nearly as I understand it, building NSPR with
>> a WIN95 target is done with winsock.h and a few items plucked from
>> winsock2.h, but the SCTP header file depends on several things defined in
>> winsock2.h, mswsock.h and ws2tcpip.h.  As a first cut, I've been trying to
>> identify those items and define them in a header file that I include in
>> prio.h ahead of the SCTP header file.  I don't have a solid enough
>> understanding of the relationships among the various NSPR include files to
>> be sure that this is a viable approach, and I suspect that even if it is
>> there's probably a cleaner approach.  I'd be grateful for any suggestions
>> about how to make this work, or a better way to approach it.  Thanks very
>> much.
> 
> Hi Jon,
> 
> This newsgroup is the right one for this question.
> 
> You need to solve two problems.
> 
> 1. prio.h should not depend on structures defiined in the
> system SCTP header file.  Instead, it needs to define its own
> equivalent structures.  For convenience, it can define its own
> structures to be "isomorphic" to the real SCTP structures, so
> that we can safely cast a pointer to one to a pointer to the other.
> But that's not required -- our code can also map one structure
> to the other by manual copying of the fields.

Initially I defined isomorphic structures in prio.h, but later, for
simplicity, I simply typedef'd new NSPR structures to the actual SCTP
structures.  I now define isomorphic structures in a new header file
called prsctp.h which is included in prio.h.  These are needed for 
additions to the PRSocketOptionData structure.

However, I still have an issue because many SCTP data structures include
an opaque data structure of type sctp_assoc_t.  Currently, I include
these sctp_assoc_t structures in my equivalent isomorphic structures,
which requires me to include the SCTP header file in prsctp.h, and that
in turn requires me to include windows.h and a handful of items from
winsock2.h, mswsock.h and ws2tcpip.h.  Is there a better/preferred way
to handle these opaque structures?

> 2. The second problem is the <winsock.h> vs. <winsock2.h>
> issue.  I believe that the problem is opposite to what you
> described.  NSPR includes <winsock2.h>, and has to
> go out of its ways to include <winsock.h> in isolated
> cases, for example,
> http://mxr.mozilla.org/nspr/source/nsprpub/pr/src/io/prmapopt.c
> So hopefully this is a non-issue for you.

prmapopt.c is actually one of my main concerns.  I've added
a number of SCTP socket options to prmapopt.c and I therefore need to 
include the SCTP header file.  Currently, prmapopt.c gets the SCTP 
header file through this include chain: 
primpl.h<--nspr.h<--prio.h<--prsctp.h<--ws2sctp.h, which seems to work 
fine for the WIN95 target build.  I looked through the code to see where 
winsock2.h is being included, but couldn't find it anywhere.  I did see 
that winsock.h is included in a number of places.  Is winsock2.h 
included through windows.h?

Thanks,
Jon