@@ -156,24 +156,18 @@ func (fd *netFD) dial(ctx context.Context, laddr, raddr sockaddr, ctrlFn func(st
156
156
}
157
157
}
158
158
// Record the local and remote addresses from the actual socket.
159
- // For the local address, use
160
- // 1) the one returned by Getsockname, if that succeeds; or
161
- // 2) the one passed to us as the laddr parameter; or
162
- // 3) nil.
159
+ // Get the local address by calling Getsockname.
163
160
// For the remote address, use
164
161
// 1) the one returned by the connect method, if any; or
165
162
// 2) the one from Getpeername, if it succeeds; or
166
163
// 3) the one passed to us as the raddr parameter.
167
- var laddrName Addr = laddr
168
- if lsa , err := syscall .Getsockname (fd .pfd .Sysfd ); err == nil {
169
- laddrName = fd .addrFunc ()(lsa )
170
- }
164
+ lsa , _ = syscall .Getsockname (fd .pfd .Sysfd )
171
165
if crsa != nil {
172
- fd .setAddr (laddrName , fd .addrFunc ()(crsa ))
166
+ fd .setAddr (fd . addrFunc ()( lsa ) , fd .addrFunc ()(crsa ))
173
167
} else if rsa , _ = syscall .Getpeername (fd .pfd .Sysfd ); rsa != nil {
174
- fd .setAddr (laddrName , fd .addrFunc ()(rsa ))
168
+ fd .setAddr (fd . addrFunc ()( lsa ) , fd .addrFunc ()(rsa ))
175
169
} else {
176
- fd .setAddr (laddrName , raddr )
170
+ fd .setAddr (fd . addrFunc ()( lsa ) , raddr )
177
171
}
178
172
return nil
179
173
}
0 commit comments