Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
mf
go-multiaddr
Commits
fb33680d
Commit
fb33680d
authored
Nov 05, 2014
by
Juan Batiz-Benet
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
net: added InterfaceMultiaddrs
parent
5d64ba12
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
30 additions
and
6 deletions
+30
-6
convert.go
convert.go
+8
-1
convert_test.go
convert_test.go
+1
-1
doc.go
doc.go
+2
-2
net.go
net.go
+18
-1
net_test.go
net_test.go
+1
-1
No files found.
convert.go
View file @
fb33680d
package
net
package
ma
net
import
(
"fmt"
...
...
@@ -70,6 +70,13 @@ func FromNetAddr(a net.Addr) (ma.Multiaddr, error) {
}
return
FromIP
(
ac
.
IP
)
case
"ip+net"
:
ac
,
ok
:=
a
.
(
*
net
.
IPNet
)
if
!
ok
{
return
nil
,
errIncorrectNetAddr
}
return
FromIP
(
ac
.
IP
)
default
:
return
nil
,
fmt
.
Errorf
(
"unknown network %v"
,
a
.
Network
())
}
...
...
convert_test.go
View file @
fb33680d
package
net
package
ma
net
import
(
"net"
...
...
doc.go
View file @
fb33680d
// Package net provides Multiaddr specific versions of common
// Package
ma
net provides Multiaddr specific versions of common
// functions in stdlib's net package. This means wrappers of
// standard net symbols like net.Dial and net.Listen, as well
// as conversion to/from net.Addr.
package
net
package
ma
net
net.go
View file @
fb33680d
package
net
package
ma
net
import
(
"fmt"
...
...
@@ -216,3 +216,20 @@ func Listen(laddr ma.Multiaddr) (Listener, error) {
laddr
:
laddr
,
},
nil
}
// InterfaceMultiaddrs will return the addresses matching net.InterfaceAddrs
func
InterfaceMultiaddrs
()
([]
ma
.
Multiaddr
,
error
)
{
addrs
,
err
:=
net
.
InterfaceAddrs
()
if
err
!=
nil
{
return
nil
,
err
}
maddrs
:=
make
([]
ma
.
Multiaddr
,
len
(
addrs
))
for
i
,
a
:=
range
addrs
{
maddrs
[
i
],
err
=
FromNetAddr
(
a
)
if
err
!=
nil
{
return
nil
,
err
}
}
return
maddrs
,
nil
}
net_test.go
View file @
fb33680d
package
net
package
ma
net
import
(
"bytes"
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment