Get ip address from tcp socket

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
MaFa_974161
Level 5
Level 5
100 sign-ins 50 replies posted 50 questions asked

Hello ...

I have a server tcp socket connected to a client.

I want to get ip address of the client.

Here the code.

 

wiced_tcp_socket_t tcp_socket_msg;

UINT status;

 

status = wiced_tcp_create_socket ( &tcp_socket_msg, WICED_AP_INTERFACE );

if ( status != WICED_SUCCESS )
{
WPRINT_APP_INFO( ("wiced_tcp_create_socket failed, status = %d\n", status) );
}

 

status = wiced_tcp_listen ( &tcp_socket_msg, 50002 );

if ( status != WICED_SUCCESS )
{
WPRINT_APP_INFO( ("wiced_tcp_listen failed, status = %d\n", status) );
wiced_tcp_delete_socket ( &tcp_socket_msg );
return;
}

 

do
{
status = wiced_tcp_accept ( &tcp_socket_msg );

if ( status == WICED_SUCCESS )
{
WPRINT_APP_INFO( ("wiced_tcp_accept ok!\n") );
break;
}

WPRINT_APP_INFO( ("wiced_tcp_accept failed, status = %d\n", status) );

} while ( status == WICED_TCPIP_SOCKET_CLOSED );

 

HOW GET TCP CLIENT ADDRESS FROM tcp_socket_msg ???

 

0 Likes
1 Solution
YashM
Moderator
Moderator
Moderator
First question asked 250 sign-ins 100 replies posted

Hi

Just for your reference, you can try out the example code available under snip directory i.e. ap_clients_rssi.

The above example depicts the same application which you are trying to achieve. Here, the WICED device acts as an AP and it shows the number of clients (STA), along with their MAC and IP address, connected to the WICED AP.

Regards

View solution in original post

0 Likes
7 Replies
YashM
Moderator
Moderator
Moderator
First question asked 250 sign-ins 100 replies posted

Hi

You can try the following API:

wiced_result_t wiced_udp_packet_get_info( wiced_packet_t* packet, wiced_ip_address_t* address, uint16_t* port )

(Avoid the name "udp" it can be used for "tcp" as well)

Let me know whether you are able to get the IP from the above API or not.

Regards

MaFa_974161
Level 5
Level 5
100 sign-ins 50 replies posted 50 questions asked

I use ...

 

uint16_t port = 0;
status = wiced_tcp_client_peer ( &tcp_socket_msg, &tablet_ip_address, &port );

if ( status != WICED_SUCCESS )
{
WPRINT_APP_INFO( ("[##] wiced_tcp_client_peer failed, status = %d\n", status) );
return WICED_ERROR;
}

 

it's equivalent ?

0 Likes
YashM
Moderator
Moderator
Moderator
First question asked 250 sign-ins 100 replies posted

Hi

You can check the information of the APIs under C:\Users\<name>\WICED-Studio-6.6\43xxx_Wi-Fi\doc\API.html.

The wiced_tcp_client_peer(*args*) -> will give you the IP address and the source port of the server to which the client is connected.

The wiced_udp_packet_get_info(*args*) -> gives the remote IP address and UDP/TCP port of a received packet.

I assume you need the client's IP address. 

Let me know what difference do you see.

Regards

0 Likes
MaFa_974161
Level 5
Level 5
100 sign-ins 50 replies posted 50 questions asked

"wiced_tcp_client_peer works" for me but my problemi is that

WICED is a TCP server, Android Tablet is the TCP client and I have to get Tablet IP after TCP connection is established

without any TCP packet exchanged.

WICED is configured as Access Point, Tablet as STA tion.

 

0 Likes
YashM
Moderator
Moderator
Moderator
First question asked 250 sign-ins 100 replies posted

Hi

Just for your reference, you can try out the example code available under snip directory i.e. ap_clients_rssi.

The above example depicts the same application which you are trying to achieve. Here, the WICED device acts as an AP and it shows the number of clients (STA), along with their MAC and IP address, connected to the WICED AP.

Regards

0 Likes

@YashM wrote:

Hi

Just for your reference, you can try out the example code available under snip directory i.e. ap_clients_rssi.

The above example depicts the same application which you are trying to achieve. Here, the WICED device acts as an AP and it shows the number of clients (STA), along with their MAC and IP address, connected to the WICED AP.

Regards


This seems wrong direction because it won't work if your device is running as STA.

The low level network stack supports getting peer IP address after accepted a TCP connection.
The thing is wiced layer API does not provide such API, why not add it in new SDK?
And at the moment, use the low level network stack API to get peer IP address.

0 Likes

Fortunately

I run WICED as AP.

0 Likes