Parse an IP Address: Difference between revisions

m
added a ;Task and ;Example header sections, added highlighting, split long paragraphs, added whitespace before the TOC.
(Added C/POSIX solution)
m (added a ;Task and ;Example header sections, added highlighting, split long paragraphs, added whitespace before the TOC.)
Line 1:
{{task}}
{{task}}The purpose of this task is to demonstrate parsing of text-format IP addresses, using IPv4 and IPv6.
 
Taking the following as inputs:
Line 24 ⟶ 26:
 
 
;Task:
Emit each described IP address as a hexadecimal integer representing the address, the address space, and the port number specified, if any. In languages where variant result types are clumsy, the result should be ipv4 or ipv6 address number, something which says which address space was represented, port number and something that says if the port was specified.
Emit each described IP address as a hexadecimal integer representing the address, the address space, and the port number specified, if any.
 
Emit each described IP address as a hexadecimal integer representing the address, the address space, and the port number specified, if any. In languages where variant result types are clumsy, the result should be ipv4 or ipv6 address number, something which says which address space was represented, port number and something that says if the port was specified.
For example 127.0.0.1 has the address number 7F000001 (2130706433 decimal) in the ipv4 address space. ::ffff:127.0.0.1 represents the same address in the ipv6 address space where it has the address number FFFF7F000001 (281472812449793 decimal). Meanwhile ::1 has address number 1 and serves the same purpose in the ipv6 address space that 127.0.0.1 serves in the ipv4 address space.
 
 
;Example:
'''127.0.0.1'''   has the address number   '''7F000001'''   (2130706433 decimal)
in the ipv4 address space.
 
'''::ffff:127.0.0.1'''   represents the same address in the ipv6 address space where it has the
address number   '''FFFF7F000001'''   (281472812449793 decimal).
 
'''::1'''   has address number   '''1'''   and serves the same purpose in the ipv6 address
space that   '''127.0.0.1'''   serves in the ipv4 address space.
<br><br>
 
=={{header|C}}==