net/family.fz
# This file is part of the Fuzion language implementation.
#
# The Fuzion language implementation is free software: you can redistribute it
# and/or modify it under the terms of the GNU General Public License as published
# by the Free Software Foundation, version 3 of the License.
#
# The Fuzion language implementation is distributed in the hope that it will be
# useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
# License for more details.
#
# You should have received a copy of the GNU General Public License along with The
# Fuzion language implementation. If not, see <https://www.gnu.org/licenses/>.
# -----------------------------------------------------------------------
#
# Tokiwa Software GmbH, Germany
#
# Source code of Fuzion standard library feature net.family
#
# -----------------------------------------------------------------------
# defines constants for protocol families which
# can be used for network communication.
#
public family is
# Internet Protocol Version 4
public ipv4 is
public redef as_string String =>
"IPv4"
# Internet Protocol Version 6
public ipv6 is
public redef as_string String =>
"IPv6"
private:public val : choice ipv4 ipv6 is
module as_num i32 =>
match val.this
ipv4 => 2
ipv6 => 10
public redef as_string String =>
match val.this
i4 ipv4 => i4.as_string
i6 ipv6 => i6.as_string
# convenience feature to get the localhost address of a family
public localhost(f net.family.val) String =>
match f
net.family.ipv4 => "127.0.0.1"
net.family.ipv6 => "::1"