Use of Hardcoded IPv4 Addresses
The longevity of IPv4 resulted in hard coding many well-known IPv4 addresses, such as loopback addresses (127.x.x.x), integer constants such as INADDR_LOOPBACK, among others. The practice of hard coding these addresses presents obvious problems when modifying and existing application to support IPv6 or creating new IP version-independent programs.
Best Practice
- The best approach is to avoid hardcoding any addresses.
Code To Avoid
- Avoid using hardcoded addresses in code.
To modify your existing code base from IPv4 to IPv4- and IPv6-interoperability
- Acquire the Checkv4.exe utility. The Checkv4.exe utility is installed as part of the Microsoft Windows Software Development Kit (SDK) released for Windows Vista and later.
- Run the Checkv4.exe utility against your code. Learn about how to run the Checkv4.exe utility against your files in the section on Using the Checkv4.exe Utility.
- The Checkv4.exe utility alerts you to the presence of common defines for IPv4 addresses, such as INADDR_LOOPBACK. Modify any code that uses literal strings with code that is protocol-version agnostic.
- Search your code base for other potential literal strings, as appropriate.
The Checkv4.exe utility can help you find common literal strings, but there may be others that are specific to your application. You should perform thorough searching and testing to ensure your code base has eradicated potential problems associated with literal strings.
Related topics