Article 7276 of comp.lang.perl:
Xref: feenix.metronet.com comp.lang.perl:7276
Path: feenix.metronet.com!news.ecn.bgu.edu!usenet.ins.cwru.edu!agate!ames!koriel!sh.wide!wnoc-tyo-news!scslwide!wsgw!headgw!cvgw3!tshiono
From:
[email protected] (Toru SHIONO)
Newsgroups: comp.lang.perl
Subject: Re: pack/unpack question
Message-ID: <
[email protected]>
Date: 27 Oct 93 00:29:32 GMT
References: <
[email protected]>
Sender:
[email protected] (Usenet News System)
Organization: Sony Corporation, Tokyo, Japan
Lines: 28
Nntp-Posting-Host: aquarius
X-Newsreader: prn Ver 1.07
In-reply-to:
[email protected]'s message of 25 Oct 93 20:44:40 GMT
In article <
[email protected]>
[email protected] (Daniel Rich) writes:
:Can anyone tell me why the following code segment does not work?
:
:For the following:
: $addr is a valid ip address (ie. 127.0.0.1)
: $mask is a ip mask (ie. 255.255.255.255)
: $peeraddr is the result of getpeerbyname
:
:$addr = pack("C4", (split('\.',$addr)));
:$mask = pack("C4", (split('\.',$mask)));
:if (((unpack($main'sockaddr, $peeraddr))[2] & $mask) == $addr) {
: # Grant access
:} else {
: # Deny access
:}
Put something like:
vec($foo, 0, 1);
somewhere in your code to tell Perl that you want bitwise logical
operation between binary strings.
Use `eq' in place of `==' to compare binary strings.
--
Toru "devil-may-care" Shiono Sony Corporation, JAPAN