概述
熟悉linux网络编程的应该对这个很熟悉了,直接上代码ing:
#include "..."
#define DES_IPADDR "xxx.xxx.xxx.xxx"
#define DES_PORT (xxxxx)
CFW_TCPIP_SOCKET_ADDR dest_addr;
uint8_t sockfd1 = -1; //sockfd
#define MAX_LEN 1500
uint8_t BUFFER[MAX_LEN];
static VOID test_udp_rsp(void *param)
{
static uint8_t flag = 0;
COS_EVENT *pEvent = (COS_EVENT *)param;
COS_PRINTFI("test_udp_rsp Got 0x%x,0x%x,0x%x,0x%x",
pEvent->nEventId, pEvent->nParam1, pEvent->nParam2, pEvent->nParam3);
int uSocket = (int)pEvent->nParam1;
UINT16 uDataSize = pEvent->nParam2;
UINT8 *pData;
CFW_TCPIP_SOCKET_ADDR from_addr;
UINT32 iResult;
INT32 fromLen = sizeof(CFW_TCPIP_SOCKET_ADDR);
switch (pEvent->nEventId)
{
case EV_CFW_TCPIP_REV_DATA_IND:
COS_PRINTFI("test_udp_rsp socket:%d, len:%d", uSocket, uDataSize);
pData = COS_MALLOC(pEvent->nParam2 + 1);
memset(pData, 0, pEvent->nParam2 + 1);
if (pData == NULL)
return;
iResult = CFW_TcpipSocketRecvfrom(uSocket, pData, uDataSize, 0, &from_addr, &fromLen);
if (SOCKET_ERROR == iResult){
}
else
{
memset(BUFFER, 0, MAX_LEN);
// ((char *)pData)[uDataSize] = '