+ register struct ip *ip = mtod(m, struct ip *);
+ register struct ifnet *ifp;
+ int len, hlen = sizeof (struct ip), off, error = 0;
+ struct route iproute;
+ struct sockaddr *dst;
+
+ if (opt) /* XXX */
+ (void) m_free(opt); /* XXX */
+ /*
+ * Fill in IP header.
+ */
+ ip->ip_hl = hlen >> 2;
+ if ((flags & IP_FORWARDING) == 0) {
+ ip->ip_v = IPVERSION;
+ ip->ip_off &= IP_DF;
+ ip->ip_id = htons(ip_id++);
+ }
+
+ /*
+ * Route packet.
+ */
+ if (ro == 0) {
+ ro = &iproute;
+ bzero((caddr_t)ro, sizeof (*ro));
+ }
+ dst = &ro->ro_dst;
+ if (ro->ro_rt == 0) {
+ ro->ro_dst.sa_family = AF_INET;
+ ((struct sockaddr_in *)&ro->ro_dst)->sin_addr = ip->ip_dst;
+ /*
+ * If routing to interface only,
+ * short circuit routing lookup.
+ */
+ if (flags & IP_ROUTETOIF) {
+ ifp = if_ifonnetof(in_netof(ip->ip_dst));
+ if (ifp == 0) {
+ error = ENETUNREACH;
+ goto bad;
+ }
+ goto gotif;
+ }
+ rtalloc(ro);
+ }
+ if (ro->ro_rt == 0 || (ifp = ro->ro_rt->rt_ifp) == 0) {
+ error = ENETUNREACH;
+ goto bad;
+ }
+ ro->ro_rt->rt_use++;
+ if (ro->ro_rt->rt_flags & RTF_GATEWAY)
+ dst = &ro->ro_rt->rt_gateway;
+gotif:
+#ifndef notdef
+ /*
+ * If source address not specified yet, use address
+ * of outgoing interface.
+ */
+ if (in_lnaof(ip->ip_src) == INADDR_ANY)
+ ip->ip_src.s_addr =
+ ((struct sockaddr_in *)&ifp->if_addr)->sin_addr.s_addr;
+#endif
+
+ /*
+ * Look for broadcast address and
+ * and verify user is allowed to send
+ * such a packet.
+ */
+ if (in_lnaof(((struct sockaddr_in *)dst)->sin_addr) == INADDR_ANY) {
+ if ((ifp->if_flags & IFF_BROADCAST) == 0) {
+ error = EADDRNOTAVAIL;
+ goto bad;
+ }
+ if ((flags & IP_ALLOWBROADCAST) == 0) {
+ error = EACCES;
+ goto bad;
+ }
+ /* don't allow broadcast messages to be fragmented */
+ if (ip->ip_len > ifp->if_mtu) {
+ error = EMSGSIZE;
+ goto bad;
+ }
+ }