Forum Discussion

Altera_Forum's avatar
Altera_Forum
Icon for Honored Contributor rankHonored Contributor
14 years ago

NicheStack TCP Client not working with some servers

I've been trying to talk to an Arecont IP camera via a TCP socket client on a BeMicro Nios2 app.

The connection to the camera always failed to establish, although it was ok if I substituted the camera for a TCP server on a Windows PC.

After lots of debug, I noted that the ARP reply from the camera did not have the correct Target Protocol (IP) Address (TPA); it actually contained the camera's IP address. It should have the originating client IP address.

Investigation revealed that the NicheStack ARP receiver code filters the ARP messages using the Target IP Address (TPA).

The code is as follows:

{bsp}/iniche/src/ip/et_arp.c

int

arprcv(PACKET pkt)

{

...

/* check ARP's target IP against our net's: */

#ifdef IP_MULTICAST

if ((arphdr->ar_tpa != pkt->net->n_ipaddr) && /* if it's not for me.... */

(!IN_MULTICAST(ntohl(arphdr->ar_tpa))))

#else

if (arphdr->ar_tpa != pkt->net->n_ipaddr)

#endif/* IP_MULTICAST */

{

LOCK_NET_RESOURCE(FREEQ_RESID);

pk_free(pkt); /* not for us, dump & ret (proxy here later?) */

UNLOCK_NET_RESOURCE(FREEQ_RESID);

return (ENP_NOT_MINE);

}

As the Target IP Address does not match the client IP address, ARP discards the camera response. A connection timeout results.

Whilst the code to filter the ARP responses can be commented out, it exposes the stack to much higher traffic and buffer errors can result.

Question? Is the camera in error by not setting the ARP reply Target IP Address (TPA) correctly or is the NicheStack in error by filtering on it?

13 Replies