|
2 | 2 | //
|
3 | 3 | // This source file is part of the SwiftNIO open source project
|
4 | 4 | //
|
5 |
| -// Copyright (c) 2017-2018 Apple Inc. and the SwiftNIO project authors |
| 5 | +// Copyright (c) 2017-2021 Apple Inc. and the SwiftNIO project authors |
6 | 6 | // Licensed under Apache License v2.0
|
7 | 7 | //
|
8 | 8 | // See LICENSE.txt for license information
|
|
11 | 11 | // SPDX-License-Identifier: Apache-2.0
|
12 | 12 | //
|
13 | 13 | //===----------------------------------------------------------------------===//
|
14 |
| -// |
15 |
| -// Interfaces.swift |
16 |
| -// NIO |
17 |
| -// |
18 |
| -// Created by Cory Benfield on 27/02/2018. |
19 |
| -// |
20 | 14 |
|
21 | 15 | #if os(Linux) || os(FreeBSD) || os(Android)
|
22 | 16 | import CNIOLinux
|
@@ -371,158 +365,3 @@ extension NIONetworkDevice: Hashable {
|
371 | 365 | hasher.combine(self.interfaceIndex)
|
372 | 366 | }
|
373 | 367 | }
|
374 |
| - |
375 |
| -/// A representation of a single network interface on a system. |
376 |
| -@available(*, deprecated, renamed: "NIONetworkDevice") |
377 |
| -public final class NIONetworkInterface { |
378 |
| - // This is a class because in almost all cases this will carry |
379 |
| - // four structs that are backed by classes, and so will incur 4 |
380 |
| - // refcount operations each time it is copied. |
381 |
| - |
382 |
| - /// The name of the network interface. |
383 |
| - public let name: String |
384 |
| - |
385 |
| - /// The address associated with the given network interface. |
386 |
| - public let address: SocketAddress |
387 |
| - |
388 |
| - /// The netmask associated with this address, if any. |
389 |
| - public let netmask: SocketAddress? |
390 |
| - |
391 |
| - /// The broadcast address associated with this socket interface, if it has one. Some |
392 |
| - /// interfaces do not, especially those that have a `pointToPointDestinationAddress`. |
393 |
| - public let broadcastAddress: SocketAddress? |
394 |
| - |
395 |
| - /// The address of the peer on a point-to-point interface, if this is one. Some |
396 |
| - /// interfaces do not have such an address: most of those have a `broadcastAddress` |
397 |
| - /// instead. |
398 |
| - public let pointToPointDestinationAddress: SocketAddress? |
399 |
| - |
400 |
| - /// If the Interface supports Multicast |
401 |
| - public let multicastSupported: Bool |
402 |
| - |
403 |
| - /// The index of the interface, as provided by `if_nametoindex`. |
404 |
| - public let interfaceIndex: Int |
405 |
| - |
406 |
| - /// Create a brand new network interface. |
407 |
| - /// |
408 |
| - /// This constructor will fail if NIO does not understand the format of the underlying |
409 |
| - /// socket address family. This is quite common: for example, Linux will return AF_PACKET |
410 |
| - /// addressed interfaces on most platforms, which NIO does not currently understand. |
411 |
| -#if os(Windows) |
412 |
| - internal init?(_ pAdapter: UnsafeMutablePointer<IP_ADAPTER_ADDRESSES>, |
413 |
| - _ pAddress: UnsafeMutablePointer<IP_ADAPTER_UNICAST_ADDRESS>) { |
414 |
| - self.name = String(decodingCString: pAdapter.pointee.FriendlyName, |
415 |
| - as: UTF16.self) |
416 |
| - |
417 |
| - guard let address = pAddress.pointee.Address.lpSockaddr.convert() else { |
418 |
| - return nil |
419 |
| - } |
420 |
| - self.address = address |
421 |
| - |
422 |
| - // TODO: convert the prefix length to the mask itself |
423 |
| - let v4mask: (UINT8) -> SocketAddress? = { _ in |
424 |
| - var buffer: [CChar] = |
425 |
| - Array<CChar>(repeating: 0, count: Int(INET_ADDRSTRLEN)) |
426 |
| - var mask: sockaddr_in = sockaddr_in() |
427 |
| - mask.sin_family = ADDRESS_FAMILY(AF_INET) |
428 |
| - _ = buffer.withUnsafeMutableBufferPointer { |
429 |
| - try! NIOBSDSocket.inet_ntop(af: .inet, src: &mask, |
430 |
| - dst: $0.baseAddress!, |
431 |
| - size: INET_ADDRSTRLEN) |
432 |
| - } |
433 |
| - return SocketAddress(mask) |
434 |
| - } |
435 |
| - let v6mask: (UINT8) -> SocketAddress? = { _ in |
436 |
| - var buffer: [CChar] = |
437 |
| - Array<CChar>(repeating: 0, count: Int(INET6_ADDRSTRLEN)) |
438 |
| - var mask: sockaddr_in6 = sockaddr_in6() |
439 |
| - mask.sin6_family = ADDRESS_FAMILY(AF_INET6) |
440 |
| - _ = buffer.withUnsafeMutableBufferPointer { |
441 |
| - try! NIOBSDSocket.inet_ntop(af: .inet6, src: &mask, |
442 |
| - dst: $0.baseAddress!, |
443 |
| - size: INET6_ADDRSTRLEN) |
444 |
| - } |
445 |
| - return SocketAddress(mask) |
446 |
| - } |
447 |
| - |
448 |
| - switch pAddress.pointee.Address.lpSockaddr.pointee.sa_family { |
449 |
| - case ADDRESS_FAMILY(AF_INET): |
450 |
| - self.netmask = v4mask(pAddress.pointee.OnLinkPrefixLength) |
451 |
| - self.interfaceIndex = Int(pAdapter.pointee.IfIndex) |
452 |
| - case ADDRESS_FAMILY(AF_INET6): |
453 |
| - self.netmask = v6mask(pAddress.pointee.OnLinkPrefixLength) |
454 |
| - self.interfaceIndex = Int(pAdapter.pointee.Ipv6IfIndex) |
455 |
| - default: |
456 |
| - return nil |
457 |
| - } |
458 |
| - |
459 |
| - // TODO(compnerd) handle broadcast/ppp/multicast information |
460 |
| - self.broadcastAddress = nil |
461 |
| - self.pointToPointDestinationAddress = nil |
462 |
| - self.multicastSupported = false |
463 |
| - } |
464 |
| -#else |
465 |
| - internal init?(_ caddr: ifaddrs) { |
466 |
| - self.name = String(cString: caddr.ifa_name) |
467 |
| - |
468 |
| - guard caddr.ifa_addr != nil else { |
469 |
| - return nil |
470 |
| - } |
471 |
| - |
472 |
| - guard let address = caddr.ifa_addr!.convert() else { |
473 |
| - return nil |
474 |
| - } |
475 |
| - self.address = address |
476 |
| - |
477 |
| - if let netmask = caddr.ifa_netmask { |
478 |
| - self.netmask = netmask.convert() |
479 |
| - } else { |
480 |
| - self.netmask = nil |
481 |
| - } |
482 |
| - |
483 |
| - if (caddr.ifa_flags & UInt32(IFF_BROADCAST)) != 0, let addr = caddr.broadaddr { |
484 |
| - self.broadcastAddress = addr.convert() |
485 |
| - self.pointToPointDestinationAddress = nil |
486 |
| - } else if (caddr.ifa_flags & UInt32(IFF_POINTOPOINT)) != 0, let addr = caddr.dstaddr { |
487 |
| - self.broadcastAddress = nil |
488 |
| - self.pointToPointDestinationAddress = addr.convert() |
489 |
| - } else { |
490 |
| - self.broadcastAddress = nil |
491 |
| - self.pointToPointDestinationAddress = nil |
492 |
| - } |
493 |
| - |
494 |
| - if (caddr.ifa_flags & UInt32(IFF_MULTICAST)) != 0 { |
495 |
| - self.multicastSupported = true |
496 |
| - } else { |
497 |
| - self.multicastSupported = false |
498 |
| - } |
499 |
| - |
500 |
| - do { |
501 |
| - self.interfaceIndex = Int(try Posix.if_nametoindex(caddr.ifa_name)) |
502 |
| - } catch { |
503 |
| - return nil |
504 |
| - } |
505 |
| - } |
506 |
| -#endif |
507 |
| -} |
508 |
| - |
509 |
| -@available(*, deprecated, renamed: "NIONetworkDevice") |
510 |
| -extension NIONetworkInterface: CustomDebugStringConvertible { |
511 |
| - public var debugDescription: String { |
512 |
| - let baseString = "Interface \(self.name): address \(self.address)" |
513 |
| - let maskString = self.netmask != nil ? " netmask \(self.netmask!)" : "" |
514 |
| - return baseString + maskString |
515 |
| - } |
516 |
| -} |
517 |
| - |
518 |
| -@available(*, deprecated, renamed: "NIONetworkDevice") |
519 |
| -extension NIONetworkInterface: Equatable { |
520 |
| - public static func ==(lhs: NIONetworkInterface, rhs: NIONetworkInterface) -> Bool { |
521 |
| - return lhs.name == rhs.name && |
522 |
| - lhs.address == rhs.address && |
523 |
| - lhs.netmask == rhs.netmask && |
524 |
| - lhs.broadcastAddress == rhs.broadcastAddress && |
525 |
| - lhs.pointToPointDestinationAddress == rhs.pointToPointDestinationAddress && |
526 |
| - lhs.interfaceIndex == rhs.interfaceIndex |
527 |
| - } |
528 |
| -} |
0 commit comments