0001 // IP.swift 0002 // 0003 // The MIT License (MIT) 0004 // 0005 // Copyright (c) 2015 Zewo 0006 // 0007 // Permission is hereby granted, free of charge, to any person obtaining a copy 0008 // of this software and associated documentation files (the "Software"), to deal 0009 // in the Software without restriction, including without limitation the rights 0010 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 0011 // copies of the Software, and to permit persons to whom the Software is 0012 // furnished to do so, subject to the following conditions: 0013 // 0014 // The above copyright notice and this permission notice shall be included in all 0015 // copies or substantial portions of the Software. 0016 // 0017 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 0018 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 0019 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 0020 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 0021 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 0022 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 0023 // SOFTWARE. 0024 0025 import CLibvenice 0026 @_exported import Venice 0027 0028 public enum IPMode{ 0029 case IPV4
IP.swift:52 public init(localAddress: String? = nil, port: Int = 0, mode: IPMode = .IPV4Prefered) throws {IP.swift:61 public init(networkInterface: String, port: Int = 0, mode: IPMode = .IPV4Prefered) throws {IP.swift:66 public init(remoteAddress: String, port: Int, mode: IPMode = .IPV4Prefered, deadline: Deadline = never) throws {0030 case IPV6
IP.swift:36 case .IPV4: return 10031 case IPV4Prefered
IP.swift:37 case .IPV6: return 20032 case IPV6Prefered
IP.swift:38 case .IPV4Prefered: return 3IP.swift:52 public init(localAddress: String? = nil, port: Int = 0, mode: IPMode = .IPV4Prefered) throws {IP.swift:61 public init(networkInterface: String, port: Int = 0, mode: IPMode = .IPV4Prefered) throws {0033 0034 var code: Int32 { 0035 switch self { 0036 case .IPV4: return 1 0037 case .IPV6: return 2 0038 case .IPV4Prefered: return 3 0039 case .IPV6Prefered: return 4 0040 } 0041 } 0042 } 0043 0044 public struct IP
IP.swift:39 case .IPV6Prefered: return 4{ 0045 public let address
IP.swift:53 try IP.assertValidPort(port)IP.swift:62 try IP.assertValidPort(port)IP.swift:78 extension IP: CustomStringConvertible {: ipaddr 0046 0047 public init(address: ipaddr) throws { 0048 self.address = address 0049 try IPError.assertNoError() 0050 } 0051 0052 public init(localAddress: String? = nil, port: Int = 0, mode: IPMode = .IPV4Prefered) throws { 0053 try IP.assertValidPort(port) 0054 if let localAddress = localAddress { 0055 try self.init(address: iplocal(localAddress, Int32(port), mode.code)) 0056 } else { 0057 try self.init(address: iplocal(nil, Int32(port), mode.code)) 0058 } 0059 } 0060 0061 public init(networkInterface: String, port: Int = 0, mode: IPMode = .IPV4Prefered) throws { 0062 try IP.assertValidPort(port) 0063 try self.init(address: iplocal(networkInterface, Int32(port), mode.code)) 0064 } 0065 0066 public init(remoteAddress: String, port: Int, mode: IPMode = .IPV4Prefered, deadline: Deadline = never) throws { 0067 try IP.assertValidPort(port) 0068 try self.init(address: ipremote(remoteAddress, Int32(port), mode.code, deadline)) 0069 } 0070 0071 private static func assertValidPort
IP.swift:48 self.address = addressIP.swift:81 ipaddrstr(address, &buffer)(port: Int) throws { 0072 if port < 0 || port > 0xffff { 0073 throw IPError.InvalidPort(description: "Port number should be between 0 and 0xffff") 0074 } 0075 } 0076 } 0077 0078 extension IP: CustomStringConvertible { 0079 public var description: String { 0080 var buffer = [Int8](count: 46, repeatedValue: 0) 0081 ipaddrstr(address, &buffer) 0082 return String.fromCString(buffer)! 0083 } 0084 }
IP.swift:53 try IP.assertValidPort(port)IP.swift:62 try IP.assertValidPort(port)