(42S) IP Address/Subnet Calculator
|
10-25-2019, 03:40 PM
(This post was last modified: 10-25-2019 10:01 PM by Dave Britten.)
Post: #1
|
|||
|
|||
(42S) IP Address/Subnet Calculator
This program performs a few specific IP address/subnet calculations:
1. Convert a subnet mask to the corresponding CIDR suffix, and vice versa (e.g. 255.255.0.0 <-> /16) 2. Calculate the total number of host addresses available for a given subnet mask 3. Determine the network address for a given IP address and subnet mask pair 4. Determine the broadcast address for a given IP address and subnet mask pair Usage XEQ "IPADR" to start the program. All functions are carried out from a single menu. The "ADDR", "MASK", and "CIDR" keys allow for entry or calculation/display of the IP address, subnet mask, or CIDR suffix respectively. These work like typical solver menu keys. When pressed after entering data, they store the value. When pressed without data, they calculate/display the result. The "HOSTS", "NET", and "BCAST" keys calculate (i.e. they are read-only) the total number of host IP addresses available, the network address, and the broadcast address respectively. To enter an IP address or subnet mask, use all four levels of the stack to enter an address. Essentially, you press ENTER instead of putting decimal points between the bytes. T should contain the first byte (0-255), Z the second byte, and so on. The subnet mask and CIDR suffix will be automatically calculated whenever the other is entered. CIDR will only be calculated if all 1 bits in the subnet mask are left-aligned. In cases where the subnet mask is not left-aligned (e.g. 255.0.255.0), CIDR will be shown as 0. Calculating "HOSTS" requires entry of either "MASK" or "CIDR". Calculating "NET" or "BCST" requires entering "ADDR" and either "MASK" or "CIDR". Note that these can still be calculated normally even if you enter a network or broadcast address for "ADDR". You don't have to enter a host address. Examples 1. Calculate the CIDR suffix that corresponds to the subnet mask 255.255.240.0. 255 [ENTER] 255 [ENTER] 240 [ENTER] 0 ["MASK"] : MASK=255.255.240.0 ["CIDR"] : CIDR=20 2. Calculate the subnet mask for the CIDR suffix /18. 18 ["CIDR"] : CIDR=18 ["MASK"] : MASK=255.255.192.0 3. Determine the number of possible hosts on a network with subnet mask 255.255.254.0. 255 [ENTER] [ENTER] 254 [ENTER] 0 : MASK=255.255.254.0 ["HOSTS"] : HOSTS=510 4. Determine the subnet mask, network address, and broadcast address for a station with IP address 172.16.1.108/22. 172 [ENTER] 16 [ENTER] 1 [ENTER] 108 ["ADDR"] : ADDR=172.16.1.108 22 ["CIDR"] : CIDR=22 ["MASK"] : MASK=255.255.252.0 ["NET"] : NET=172.16.0.0 ["BCST"] : BCAST=172.16.3.255 Program Code Code: 00 { 446-Byte Prgm } IPAddress.zip (Size: 486 bytes / Downloads: 19) |
|||
10-25-2019, 05:49 PM
Post: #2
|
|||
|
|||
RE: (42S) IP Address/Subnet Calculator
Thanks for sharing, Dave.
Saludos Saluti Cordialement Cumprimentos MfG BR + + + + + Luigi Vampa + Free42 '<3' I + + |
|||
10-25-2019, 08:56 PM
(This post was last modified: 10-25-2019 08:57 PM by cdmackay.)
Post: #3
|
|||
|
|||
RE: (42S) IP Address/Subnet Calculator
Thanks very much for this, Dave.
Is there any reason why it might not work on a DM42? Is it dependent on any particular settings? I enter: 192 ENTER 168 ENTER 2 ENTER 1 ADDR and get: ADDR=0.0.0.8 T: 0.0000 Z: 8.0000 Y: 8.0000 X: 8.0000 Am I doing something stupid? thanks. Cambridge, UK 41CL/DM41X 12/15C/16C DM15/16 17B/II/II+ 28S 42S/DM42 32SII 48GX 50g 35s WP34S PrimeG2 WP43S/pilot/C47 Casio, Rockwell 18R |
|||
10-25-2019, 09:34 PM
Post: #4
|
|||
|
|||
RE: (42S) IP Address/Subnet Calculator
(10-25-2019 08:56 PM)cdmackay Wrote: Thanks very much for this, Dave. Hmm, it SHOULD work; I've run it on both my 42S and DM42. Let me take another look at the code and see if there's anything flag-dependent that's not obvious at first. |
|||
10-25-2019, 09:39 PM
Post: #5
|
|||
|
|||
RE: (42S) IP Address/Subnet Calculator
1st, thanks Dave, this is not only interesting but also very useful!
2nd, cd is right, something is amiss with the .raw file. I imported it into Free42, did XEQ "IPADR", but when then following the examples, get incorrect results. 255 [ENTER] 255 [ENTER] 240 [ENTER] 0 ["MASK"] : "MASK=0.0.0.0" Feasibly an issue with Free42, but highly unlikely. Is the provided file the correct version? --Bob Prosperi |
|||
10-25-2019, 09:47 PM
Post: #6
|
|||
|
|||
RE: (42S) IP Address/Subnet Calculator
(10-25-2019 09:39 PM)rprosperi Wrote: Feasibly an issue with Free42, but highly unlikely. Is the provided file the correct version? The .raw file differs with the listing file beginning at line 22 (XEQ 13 vs. XEQ 10). Not sure which is correct, so I'll let you decide. --Bob Prosperi |
|||
10-25-2019, 10:05 PM
(This post was last modified: 10-25-2019 10:14 PM by Dave Britten.)
Post: #7
|
|||
|
|||
RE: (42S) IP Address/Subnet Calculator
Well this is bizarre! There are a couple places in the program that are supposed to be XEQ 10, but somehow that step has been replaced with XEQ 13 LBL 9 in both cases. Some kind of Free42 bug perhaps? A fresh copy of the raw file from my DM42 is 2 bytes smaller than the raw file exported from Free42 2.5.10.
The code listing appears correct, and it runs fine on Free42 after importing the raw file from my DM42, so I think the issue only affects exporting programs. I've uploaded a fresh copy of the raw file taken directly from my DM42 and not modified/exported in Free42 on my computer. I also took the liberty of making the left-aligned subnet mask detection a bit more reliable. Reimport the updated raw file (or key in the code changes) and you should be good to go. EDIT: Enter this tiny program in Free42 2.5.10: LBL "TEST" XEQ 10 END Export it and reimport it, and suddenly it becomes this: LBL "TEST" XEQ 13 LBL 9 END And it's reported as being one byte larger. I've emailed Thomas, so no need to storm his inbox with additional bug reports. |
|||
10-25-2019, 10:27 PM
Post: #8
|
|||
|
|||
RE: (42S) IP Address/Subnet Calculator
(10-25-2019 10:05 PM)Dave Britten Wrote: I've uploaded a fresh copy of the raw file taken directly from my DM42 and not modified/exported in Free42 on my computer. yup, perfect now, thanks Dave. And thanks again, this one really is useful; I load lots of fun things onto my DM42, but not all of them are actually useful Cambridge, UK 41CL/DM41X 12/15C/16C DM15/16 17B/II/II+ 28S 42S/DM42 32SII 48GX 50g 35s WP34S PrimeG2 WP43S/pilot/C47 Casio, Rockwell 18R |
|||
10-25-2019, 11:28 PM
Post: #9
|
|||
|
|||
RE: (42S) IP Address/Subnet Calculator
Thanks for the rapid analysis and fix!
So, guessing the issue is not in Free42, typically a safe bet, turned out to be a bad guess. The bug is quite odd, I'm curious to hear from Thomas what that's all about. Thanks Dave! --Bob Prosperi |
|||
10-26-2019, 12:03 AM
Post: #10
|
|||
|
|||
RE: (42S) IP Address/Subnet Calculator
(10-25-2019 11:28 PM)rprosperi Wrote: Thanks for the rapid analysis and fix! To quote the pertinent part of Thomas' email reply: Quote:fopen(filename, "w") instead of fopen(filename, "wb") So there was inappropriate CR/LF translation happening in binary data, which I should have immediately guessed upon seeing that the issue involved 10 and 13 and an increase in 1 byte per occurrence. Thomas already has 2.5.11 uploaded on his site, and the release notes suggest this bug only affected the Windows version. |
|||
10-26-2019, 01:07 AM
Post: #11
|
|||
|
|||
RE: (42S) IP Address/Subnet Calculator
(10-26-2019 12:03 AM)Dave Britten Wrote: So there was inappropriate CR/LF translation happening in binary data, which I should have immediately guessed upon seeing that the issue involved 10 and 13 and an increase in 1 byte per occurrence. Good eye, noting the 13/10 relevance. I looked up the extra LBL 09, which is 0x0A, but couldn't figure how the XEQ 10 became 13. Like most issues, it's totally clear once you see the answer. :-) --Bob Prosperi |
|||
10-26-2019, 01:46 AM
(This post was last modified: 10-26-2019 07:04 PM by Thomas Okken.)
Post: #12
|
|||
|
|||
RE: (42S) IP Address/Subnet Calculator
(10-26-2019 01:07 AM)rprosperi Wrote:(10-26-2019 12:03 AM)Dave Britten Wrote: So there was inappropriate CR/LF translation happening in binary data, which I should have immediately guessed upon seeing that the issue involved 10 and 13 and an increase in 1 byte per occurrence. Yes, when I saw Dave's email, I groaned because I knew right away what was wrong, and it's such a rookie mistake. Introduced, like annoyingly many other bugs, in Free42 2.5, when the logic that creates state and raw files was moved from the platform-specific shells into the portable core. The LF-to-CRLF translation performed on files opened with fopen(filename, "w") happens only in Windows; on Unix-like operating systems, which is everything else, "w" behaves like "wb", and so raw files were always saved correctly on those platforms. |
|||
« Next Oldest | Next Newest »
|
User(s) browsing this thread: 1 Guest(s)