-
Notifications
You must be signed in to change notification settings - Fork 3
refactor: change fetchIP to return IP list with interface types #22
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -18,35 +18,41 @@ public final class NetworkFetcher: Fetcher { | |
| public init() {} | ||
|
|
||
| public func fetch() -> Network { | ||
| let ip = fetchIP() | ||
| let ipList = fetchIPList() | ||
| let type = fetchType() | ||
|
|
||
| return Network( | ||
| ip: ip, | ||
| ip: ipList, | ||
| isCellular: type == .cellular, | ||
| isWiFi: type == .wifi | ||
| ) | ||
| } | ||
| } | ||
|
|
||
| public struct InterfaceType: Hashable { | ||
| let name: String | ||
| let family: sa_family_t | ||
| } | ||
|
|
||
| public struct IP { | ||
| public let ip: String | ||
| public let interfaceType: InterfaceType | ||
| } | ||
|
|
||
| public struct Network { | ||
| public let ip: String? | ||
| public let ip: [IP] | ||
| public let isCellular: Bool | ||
| public let isWiFi: Bool | ||
| } | ||
|
|
||
| extension NetworkFetcher { | ||
| private func fetchIP() -> String? { | ||
| struct InterfaceType: Hashable { | ||
| let name: String | ||
| let family: sa_family_t | ||
| } | ||
| private func fetchIPList() -> [IP] { | ||
|
|
||
| var ipStorage: [InterfaceType: String] = [:] | ||
|
|
||
| var interfacesPointer: UnsafeMutablePointer<ifaddrs>? | ||
| guard getifaddrs(&interfacesPointer) == 0 else { return nil } | ||
| guard let interfaceFirstPointer = interfacesPointer else { return nil } | ||
| guard getifaddrs(&interfacesPointer) == 0 else { return [] } | ||
| guard let interfaceFirstPointer = interfacesPointer else { return [] } | ||
|
|
||
| for interfacePointer in sequence( | ||
| first: interfaceFirstPointer, | ||
|
|
@@ -86,13 +92,11 @@ extension NetworkFetcher { | |
| InterfaceType(name: "utun0", family: sa_family_t(AF_INET6)) | ||
| ] | ||
|
|
||
| for search in searchs { | ||
| if let ip = ipStorage[search] { | ||
| return ip | ||
| return ipStorage | ||
| .filter { searchs.contains($0.key) } | ||
| .map { key, value in | ||
| IP(ip: value, interfaceType: key) | ||
| } | ||
|
Comment on lines
+95
to
99
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 반환되는 IP 배열의 순서가 보장되지 않습니다.
🔧 순서 보장을 위한 수정 제안- return ipStorage
- .filter { searchs.contains($0.key) }
- .map { key, value in
- IP(ip: value, interfaceType: key)
- }
+ return searchs.compactMap { interfaceType in
+ guard let ip = ipStorage[interfaceType] else { return nil }
+ return IP(ip: ip, interfaceType: interfaceType)
+ }🤖 Prompt for AI Agents |
||
| } | ||
|
|
||
| return nil | ||
| } | ||
|
|
||
| private func fetchType() -> NetworkType { | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
InterfaceType속성의 접근 제어자가 누락되었습니다.public struct이지만name과family속성에 접근 제어자가 없어 기본값인internal이 적용됩니다. 외부 모듈에서IP.interfaceType.name이나IP.interfaceType.family에 접근할 수 없게 됩니다.🔧 접근 제어자 추가 제안
public struct InterfaceType: Hashable { - let name: String - let family: sa_family_t + public let name: String + public let family: sa_family_t }📝 Committable suggestion
🤖 Prompt for AI Agents