Canonicalize CIDR: Difference between revisions
→{{header|TXR}}: Remove the solution which wastefully does the bit stripping that naddr-str already performed.
(→{{header|TXR}}: Take advantage of that inaddr-str already canonicalizes the numeric address.) |
(→{{header|TXR}}: Remove the solution which wastefully does the bit stripping that naddr-str already performed.) |
||
Line 1,748:
=={{header|TXR}}==
The <code>inaddr-str</code> function in TXR Lisp parses IPv4 addresses, converting them to a <code>sockaddr-in</code> structure. If there is a slash notation present, it is recognized. The prefix value is validated and stored in the structure as the <code>prefix</code> value, and the numeric address is canonicalized to clear the irrelevant bits. Thus, the solution looks like this:
<syntaxhighlight lang="txrlisp">(defun cidr-canon (str)
Line 1,762 ⟶ 1,754:
`@(str-inaddr a.addr)/@{a.prefix}`))</syntaxhighlight>
The built-in function <code>inaddr-str-net</code> will produce this condensed prefix notation:
|