@@ -331,20 +331,25 @@ static struct sockaddr_un BuildUnixSocketName(const std::string &pathname) {
331
331
// On Linux we can create it in the abstract namespace which doesn't
332
332
// consume a pathname.
333
333
addr.sun_path [0 ] = ' \0 ' ;
334
- memcpy (addr.sun_path + 1 , pathname.c_str (), std::min (pathname.size (), sizeof (addr.sun_path ) - 2 ));
334
+ memcpy (addr.sun_path + 1 , pathname.c_str (),
335
+ std::min (pathname.size (), sizeof (addr.sun_path ) - 2 ));
335
336
#else
336
337
// Portable uses the file system so it must be a valid path name.
337
- memcpy (addr.sun_path , pathname.c_str (), std::min (pathname.size (), sizeof (addr.sun_path ) - 1 ));
338
+ memcpy (addr.sun_path , pathname.c_str (),
339
+ std::min (pathname.size (), sizeof (addr.sun_path ) - 1 ));
338
340
#endif
339
341
return addr;
340
342
}
341
343
342
- static std::string ExtractUnixSocketNameString (const struct sockaddr_un &addr, socklen_t addrlen) {
344
+ static std::string ExtractUnixSocketNameString (const struct sockaddr_un &addr,
345
+ socklen_t addrlen) {
343
346
#if defined(__linux__)
344
- auto addr_str_len = strnlen (addr.sun_path + 1 , addrlen - offsetof (sockaddr_un, sun_path) - 1 );
347
+ auto addr_str_len =
348
+ strnlen (addr.sun_path + 1 , addrlen - offsetof (sockaddr_un, sun_path) - 1 );
345
349
return std::string (addr.sun_path + 1 , addr.sun_path + addr_str_len + 1 );
346
350
#else
347
- auto addr_str_len = strnlen (addr.sun_path , addrlen - offsetof (sockaddr_un, sun_path));
351
+ auto addr_str_len =
352
+ strnlen (addr.sun_path , addrlen - offsetof (sockaddr_un, sun_path));
348
353
return std::string (addr.sun_path , addr.sun_path + addr_str_len);
349
354
#endif
350
355
}
@@ -900,11 +905,16 @@ absl::Status VirtualStreamSocket::Connect(const VirtualAddress &addr) {
900
905
901
906
absl::StatusOr<VirtualAddress>
902
907
VirtualStreamSocket::LocalAddress (uint32_t port) const {
908
+ #if defined(IOCTL_VM_SOCKETS_GET_LOCAL_CID)
903
909
int32_t cid;
904
910
int e = ioctl (fd_.Fd (), IOCTL_VM_SOCKETS_GET_LOCAL_CID, &cid);
905
911
if (e == -1 ) {
906
912
return absl::InternalError (" Failed to get local CID" );
907
913
}
914
+ #else
915
+ // If we cannot get the local CID, return ANY.
916
+ int32_t cid = VMADDR_CID_ANY;
917
+ #endif
908
918
return VirtualAddress (cid, port);
909
919
}
910
920
0 commit comments