Credentials getCredentials(int fd)
{
socklen_t length = 256;
- char buf[256];
- struct ucred cred;
+ char buf[256] = {0,};
+ struct ucred cred = {0,};
socklen_t credsz = sizeof(cred);
if (::getsockopt(fd, SOL_SOCKET, SO_PEERCRED, &cred, &credsz)) {
throw SocketException(klay::GetSystemErrorMessage());
}
- if (::getsockopt(fd, SOL_SOCKET, SO_PEERSEC, buf, &length)) {
+ int ret = ::getsockopt(fd, SOL_SOCKET, SO_PEERSEC, buf, &length);
+ // Ignores when the option is not supported by the protocol(ENOPROTOOPT).
+ if (ret != 0 && ret != ENOPROTOOPT) {
throw SocketException(klay::GetSystemErrorMessage());
}