static void udp_received(struct net_context *context, struct net_pkt *pkt, int status, void *user_data) { struct net_pkt *reply_pkt; struct sockaddr dst_addr; sa_family_t family = net_pkt_family(pkt); static char dbg[MAX_DBG_PRINT + 1]; int ret; snprintf(dbg, MAX_DBG_PRINT, "UDP IPv%c", family == AF_INET6 ? '6' : '4'); set_dst_addr(family, pkt, &dst_addr); reply_pkt = build_reply_pkt(dbg, context, pkt); net_pkt_unref(pkt); ret = net_context_sendto(reply_pkt, &dst_addr, family == AF_INET6 ? sizeof(struct sockaddr_in6) : sizeof(struct sockaddr_in), pkt_sent, 0, UINT_TO_POINTER(net_pkt_get_len(reply_pkt)), user_data); if (ret < 0) { printk("Cannot send data to peer (%d)", ret); net_pkt_unref(reply_pkt); } }
void init_package_head(ap_package_t *pkt, U8 data_type,U8 src_addr, U8 dst_addr, U8 port, U8 ttl, U8 type) { memset(pkt, 0, sizeof(ap_package_t)); set_src_addr(pkt, src_addr); set_dst_addr(pkt, dst_addr); set_port(pkt, port); set_ttl(pkt, ttl);//赋值为7 set_type(pkt, type);//type传入参数为0 set_CoS(pkt,data_type); }