diff -crN tng/source/utils/nmblookup.c tng-modified/source/utils/nmblookup.c *** tng/source/utils/nmblookup.c Sat Dec 21 12:15:56 2002 --- tng-modified/source/utils/nmblookup.c Wed Feb 26 03:40:34 2003 *************** *** 20,25 **** --- 20,33 ---- */ + /* + Modified for -X switch, which specifically queries a host to determine + if it is a PDC or BDC. Only real problems, are hosts that return: + INet~Services with 0x1c, but it'll be apparent. + netmask@enZotech.net + http://www.enZotech.net/files/nmb-pdc.patch + */ + #include "includes.h" #include "libsamba.h" #include "libnmb.h" *************** *** 74,79 **** --- 82,88 ---- printf("\t-T translate IP addresses into names\n"); printf("\t-r Use root port 137 (Win95 only replies to this)\n"); printf("\t-A Do a node status on as an IP Address\n"); + printf("\t-X Check if it is a PDC or BDC\n"); printf("\t-i NetBIOS scope Use the given NetBIOS scope for name queries\n"); printf("\t-s smb.conf file Use the given path to the smb.conf file\n"); printf("\t-h Print this help message.\n"); *************** *** 130,135 **** --- 139,197 ---- printf("\n"); } + static void do_pdc_status(int fd, char *name, int type, struct in_addr ip) + { + struct nmb_name nname; + int count, i, j; + int a = 0; + int b = 0; + struct node_status *status; + fstring cleanname; + + printf("Checking for PDC or BDC of %s\n\n",inet_ntoa(ip)); + make_nmb_name(&nname, name, type); + status = name_status_query(fd,&nname,ip,&count); + if (status) { + for (i=0;i 0) || (b == 0 && a > 0)) + printf("Host determined to be a BDC\n"); + + else if (a > 0 && b > 0) + printf("Host determined to be a PDC\n"); + + else + printf("Host is not a PDC or BDC\n"); + } + } + + + + + + + + + /**************************************************************************** send out one query *************** *** 197,202 **** --- 259,265 ---- BOOL find_master=False; int i; BOOL lookup_by_ip = False; + BOOL CheckPDC = False; const char *commandline_debuglevel = NULL; debug_parse_levels("1"); *************** *** 208,214 **** charset_initialise(); ! while ((opt = getopt(argc, argv, "d:B:U:i:s:SMrhARTw")) != EOF) switch (opt) { case 'B': --- 271,277 ---- charset_initialise(); ! while ((opt = getopt(argc, argv, "d:B:U:i:s:SMrhARTwX")) != EOF) switch (opt) { case 'B': *************** *** 260,265 **** --- 323,331 ---- case 'A': lookup_by_ip = True; break; + case 'X': + CheckPDC = True; + break; default: usage(); exit(1); *************** *** 317,322 **** --- 383,396 ---- continue; } + if(CheckPDC) + { + fstrcpy(lookup,"*"); + ip = *interpret_addr2(argv[i]); + do_pdc_status(ServerFD, lookup, lookup_type, ip); + continue; + } + if (find_master) { if (*lookup == '-') { fstrcpy(lookup,"\01\02__MSBROWSE__\02");