IP address in different formats - networking

Normally, we see IP address in this format:
"108.169.14.35",
however, if I convert it to "-o pipe" (old machine) format ,it appears like this "0|0|0|1823018531"
Now I would like to understand what causes the IP address to look entirely different. And is there a way to convert it back from "-o pipe" to "normal" format ?

1823018531 is the IP address 108.169.14.35 written in decimal format. No way to know what the zeros are for.
To convert the decimal format to "dotted quad", the standard library of your programming language probably has a subroutine for it. if not, you get the numbers from last to first by dividing by 256 and taking the remainder, and then dividing by 256 again and taking the remainder, and repeating two more times.

Related

How to write in network address/netmask the following address space?

I'd like to ask how to write in network address/netmask the following address space:
63.39.191.192 - 63.40.192.223
On paper, I couldn't figure any way of doing it, so I tried using a network address calculator to figure it out.
I inputed the first IP address and started toying with the netmask.
What I couldn't understand is how the first and last usable address varied based on the netmask.
So, here I am, hoping that you might explain to me how the first and last IP address are determined based on the netmask and how to solve that problem.
There are two things that someone might mean by a address/netmask pair. One option is something that looks like 192.168.0.1/24. This means that the first 24 bits of an acceptable address must match the given address. This is a common way of expressing subnets, however it is not possible to express your range like this. This means that you will not be able to work out a solution in the calculator you linked, which uses this method as input.
The other way is as a pair of dotted quads. The subnet above would be expressed like this: 192.168.0.1/255.255.255.0. Everything which can be expressed in the first way can be expressed in the second way, but the converse is not true.
To understand how to solve your problem using the second format, you have to know something about binary numbers. Each part of the dotted quad is a number 0-255 and can be expressed as a binary number with eight digits (bits). Thus the whole address is a binary number made up of 32 bits, each of which is either 0 or 1.
A network specification is an address, followed by another 32-bit number, expressed as an address. What the second number means is this: each place in that number where the digit is 1, the first address has to match on that digit. Each place where the digit in the netmask is 0, no match is needed. So you see how matching the first 24 bits is the same as matching 255.255.255.0, which is a 32-bit number made up of 24 1's followed by 8 0's.
You can also see how some netmasks can't be expressed in the first type. Any netmask which isn't one string of repeated 1's followed by the rest 0's, can't be written like this. The reason for the first type is that most real-world networks do have netmasks of this form.
To construct a netmask of the second type, you can work with one byte at a time. The first byte of the address has to match exactly 63. So the address will be 63.x.x.x and the mask will be 255.x.x.x. As before 255, made up of all 1's, means match every bit. The second byte can be either 39 (00100111 in binary), or 40 (00101000). This one can't be expressed as any number plus a set of bits to match. Only the first four bits of the two numbers match, but if we try to do something like 63.39.x.x/255.224.x.x (224 is 11110000), we will match any second byte from 32 to 47. You should check your previous question to see if this is right, however, you should hopefully be able to figure some more out if you understand binary.
If you're not completely sure how binary works, please go away and make sure you really get it before looking into netmasks further. It really will help and it's a very good thing to know about anyway.

IP address long format: Who invented it? Is it internationally standardised?

According to this question IP address representation in the Maxmind Geolitecity database
What is the official name for this format of an ip-address?
Who invented it? Is it internationally standardised?
I mean the format without dots. Never heard of it. I know about the binary octets separated by dots.
It is called a decimal representation. IP address is a 32bit binary number which we usually represent in the dot-decimal notation you mentioned. Since it is originally an 32bit number it is easier (and faster) to store and manipulate it in it's native format (as a number) than to parse the string representation.
For example you have 10.0.0.1 address whose octets in binary looks like:
00001010.00000000.00000000.00000001
When you lose the dots and look at it like a number you get 167772161 which is what ip2long() function will return if you pass 10.0.0.1 as an argument.

IPv6 zero compression

When using zero-compression on the following IPv6 address
2001:0DB8:0000:CD30:0000:0000:0000:0000/60
Why is this not correct:
2001:DB8::CD30::/60
... while this is:
2001:DB8:0:CD30::/60
Zero compression can only be made once. The reason for this is, that the IPv6 address is not unique any more otherwise.
Take your example 2001:DB8::CD30::/60 will it expand to
2001:0DB8:0000:0000:0000:CD30:0000:0000/60
or
2001:0DB8:0000:0000:CD30:0000:0000:0000/60
or
2001:0DB8:0000:CD30:0000:0000:0000:0000/60
...?
If only one "::" is used, the result will always be unique as there is only one possible fixed number of zeros to be inserted.
Because it is ambiguous.
The address 2001:DB8::CD30:: could be expanded in any of the following possibilities:
2001:DB8:0:CD30:0:0:0:0
2001:DB8:0:0:CD30:0:0:0
2001:DB8:0:0:0:CD30:0:0
2001:DB8:0:0:0:0:CD30:0
The reason is that :: is used to shorten multiple zeros in the 16-bit address field.
In your example 2001:0DB8:0000:CD30:0000:0000:0000:0000/60, it only has multiple 0s in the 16-bit field at the suffix, the 0000 in 2001:0DB8:0000:CD30: is just one 16-bit field and you'd just use 0 to shorten it.
More interesting question: How would you shorten this2001:0000:0000:CD30:0000:0000:0000:0000/60?
It is defined in the standard:
In addition, Section 2.2 of [RFC4291] notes,
'The "::" can only appear once in an address.'
What it means that the address can be written as either:
2001:0:0:CD30::/60 OR 2001::0:CD30:0:0:0:0/60.
Both are valid, but I'd prefer the first representation since the purpose of zeroco mpression is to shorten the address where the first representation is shorter.

Is 192.056.2.01 a valid representation of an v4 ip?

I'm writing some code to convert an v4 ip stored in a string to a custom data type (a class with 4 integers in this case).
I was wondering if I should accept ips like the one I put in the title or only ips wiht no preceding zeros, let's see it with an example.
This two ips represent the same to us (humans) and for example windows network configuration accepts them:
192.56.2.1 and 192.056.2.01
But I was wondering if the second one is actually correct or not.
I mean, according to the RFC is the second ip valid?.
Thanks in advance.
Be careful, inet_addr(3) is one of Unix's standard API to translate a textual representation of IPv4 address into an internal representation, and it interprets 056 as an octal number:
http://pubs.opengroup.org/onlinepubs/9699919799/functions/inet_addr.html
All numbers supplied as parts in IPv4 dotted decimal notation may be decimal, octal, or hexadecimal, as specified in the ISO C standard (that is, a leading 0x or 0X implies hexadecimal; otherwise, a leading '0' implies octal; otherwise, the number is interpreted as decimal).
Its younger brothers like inet_ntop(3) and getaddrinfo(3) are all the same:
http://pubs.opengroup.org/onlinepubs/9699919799/functions/inet_ntop.html
http://pubs.opengroup.org/onlinepubs/9699919799/functions/getaddrinfo.html
Summary
Although such textual representations of IP addresses like 192.056.2.01 might be valid on all platforms, different OS interpret them differently.
This would be enough reason for me to avoid such a way of textual representation.
Pros
In decimal numerotation 056 is equals to 56 so why not?
Cons
0XX format is commonly used to octal numerotation
Whatever your decisions just put it on your documentation and it will be ok :)
Defining if it is correct or not depends on your implementation.
As you mentioned windows OS considers it correct because it removes any leading zeros when it resolves the IP.
So if in your program you set an appropriate logic, e.g every subset of the IP stored in your 4 integer class, without the leading zeros, it will be correct for your case too.
Textual Representation of IPv4 and IPv6 Addresses is an “Internet-Draft”,
which, I guess, is like an RFC wanna-be. 
(Also, it expired a decade ago, on 2005-08-23,
and, apparently, has not been reissued,
so it’s not even close to being official.) 
Anyway, in Section 2: History it says,
The original IPv4 “dotted octet” format was never fully defined in any RFC,
so it is necessary to look at usage,
rather than merely find an authoritative definition,
to determine what the effective syntax was. 
The first mention of dotted octets in the RFC series is …
four dot-separated parts, each of which consists of
“three digits representing an integer value in the range 0 through 255”.
A few months later, [[IPV4-NUMB][3]] …
used dotted decimal format, zero-filling each encoded octet to three digits.
                ⋮
Meanwhile,
a very popular implementation of IP networking went off in its own direction. 
4.2BSD introduced a function inet_aton(), …
[which] allowed octal and hexadecimal in addition to decimal,
distinguishing these radices by using the C language syntax
involving a prefix “0” or “0x”, and allowed the numbers to be arbitrarily long.
The 4.2BSD inet_aton() has been widely copied and imitated,
and so is a de facto standard
for the textual representation of IPv4 addresses. 
Nevertheless, these alternative syntaxes have now fallen out of use …
[and] All the forms except for decimal octets are seen as non-standard
(despite being quite widely interoperable) and undesirable.
So, even though [POSIX defines the behavior of inet_addr][4]
to interpret leading zero as octal (and leading “0x” as hex),
it may be safest to avoid it.
P.S. [RFC 790][3] has been obsoleted by [RFC 1700][5],
which uses decimal numbers of one, two, or three digits,
without leading zeroes.
[3]: https://www.rfc-editor.org/rfc/rfc790 "the "Assigned Numbers" RFC"
[4]: http://pubs.opengroup.org/onlinepubs/9699919799/functions/inet_addr.html
[5]: https://www.rfc-editor.org/rfc/rfc1700

Assembler memory address representation

I'm trying to get into assembler and I often come across numbers in the following form:
org 7c00h
; initialize the stack:
mov ax, 07c0h
mov ss, ax
mov sp, 03feh ; top of the stack.
7c00h, 07c0h, 03feh - What is the name of this number notation? What do they mean? Why are they used over "normal" decimal numbers?
It's hexadecimal, the numeral system with 16 digits 0-9 and A-F. Memory addresses are given in hex, because it's shorter, easier to read, and the numbers that represent memory locations don't mean anything special to humans, so no sense to have long numbers. I would guess that somewhere in the past someone had to type in some addresses by hand as well, might as well have started there.
Worth noting also, 0:7C00 is the boot sector load address.
Further worth noting: 07C0:03FE is the same address as 0:7FFE due to the way segmented addressing works.
This guy's left himself a 510 byte stack (he made the very typical off-by-two error in setting up the boot sector's stack).
These are numbers in hexadecimal notation, i.e. in base 16, where A to F have the digit values 10 to 15.
One advantage is that there is a more direct conversion to binary numbers. With a little bit of practice it is easy to see which bits in the number are 1 and which are 0.
Another is is that many numbers used internally, such as memory addresses, are round numbers in hexadecimal, i.e. contain a lot of zeros.

Resources