Quote:
Originally posted by Doucette
Very interesting, but where does 65.106.95.13 come from? |
nslookup says its name is ia.xo.com, but when I try to ping it DNS fails to resolve the address. I assume that it is part of the Internet infrastructure.
Back to the original question of leading zeros, for general purposes, I wrote a quick program last night to verify that ping's treatment of IP-octet leading zeros was not atypical.
The standard sockets function for converting a dotted-decimal character string to a usable IP address (unsigned long in network byte-order) is inet_addr(). The program, iptest, takes a dotted-decimal address as its input, converts it with inet_addr(), and prints out the contents of the resultant address. The listing is at the end.
Under Winsock:
C:\dcw\PROJECTS\IPtest>iptest 66.218.71.85
66.218.71.85 --> 66.218.71.85
C:\dcw\PROJECTS\IPtest>iptest 066.218.071.085
066.218.071.085 --> 54.218.57.69
On Linux:
[dwise@pc10593 iptest]$ ./iptest 66.218.71.85
66.218.71.85 --> 66.218.71.85
[dwise@pc10593 iptest]$ ./iptest 066.218.071.85
066.218.071.85 --> 54.218.57.85
[dwise@pc10593 iptest]$ ./iptest 066.218.071.085
066.218.071.085 is not an IP address
[dwise@pc10593 iptest]$ ./iptest 066.218.071.045
066.218.071.045 --> 54.218.57.37
Interestingly, on Linux, an invalid octal digit (eg, '8') results in an error, whereas under Winsock an error is not generated even though it somehow messes up the octal conversion.
compiled under Windows with: gcc main.c -o iptest -lwsock32
WINSOCK must be defined
compiled under Linux with: gcc main.c -o iptest
WINSOCK must be undef'd
#define WINSOCK
#include <stdio.h>
#ifdef WINSOCK
#include "winsock.h"
#else
#include "arpa/inet.h"
#endif
int main(int argc, char *argv[])
{
unsigned long ulIP;
unsigned char *cp;
char address[80];
if (argc != 2) // ie, if no argument passed
{
printf("Usage: iptest <dotted decimal IP address>\n");
exit(1);
}
strcpy(address,argv[1]);
cp = (unsigned char*)&ulIP;
// convert dotted-decimal to network-order address
ulIP = inet_addr(address);
if (ulIP == -1L)
printf("%s is not an IP address\n",address);
else
printf("%s --> %d.%d.%d.%d\n",address,*cp,*(cp+1),*(cp+2),*(cp+3));
return 0;
}