File tree Expand file tree Collapse file tree 4 files changed +59
-16
lines changed
js/src/main/scala/com/comcast/ip4s
jvm-native/src/main/scala/com/comcast/ip4s
jvm/src/main/scala/com/comcast/ip4s
shared/src/main/scala/com/comcast/ip4s Expand file tree Collapse file tree 4 files changed +59
-16
lines changed Original file line number Diff line number Diff line change 1+ /*
2+ * Copyright 2018 Comcast Cable Communications Management, LLC
3+ *
4+ * Licensed under the Apache License, Version 2.0 (the "License");
5+ * you may not use this file except in compliance with the License.
6+ * You may obtain a copy of the License at
7+ *
8+ * http://www.apache.org/licenses/LICENSE-2.0
9+ *
10+ * Unless required by applicable law or agreed to in writing, software
11+ * distributed under the License is distributed on an "AS IS" BASIS,
12+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+ * See the License for the specific language governing permissions and
14+ * limitations under the License.
15+ */
16+
17+ package com .comcast .ip4s
18+
19+ private [ip4s] trait NetworkInterfaceCompanionPlatform
Original file line number Diff line number Diff line change 1+ /*
2+ * Copyright 2018 Comcast Cable Communications Management, LLC
3+ *
4+ * Licensed under the Apache License, Version 2.0 (the "License");
5+ * you may not use this file except in compliance with the License.
6+ * You may obtain a copy of the License at
7+ *
8+ * http://www.apache.org/licenses/LICENSE-2.0
9+ *
10+ * Unless required by applicable law or agreed to in writing, software
11+ * distributed under the License is distributed on an "AS IS" BASIS,
12+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+ * See the License for the specific language governing permissions and
14+ * limitations under the License.
15+ */
16+
17+ package com .comcast .ip4s
18+
19+ import java .net .{InterfaceAddress as JInterfaceAddress , NetworkInterface as JNetworkInterface }
20+
21+ import CollectionCompat .*
22+
23+ private [ip4s] trait NetworkInterfaceCompanionPlatform {
24+
25+ def fromJava (jni : JNetworkInterface ): NetworkInterface =
26+ NetworkInterface (
27+ jni.getName,
28+ jni.getDisplayName,
29+ Option (jni.getHardwareAddress).flatMap(MacAddress .fromBytes),
30+ jni.getInterfaceAddresses.asScala.toList.map(fromJavaInterfaceAddress),
31+ jni.isLoopback,
32+ jni.isUp
33+ )
34+
35+ private def fromJavaInterfaceAddress (ifa : JInterfaceAddress ): Cidr [IpAddress ] =
36+ Cidr (IpAddress .fromInetAddress(ifa.getAddress), ifa.getNetworkPrefixLength.toInt)
37+ }
Original file line number Diff line number Diff line change 1717package com .comcast .ip4s
1818
1919import cats .effect .Async
20- import java .net .{ InterfaceAddress as JInterfaceAddress , NetworkInterface as JNetworkInterface }
20+ import java .net .NetworkInterface as JNetworkInterface
2121
2222import CollectionCompat .*
2323
@@ -29,21 +29,8 @@ private[ip4s] trait NetworkInterfacesCompanionPlatform {
2929 F .blocking {
3030 collection.immutable.ListMap .empty[String , NetworkInterface ] ++
3131 JNetworkInterface .getNetworkInterfaces.asScala.toList.map(jni =>
32- jni.getName -> fromJavaNetworkInterface (jni)
32+ jni.getName -> NetworkInterface .fromJava (jni)
3333 )
3434 }
35-
36- private def fromJavaNetworkInterface (jni : JNetworkInterface ): NetworkInterface =
37- NetworkInterface (
38- jni.getName,
39- jni.getDisplayName,
40- Option (jni.getHardwareAddress).flatMap(MacAddress .fromBytes),
41- jni.getInterfaceAddresses.asScala.toList.map(fromJavaInterfaceAddress),
42- jni.isLoopback,
43- jni.isUp
44- )
45-
46- private def fromJavaInterfaceAddress (ifa : JInterfaceAddress ): Cidr [IpAddress ] =
47- Cidr (IpAddress .fromInetAddress(ifa.getAddress), ifa.getNetworkPrefixLength.toInt)
4835 }
4936}
Original file line number Diff line number Diff line change @@ -43,7 +43,7 @@ sealed trait NetworkInterface {
4343 def isUp : Boolean
4444}
4545
46- object NetworkInterface {
46+ object NetworkInterface extends NetworkInterfaceCompanionPlatform {
4747
4848 def apply (
4949 name : String ,
You can’t perform that action at this time.
0 commit comments