setsockopt
- From: Jack <junw2000@xxxxxxxxx>
- Date: Wed, 12 Sep 2007 05:59:56 -0000
Hi,
In the following code,
int main(int argc, char **argv) {
int SendSocket;
struct sockaddr_in SendAddr, ClentAddr;
int Port = 27015;
int socketFd;
if( (socketFd = socket(AF_INET, SOCK_DGRAM, 0))< 0)
{
cout << "Failed to open a socket." << "Error No: "<< endl;
exit(0);
}
SendAddr.sin_family = AF_INET;
SendAddr.sin_port = htons(Port);
SendAddr.sin_addr.s_addr = htonl ( INADDR_ANY );
if ( bind( socketFd, (struct sockaddr *) &SendAddr, sizeof(struct
sockaddr) ) < 0 )
{
perror("WRONG");
cout << "Unable to bind to " << Port << " Last error : " <<
errno << endl;
}
int udpbuf = 0;
socklen_t len;
int ret1 = getsockopt(socketFd, SOL_SOCKET, SO_RCVBUF, &udpbuf,
&len);
cout<<"udpbuf:
"<<udpbuf<<end; //
LINE1
int udpbuf0 = atoi(argv[1]);
int ret11 = setsockopt(socketFd, SOL_SOCKET, SO_RCVBUF, &udpbuf0,
sizeof(udpbuf0));
//
LINE2
int udpbuf1;
socklen_t len1;
int ret111 = getsockopt(socketFd, SOL_SOCKET, SO_RCVBUF, &udpbuf1,
&len1);
cout<<"udpbuf1:
"<<udpbuf1<<endl; //
LINE3
}
LINE1 gets the default UDP buffer size. LINE2 sets a new value. LINE3
gets the new UDP buffer size. When running the code on Linux system,
why the output at LINE3 is double the value at LINE2? For example, if
udpbuf0 is 11000, the output of LINE3 is 22000.
Thanks.
Jack
.
- Follow-Ups:
- Re: setsockopt
- From: David Schwartz
- Re: setsockopt
- From: Nikolaos D. Bougalis
- Re: setsockopt
- Prev by Date: Re: writing drivers using C++
- Next by Date: Kernel Compilation - Kernel Panic - Not Synching: VFS: unable to mount root fs on unkown-block(0,0)
- Previous by thread: upgrading drivers of 2.4 kernel to 2.6 kernel
- Next by thread: Re: setsockopt
- Index(es):