- /* Build the IP header. */
- ip = (struct ip *)b;
- ip->ip_v = 4;
- ip->ip_hl = sizeof(*ip)/4;
- ip->ip_tos = IPTOS_RELIABILITY;
- ip->ip_len = sane_htons(mtu);
- STEP(st->q); ip->ip_id = htons(st->q);
- ip->ip_off = sane_htons(0 | IP_DF);
- ip->ip_ttl = 64;
- ip->ip_p = IPPROTO_UDP;
- ip->ip_sum = 0;
- ip->ip_src = st->me.sin.sin_addr;
- ip->ip_dst = st->a.sin.sin_addr;
-
- /* Build a UDP packet in the output buffer. */
- udp = (struct udphdr *)(ip + 1);
- udp->uh_sport = st->srcport;
- udp->uh_dport = st->dstport;
- udp->uh_ulen = htons(mtu - sizeof(*ip));
- udp->uh_sum = 0;
-
- /* Copy the payload. */
- p = (unsigned char *)(udp + 1);
- memcpy(p, buf, mtu - (p - b));
-
- /* Calculate the UDP checksum. */
- ph.ph_src = ip->ip_src;
- ph.ph_dst = ip->ip_dst;
- ph.ph_z = 0;
- ph.ph_p = IPPROTO_UDP;
- ph.ph_len = udp->uh_ulen;
- ck = IPCK_INIT;
- ck = ipcksum(&ph, sizeof(ph), ck);
- ck = ipcksum(udp, mtu - sizeof(*ip), ck);
- udp->uh_sum = htons(ck);
+ switch (st->a.sa.sa_family) {
+
+ case AF_INET:
+
+ /* Build the IP header. */
+ ip = (struct ip *)b;
+ ip->ip_v = 4;
+ ip->ip_hl = sizeof(*ip)/4;
+ ip->ip_tos = IPTOS_RELIABILITY;
+ ip->ip_len = sane_htons(mtu);
+ STEP(st->q); ip->ip_id = htons(st->q);
+ ip->ip_off = sane_htons(0 | IP_DF);
+ ip->ip_ttl = 64;
+ ip->ip_p = IPPROTO_UDP;
+ ip->ip_sum = 0;
+ ip->ip_src = st->me.sin.sin_addr;
+ ip->ip_dst = st->a.sin.sin_addr;
+
+ /* Build a UDP packet in the output buffer. */
+ udp = (struct udphdr *)(ip + 1);
+ udp->uh_sport = st->srcport;
+ udp->uh_dport = st->dstport;
+ udp->uh_ulen = htons(mtu - sizeof(*ip));
+ udp->uh_sum = 0;
+
+ /* Copy the payload. */
+ p = (unsigned char *)(udp + 1);
+ memcpy(p, buf, mtu - (p - b));
+
+ /* Calculate the UDP checksum. */
+ ph.ph_src = ip->ip_src;
+ ph.ph_dst = ip->ip_dst;
+ ph.ph_z = 0;
+ ph.ph_p = IPPROTO_UDP;
+ ph.ph_len = udp->uh_ulen;
+ ck = IPCK_INIT;
+ ck = ipcksum(&ph, sizeof(ph), ck);
+ ck = ipcksum(udp, mtu - sizeof(*ip), ck);
+ udp->uh_sum = htons(ck);
+
+ break;
+
+ default:
+ abort();
+ }