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
p2p
go-sockaddr
Commits
294479d0
Unverified
Commit
294479d0
authored
Apr 23, 2021
by
Steven Allen
Committed by
GitHub
Apr 23, 2021
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #20 from libp2p/fix/19
fix: allocate "any" socket type then cast
parents
d0ced09a
e4f0a92f
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
15 additions
and
11 deletions
+15
-11
sockaddr_windows.go
sockaddr_windows.go
+15
-11
No files found.
sockaddr_windows.go
View file @
294479d0
...
@@ -17,30 +17,34 @@ func sockaddrToAny(sa windows.Sockaddr) (*windows.RawSockaddrAny, Socklen, error
...
@@ -17,30 +17,34 @@ func sockaddrToAny(sa windows.Sockaddr) (*windows.RawSockaddrAny, Socklen, error
if
sa
.
Port
<
0
||
sa
.
Port
>
0xFFFF
{
if
sa
.
Port
<
0
||
sa
.
Port
>
0xFFFF
{
return
nil
,
0
,
syscall
.
EINVAL
return
nil
,
0
,
syscall
.
EINVAL
}
}
var
raw
windows
.
RawSockaddrInet4
raw
.
Family
=
windows
.
AF_INET
raw
:=
new
(
windows
.
RawSockaddrAny
)
p
:=
(
*
[
2
]
byte
)(
unsafe
.
Pointer
(
&
raw
.
Port
))
raw
.
Addr
.
Family
=
windows
.
AF_INET
raw4
:=
(
*
windows
.
RawSockaddrInet4
)(
unsafe
.
Pointer
(
raw
))
p
:=
(
*
[
2
]
byte
)(
unsafe
.
Pointer
(
&
raw4
.
Port
))
p
[
0
]
=
byte
(
sa
.
Port
>>
8
)
p
[
0
]
=
byte
(
sa
.
Port
>>
8
)
p
[
1
]
=
byte
(
sa
.
Port
)
p
[
1
]
=
byte
(
sa
.
Port
)
for
i
:=
0
;
i
<
len
(
sa
.
Addr
);
i
++
{
for
i
:=
0
;
i
<
len
(
sa
.
Addr
);
i
++
{
raw
.
Addr
[
i
]
=
sa
.
Addr
[
i
]
raw
4
.
Addr
[
i
]
=
sa
.
Addr
[
i
]
}
}
return
(
*
windows
.
RawSockaddrAny
)(
unsafe
.
Pointer
(
&
raw
))
,
Socklen
(
unsafe
.
Sizeof
(
raw
)),
nil
return
raw
,
Socklen
(
unsafe
.
Sizeof
(
*
raw
4
)),
nil
case
*
windows
.
SockaddrInet6
:
case
*
windows
.
SockaddrInet6
:
if
sa
.
Port
<
0
||
sa
.
Port
>
0xFFFF
{
if
sa
.
Port
<
0
||
sa
.
Port
>
0xFFFF
{
return
nil
,
0
,
syscall
.
EINVAL
return
nil
,
0
,
syscall
.
EINVAL
}
}
var
raw
windows
.
RawSockaddrInet6
raw
.
Family
=
windows
.
AF_INET6
raw
:=
new
(
windows
.
RawSockaddrAny
)
p
:=
(
*
[
2
]
byte
)(
unsafe
.
Pointer
(
&
raw
.
Port
))
raw
.
Addr
.
Family
=
windows
.
AF_INET6
raw6
:=
(
*
windows
.
RawSockaddrInet6
)(
unsafe
.
Pointer
(
raw
))
p
:=
(
*
[
2
]
byte
)(
unsafe
.
Pointer
(
&
raw6
.
Port
))
p
[
0
]
=
byte
(
sa
.
Port
>>
8
)
p
[
0
]
=
byte
(
sa
.
Port
>>
8
)
p
[
1
]
=
byte
(
sa
.
Port
)
p
[
1
]
=
byte
(
sa
.
Port
)
raw
.
Scope_id
=
sa
.
ZoneId
raw
6
.
Scope_id
=
sa
.
ZoneId
for
i
:=
0
;
i
<
len
(
sa
.
Addr
);
i
++
{
for
i
:=
0
;
i
<
len
(
sa
.
Addr
);
i
++
{
raw
.
Addr
[
i
]
=
sa
.
Addr
[
i
]
raw
6
.
Addr
[
i
]
=
sa
.
Addr
[
i
]
}
}
return
(
*
windows
.
RawSockaddrAny
)(
unsafe
.
Pointer
(
&
raw
))
,
Socklen
(
unsafe
.
Sizeof
(
raw
)),
nil
return
raw
,
Socklen
(
unsafe
.
Sizeof
(
*
raw
6
)),
nil
case
*
windows
.
SockaddrUnix
:
case
*
windows
.
SockaddrUnix
:
return
nil
,
0
,
syscall
.
EWINDOWS
return
nil
,
0
,
syscall
.
EWINDOWS
...
...
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