From cac2c176efd85c06b55dfebb623be66ad548b317 Mon Sep 17 00:00:00 2001 From: Erich Hoover Date: Tue, 2 Nov 2010 16:35:04 -0600 Subject: [PATCH] include: Add macros for retrieving control message headers. --- include/ws2def.h | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/include/ws2def.h b/include/ws2def.h index 00b10abb702..8c1fc4a4cf1 100644 --- a/include/ws2def.h +++ b/include/ws2def.h @@ -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_ */ -- 2.11.4.GIT