/*! * \brief Send an ICMP message to a given destination. * * \param type Type of the ICMP message. See NutIcmpOutput() for * a list of valid types. * \param code Type subcode. * \param spec Type specific data item. * \param dest IP address of the target. * \param nb Network buffer structure containing the message to be sent. * The structure must have been allocated by a previous * call NutNetBufAlloc() and will be freed if this function * returns with an error. * * \return 0 on success, -1 otherwise. */ int NutIcmpReply(uint8_t type, uint8_t code, uint32_t spec, uint32_t dest, NETBUF * nb) { ICMPHDR *icp; if ((nb = NutNetBufAlloc(nb, NBAF_TRANSPORT, sizeof(ICMPHDR))) == 0) return -1; icp = (ICMPHDR *) nb->nb_tp.vp; icp->icmp_code = code; icp->icmp_spec = spec; return NutIcmpOutput(type, dest, nb); }
/* * Send out ICMP echo response. */ static int NutIcmpReflect(NUTDEVICE * dev, u_char type, NETBUF * nb) { IPHDR *ip; ICMPHDR *icmp; u_long dest; IFNET *nif; ip = nb->nb_nw.vp; icmp = nb->nb_tp.vp; dest = ip->ip_src; nif = dev->dev_icb; ip->ip_src = nif->if_local_ip; ip->ip_ttl = MAXTTL; return NutIcmpOutput(type, dest, nb); }