how to know connected host system IP?

キャンセル
次の結果を表示 
表示  限定  | 次の代わりに検索 
もしかして: 

how to know connected host system IP?

1,355件の閲覧回数
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,236件の閲覧回数
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,236件の閲覧回数
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,236件の閲覧回数
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 件の賞賛
返信