how to know connected host system IP?

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

how to know connected host system IP?

384 Views
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

Labels (1)
0 Kudos
3 Replies

265 Views
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 Kudos

265 Views
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 Kudos

265 Views
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 Kudos