M
Mariano
I have a socket-client application, on the server side I have a file
descriptor for client connection, now I've to know what is the client
name (otherwise IP address). I have tried to write a function, but ->
operator doesn't work. Someone know the solution???
void traccia_user(int fd)
{
int tmp_len;
struct sockaddr_in tmp;
char hbuf[NI_MAXHOST], sbuf[NI_MAXSERV];
unsigned int addrlen=sizeof(tmp);
getpeername(fd,(struct sockaddr*)&tmp,&addrlen);
printf("Client IP: %s\nClient port: %d
\n",inet_ntoa(tmp.sin_addr),tmp.sin_port);
tmp_len = sizeof(tmp);
if (getnameinfo(tmp, tmp->tmp_len, hbuf, sizeof(hbuf), sbuf,
sizeof(sbuf), NI_NUMERICHOST | NI_NUMERICSERV) == 0)
printf("host=%s, serv=%s", hbuf, sbuf);
}
descriptor for client connection, now I've to know what is the client
name (otherwise IP address). I have tried to write a function, but ->
operator doesn't work. Someone know the solution???
void traccia_user(int fd)
{
int tmp_len;
struct sockaddr_in tmp;
char hbuf[NI_MAXHOST], sbuf[NI_MAXSERV];
unsigned int addrlen=sizeof(tmp);
getpeername(fd,(struct sockaddr*)&tmp,&addrlen);
printf("Client IP: %s\nClient port: %d
\n",inet_ntoa(tmp.sin_addr),tmp.sin_port);
tmp_len = sizeof(tmp);
if (getnameinfo(tmp, tmp->tmp_len, hbuf, sizeof(hbuf), sbuf,
sizeof(sbuf), NI_NUMERICHOST | NI_NUMERICSERV) == 0)
printf("host=%s, serv=%s", hbuf, sbuf);
}