tfUseCollisionDetection

Jump to: navigation, search

Table of Contents >> Optional Protocols >> AutoIP Configuration


#include <trsocket.h>



int tfUseCollisionDetection (
ttUserInterface interfaceHandle,
ttUserIpAddress ipAddress,
ttArpChkCBFunc userCbFunc
);
Conditional parameter. See details in Parameters below.


Function Description

This function allows the Treck stack to check that no other host is using a given IP address. This command instructs the Treck stack to store the given IP address, so that it can later on check for ARP requests, or replies coming from any interface, not originated by this host, and whose ARP sender addresses are the same as the given IP address. The collision detection will only start after the user calls tfUserStartArpSend(). The collision detection will continue until the user calls tfCancelCollisionDetection(). If the interface given by tfUserStartArpSend() is not configured yet, the Treck stack will also check for ARP probes sent by other hosts. The user gives a call back function to be called when a match on an ARP request, or ARP reply, or ARP probe, occurs. The interface handle, passed to the call back function, is the interface handle passed to the tfUserStartArpSend() function. The call back function can also be called if the timeout given to the tfUserStartArpSend() expires before an ARP request, or reply occurs.

The user will pass the IP address to check, a call back function, and a parameter to be passed as is to the call back function.

tfUseCollisionDetection() will first check the ARP cache for a match on the IP address to see whether another host is already using that IP address. If a match is found, it will return TM_EADDRINUSE, to indicate that another host is using the IP address. In that case the collision detection will stop right away.

tfUseCollisionDetection() will add an entry for that IP address in the global collision detection list. When incoming ARP requests, and replies come, the ARP sender IP address will be checked for a match with this entry in that list.

If an ARP reply, or request, or probe (only if interface is not configured) is received, while the IP address is being checked for collision, then the Treck stack will call the call back function in the context of the recv task, with TM_EADDRINUSE error code.

If the tfUserStartArpSend() timeout expires before the Treck stack receives any ARP reply/request, then the Treck stack will call the call back function in the context of the timer task, with the TM_ENOERROR error code.

Once started, the collision detection will stop only when the user calls tfCancelCollisionDetection().

The user can call tfUseCollisionDetection() at any time after tfStartTreck() has been called.


Parameters

  • interfaceHandle
    Interface ID as returned by tfAddInterface(). NOTE: This parameter is conditional and only present when TM_USE_STRONG_ESL is defined at compile time. For more information, please see Appendix C: Strong End System Model / Weak End System Model.
  • ipAddress
    The IP address to check.
  • userCbFunc
    Call back function. Called by the Treck stack when either an ARP reply or ARP request has been received whose source IP address matches the above IP address. Also called when a matching ARP probe is received while the interface has not been configured yet. Also called when the tfUserStartArpSend() timeout expires. See below.
  • userCbParam
    Parameter to be passed as is to the user call back function. See below.


Returns

  • TM_ENOERROR
    Success.
  • TM_EINVAL
    userCbFunc is NULL.
  • TM_EADDRINUSE
    Another host on the network has been configured with the IP address. (We found the ARP mapping in the ARP cache.)
  • TM_EALREADY
    tfUseCollisionDetection() has already been called for that IP address.
  • TM_ENOBUFS
    Not enough memory to allocate a collision detection entry.


User Callback Function: ttArpChkCBFunc

int userCbFunc (
ttUserInterface interfaceHandle,
ttUserIpAddress ipAddress,
int errorCode,
ttUserGenericUnion userCbParam
);


ttArpChkCBFunc Parameters

  • interfaceHandle
    Interface as provided to tfUserStartArpSend().
  • ipAddress
    IP address to check for collision.
  • errorCode
    Status of the ARP IP address collision detection. See below.
  • userCbParam
    Parameter as passed by the user to tfUseCollisionDetection().


Possible 'errorCode' Values

  • TM_ENOERROR
    The timeout period for sending ARP requests/Arp probes expired. See tfUserStartArpSend(). Collision detection will still continue, until the user calls tfCancelCollisionDetection().
  • TM_EADDRINUSE
    An ARP reply, or ARP request, or ARP probe (interface not configured yet) has been received. Collision detection will still continue, until the user calls tfCancelCollisionDetection().


Table of Contents >> Optional Protocols >> AutoIP Configuration