0

getpeername() is getting failed only when i run the code with valgrind. If i run normally, getpeername is not getting failed.

Argument "in" will be having socket related information and "out" will not be having garbage(not initialized).

SOCK_GetPeerName(ITS_SocketInfo in, ITS_SocketInfo out) { char buf[BUF_SZ] = {0};

memset(out, 0, sizeof(ITS_SocketInfo));

out->socket = in->socket;
out->type = in->type;

if ( (out->addr = calloc(1, sizeof(struct sockaddr))) == NULL)
{  
    return (ITS_ENOMEM);
}

out->asize = sizeof(struct sockaddr);

if (getpeername(in->socket, out->addr, (socklen_t*)&out->asize) != 0)
{  
    ITS_TRACE_ERROR(("Error: %s errno: %d\n", strerror_r(errno, buf, BUF_SZ), errno));  <--- failing with errno : 13 (permission denied)
    free(out->addr);
    return (ITS_EBADSOCKET);
}

out->af = in->af;

return (ITS_SUCCESS);

This issue has occured only with centOS 6 series and if i run the same source code with centOS 7.1 with valgrind, getpeername is not getting failed.

Could any one help me out to figure out this issue?

0 Answers0