[Search for users] [Overall Top Noters] [List of all Conferences] [Download this site]

Conference turris::digital_unix

Title:DIGITAL UNIX(FORMERLY KNOWN AS DEC OSF/1)
Notice:Welcome to the Digital UNIX Conference
Moderator:SMURF::DENHAM
Created:Thu Mar 16 1995
Last Modified:Fri Jun 06 1997
Last Successful Update:Fri Jun 06 1997
Number of topics:10068
Total number of notes:35879

8762.0. "A novice question about sockets." by CADSYS::BOGDANOV () Fri Feb 07 1997 17:53

Hi,
	I'm running through the network programming course and trying to get a
small program to work. However, the 'setsockopt' call alwys gives me an Invalid
argument message. I was not able to figure out a reason for it. Can somebody
help?

     . . .

    if ((sd = socket(AF_INET, SOCK_STREAM, 0)) == -1)
	perror("socket error"), exit(1);

    memset(&addr, 0, sizeof addr);

    addr.sin_family = AF_INET;
    addr.sin_addr.s_addr = inet_addr(SERV_ADDR);
    addr.sin_port = htons(SERV_PORT);

    if (connect(sd, (struct sockaddr *)&addr, sizeof(addr)) == -1)
	perror("connect error"), exit(1);

       
    {
	int to = 2;
	if (setsockopt(sd, SOL_SOCKET, SO_RCVTIMEO, &to, 4) == -1)
	    perror("set sock opt"), exit(0);

	// Here is a message
	// set sock opt: Invalid argument
    }

    . . .
 

I'm running osf 3.2d

>> Serge
T.RTitleUserPersonal
Name
DateLines
8762.1netrix.lkg.dec.com::thomasThe Code WarriorFri Feb 07 1997 21:321
SO_RCVTIMEO takes a struct timeval, not an int.
8762.2VAXCPU::michaudJeff Michaud - ObjectBrokerFri Feb 07 1997 22:037
> I'm running through the network programming course ....
> 	if (setsockopt(sd, SOL_SOCKET, SO_RCVTIMEO, &to, 4) == -1)
                                                         ^

	I'd take off major points right here for hardcoding in a
	"magic" number into the code like this.  The 4 should 
	be replaced with "sizeof to" (w/out the quotes).
8762.3VAXCPU::michaudJeff Michaud - ObjectBrokerFri Feb 07 1997 22:058
> SO_RCVTIMEO takes a struct timeval, not an int.

	And this looks like .0 should file a QAR against the setsockopt
	man page which says:

            "SO_RCVTIMEO
                Sets receive time out.  This option takes an int value."
                                                             ^^^
8762.4Thanks a lotCADSYS::BOGDANOVMon Feb 10 1997 12:097
> SO_RCVTIMEO takes a struct timeval, not an int.

QAR #51438.


The same mistake was done in internal 'self-peace' cource on Network Application
Programming (EY-K021E-SG-0001).
8762.5I should have checked it first!CADSYS::BOGDANOVMon Feb 10 1997 12:2817
> SO_RCVTIMEO takes a struct timeval, not an int.

Oops.

	Still cannot get it to work:

	
	struct timeval to;
	. . .
	to.tv_sec = 2;
	to.tv_usec = 0;
	if (setsockopt(sd, SOL_SOCKET, SO_RCVTIMEO, &to, sizeof to ) == -1)
	    perror("set sock opt"); //, exit(0);

	. . .

set sock opt: Argument out of domain
8762.6IOSG::MARSHALLMon Feb 10 1997 13:3310
	struct timeval to;
	. . .
	to.tv_sec = 2;
	to.tv_usec = 0;

set sock opt: Argument out of domain

WAG: do you explicitly zero all the other elements of the timeval struct?

Scott
8762.7VAXCPU::michaudJeff Michaud - ObjectBrokerMon Feb 10 1997 13:3910
>> 	to.tv_sec = 2;
>> 	to.tv_usec = 0;
> WAG: do you explicitly zero all the other elements of the timeval struct?

	timeval has only the two members above

> set sock opt: Argument out of domain

	this sounds like it 2 seconds is not a valid timeout (ie. it's
	too small or too big).
8762.8CADSYS::BOGDANOVMon Feb 10 1997 13:545
I got it to work on DUNIX 4.0A .

It looks like a BUG on 3.2D-1.

>> Serge