cancel
Showing results for 
Search instead for 
Did you mean: 

how to get IP of a client Socket connected

Hoang_Tran
Associate III

I'm writing a program using socket API. when a client Socket connected to my server Socket ,I tried to get its IP address but the result returned 0.0.0.0.

int ConnectFD = accept(socketFD, (struct sockaddr *)&remotehost, (socklen_t *)&sockaddrsize);
if( ConnectFD != -1)
{
	struct sockaddr_in *ad;
	socklen_t len;
	ad = (struct sockaddr_in*)&remotehost;	printf("client%sconnected,ID:%d\n",ip4addr_ntoa((structip4_addr*)&ad>sin_addr),ConnectFD);

0690X000008BZEEQA4.png

2 REPLIES 2
Hoang_Tran
Associate III

up

Hoang_Tran
Associate III

up