@@ -14,11 +14,6 @@ import (
1414 "github.com/xjasonlyu/tun2socks/v2/proxy"
1515)
1616
17- const (
18- defaultDeviceType = "tun"
19- defaultProxyType = "socks5"
20- )
21-
2217func parseRestAPI (s string ) (* url.URL , error ) {
2318 if ! strings .Contains (s , "://" ) {
2419 s = fmt .Sprintf ("%s://%s" , "http" , s )
@@ -48,7 +43,7 @@ func parseRestAPI(s string) (*url.URL, error) {
4843
4944func parseDevice (s string , mtu uint32 ) (device.Device , error ) {
5045 if ! strings .Contains (s , "://" ) {
51- s = fmt .Sprintf ("%s://%s" , defaultDeviceType , s )
46+ s = fmt .Sprintf ("%s://%s" , tun . Driver , s )
5247 }
5348
5449 u , err := url .Parse (s )
@@ -80,7 +75,7 @@ func parseFD(u *url.URL, mtu uint32) (device.Device, error) {
8075
8176func parseProxy (s string ) (proxy.Proxy , error ) {
8277 if ! strings .Contains (s , "://" ) {
83- s = fmt .Sprintf ("%s://%s" , defaultProxyType , s )
78+ s = fmt .Sprintf ("%s://%s" , "socks5" /* default */ , s )
8479 }
8580
8681 u , err := url .Parse (s )
@@ -90,8 +85,9 @@ func parseProxy(s string) (proxy.Proxy, error) {
9085 return proxy .Parse (u )
9186}
9287
93- func parseMulticastGroups (s string ) (multicastGroups []netip.Addr , _ error ) {
94- for _ , ip := range strings .Split (s , "," ) {
88+ func parseMulticastGroups (v []string ) ([]netip.Addr , error ) {
89+ groups := make ([]netip.Addr , 0 , len (v ))
90+ for _ , ip := range v {
9591 if ip = strings .TrimSpace (ip ); ip == "" {
9692 continue
9793 }
@@ -102,7 +98,7 @@ func parseMulticastGroups(s string) (multicastGroups []netip.Addr, _ error) {
10298 if ! addr .IsMulticast () {
10399 return nil , fmt .Errorf ("invalid multicast IP: %s" , addr )
104100 }
105- multicastGroups = append (multicastGroups , addr )
101+ groups = append (groups , addr )
106102 }
107- return
103+ return groups , nil
108104}
0 commit comments