Remote IP Address Lookup for Incoming TCP Packets

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

cross mob
Anonymous
Not applicable

Is there a method to determine the remote IP address and socket when receiving TCP packets, so that the info can be properly logged? i.e.: "Received xxx from 192.168.1.110:5000\r\n"

UDP packets can make use of wiced_udp_packet_get_info but there doesn't seem to be a way to do this with TCP packets (there isn't a 'wiced_tcp_packet_get_info' function)?

I was digging into the low level wiced_tcp_socket_t implementation but this differents between NetX and lwip, and even hard-coding struct members from the NetX implementation (yuck) I still didn't get meaningful data back for the remote IP address and socket when TCP data arrives on the test echo server.

For reference sake I think the NetX fields are 'nx_tcp_socket_connect_ip' and 'nx_tcp_socket_connect_port', but this is a terrible approach anyway.

Unless I'm fundamentally misunderstanding something, this seems like a pretty big gap in the API that there isn't an easy way to get access to the remote IP address.  If there is an example of how to do this, can you please point me to it or provide a simple code snippet showing how we can log this info in something basic like the TCP echo server provided?

0 Likes
1 Solution
Anonymous
Not applicable

The UDP helper function seems to work with TCP data as well despite the unfortunate name, so:

  wiced_ip_address_t src_ip_addr;

  uint16_t           src_port;

  wiced_udp_packet_get_info(rx_packet, &src_ip_addr, &src_port);

  WPRINT_APP_INFO(("TCP RX from %u.%u.%u.%u:%d\n", U32_TO_U8S_BE(src_ip_addr.ip.v4), src_port));

View solution in original post

0 Likes
2 Replies
Anonymous
Not applicable

For reference sake, we're using the 3.1.2 API with NetX, though we may switch to FreeRTOS and LWIP for production so something that plays well with either stack would be nice here if possible.

0 Likes
Anonymous
Not applicable

The UDP helper function seems to work with TCP data as well despite the unfortunate name, so:

  wiced_ip_address_t src_ip_addr;

  uint16_t           src_port;

  wiced_udp_packet_get_info(rx_packet, &src_ip_addr, &src_port);

  WPRINT_APP_INFO(("TCP RX from %u.%u.%u.%u:%d\n", U32_TO_U8S_BE(src_ip_addr.ip.v4), src_port));

0 Likes