summaryrefslogtreecommitdiff
path: root/source3/libsmb
diff options
context:
space:
mode:
authorAndrew Tridgell <tridge@samba.org>1998-08-30 08:45:23 +0000
committerAndrew Tridgell <tridge@samba.org>1998-08-30 08:45:23 +0000
commit179e8c66f121e01b5e69ad8b1c39f8a1a1e45814 (patch)
treee404f029fbf2641365d5f618217d741cffae462c /source3/libsmb
parent3debe642bd299e1aed8578df342f4bfecf5d8b3b (diff)
downloadsamba-179e8c66f121e01b5e69ad8b1c39f8a1a1e45814.tar.gz
samba-179e8c66f121e01b5e69ad8b1c39f8a1a1e45814.tar.bz2
samba-179e8c66f121e01b5e69ad8b1c39f8a1a1e45814.zip
changed the way that name query records are sorted in replies. They
are now sorted by the number of common leading bits in the IP address with the address of the querying host. (This used to be commit 4460a1bc6aa7666d1c71d32ba73855d6ed32320a)
Diffstat (limited to 'source3/libsmb')
-rw-r--r--source3/libsmb/nmblib.c44
1 files changed, 44 insertions, 0 deletions
diff --git a/source3/libsmb/nmblib.c b/source3/libsmb/nmblib.c
index 81a9505d6b..7729380615 100644
--- a/source3/libsmb/nmblib.c
+++ b/source3/libsmb/nmblib.c
@@ -908,3 +908,47 @@ struct packet_struct *receive_packet(int fd,enum packet_type type,int t)
}
+/****************************************************************************
+return the number of bits that match between two 4 character buffers
+ ***************************************************************************/
+static int matching_bits(uchar *p1, uchar *p2)
+{
+ int i, j, ret = 0;
+ for (i=0; i<4; i++) {
+ if (p1[i] != p2[i]) break;
+ ret += 8;
+ }
+
+ if (i==4) return ret;
+
+ for (j=0; j<8; j++) {
+ if ((p1[i] & (1<<(7-j))) != (p2[i] & (1<<(7-j)))) break;
+ ret++;
+ }
+
+ return ret;
+}
+
+
+static uchar sort_ip[4];
+
+/****************************************************************************
+compare two query reply records
+ ***************************************************************************/
+static int name_query_comp(uchar *p1, uchar *p2)
+{
+ return matching_bits(p2+2, sort_ip) - matching_bits(p1+2, sort_ip);
+}
+
+/****************************************************************************
+sort a set of 6 byte name query response records so that the IPs that
+have the most leading bits in common with the specified address come first
+ ***************************************************************************/
+void sort_query_replies(char *data, int n, struct in_addr ip)
+{
+ if (n <= 1) return;
+
+ putip(sort_ip, (char *)&ip);
+
+ qsort(data, n, 6, name_query_comp);
+}