Re: [PATCH V3 0/6] IB Netlink Interface and RDMA CM exports

Jason Gunthorpe
2010-12-14T18:27:46Z

On Mon, Dec 13, 2010 at 06:22:44PM +0200, Nir Muchtar wrote:

> static int format_address(void *addr, char *buff)
> {
> struct sockaddr_in *addr_in = (struct sockaddr_in *)addr;
> if (addr_in->sin_addr.s_addr) {
> sprintf(buff, "%s/%d", inet_ntoa(addr_in->sin_addr), ntohs(addr_in->sin_port));
> }
> else
> sprintf(buff, "N/A");
> return 0;
> }

This should be:

static void format_address(const void *addr,size_t alen,
char *buff, size_t len)
{
const sockaddr_storage *ss = addr;
if (ss->ss_family == AF_INET && alen == sizeof(sockaddr_in)) {
const sockaddr_in *ss4 = addr;
char S[64];
snprintf(buff,len,"%s-%d",inet_ntop(ss->ss_family,ss4->sin_addr,S,sizeof(S)),ntohs(ss4->sin_port));
return;
}
if (ss->ss_family == AF_INET6 && alen == sizeof(sockaddr_in6)) {
const sockaddr_in6 *ss6 = addr;
char S[64];
snprintf(buff,len,"%s-%d",inet_ntop(ss->ss_family,ss6->sin6_addr,S,sizeof(S)),ntohs(ss6->sin6_port));
return;
}
snprintf(buff,len,"??");
}

Jason