LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Networking
User Name
Password
Linux - Networking This forum is for any issue related to networks or networking.
Routing, network cards, OSI, etc. Anything is fair game.

Notices


Reply
  Search this Thread
Old 11-25-2014, 01:23 PM   #1
vrs
LQ Newbie
 
Registered: Jul 2012
Posts: 21

Rep: Reputation: Disabled
IP address format


Greetings!

Sorry for asking a dumb question but I couldnt find answer to this question by googling so here I am.

Does an IP address with format such as 010.008.016.040 considered as valid? If yes, where in spec/RFS says it is valid or invalid? Any pointer to that RFS will be highly appreciated.

So I have an IP 10.8.17.91 (in a /22 networn) which I can ping successfully but then if I try to ping 010.8.17.91, there is no response for that ping and if I try to ping 10.08.17.91 it says, unknown host!.

Isn't 10.8.17.91 same as 010.8.17.91 or 10.08.17.91?
Pardon me if I missed any glaring IP format specification which addresses this query.

Thanks in advance.
 
Old 11-25-2014, 01:51 PM   #2
astrogeek
Moderator
 
Registered: Oct 2008
Distribution: Slackware [64]-X.{0|1|2|37|-current} ::12<=X<=15, FreeBSD_12{.0|.1}
Posts: 6,264
Blog Entries: 24

Rep: Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194
It is not so much whether an IP address with leading zeros is "valid", it depends very much on what programs the address is being passed to and whether they recognize, and convert, octal notation.

Many programs treat numbers with leading zeros as octal (base 8), others treat them as decimal values with leading zeros. Some accept hexadecimal notation (0x1c for ex.) others do not.

A quick internet search turned up many links to discussions of the subject, but nothing definitive in the context of IP addresses.

So my best answer would be that what is "valid" for IP addresses is that which will ALWAYS be interpreted as the same decimal numeric value, and that would be those without leading zeros in the address components (octets).

In your example address, the leading octet is '10'. That is ten in decimal (0xA in hex, 12 in octal). When you pass it as '010' any programs that recognize octal will take that to be 010 octal, or 8 decimal - a different thing!

Hope that helps.

Last edited by astrogeek; 11-25-2014 at 02:02 PM.
 
Old 11-25-2014, 01:57 PM   #3
vrs
LQ Newbie
 
Registered: Jul 2012
Posts: 21

Original Poster
Rep: Reputation: Disabled
Folks

I got the answer. 010.008.016.040 is NOT a valid IP address but 010.007.016.040 is a valid IP address.

Linux systems (and may be other OS as well) treats the format as binary and converts it into decimal and then 'works' on it.

Updating the answer here just in case some one stumble upon this page trying to find out the answer to similar question....
 
Old 11-25-2014, 02:01 PM   #4
vrs
LQ Newbie
 
Registered: Jul 2012
Posts: 21

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by astrogeek View Post
It is not so much whether an IP address with leading zeros is "valid", it depends very much on what program the address is being passed to and whether it recognizes octal notation.

Many programs treat numbers with leading zeros as octal (base 8), others do not. Some accept hexadecimal notation (0x1c for ex.) others do not.

A quick internet search turned up many links to discussions of the subject, but nothing definitive in the context of IP addresses.

So my best answer would be that what is "valid" for IP addresses is that which will ALWAYS be interpreted as the same decimal numeric value, and that would be those without leading zeros in the address components.

For example, in your address, the leading octet is '10'. That is ten in decimal (0xA in hex, 12 in octal). When you pass it as '010' and programs that recognize octal will take that to be 010 octal, or 8 decimal - a different thing!

Hope that helps.
Appreciate your inputs here astrogreek.

So the background of this thread was to find whether the passes argument to a program is a valid IP address or not (using bash).
While programming, this scenario came into my mind...
 
Old 11-25-2014, 02:17 PM   #5
astrogeek
Moderator
 
Registered: Oct 2008
Distribution: Slackware [64]-X.{0|1|2|37|-current} ::12<=X<=15, FreeBSD_12{.0|.1}
Posts: 6,264
Blog Entries: 24

Rep: Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194
Quote:
Originally Posted by vrs View Post
Folks
I got the answer. 010.008.016.040 is NOT a valid IP address but 010.007.016.040 is a valid IP address.
AH! Yes, in base 8, octal notation, '8' is not a valid number token, so sending it '008' means octal '8' which is not valid. '7' on the other hand is a valid octal token so 007 is a valid octal number.

This illustrates that the problem is not about valid IP addresses, but rather about numeric bases.

Quote:
Originally Posted by vrs View Post
Linux systems (and may be other OS as well) treats the format as binary and converts it into decimal and then 'works' on it.

Updating the answer here just in case some one stumble upon this page trying to find out the answer to similar question....
Actually, IP addresses are pretty much always used as binary masks - that is what makes the scheme so efficient in many ways, so what is important is the numeric value used to arrive at the binary representation - i.e. the base of the original number.

We generally pass IP addresses as base 10 values, but if a program recognizes a number with a leading zero as base 8 then it will implicitly use the octal value as the numeric value resulting in a different binary representation.

Anyway, glad you got it working!

Last edited by astrogeek; 11-25-2014 at 02:29 PM. Reason: The meaning of the first statement c'licked', added explanation...
 
Old 11-25-2014, 02:26 PM   #6
vrs
LQ Newbie
 
Registered: Jul 2012
Posts: 21

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by astrogeek View Post
Not sure what you mean by this...?



Actually, IP addresses are pretty much always used as binary masks - that is what makes the scheme so efficient in many ways, so what is important is the numeric value used to arrive at the binary representation - i.e. the base of the original number.

We generally pass IP addresses as base 10 values, but if a program recognizes a number with a leading zero as base 8 then it will implicitly use the octal value as the numeric value resulting in a different binary representation.

Anyway, glad you got it working!
Thanks astrogreek.
I mis communicated in my above reply. It should have read as octal (than binary). Leading zero is converted into decimal (from octal format).


010.008.016.040 -> is not a valid octal (008) where the other 010.007.016.040 is valid octal.
 
Old 11-25-2014, 02:30 PM   #7
astrogeek
Moderator
 
Registered: Oct 2008
Distribution: Slackware [64]-X.{0|1|2|37|-current} ::12<=X<=15, FreeBSD_12{.0|.1}
Posts: 6,264
Blog Entries: 24

Rep: Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194
Thanks, I finally understood your meaning after clicking submit - updated now.

Good luck!
 
Old 11-25-2014, 02:52 PM   #8
rknichols
Senior Member
 
Registered: Aug 2009
Distribution: Rocky Linux
Posts: 4,779

Rep: Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212
Quote:
Originally Posted by vrs View Post
010.008.016.040 -> is not a valid octal (008)
and the remaining missing link is that, since this is not a valid number, that whole 15-character string will be taken as a hostname and an attempt made to look it up on DNS, which fails with "host not found".

BTW, that whole dotted quad address gets converted to a 32-bit number, so "ping 10.8.16.40" is equivalent to "ping 168300584".
 
1 members found this post helpful.
  


Reply



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

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Which format should I expect in output of the buffer address from fbset.c? Didier Spaier Slackware 11 07-21-2014 11:58 AM
qrencode - vcard format issues with address sycamorex Linux - General 2 01-27-2012 09:20 AM
Command to know the stub domain ip address in ip4 format cola Slackware 7 04-10-2010 08:19 AM
need ip address and gateway in a particular format lothario Linux - Networking 3 05-06-2006 09:45 AM
Shell script ip address format check. rooch84 Linux - Software 6 08-18-2004 09:14 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Networking

All times are GMT -5. The time now is 08:18 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration