Q: Recently, I got a IP address for my computer in one of my university's resident halls. The address is read as xxx.xxx.xxx.070. So I did a ping to this address (just want to make sure it's not used by other people since I haven't connected my machine) and found out the machine already exists. When I did a telnet, I was really connected to a machine. By looking more carefully, I found I was connected to xxx.xxx.xxx.56 instead. What is the explanation?
A: Understanding the mystery requires you to know several facts:
1) 56 in decimal is 70 in octal (base 8).
2) The C programming language (and UNIX programs in general) follow the convention of interpreting constants with a leading zero as being an octal number.
3) Many TCP/IP programs such as ping and telnet that accept a dotted decimal address as an argument follow the C conventon.
I suppose that someone who was unaware that software could be confused by leading zeroes chose to represent 70 as 070 when they handed out your address. They probably thought it would make the printed version look nicer...
No comments:
Post a Comment