0

trying to collect 1261 UDP packet in 2D Char array using recvfrom function

define RxBuffSize   1514
define TotalPacket  1261

char    RxBuff[RxBuffSize]      =   {0};

and the code i am trying to use is:

for (Count =0; Count <= TotalPacket; Count++)
{
    recvfrom(sock, RxBuff[Count],RxBuffSize,0,(struct sockaddr *)&Sender_addr, &Sender_addrlen);        
}

or no idea how to start just wanted to store all 1261 packets into RxBuff so that I can access packet data by its packet number for getting the data from packet by its packet number.

printf("%x ",Payload[packetno][data]);
p10ben
  • 425
  • 1
  • 6
  • 17

1 Answers1

0

You'll need enough space to store all of the packets contiguously. You can either statically allocate a 2D array

char RxBuff [RxBuffSize][1261];

or use calloc

char *RxBuff = calloc(RxBuffSize, 1261);

Then loop over recvfrom 1261 times just like in your question:

for (Count = 0; Count <= TotalPacket; Count++)
{
    recvfrom(sock, RxBuff[Count],RxBuffSize,0,(struct sockaddr *)&Sender_addr, &Sender_addrlen);
}
p10ben
  • 425
  • 1
  • 6
  • 17