Close Menu
    DevStackTipsDevStackTips
    • Home
    • News & Updates
      1. Tech & Work
      2. View All

      Sunshine And March Vibes (2025 Wallpapers Edition)

      May 15, 2025

      The Case For Minimal WordPress Setups: A Contrarian View On Theme Frameworks

      May 15, 2025

      How To Fix Largest Contentful Paint Issues With Subpart Analysis

      May 15, 2025

      How To Prevent WordPress SQL Injection Attacks

      May 15, 2025

      Intel’s latest Arc graphics driver is ready for DOOM: The Dark Ages, launching for Premium Edition owners on PC today

      May 15, 2025

      NVIDIA’s drivers are causing big problems for DOOM: The Dark Ages, but some fixes are available

      May 15, 2025

      Capcom breaks all-time profit records with 10% income growth after Monster Hunter Wilds sold over 10 million copies in a month

      May 15, 2025

      Microsoft plans to lay off 3% of its workforce, reportedly targeting management cuts as it changes to fit a “dynamic marketplace”

      May 15, 2025
    • Development
      1. Algorithms & Data Structures
      2. Artificial Intelligence
      3. Back-End Development
      4. Databases
      5. Front-End Development
      6. Libraries & Frameworks
      7. Machine Learning
      8. Security
      9. Software Engineering
      10. Tools & IDEs
      11. Web Design
      12. Web Development
      13. Web Security
      14. Programming Languages
        • PHP
        • JavaScript
      Featured

      A cross-platform Markdown note-taking application

      May 15, 2025
      Recent

      A cross-platform Markdown note-taking application

      May 15, 2025

      AI Assistant Demo & Tips for Enterprise Projects

      May 15, 2025

      Celebrating Global Accessibility Awareness Day (GAAD)

      May 15, 2025
    • Operating Systems
      1. Windows
      2. Linux
      3. macOS
      Featured

      Intel’s latest Arc graphics driver is ready for DOOM: The Dark Ages, launching for Premium Edition owners on PC today

      May 15, 2025
      Recent

      Intel’s latest Arc graphics driver is ready for DOOM: The Dark Ages, launching for Premium Edition owners on PC today

      May 15, 2025

      NVIDIA’s drivers are causing big problems for DOOM: The Dark Ages, but some fixes are available

      May 15, 2025

      Capcom breaks all-time profit records with 10% income growth after Monster Hunter Wilds sold over 10 million copies in a month

      May 15, 2025
    • Learning Resources
      • Books
      • Cheatsheets
      • Tutorials & Guides
    Home»Development»CodeSOD: How to Validate an IP Address

    CodeSOD: How to Validate an IP Address

    July 24, 2024

    Andy has some concerns about future proofing. In this case, he sends us some C# code that’s supposed to validate an IP address.

    string[] address = StringTools.splitStr(IP, ‘.’);
    if (address.length < 4) {
    throw new Exception(“Bad IP format : “ + IP); }

    Andy writes: “IPv6 will never be a thing!”

    It’s not just IPv6, of course. There are plenty of ways one might choose to represent an IP address that don’t use dot decimal notation- any 32 bit integer is potentially an IP address. But we usually represent the IP address this way. No, there’s another problem with this particular parser: it checks in address.length < 4.

    Now, this is actually genius. You see, our choices are IPv4 (32 bits of addresses), or IPv6 (128 bits of addresses), but what if we only want, oh, I don’t know, 40 bits? Well, this code will think 555.192.168.0.1 is a perfectly valid IP address, and frankly, why shouldn’t it be? A perfect bridge between IPv4 and IPv6. I’d call it IPv5, except for the fact that we had to skip 5 because of weird reasons.

    Also, C# already has a function for parsing IP addresses which also has the benefit of doing it correctly.

    [Advertisement]
    Utilize BuildMaster to release your software with confidence, at the pace your business demands. Download today!

    Source: Read More 

    Facebook Twitter Reddit Email Copy Link
    Previous ArticleHow we improved availability through iterative simplification
    Next Article Hiring Kit: Virtual Reality Designer

    Related Posts

    Security

    Nmap 7.96 Launches with Lightning-Fast DNS and 612 Scripts

    May 16, 2025
    Common Vulnerabilities and Exposures (CVEs)

    CVE-2025-4743 – Code-projects Employee Record System SQL Injection Vulnerability

    May 16, 2025
    Leave A Reply Cancel Reply

    Continue Reading

    You can get a free $349 Starlink kit if you live in one of these US states

    News & Updates

    Good Vibes Only: A Vibe Coding Primer

    Development

    How to Use Notion for Small Businesses in 2025

    Web Development

    Researcher Indicates PCTattletale Stalkerware Found on US Hotels, Corporate and Law Firm Computers Leaks Recordings

    Development

    Highlights

    Development

    Laravel 12 is Now Released

    February 25, 2025

    Laravel 12 has been released. It introduces new starter kits for React, Vue, and Livewire…

    Sigma: Changing AI Perception with Multi-Modal Semantic Segmentation through a Siamese Mamba Network for Enhanced Environmental Understanding

    April 10, 2024

    14 Best Free and Open Source CLI Tools to Find and Delete Duplicate Files

    December 17, 2024

    How to inspire the next generation of scientists | Unlocked 403: Cybersecurity podcast

    May 8, 2024
    © DevStackTips 2025. All rights reserved.
    • Contact
    • Privacy Policy

    Type above and press Enter to search. Press Esc to cancel.