int _gai_addr_sort(const void *a, const void *b) { si_item_t **item_a, **item_b; si_addrinfo_t *p, *q; struct sockaddr *sp, *sq; item_a = (si_item_t **)a; item_b = (si_item_t **)b; p = (si_addrinfo_t *)((uintptr_t)*item_a + sizeof(si_item_t)); q = (si_addrinfo_t *)((uintptr_t)*item_b + sizeof(si_item_t)); sp = (struct sockaddr *)p->ai_addr.x; sq = (struct sockaddr *)q->ai_addr.x; /* * sa_dst_compare(A,B) returns -1 if A is less desirable than B, * 0 if they are equally desirable, and 1 if A is more desirable. * qsort() expects the inverse, so we swap sp and sq. */ #ifdef APPORTABLE #warning TODO: FIXME // this is the worst idea I have written down in code in many months... if (sq == sp) { return 0; } else if ((uintptr_t)sq < (uintptr_t)sp) { return -1; } else { return 1; } #else return sa_dst_compare(sq, sp, 0); #endif }
int _gai_addr_sort(const void *a, const void *b) { si_item_t **item_a, **item_b; si_addrinfo_t *p, *q; struct sockaddr *sp, *sq; item_a = (si_item_t **)a; item_b = (si_item_t **)b; p = (si_addrinfo_t *)((uintptr_t)*item_a + sizeof(si_item_t)); q = (si_addrinfo_t *)((uintptr_t)*item_b + sizeof(si_item_t)); sp = (struct sockaddr *)p->ai_addr.x; sq = (struct sockaddr *)q->ai_addr.x; /* * sa_dst_compare(A,B) returns -1 if A is less desirable than B, * 0 if they are equally desirable, and 1 if A is more desirable. * qsort() expects the inverse, so we swap sp and sq. */ return sa_dst_compare(sq, sp, 0); }