void ccnl_core_RX(struct ccnl_relay_s *relay, int ifndx, unsigned char *data, int datalen, struct sockaddr *sa, int addrlen) { unsigned char *base = data; struct ccnl_face_s *from; int enc, suite = -1, skip; dispatchFct dispatch; (void) base; // silence compiler warning (if USE_DEBUG is not set) DEBUGMSG_CORE(DEBUG, "ccnl_core_RX ifndx=%d, %d bytes\n", ifndx, datalen); // DEBUGMSG_ON(DEBUG, "ccnl_core_RX ifndx=%d, %d bytes\n", ifndx, datalen); #ifdef USE_STATS if (ifndx >= 0) relay->ifs[ifndx].rx_cnt++; #endif from = ccnl_get_face_or_create(relay, ifndx, sa, addrlen); if (!from) { DEBUGMSG_CORE(DEBUG, " no face\n"); return; } else { DEBUGMSG_CORE(DEBUG, " face %d, peer=%s\n", from->faceid, ccnl_addr2ascii(&from->peer)); } // loop through all packets in the received frame (UDP, Ethernet etc) while (datalen > 0) { // work through explicit code switching while (!ccnl_switch_dehead(&data, &datalen, &enc)) suite = ccnl_enc2suite(enc); if (suite == -1) suite = ccnl_pkt2suite(data, datalen, &skip); if (!ccnl_isSuite(suite)) { DEBUGMSG_CORE(WARNING, "?unknown packet format? ccnl_core_RX ifndx=%d, %d bytes starting with 0x%02x at offset %zd\n", ifndx, datalen, *data, data - base); return; } // dispatch = ccnl_core_RX_dispatch[suite]; dispatch = ccnl_core_suites[suite].RX; if (!dispatch) { DEBUGMSG_CORE(ERROR, "Forwarder not initialized or dispatcher " "for suite %s does not exist.\n", ccnl_suite2str(suite)); return; } if (dispatch(relay, from, &data, &datalen) < 0) break; if (datalen > 0) { DEBUGMSG_CORE(WARNING, "ccnl_core_RX: %d bytes left\n", datalen); } } }
// return 1 for Reply, 0 for Request, -1 if invalid int iottlv_isReply(unsigned char *buf, int len) { int enc = 1, suite; unsigned int typ; int vallen; while (!ccnl_switch_dehead(&buf, &len, &enc)); suite = ccnl_enc2suite(enc); if (suite != CCNL_SUITE_IOTTLV) return -1; DEBUGMSG(DEBUG, "suite ok\n"); if (len < 1 || ccnl_iottlv_dehead(&buf, &len, &typ, &vallen) < 0) return -1; DEBUGMSG(DEBUG, "typ=%d, len=%d\n", typ, vallen); if (typ == IOT_TLV_Reply) return 1; if (typ == IOT_TLV_Request) return 0; return -1; }