+ ip->ip_id = htons(ip_id++);
+
+ /*
+ * Find interface for this packet in the routing
+ * table. Note each interface has placed itself
+ * in there at boot time, so calls to rtalloc
+ * degenerate to if_ifonnetof(ip->ip_dst.s_net).
+ */
+ if (ro == 0) {
+ ro = &iproute;
+ bzero((caddr_t)ro, sizeof (*ro));
+ }
+ if (ro->ro_rt == 0) {
+ ro->ro_dst.sa_family = AF_INET;
+ ((struct sockaddr_in *)&ro->ro_dst)->sin_addr = ip->ip_dst;
+ rtalloc(ro);
+ }
+ if (ro->ro_rt == 0 || (ifp = ro->ro_rt->rt_ifp) == 0) {
+ extern int ipprintfs;
+
+ if (ipprintfs)
+ printf("no route to %x (from %x, len %d)\n",
+ ip->ip_dst.s_addr, ip->ip_src.s_addr, ip->ip_len);
+ error = ENETUNREACH;
+ goto bad;
+ }
+ dst = ro->ro_rt->rt_flags & RTF_DIRECT ?
+ (struct sockaddr *)&ro->ro_dst : &ro->ro_rt->rt_gateway;
+ if (ro == &iproute)
+ RTFREE(ro->ro_rt);
+ if (!allowbroadcast && (ifp->if_flags & IFF_BROADCAST)) {
+ struct sockaddr_in *sin;
+
+ sin = (struct sockaddr_in *)&ifp->if_broadaddr;
+ if (sin->sin_addr.s_addr == ip->ip_dst.s_addr) {
+ error = EPERM; /* ??? */
+ goto bad;
+ }
+ }