+#ifdef INET6
+ bzero(&tha, sizeof(tha));
+ rev = 0;
+ if (ip6) {
+ if (sport > dport) {
+ rev = 1;
+ } else if (sport == dport) {
+ int i;
+
+ for (i = 0; i < 4; i++) {
+ if (((u_int32_t *)(&ip6->ip6_src))[i] >
+ ((u_int32_t *)(&ip6->ip6_dst))[i]) {
+ rev = 1;
+ break;
+ }
+ }
+ }
+ if (rev) {
+ tha.src = ip6->ip6_dst;
+ tha.dst = ip6->ip6_src;
+ tha.port = dport << 16 | sport;
+ } else {
+ tha.dst = ip6->ip6_dst;
+ tha.src = ip6->ip6_src;
+ tha.port = sport << 16 | dport;
+ }
+ } else {
+ if (sport > dport ||
+ (sport == dport &&
+ ip->ip_src.s_addr > ip->ip_dst.s_addr)) {
+ rev = 1;
+ }
+ if (rev) {
+ *(struct in_addr *)&tha.src = ip->ip_dst;
+ *(struct in_addr *)&tha.dst = ip->ip_src;
+ tha.port = dport << 16 | sport;
+ } else {
+ *(struct in_addr *)&tha.dst = ip->ip_dst;
+ *(struct in_addr *)&tha.src = ip->ip_src;
+ tha.port = sport << 16 | dport;
+ }
+ }
+#else