Article 5WQ1A CodeSOD: A Cup of CIDR

CodeSOD: A Cup of CIDR

by
Remy Porter
from The Daily WTF on (#5WQ1A)

Marco sends us some code that he wrote, back in the far off days of 2003. He wrote some code to handle network addresses. Unfortunately, it never quite worked. Specifically it could only handle addresses in the /24 subnet.

Now, this was written in Perl, so you know it involves regexes.

@IPstart = split(/\./,$start);@IPend = split(/\./,$end); &Check_Start_and_EndIP; # converts "short" (dotted) IPs to "long" (undotted) IPs $IPstart = (($IPstart[0]*16777216)+($IPstart[1]*65536)+($IPstart[2]*256)+$IPstart[3]); $IPend = (($IPend[0]*16777216)+($IPend[1]*65536)+($IPend[2]*256)+$IPend[3]); if($IPend < $IPstart) { die "Can't scan backwards"; }$CountIp = $IPstart;$EndIp = $IPend+1; while($CountIp ne $EndIp) { @Class = &GetIP($CountIp); push(@targetlist, "$Class[1]\.$Class[2]\.$Class[3]\.$Class[4]"); $CountIp++; }

This, by the way, is Marco's attempt to fix the broken code. As Marco puts it: "I am not a coder. I 'fix' things."

buildmaster-icon.png [Advertisement] Utilize BuildMaster to release your software with confidence, at the pace your business demands. Download today! TheDailyWtf?d=yIl2AUoC8zA
External Content
Source RSS or Atom Feed
Feed Location http://syndication.thedailywtf.com/TheDailyWtf
Feed Title The Daily WTF
Feed Link http://thedailywtf.com/
Reply 0 comments