[PATCH 2/7] dpwsockx: Implementation of SPInit

Henri Verbeet hverbeet at gmail.com
Wed Sep 9 16:02:10 CDT 2009


2009/9/9 Ismael Barros² <razielmine at gmail.com>:
> -------------
>
> #ifdef WORDS_BIGENDIAN
>
> static inline u_short __dpws_ushort_swap(u_short s)
> {
>    return (s >> 8) | (s << 8);
> }
> static inline u_long __dpws_ulong_swap(u_long l)
> {
>    return ((u_long)__dpws_ushort_swap((u_short)l) << 16) |
> __dpws_ushort_swap((u_short)(l >> 16));
> }
>
> #define dpws_letohl(l) __dpws_ulong_swap(l)
> #define dpws_letohs(s) __dpws_ushort_swap(s)
> #define dpws_htolel(l) __dpws_ulong_swap(l)
> #define dpws_htoles(s) __dpws_ushort_swap(s)
>
> #else /* WORDS_BIGENDIAN */
>
> #define dpws_letohl(l) ((u_long)(l))
> #define dpws_letohs(s) ((u_short)(s))
> #define dpws_htolel(l) ((u_long)(l))
> #define dpws_htoles(s) ((u_short)(s))
>
> #endif /* WORDS_BIGENDIAN */
>
>
> #include "pshpack1.h"
>
> typedef struct tagDPSP_MSG_HEADER
> {
>    DWORD       mixed;
>    SOCKADDR_IN SockAddr;
> } DPSP_MSG_HEADER, *LPDPSP_MSG_HEADER;
> typedef const DPSP_MSG_HEADER* LPCDPSP_MSG_HEADER;
>
> #include "poppack.h"
>
>
> #define DPSP_MSG_TOKEN_REMOTE    0xFAB00000
> #define DPSP_MSG_TOKEN_FORWARDED 0xCAB00000
> #define DPSP_MSG_TOKEN_SERVER    0xBAB00000
>
> #define DPSP_MSG_MAKE_MIXED(s,t) dpws_htolel((s) | (t))
> #define DPSP_MSG_SIZE(m)         dpws_letohl((m) & 0x000FFFFF)
> #define DPSP_MSG_TOKEN(m)        ((m) & 0xFFF00000)
>

I think it should be like this:
#define DPSP_MSG_SIZE(m)         (dpws_letohl(m) & 0x000FFFFF)
#define DPSP_MSG_TOKEN(m)        (dpws_letohl(m) & 0xFFF00000)

I.e., swap before masking. Perhaps you just want to do this though:
#define DPSP_MSG_MAKE_MIXED(s,t) ((s) | (t))
#define DPSP_MSG_SIZE(m)         ((m) & 0x000fffff)
#define DPSP_MSG_TOKEN(m)        ((m) & 0xfff00000)
...
m = DPSP_MSG_MAKE_MIXED(s, t);
header.mixed = dpws_htolel(m);
...
m = dpws_letohl(header.mixed);
s = DPSP_MSG_SIZE(m);
t = DPSP_MSG_SIZE(m);



More information about the wine-devel mailing list