{"id":3461,"date":"2014-08-27T17:12:19","date_gmt":"2014-08-27T17:12:19","guid":{"rendered":"http:\/\/really.zonky.org\/?p=3461"},"modified":"2014-08-27T17:12:19","modified_gmt":"2014-08-27T17:12:19","slug":"unusual-ip-representations-and-why-hp-needs-slapping-with-a-rotten-haddock","status":"publish","type":"post","link":"https:\/\/really.zonky.org\/?p=3461","title":{"rendered":"&#8220;Unusual&#8221; IP Representations, and Why HP Needs Slapping With A Rotten Haddock"},"content":{"rendered":"<p>This post came about because HP (in their infinite wisdom) decided to make the web-based printer control all neat and tidy by aligning all of the IP columns and filling up the space with leading zeros. Spotted the problem yet?<\/p>\n<p>Well you&#8217;re quicker than I was; although I had the advantage of knowing that something was wrong and that somebody had pasted that IP address with leading zeros, it took me a few seconds to wonder if it was just possible that leading zeros might be doing something &#8220;odd&#8221;.<\/p>\n<p>The thing about IPv4 addresses (and IPv6 as well, but I&#8217;ll not be pasting in examples for those as they&#8217;re too long) is that they are\u00a0<em>not<\/em> simply what we see on screen as\u00a0<em>10.0.0.1<\/em> (or whatever). That\u00a0<em>representation<\/em> is converted into a 32-bit binary number which is used as the address. As an example :-<\/p>\n<pre>\r\n\u2713 mike@pica\u00bb <b>ping -c 1 10.0.0.1<\/b>\r\nPING 10.0.0.1 (10.0.0.1) 56(84) bytes of data.\r\n64 bytes from 10.0.0.1: icmp_req=1 ttl=255 time=0.688 ms\r\n\r\n--- 10.0.0.1 ping statistics ---\r\n1 packets transmitted, 1 received, 0% packet loss, time 0ms\r\nrtt min\/avg\/max\/mdev = 0.688\/0.688\/0.688\/0.000 ms\r\n\u2713 mike@pica\u00bb <b>ping -c 1 167772161<\/b>  \r\nPING 167772161 (10.0.0.1) 56(84) bytes of data.\r\n64 bytes from 10.0.0.1: icmp_req=1 ttl=255 time=6.04 ms\r\n\r\n--- 167772161 ping statistics ---\r\n1 packets transmitted, 1 received, 0% packet loss, time 0ms\r\nrtt min\/avg\/max\/mdev = 6.040\/6.040\/6.040\/0.000 ms\r\n<\/pre>\n<p>As you can see, you do not have to use the conventional &#8220;dotted quad&#8221; representation; you can use the integer equivalent instead. You can also see why the &#8220;dotted quad&#8221; representation was invented!<\/p>\n<p>To convert the &#8220;dotted quad&#8221; notation to an integer that can be used at the lowest level, certain calculations are performed. Either because of a peculiar clause in the original specifications of IPv4 addresses, <em>or<\/em> (and potentially more likely) as a side effect of one of the earliest implementations of IPv4, certain other representations are possible :-<\/p>\n<pre>\r\n\u2713 mike@pica\u00bb <b>ping -c 1 0xa.0.0.1<\/b>\r\nPING 0xa.0.0.1 (10.0.0.1) 56(84) bytes of data.\r\n64 bytes from 10.0.0.1: icmp_req=1 ttl=255 time=1.34 ms\r\n\r\n--- 0xa.0.0.1 ping statistics ---\r\n1 packets transmitted, 1 received, 0% packet loss, time 0ms\r\nrtt min\/avg\/max\/mdev = 1.341\/1.341\/1.341\/0.000 ms\r\n\u2713 mike@pica\u00bb <b>ping -c 1 012.0.0.1<\/b>\r\nPING 012.0.0.1 (10.0.0.1) 56(84) bytes of data.\r\n64 bytes from 10.0.0.1: icmp_req=1 ttl=255 time=1.03 ms\r\n\r\n--- 012.0.0.1 ping statistics ---\r\n1 packets transmitted, 1 received, 0% packet loss, time 0ms\r\nrtt min\/avg\/max\/mdev = 1.034\/1.034\/1.034\/0.000 ms\r\n<\/pre>\n<p>As you can see, each individual octet (the numbers between the dots) can be represented in decimal (as we expect), in hexadecimal (by prepending &#8220;0x&#8221;), <em>or<\/em> most dangerously, octal (by prepending at least one &#8220;0&#8221;).<\/p>\n<p>So an apparently innocuous IP address like <em>10.0.0.030<\/em> will actually by converted into an integer that can be converted back into a more usual <em>10.0.0.24<\/em> :-<\/p>\n<pre>\r\n\u2713 mike@pica\u00bb <b>ping 10.0.0.030<\/b>\r\nPING 10.0.0.030 (10.0.0.24) 56(84) bytes of data.\r\n<\/pre>\n<p>There are several lessons to learn from this :-<\/p>\n<ol>\n<li>HP needs slapping with a really rotten haddock to make them realise that their printers have web interfaces that are unhelpful in the extreme.\n<li>Leading zeros may be harmful, or at least may result in being slapped with a rotten haddock.\n<li>Leading zeros in IP addresses indicate the use of octal and so the result may not be what you expect.\n<li>Reading the screen can be helpful when diagnosing problems. It may be easy to miss, but there are clues enough to solve this little challenge even without knowing about octal.\n<\/ol>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>This post came about because HP (in their infinite wisdom) decided to make the web-based printer control all neat and tidy by aligning all of the IP columns and filling up the space with leading zeros. Spotted the problem yet? Well you&#8217;re quicker than I was; although I had the advantage of knowing that something <a href='https:\/\/really.zonky.org\/?p=3461' class='excerpt-more'>[&#8230;]<\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2},"jetpack_post_was_ever_published":false,"_share_on_mastodon":"0"},"categories":[4,226],"tags":[],"class_list":["post-3461","post","type-post","status-publish","format-standard","hentry","category-it","category-working-notes","category-4-id","category-226-id","post-seq-1","post-parity-odd","meta-position-corners","fix"],"share_on_mastodon":{"url":"","error":""},"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p1f2KI-TP","_links":{"self":[{"href":"https:\/\/really.zonky.org\/index.php?rest_route=\/wp\/v2\/posts\/3461","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/really.zonky.org\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/really.zonky.org\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/really.zonky.org\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/really.zonky.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=3461"}],"version-history":[{"count":3,"href":"https:\/\/really.zonky.org\/index.php?rest_route=\/wp\/v2\/posts\/3461\/revisions"}],"predecessor-version":[{"id":3464,"href":"https:\/\/really.zonky.org\/index.php?rest_route=\/wp\/v2\/posts\/3461\/revisions\/3464"}],"wp:attachment":[{"href":"https:\/\/really.zonky.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=3461"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/really.zonky.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=3461"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/really.zonky.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=3461"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}