端口 抓包 UDP。帮忙编译出来。高分悬赏!
需要:
抓包》》from自本地 6112端口 to 255.255.255.255:6112 的所有UDP包
返回byte[]
我现在有部分代码:
我要的数组 getbyte(){
DWORD dwFlags;
DWORD dwBytesRead;
WSABUF wbuf;
char buf[0x1500];
wbuf.len =0x1500;
wbuf.buf=buf;
int k=0;
// InitSocket();
WORD wReqVer = MAKEWORD(2, 2);
WSADATA wsa;
if(::WSAStartup(wReqVer, &wsa))return NULL;
//
m_sock=::WSASocket(AF_INET,SOCK_DGRAM,IPPROTO_UDP,NULL,0,WSA_FLAG_OVERLAPPED);
if (m_sock==INVALID_SOCKET) return NULL;
//绑定
SOCKET_ADDRESS_LIST *slist=NULL;
char buff[2048];
DWORD dwBytesRet2;
SOCKADDR_IN if0;
if (SOCKET_ERROR==WSAIoctl(m_sock,SIO_ADDRESS_LIST_QUERY,
NULL,0,buff,2048,&dwBytesRet2,NULL,NULL))
return NULL;
slist=(SOCKET_ADDRESS_LIST *)buf;
if (slist->iAddressCount<=0) return NULL;
if0.sin_addr.s_addr =
((SOCKADDR_IN *)slist->Address[0].lpSockaddr)->sin_addr.s_addr;
if0.sin_family=AF_INET;
if0.sin_port =htons(0);
if(SOCKET_ERROR == ::bind(m_sock, (SOCKADDR *)&if0, sizeof(if0)))
return NULL;
//
DWORD dwVal=1;
DWORD dwBytesRet;
if (SOCKET_ERROR==WSAIoctl(m_sock, SIO_RCVALL, &dwVal,
sizeof(dwVal), NULL, 0, &dwBytesRet, NULL, NULL)) return NULL;
while(true)
{
dwFlags=0;
WSARecv(m_sock , &wbuf, 1, &dwBytesRead, &dwFlags, NULL, NULL);
wbuf.len=dwBytesRead;
WSABUF* pBuf = (WSABUF *)&wbuf;
UCHAR* buf = (UCHAR *)pBuf->buf;
buf = (UCHAR *)::GlobalAlloc(GPTR, pBuf->len);
memcpy(buf, pBuf->buf, pBuf->len);
WSABUF *pbuf = new WSABUF;
pbuf->buf = (char *)buf;
pbuf->len = pBuf->len;
if( 判断我的条件 ){
printf("源IP:%d.%d.%d.%d ",buf[12], buf[13], buf[14], buf[15]);
printf("目的IP:%d.%d.%d.%d\n",buf[16], buf[17], buf[18], buf[19]);
return 我要的数组
}
}
}