An agent can send an UNREGISTER packet if some other subagent does a register for the same sub-tree at a higher priority. An agent can also send an UNREGISTER if, for example, an SNMP manager tells it to "invalidate" the subagent connection or the registered sub-tree.
Here is an example of how to handle such a packet.
#include <snmp_dpi.h> /* DPI 2.0 API definitions */
static int do_unreg(snmp_dpi_hdr *hdr_p,
snmp_dpi_ureg_packet *pack_p)
{
printf("DPI UNREGISTER received from agent, reason=%d\n",
pack_p->reason_code);
printf(" sub-tree=%s\n",pack_p->group_p);
DPIdisconnect_from_agent(handle);
return(-1); /* causes exit in main loop */
} /* end of do_unreg() */