5 ms·
Similarly, browsers also accept IP addresses in decimal form, for example http://16843009 http://16843009 for 1.1.1.1
by tech234a 1y ago
Similarly, browsers also accept IP addresses in decimal form, for example http://16843009 http://16843009 for 1.1.1.1
- ryao 1y agoThey will accept IPv4 addresses in IPv6 addresses too: http://[::ffff:1.1.1.1]/ http://[::ffff:1.1.1.1]/ Sadly, cloudflare does not.
- esperent 1y agoWhat's decimal form (base ten?) and why is that 16843009 the decimal form of 1.1.1.1?
- itsgrimetime 1y ago00000001 00000001 00000001 00000001 = 16843009 in base 10 (concatenate each dot-separated 8bit number as one big base 10)
- phanimahesh 1y agoIP addresses are 4 bytes, each in the range 0-255. In binary bits xyz would be equivalent to decimal x2^2+y2+z. Similarly, bytes abc would be equivalent to decimal a256^2+b256+c. IP address p.q.r.s is decimal p256^3+q256^2+r*256+s.
- fluidcruft 1y ago1.1.1.1 is 0x01010101 and 0x01010101 is 16843009 in decimal
- ForOldHack 1y agoUm no. Parent is exactly right: p256^3+q256^2+r*256+s
- bawolff 1y agoBoth of these are the same thing
- fluidcruft 1y agoYour homework is to read up on the structure of the IP4 dataframe header.
- esperent 1y ago> 1.1.1.1 is 0x01010101 Huh, in many years of web development I never knew that. Thanks!
- johannes1234321 1y agoOnce you got that you will have a way simpler time to understand netmasks and similar and calculate IP ranges etc. it's just a 32bit integer (in ipv4; 64bit with ipv6) and the dots separate the individual bytes to give a "human friendly" representation.
- 90s_dev 1y agoI'm bad at math. What's the algorithm for this? Something about 256^(1..4)?
- davejagoda 1y agoecho 256^3+256^2+256^1+256^0|bc 16843009
- 90s_dev 1y agoHa, then I was right, but with a one-off error!
- hug 1y agoIPs are 4 octets, normally represented as a decimal between 0 and 255, or 00000000 and 1111111 in binary. Remove the dots and concat the binary value for 1.1.1.1 and you get 00000001000000010000000100000001. Convert that binary value to decimal and you get 16843009.
- opello 1y agoYou can think about it like the IP address in hex if you like: 0x01.0x01.0x01.0x01 becomes 0x01010101 which is 16,843,009. So the first 0x01 is 0x01000000 which is the familiar 16,777,216 which then gets the further "base 256 digits" added to it. Or maybe in your terms it's 256^(0..3) where you can think of it like each dotted component is a symbol (like 0-9 in base 10) where each component is a position digit. Where the right-most element is the "256^0" ("ones") digit, and the left most element is the "256^3" ("16,777,216s") digit.
- bingo-bongo 1y agoAnd the shortened form, eg. http://127.1/ http://127.1/ (for 127.0.0.1)
- ranger207 1y agoUsually they'll also accept octal with a leading zero (010.010.010.010 is 8.8.8.8), hexadecimal with a leading 0x, and omitted 0 octets (127.1 is 127.0.0.1). IIRC these are all adopted from BSD's sockets library, or some similar early IP implementation
- Mindless2112 1y agoor http://1.65793 http://1.65793 or http://1.1.257 http://1.1.257
- layer8 1y agoWhich doesn’t conform to RFC 3986, by the way. The syntax rule for host is ambiguous because it does not completely distinguish between an IPv4address and a reg-name. In order to disambiguate the syntax, we apply the "first-match-wins" algorithm: If host matches the rule for IPv4address, then it should be considered an IPv4 address literal and not a reg-name. This means that URL syntax like http://16843009/ http://16843009/, http://127.1/ http://127.1/, http://010.010.010.010/ http://010.010.010.010/, and http://127.0.0.1./ http://127.0.0.1./ (note the final dot) should be interpreted as domain names, not as IP addresses. (Domain labels are allowed to be purely numeric.)
- chrismorgan 1y agoBut it does comply with WHATWG’s URL Standard, which declares the goal of obsoleting RFC 3986, providing something that’s actually robustly implementable, and reflecting reality. Some things do definitely try to follow RFC 3986 still, but my feeling is that it’s mostly legacy stuff, and the URL Standard is much more important these days. Though RFCs dealing with URLs will probably still cite it (e.g. RFC 9110, HTTP Semantics, June 2022). https://url.spec.whatwg.org/#host-parsing https://url.spec.whatwg.org/#host-parsing, follow step seven.
- layer8 1y agoTrue, though the WHATWG algorithm still raises validation errors internally for all these cases. Meaning, while these representations are leniently accepted, they aren’t intended to be valid representations.