Thursday, September 6, 2007

#include "cc352.h"
#include <netinet/tcp.h>

int main(int argc, char **argv)
{
int fd; //socket descriptor
int sndbuff = 32*1024; //send buffer
int rcvbuff = 32*1024;
int error;//to hold the errocode

socklen_t len; // option len for getsock
//create the socket.
fd = socket(AF_INET,SOCK_STREAM,0);
//call the socket option
error = setsockopt(fd,SOL_SOCKET,
SO_SNDBUF,&sndbuff,
sizeof(sndbuff));
//setsockopt return 0 when it is ok -1 for error
if(error)
{
printf("Set sockopt fails!n");
return -1;
}
//set the rcv buffer.
error = setsockopt(fd,SOL_SOCKET,
SO_RCVBUF,&rcvbuff,
sizeof(rcvbuff));
if(error)
{
printf("Set socket option fail!n");
return -1;
}

//checking the values
error = getsockopt(fd,SOL_SOCKET,
SO_SNDBUF,&sndbuff,&len);

if(error)
{
printf("Get Socket option fails!n");
return -1;
}

error = getsockopt(fd,SOL_SOCKET,
SO_RCVBUF,&rcvbuff,&len);
if(error)
{
printf("Get Socket option fails!n");
return -1;
}
/*print the buffer sizes */
printf("Socket fd: %d n",fd);
printf("Send Buffer %d bytes n",sndbuff);
printf("Receive Buffer %d bytes n", rcvbuff);
return 0;
//any way kernel will decide the size.. so no way. myone says 65536::

}