[PATCH 2/4] include: Add macros for retrieving control message headers.

Alexandre Julliard julliard at winehq.org
Mon Nov 1 05:42:57 CDT 2010


Erich Hoover <ehoover at mines.edu> writes:

> @@ -185,6 +185,25 @@ VOID WINAPI GetAcceptExSockaddrs(PVOID, DWORD, DWORD, DWORD, struct WS(sockaddr)
>  BOOL WINAPI TransmitFile(SOCKET, HANDLE, DWORD, DWORD, LPOVERLAPPED, LPTRANSMIT_FILE_BUFFERS, DWORD);
>  INT  WINAPI WSARecvEx(SOCKET, char *, INT, INT *);
>  
> +/*
> + * Macros for retrieving control message data returned by WSARecvMsg()
> + */
> +#define WSA_CMSG_DATA(cmsg)     ((UCHAR*)((WSACMSGHDR*)(cmsg)+1))
> +#define WSA_CMSG_FIRSTHDR(mhdr) \
> +        ((size_t) (mhdr)->Control.len >= sizeof(WSACMSGHDR)		      \
> +         ? (WSACMSGHDR *) (mhdr)->Control.buf : (WSACMSGHDR *) 0)
> +#define WSA_CMSG_ALIGN(len)     (((len) + sizeof (size_t) - 1) \
> +                                 & (size_t) ~(sizeof (size_t) - 1))
> +static inline WSACMSGHDR *WSA_CMSG_NXTHDR(WSAMSG *msg, WSACMSGHDR *cmsg)
> +{
> +    if ((size_t)(msg)->Control.len<sizeof(WSACMSGHDR)) return 0;
> +    cmsg = (WSACMSGHDR*)((unsigned char*)cmsg + WSA_CMSG_ALIGN(cmsg->cmsg_len));
> +    if ((unsigned char*)(cmsg+1) > ((unsigned char*)msg->Control.buf + msg->Control.len)
> +        || ((unsigned char*)cmsg + WSA_CMSG_ALIGN(cmsg->cmsg_len) > ((unsigned char *)msg->Control.buf + msg->Control.len)) )
> +        return 0;
> +    return cmsg;
> +}

This should go into ws2def.h. Also WSA_CMSG_NXTHDR is supposed to be a
macro, not an inline function.

-- 
Alexandre Julliard
julliard at winehq.org



More information about the wine-devel mailing list