Skip to content

Commit 95bbf83

Browse files
committed
use github.com/wlynxg/anet package
may fix #253
1 parent f2ffd09 commit 95bbf83

File tree

6 files changed

+12
-6
lines changed

6 files changed

+12
-6
lines changed

build-all.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ GOBIN="go"
4444

4545
$GOBIN version
4646

47-
LDFLAGS="'-s -w'"
47+
LDFLAGS="'-s -w -checklinkname=0'"
4848
FAILURES=""
4949
ROOT=${PWD}
5050
OUTPUT="${ROOT}/dist/TorrServer"

server/dlna/dlna.go

+3-2
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313

1414
"github.com/anacrolix/dms/dlna/dms"
1515
"github.com/anacrolix/log"
16+
"github.com/wlynxg/anet"
1617

1718
"server/settings"
1819
"server/web/pages/template"
@@ -26,7 +27,7 @@ func Start() {
2627
Logger: logger.WithNames("dms", "server"),
2728
Interfaces: func() (ifs []net.Interface) {
2829
var err error
29-
ifaces, err := net.Interfaces()
30+
ifaces, err := anet.Interfaces()
3031
if err != nil {
3132
logger.Levelf(log.Error, "%v", err)
3233
return
@@ -171,7 +172,7 @@ func getDefaultFriendlyName() string {
171172
}
172173

173174
if host == "localhost" { // useless host, use 1st IP
174-
ifaces, err := net.Interfaces()
175+
ifaces, err := anet.Interfaces()
175176
if err != nil {
176177
return ret + ": " + userName + "@" + host
177178
}

server/go.mod

+1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ require (
2323
github.com/swaggo/files v1.0.1
2424
github.com/swaggo/gin-swagger v1.6.0
2525
github.com/swaggo/swag v1.16.3
26+
github.com/wlynxg/anet v0.0.5
2627
go.etcd.io/bbolt v1.3.10
2728
golang.org/x/exp v0.0.0-20240531132922-fd00a4e0eefc
2829
golang.org/x/image v0.18.0

server/go.sum

+2
Original file line numberDiff line numberDiff line change
@@ -338,6 +338,8 @@ github.com/ugorji/go/codec v1.2.12 h1:9LC83zGrHhuUA9l16C9AHXAqEV/2wBQ4nkvumAE65E
338338
github.com/ugorji/go/codec v1.2.12/go.mod h1:UNopzCgEMSXjBc6AOMqYvWC1ktqTAfzJZUZgYf6w6lg=
339339
github.com/willf/bitset v1.1.9/go.mod h1:RjeCKbqT1RxIR/KWY6phxZiaY1IyutSBfGjNPySAYV4=
340340
github.com/willf/bitset v1.1.10/go.mod h1:RjeCKbqT1RxIR/KWY6phxZiaY1IyutSBfGjNPySAYV4=
341+
github.com/wlynxg/anet v0.0.5 h1:J3VJGi1gvo0JwZ/P1/Yc/8p63SoW98B5dHkYDmpgvvU=
342+
github.com/wlynxg/anet v0.0.5/go.mod h1:eay5PRQr7fIVAMbTbchTnO9gG65Hg/uYGdc7mguHxoA=
341343
github.com/yuin/goldmark v1.4.1/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k=
342344
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
343345
go.etcd.io/bbolt v1.3.10 h1:+BqfJTcCzTItrop8mq/lbzL8wSGtj94UO/3U31shqG0=

server/torr/btserver.go

+3-2
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"github.com/anacrolix/publicip"
1111
"github.com/anacrolix/torrent"
1212
"github.com/anacrolix/torrent/metainfo"
13+
"github.com/wlynxg/anet"
1314

1415
"server/settings"
1516
"server/torr/storage/torrstor"
@@ -207,7 +208,7 @@ func isPrivateIP(ip net.IP) bool {
207208
}
208209

209210
func getPublicIp4() net.IP {
210-
ifaces, err := net.Interfaces()
211+
ifaces, err := anet.Interfaces()
211212
if err != nil {
212213
log.Println("Error get public IPv4")
213214
return nil
@@ -233,7 +234,7 @@ func getPublicIp4() net.IP {
233234
}
234235

235236
func getPublicIp6() net.IP {
236-
ifaces, err := net.Interfaces()
237+
ifaces, err := anet.Interfaces()
237238
if err != nil {
238239
log.Println("Error get public IPv6")
239240
return nil

server/web/server.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"github.com/gin-contrib/cors"
1111
"github.com/gin-contrib/location"
1212
"github.com/gin-gonic/gin"
13+
"github.com/wlynxg/anet"
1314

1415
"server/dlna"
1516
"server/settings"
@@ -139,7 +140,7 @@ func echo(c *gin.Context) {
139140
}
140141

141142
func getLocalIps() []string {
142-
ifaces, err := net.Interfaces()
143+
ifaces, err := anet.Interfaces()
143144
if err != nil {
144145
log.TLogln("Error get local IPs")
145146
return nil

0 commit comments

Comments
 (0)