C Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming LanguagesC Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old February 11th, 2003, 09:55 AM
Matthew Doucette Matthew Doucette is offline
matthewdoucette.com
Dev Shed Novice (500 - 999 posts)
 
Join Date: May 2002
Posts: 635 Matthew Doucette User rank is Private First Class (20 - 50 Reputation Level)Matthew Doucette User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 10 h 8 m 16 sec
Reputation Power: 11
what is the exact specifications/format for IPs?

What is the exact specifications/format for IPs?

This is what I know:

4 numbers [0..255] seperated by periods [.]

ex. 123.45.67.89

However, does this ever occur (leading zeros)?
123.045.067.089

(Sorry for posting here, but I was not sure where I should post this. Seeing that this is related to my C project, I posted here.)
__________________
Matthew Doucette / Xona.com

Reply With Quote
  #2  
Old February 11th, 2003, 10:49 AM
jonsagara's Avatar
jonsagara jonsagara is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2001
Location: USA
Posts: 286 jonsagara User rank is Private First Class (20 - 50 Reputation Level)jonsagara User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 7 m 23 sec
Reputation Power: 12
__________________
Jon Sagara

"Me fail English? That's unpossible!"

Reply With Quote
  #3  
Old February 11th, 2003, 02:50 PM
dwise1_aol's Avatar
dwise1_aol dwise1_aol is offline
Contributing User
Dev Shed God 2nd Plane (6000 - 6499 posts)
 
Join Date: Jan 2003
Location: USA
Posts: 6,123 dwise1_aol User rank is General 14th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 14th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 14th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 14th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 14th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 14th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 14th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 14th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 14th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 14th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 14th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 14th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 14th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 14th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 14th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 14th Grade (Above 100000 Reputation Level) 
Time spent in forums: 2 Months 2 Weeks 3 Days 16 h 5 m 8 sec
Reputation Power: 1949
Try the leading zeros. I did and it didn't work.

Consider the following:

C:\>ping www.yahoo.com

Pinging www.yahoo.akadns.net [66.218.71.88] with 32 bytes of data:

Reply from 66.218.71.88: bytes=32 time=327ms TTL=50
Reply from 66.218.71.88: bytes=32 time=286ms TTL=50
Reply from 66.218.71.88: bytes=32 time=310ms TTL=50
Reply from 66.218.71.88: bytes=32 time=324ms TTL=50

Ping statistics for 66.218.71.88:
Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
Minimum = 286ms, Maximum = 327ms, Average = 311ms

C:\>ping 066.218.071.088

Reply from 65.106.95.13: Destination net unreachable.
Reply from 65.106.95.13: Destination net unreachable.
Reply from 65.106.95.13: Destination net unreachable.
Reply from 65.106.95.13: Destination net unreachable.

Ping statistics for 54.218.57.72:
Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
Minimum = 0ms, Maximum = 0ms, Average = 0ms

C:\>

It appears that the leading zero fools ping into interpreting the octet as being in octal (octal 66 == decimal 54 and octal 71 == decimal 57). (Not so) coincidentally, C interprets numeric constants with leading zeros as being in octal.

Therefore, I would recommend against allowing leading zeros, or at least stripping them out of your input.

Reply With Quote
  #4  
Old February 12th, 2003, 07:39 AM
Matthew Doucette Matthew Doucette is offline
matthewdoucette.com
Dev Shed Novice (500 - 999 posts)
 
Join Date: May 2002
Posts: 635 Matthew Doucette User rank is Private First Class (20 - 50 Reputation Level)Matthew Doucette User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 10 h 8 m 16 sec
Reputation Power: 11
Very interesting, but where does 65.106.95.13 come from?

Reply With Quote
  #5  
Old February 12th, 2003, 10:03 AM
dwise1_aol's Avatar
dwise1_aol dwise1_aol is offline
Contributing User
Dev Shed God 2nd Plane (6000 - 6499 posts)
 
Join Date: Jan 2003
Location: USA
Posts: 6,123 dwise1_aol User rank is General 14th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 14th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 14th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 14th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 14th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 14th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 14th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 14th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 14th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 14th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 14th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 14th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 14th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 14th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 14th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 14th Grade (Above 100000 Reputation Level) 
Time spent in forums: 2 Months 2 Weeks 3 Days 16 h 5 m 8 sec
Reputation Power: 1949
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;
}

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesC Programming > what is the exact specifications/format for IPs?

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap