how to know connected host system IP?

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 

how to know connected host system IP?

1,376 次查看
sudhakarp
Contributor V

Hi,

     i am using frdmk64. and using kds2.0 and ksdk1.1.0 example.  i want to know connected host(or remote) system ip address.

if any function  there? i am listening one port but i dnt know which IP was connected to my device.

how to get  IP address of Remote(Host) System.

regards,

sudhakar p

标签 (1)
0 项奖励
回复
3 回复数

1,257 次查看
danielchen
NXP TechSupport
NXP TechSupport

Hi

I think you can get the ip address by getpeername(),  Please check the MQX RTOS RTCS User's guide for details

7.2.33   getpeername()

Gets the remote endpoint identifier of a socket.

Synopsis

uint32_t getpeername(

uint32_t socket,

sockaddr * name,

uint16_t * namelen)


Have a nice day,
Daniel

0 项奖励
回复

1,257 次查看
sudhakarp
Contributor V

hi,

actually i tried following method is it correct..?

client_sock = accept(conn_sock, NULL, NULL);

getpeername(conn_sock,&addr,sizeof(&addr));

printf("Remote IP=%u\n\r", ((sockaddr_in*) &addr)->sin_addr.s_addr);

but i am getting ZERO only

OUTPUT

Remote IP=0

     give some other idea.

regards,

sudhakar p

0 项奖励
回复

1,257 次查看
sudhakarp
Contributor V

Hi daniel,

thanks for your information. I got solution for this.

client_sock = accept(conn_sock, NULL, NULL); 
instead of this i tried

client_sock= accept(conn_sock, &remote_sin, &remote_addrlen);

printf("\nConnection accepted from %lx, port %d",

          remote_sin.sin_addr, remote_sin.sin_port);

regards,

sudhakar p

0 项奖励
回复