include: Add macros for retrieving control message headers.

This commit is contained in:
Erich Hoover 2010-11-02 16:35:04 -06:00 committed by Alexandre Julliard
parent 4b6d5fd583
commit cac2c176ef

View file

@ -78,4 +78,21 @@ typedef enum {
ScopeLevelGlobal = 14
} SCOPE_LEVEL;
/*
* Macros for retrieving control message data returned by WSARecvMsg()
*/
#define WSA_CMSG_DATA(cmsg) ((UCHAR*)((WSACMSGHDR*)(cmsg)+1))
#define WSA_CMSG_FIRSTHDR(mhdr) ((mhdr)->Control.len >= sizeof(WSACMSGHDR) ? (WSACMSGHDR *) (mhdr)->Control.buf : (WSACMSGHDR *) 0)
#define WSA_CMSG_ALIGN(len) (((len) + sizeof(SIZE_T) - 1) & ~(sizeof(SIZE_T) - 1))
/*
* Next Header: If the response is too short (or the next message in the response
* is too short) then return NULL, otherwise return the next control message.
*/
#define WSA_CMSG_NXTHDR(mhdr,cmsg) \
(!(cmsg) ? WSA_CMSG_FIRSTHDR(mhdr) : \
((mhdr)->Control.len < sizeof(WSACMSGHDR) ? NULL : \
(((unsigned char*)(((WSACMSGHDR*)((unsigned char*)cmsg + WSA_CMSG_ALIGN(cmsg->cmsg_len)))+1) > ((unsigned char*)(mhdr)->Control.buf + (mhdr)->Control.len)) ? NULL : \
(((unsigned char*)cmsg + WSA_CMSG_ALIGN(cmsg->cmsg_len)+WSA_CMSG_ALIGN(((WSACMSGHDR*)((unsigned char*)cmsg + WSA_CMSG_ALIGN(cmsg->cmsg_len)))->cmsg_len) > ((unsigned char*)(mhdr)->Control.buf + (mhdr)->Control.len)) ? NULL : \
(WSACMSGHDR*)((unsigned char*)cmsg + WSA_CMSG_ALIGN(cmsg->cmsg_len))))))
#endif /* _WS2DEF_ */