I've re-written a script that tries to waken PC's on our network (I had to as the Getopt::Std module didn't work on my office PC!) and it works perfectly well. Unfortunately I like to use the strict pragma in all my scripts and this re-write will not work with this. If I supply AF_INET and STOCK_DGRAM as the level and optname parameters to setsockopt it fails with the old bareword not allowed error. I thought that if I put these values in variables and passed these to my script this would satisfy the strict pragma. Nope I get the following error :-
Argument "SOCK_DGRAM" isn't numeric in socket at RC_Bad_wakeonlan.pl l +ine 59, <I NF> line 1. Argument "AF_INET" isn't numeric in socket at RC_Bad_wakeonlan.pl line + 59, <INF> line 1. socket : at RC_Bad_wakeonlan.pl line 59, <INF> line 1.
The actual code in my script is :-
my $Domain = "AF_INET" ; my $Type = "SOCK_DGRAM" ; my $Level = 'SOL_SOCKET' ; my $Optname = 'SO_BROADCAST' ; # # Alocate socket and send packet $raddr = gethostbyname($ipaddr); $them = pack_sockaddr_in($port, $raddr); $proto = getprotobyname('udp'); socket(S, $Domain, $Type, $proto) or die "socket : $!"; setsockopt(S, $Level,$Optname, 1) or die "setsockopt : $!"; print "Sending magic packet to $ipaddr:$port with $hwaddr\n";

I can obviously get this to work without using the strict pragma with this code :-
socket(S, AF_INET, SOCK_DGRAM, $proto) or die "socket : $!"; setsockopt(S, SOL_SOCKET, SO_BROADCAST, 1) or die "setsockopt : $! +";
Is my understanding of this wanting? As I say I can get round it but I'm intrigued. I was also looking for the manual entry for setsockopt(2) (as alluded to on page 785 of the "Programming Perl" book but am unable to locate it on any of our servers (the powers that be probably thought these man pages took up too much room) is this documentation available on the net?

In reply to Can you use setsockopt with the strict pragma? by ronniec

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.