tunnelkit/Sources/TunnelKitCore/IPv4Settings.swift

77 lines
2.3 KiB
Swift
Raw Permalink Normal View History

//
// IPv4Settings.swift
// TunnelKit
//
// Created by Davide De Rosa on 5/19/19.
2024-01-14 13:33:14 +00:00
// Copyright (c) 2024 Davide De Rosa. All rights reserved.
//
// https://github.com/passepartoutvpn
//
// This file is part of TunnelKit.
//
// TunnelKit 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, either version 3 of the License, or
// (at your option) any later version.
//
// TunnelKit 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 TunnelKit. If not, see <http://www.gnu.org/licenses/>.
//
import Foundation
/// Encapsulates the IPv4 settings for the tunnel.
public struct IPv4Settings: Codable, Equatable, CustomStringConvertible {
2023-04-20 19:52:45 +00:00
/// Represents an IPv4 route in the routing table.
public struct Route: Codable, Hashable, CustomStringConvertible {
2023-04-20 19:52:45 +00:00
/// The destination host or subnet.
public let destination: String
2023-04-20 19:52:45 +00:00
/// The address mask.
public let mask: String
2023-04-20 19:52:45 +00:00
/// The address of the gateway (falls back to global gateway).
public let gateway: String?
2023-04-20 19:52:45 +00:00
public init(_ destination: String, _ mask: String?, _ gateway: String?) {
self.destination = destination
self.mask = mask ?? "255.255.255.255"
self.gateway = gateway
}
2023-04-20 19:52:45 +00:00
// MARK: CustomStringConvertible
2023-04-20 19:52:45 +00:00
public var description: String {
"{\(destination)/\(mask) \(gateway?.description ?? "*")}"
}
}
2023-04-20 19:52:45 +00:00
/// The address.
2019-10-23 08:55:37 +00:00
public let address: String
2023-04-20 19:52:45 +00:00
/// The address mask.
2019-10-23 08:55:37 +00:00
public let addressMask: String
2023-04-20 19:52:45 +00:00
/// The address of the default gateway.
2019-10-23 08:55:37 +00:00
public let defaultGateway: String
2023-04-20 19:52:45 +00:00
public init(address: String, addressMask: String, defaultGateway: String) {
self.address = address
self.addressMask = addressMask
self.defaultGateway = defaultGateway
2021-10-25 14:27:27 +00:00
}
2023-04-20 19:52:45 +00:00
// MARK: CustomStringConvertible
2023-04-20 19:52:45 +00:00
public var description: String {
"addr \(address) netmask \(addressMask) gw \(defaultGateway)"
}
}