Ok, from:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winsock
/winsock/linger_2.asp

You'll note that using Winsock the linger structure is:
typedef struct linger {
  u_short l_onoff;
  u_short l_linger;
} linger;

While from:
http://www.rt.com/man/getsockopt.2.html
The linus linger structure is:
struct linger {
        int  l_onoff;   /* Linger active */
      int  l_linger;  /* How long to linger for */
};
As such, a correct way to do this in Win32:
my $setsock = setsockopt($sock,SOL_SOCKET,SO_LINGER,pack("SS",1,120));
if(defined($setsock)){
    $linger = getsockopt($sock,SOL_SOCKET,SO_LINGER);
    if(defined($linger)){
        print("setcockopt was successful to on and 120 seconds\n");
        print("Linger is $linger\n");
        print("Length of linger is ");
        print(length($linger)."\n");
        my $firstbyte = substr($linger,0,2,"");
        print("Length of linger after substr is ");
        print(length($linger)."\n");
        print("Length of firstbyte after substr is ");
        print(length($firstbyte)."\n");
        $linger = unpack("S*", $linger);
        print("The length of linger unpacked is ".length($linger)."\n");
        print("The SO_LINGER secondbyte return value is $linger\n");
        $firstbyte = unpack("S*", $firstbyte);
        print("The length of firstbyte unpacked is
".length($firstbyte)."\n");
        print("The SO_LINGER firstbyte return value is $firstbyte\n");
    } else {
        print("Return value fo SO_LINGER is undefined\n");
    }
}

Which produces the following output:
setcockopt was successful to on and 120 seconds
Linger is ? x
Length of linger is 4
Length of linger after substr is 2
Length of firstbyte after substr is 2
The length of linger unpacked is 3
The SO_LINGER secondbyte return value is 120
The length of firstbyte unpacked is 1
The SO_LINGER firstbyte return value is 1

Which is correct.

Cheers,
John




> -----Original Message-----
> From: $Bill Luebkert [mailto:[EMAIL PROTECTED] 
> Sent: Thursday, January 06, 2005 6:22 PM
> To: John Serink
> Cc: perl-win32-users@listserv.ActiveState.com
> Subject: Re: getsockopt
> 
> 
> John Serink wrote:
> 
> > Hi All:
> > 
> > Anybody know how to properly unpack this:
> > my $linger = getsockopt($sock,SOL_SOCKET,SO_LINGER);
> > 
> > I've tried every option but I can't make sense of the response. 
> > $linger is 4 bytes long according to length($linger) so it did 
> > return... I just can't figure out how to unpack the response. Have 
> > tried: C,CC,c,cc,I,II,I,ii,V,v,N,N etc...
> 
> Actually it returns an int, so i would be more correct than l.
> 
> -- 
>   ,-/-  __      _  _         $Bill Luebkert    
> Mailto:[EMAIL PROTECTED]
>  (_/   /  )    // //       DBE 
> Collectibles    Mailto:[EMAIL PROTECTED]
>   / ) /--<  o // //      Castle of Medieval Myth & Magic 
http://www.todbe.com/
-/-' /___/_<_</_</_    http://dbecoll.tripod.com/ (My Perl/Lakers stuff)

_______________________________________________
Perl-Win32-Users mailing list
Perl-Win32-Users@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Reply via email to