[Common-dev] CR-Client: Fix various network API issues

[Common-dev] CR-Client: Fix various network API issues

Aaron Colwell acolwell at real.com
Wed Aug 11 07:43:51 PDT 2004


On Tue, Aug 10, 2004 at 08:48:29PM -0700, Tom Marshall wrote:
> > Index: hxnetapi.cpp
> > ===================================================================
> > RCS file: /cvsroot/client/netwksvc/hxnetapi.cpp,v
> > retrieving revision 1.31
> > diff -u -r1.31 hxnetapi.cpp
> > --- hxnetapi.cpp	9 Jul 2004 18:46:13 -0000	1.31
> > +++ hxnetapi.cpp	11 Aug 2004 01:10:03 -0000
> > @@ -2374,7 +2374,7 @@
> >      // Get the local port from the socket info
> >      nPort = m_pData->get_local_port();
> >  
> > -    return (INT16)nPort < 0 ? HXR_OK : HXR_FAIL;
> > +    return (INT16)nPort >= 0 ? HXR_OK : HXR_FAIL;
> >  }
> >  
> >  STDMETHODIMP HXUDPSocket::JoinMulticastGroup(
> 
> Just curious here -- why is a port being cast to a signed value?  This does
> not seem right at all.

I'm not sure why the cast was put there. I suppose it was to reject values
with the MSb set. This is very old code so I doubt the original author is
around to defend it. 

> 
> > @@ -566,25 +567,25 @@
> >  UINT32
> >  hx_htonl(UINT32 n)
> >  {
> > -    return htonl(n);
> > +    return DwToNet(n);
> >  }
> >  
> >  [...]
> 
> Where are DwToNet and friends defined?

They are in common/util/pub/netbyte.h. To my knowledge these are the functions
that most of the client code uses to make this type of conversion. It is not
new by any means.

> 
> More importantly, I would like to define the canonical Helix endian
> conversion functions.  There are a bunch of different definitions across the
> codebase and I don't really like the idea of defining more of them.
> 
> htonl and friends are really just specializations of the general endian
> conversion functions.  They all boil down to this:
> 
>     #define swap16(n) /* probably platform specifc and/or inline assembly */
>     #define swap32(n) /* same */
> 
>     #if defined(BIG_ENDIAN)
>     #define be_to_net_16(n) (n)
>     #define host_to_net_16(n) (n)
>     #define le_to_net_16(n) swap16(n)
>     ... etc ...
>     #else
>     #define be_to_net_16(n) swap16(n)
>     #define host_to_net_16(n) swap16(n)
>     #define le_to_net_16(n) (n)
>     ... etc ...
>     #endif
> 
>     #define htons(n) host_to_net_16
>     #define htonl(n) host_to_net_32
>     #define ntohs(n) net_to_host_16
>     #define ntohl(n) net_to_host_16
> 
> That is, every combination of conversion from big/little/net/host endian to
> every other combination is either a swap or not.
> 
> Do we have such a definition?  If not, I would like to create one and
> document it as the canonical set of endian conversion routines instead of
> using yet another set of definitions.

The functions in netbyte.h are these functions for the client. They probably
aren't documented anywhere, but the client code uses them where endian issues
matter. Just look in common/util for some examples.

> 
> -- 
> One good reason why computers can do more work than people is that they
> never have to stop and answer the phone.





More information about the Common-dev mailing list
 

Site Map   |   Terms of Use   |   Privacy Policy   |   Contact Us

Copyright © 1995-2007 RealNetworks, Inc. All rights reserved. RealNetworks and Helix are trademarks of RealNetworks.
All other trademarks or registered trademarks are the property of their respective holders.