Hello everybody,
Years ago i left in stand-by a project of mine where the main program was supposed to send thousands ARP frames over the socket as fast as it could; but because of a programming issue i couldn't continue it.
2 days ago I decided to solve that issue.
The thing is, when the program sends bunch of data, eventually it gives the error "No buffer space available". I increased the buffer space size and it gave more sending time, but it gave the same error message later. My question is, Is there a way to send bunch of data, fast and avoiding this socket error? I don't know, by freeing it, cleaning it, etc.
I'll appreciate any help, and please excuse my poor english.
Thank you.
Here's part of the code:
unsigned int buff;
socklen_t optlen;
optlen = sizeof(buff);
...
struct sockaddr sockaddr;
struct ifreq ifreq;
memset(&ifreq, 0, sizeof(ifreq));
strcpy(sockaddr.sa_data, device); /* Transmitting device is set. */
strcpy(ifreq.ifr_name, device);
if((sock = socket(AF_PACKET, SOCK_PACKET, htons(ETH_P_ALL))) < 0)
{
perror("socket()");
exit(-1);
}
if((setsockopt(sock, SOL_SOCKET, SO_BINDTODEVICE, &ifreq, sizeof(ifreq))) < 0)
{
perror("setsockopt() cannot bind.");
exit(-1);
}
if((resource=getsockopt(sock, SOL_SOCKET, SO_SNDBUF, &buff, &optlen))<0)
{
perror("getsockopt()");
}
printf("Attempting to increase SNDBUF... ");
buff = 2147483647; /*MAXIMUM*/
if((resource = setsockopt(sock, SOL_SOCKET, SO_SNDBUF, &buff,
sizeof(buff)))<0)
{
perror("setsockopt()");
}
/*HERE'S THE TRANSMITTING PART*/
time_t startTime;
startTime = time(NULL);
while(time(NULL) - startTime < (time_assigned * 60))
{
azimuth++;
printf("%u\n", (unsigned int )azimuth);
ret= sendto(sock, &arpmsg, sizeof(struct arpmsg),0, &sockaddr,sizeof(sockaddr));
if(ret < 0 && ret != ENOBUFS)
{
perror("sendto()");
exit(-1);
}
checkordersarrival();
}