Sponsored Content
Top Forums Programming How to avoid 'No buffer space available' on C socket? Post 302858571 by Zykl0n-B on Monday 30th of September 2013 11:32:17 PM
Old 10-01-2013
How to avoid 'No buffer space available' on C socket?

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:
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();
        }

Zykl0n-B
 

10 More Discussions You Might Find Interesting

1. Programming

how to clear/clean mbufs (network buffer space)?

When I worked with client-server (socket) programming, I encountered "the socket error# 10055" which means "No buffer space available". This might be a symptom of one or more applications that didn't return system resources (like memory) properly. Temporary solution was to reboot the machine to... (7 Replies)
Discussion started by: dipti
7 Replies

2. Linux

ssh: connect to host traviata port 22: No buffer space available

What does that mean? traviata being my distant host? What am i to do? (0 Replies)
Discussion started by: penguin-friend
0 Replies

3. Shell Programming and Scripting

how to avoid space to run remotely

If I run the following command remotely after ssh than it works fine su - oracle -c "/oracle/product/102/db/bin/dbshut" But If I run the following command it doesn't work su - oracle -c "/oracle/product/102/db/bin/lsnrctl stop" Because I think there is a space is present between lsnrctl and... (1 Reply)
Discussion started by: madhusmita
1 Replies

4. UNIX for Advanced & Expert Users

connect problem for sctp socket (ipv6 socket) - Runtime fail Invalid Arguments

Hi, I was porting ipv4 application to ipv6; i was done with TCP transports. Now i am facing problem with SCTp transport at runtime. To test SCTP transport I am using following server and client socket programs. Server program runs fine, but client program fails giving Invalid Arguments for... (0 Replies)
Discussion started by: chandrutiptur
0 Replies

5. Shell Programming and Scripting

How to avoid the space

Hi, I have some problem with following command. $path='pwd'.”/pack”; When I check the value in the variable path , it give the following output /tmp/new /pack The pwd will be /tmp/new Now the problem is the spaces is added between pwd and the appended path. I need the output like... (5 Replies)
Discussion started by: kalpeer
5 Replies

6. Programming

Finding used socket receive-buffer size

I have set the receive buffer size of socket to max. setsockopt(sd,SOL_SOCKET, SO_RCVBUF,&max,optval); Am reading data from the socket in a loop(say max 100 bytes per recv) while(1) { int rlen=recv(sd,(void *)buf, 100 , 0); //err handle and processing } Assume my process is slow... (2 Replies)
Discussion started by: johnbach
2 Replies

7. Programming

Store file into a buffer to send it through a socket

Hello, I'm doing a very simple program which reads a file and sends whatever is in the file through a socket. Like the program "file2cable". Let's say i have a file containing the following, which is a hex dump of an ARP request frame: ff ff ff ff ff ff 00 1b 24 79 5a 73 08 06 00 01 08... (5 Replies)
Discussion started by: semash!
5 Replies

8. Linux

Linux Device Driver: avoid mem copy from/to user/kernel space

I recently started working with Linux and wrote my first device driver for a hardware chip controlled by a host CPU running Linux 2.6.x kernel. 1. The user space process makes an IOCTL call with pointer to a user memory buffer. 2. The kernel device driver in the big switch-case of IOCTL,... (1 Reply)
Discussion started by: agaurav
1 Replies

9. Shell Programming and Scripting

How to avoid the truncating of multiple spaces into a single space while reading a line from a file?

consider the small piece of code while read line do echo $line done < example content of example file sadasdasdasdsa erwerewrwr ergdgdfgf rgerg erwererwr the output is like sadasdasdasdsa erwerewrwr ergdgdfgf rgerg erwererwr the... (4 Replies)
Discussion started by: Kesavan
4 Replies

10. IP Networking

Clarification - Setting socket options at the same time when socket is listening

I need clarification on whether it is okay to set socket options on a listening socket simultaneously when it is being used in an accept() call? Following is the scenario:- -- Task 1 - is executing in a loop - polling a listen socket, lets call it 'fd', (whose file descriptor is global)... (2 Replies)
Discussion started by: jake24
2 Replies
GETSOCKOPT(2)						     Linux Programmer's Manual						     GETSOCKOPT(2)

NAME
getsockopt, setsockopt - get and set options on sockets SYNOPSIS
#include <sys/types.h> /* See NOTES */ #include <sys/socket.h> int getsockopt(int sockfd, int level, int optname, void *optval, socklen_t *optlen); int setsockopt(int sockfd, int level, int optname, const void *optval, socklen_t optlen); DESCRIPTION
getsockopt() and setsockopt() manipulate options for the socket referred to by the file descriptor sockfd. Options may exist at multiple protocol levels; they are always present at the uppermost socket level. When manipulating socket options, the level at which the option resides and the name of the option must be specified. To manipulate options at the sockets API level, level is specified as SOL_SOCKET. To manipulate options at any other level the protocol number of the appropriate protocol controlling the option is supplied. For example, to indicate that an option is to be interpreted by the TCP protocol, level should be set to the protocol number of TCP; see getprotoent(3). The arguments optval and optlen are used to access option values for setsockopt(). For getsockopt() they identify a buffer in which the value for the requested option(s) are to be returned. For getsockopt(), optlen is a value-result argument, initially containing the size of the buffer pointed to by optval, and modified on return to indicate the actual size of the value returned. If no option value is to be supplied or returned, optval may be NULL. Optname and any specified options are passed uninterpreted to the appropriate protocol module for interpretation. The include file <sys/socket.h> contains definitions for socket level options, described below. Options at other protocol levels vary in format and name; consult the appropriate entries in section 4 of the manual. Most socket-level options utilize an int argument for optval. For setsockopt(), the argument should be nonzero to enable a boolean option, or zero if the option is to be disabled. For a description of the available socket options see socket(7) and the appropriate protocol man pages. RETURN VALUE
On success, zero is returned. On error, -1 is returned, and errno is set appropriately. ERRORS
EBADF The argument sockfd is not a valid descriptor. EFAULT The address pointed to by optval is not in a valid part of the process address space. For getsockopt(), this error may also be returned if optlen is not in a valid part of the process address space. EINVAL optlen invalid in setsockopt(). In some cases this error can also occur for an invalid value in optval (e.g., for the IP_ADD_MEMBERSHIP option described in ip(7)). ENOPROTOOPT The option is unknown at the level indicated. ENOTSOCK The argument sockfd is a file, not a socket. CONFORMING TO
SVr4, 4.4BSD (these system calls first appeared in 4.2BSD), POSIX.1-2001. NOTES
POSIX.1-2001 does not require the inclusion of <sys/types.h>, and this header file is not required on Linux. However, some historical (BSD) implementations required this header file, and portable applications are probably wise to include it. The optlen argument of getsockopt() and setsockopt() is in reality an int [*] (and this is what 4.x BSD and libc4 and libc5 have). Some POSIX confusion resulted in the present socklen_t, also used by glibc. See also accept(2). BUGS
Several of the socket options should be handled at lower levels of the system. SEE ALSO
ioctl(2), socket(2), getprotoent(3), protocols(5), socket(7), tcp(7), unix(7) COLOPHON
This page is part of release 3.53 of the Linux man-pages project. A description of the project, and information about reporting bugs, can be found at http://www.kernel.org/doc/man-pages/. Linux 2008-12-03 GETSOCKOPT(2)
All times are GMT -4. The time now is 09:56 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy