- ip_dooptions(ip, hlen);
- if (ip->ip_dst.s_addr != n_lhost.s_addr) {
- if (--ip->ip_ttl == 0) {
- icmp_error(ip, ICMP_TIMXCEED);
- return;
+ ip_dooptions(ip);
+
+ /*
+ * Fast check on the first internet
+ * interface in the list.
+ */
+ if (ifinet) {
+ struct sockaddr_in *sin;
+
+ sin = (struct sockaddr_in *)&ifinet->if_addr;
+ if (sin->sin_addr.s_addr == ip->ip_dst.s_addr)
+ goto ours;
+ if ((ifinet->if_flags & IFF_BROADCAST) &&
+ sin->sin_addr.s_addr == ip->ip_dst.s_addr)
+ goto ours;
+ }
+ ipaddr.sin_addr = ip->ip_dst;
+ if (if_ifwithaddr((struct sockaddr *)&ipaddr) == 0) {
+ if (ipprintfs)
+ printf("forward: src %x dst %x ttl %x\n", ip->ip_src,
+ ip->ip_dst, ip->ip_ttl);
+ if (ipforwarding == 0)
+ goto bad;
+ if (ip->ip_ttl < IPTTLDEC) {
+ icmp_error(ip, ICMP_TIMXCEED, 0);
+ goto next;