utils/nmblookup.c

ソースコードを見る。

関数

static BOOL open_sockets (void)
static char * node_status_flags (unsigned char flags)
static char * query_flags (int flags)
static void do_node_status (int fd, const char *name, int type, struct in_addr ip)
static BOOL query_one (const char *lookup, unsigned int lookup_type)
int main (int argc, char *argv[])

変数

BOOL AllowDebugChange
static BOOL give_flags = False
static BOOL use_bcast = True
static BOOL got_bcast = False
static struct in_addr bcast_addr
static BOOL recursion_desired = False
static BOOL translate_addresses = False
static int ServerFD = -1
static int RootPort = False
static BOOL find_status = False


関数

static BOOL open_sockets ( void   )  [static]

nmblookup.c40 行で定義されています。

参照先 interpret_addr()open_socket_in()RootPortServerFDset_socket_options().

00041 {
00042   ServerFD = open_socket_in( SOCK_DGRAM,
00043                              (RootPort ? 137 : 0),
00044                              (RootPort ?   0 : 3),
00045                              interpret_addr(lp_socket_address()), True );
00046 
00047   if (ServerFD == -1)
00048     return(False);
00049 
00050   set_socket_options( ServerFD, "SO_BROADCAST" );
00051 
00052   DEBUG(3, ("Socket opened.\n"));
00053   return True;
00054 }

static char* node_status_flags ( unsigned char  flags  )  [static]

nmblookup.c59 行で定義されています。

参照元 do_node_status().

00060 {
00061         static fstring ret;
00062         fstrcpy(ret,"");
00063         
00064         fstrcat(ret, (flags & 0x80) ? "<GROUP> " : "        ");
00065         if ((flags & 0x60) == 0x00) fstrcat(ret,"B ");
00066         if ((flags & 0x60) == 0x20) fstrcat(ret,"P ");
00067         if ((flags & 0x60) == 0x40) fstrcat(ret,"M ");
00068         if ((flags & 0x60) == 0x60) fstrcat(ret,"H ");
00069         if (flags & 0x10) fstrcat(ret,"<DEREGISTERING> ");
00070         if (flags & 0x08) fstrcat(ret,"<CONFLICT> ");
00071         if (flags & 0x04) fstrcat(ret,"<ACTIVE> ");
00072         if (flags & 0x02) fstrcat(ret,"<PERMANENT> ");
00073         
00074         return ret;
00075 }

static char* query_flags ( int  flags  )  [static]

nmblookup.c80 行で定義されています。

参照元 query_one().

00081 {
00082         static fstring ret1;
00083         fstrcpy(ret1, "");
00084 
00085         if (flags & NM_FLAGS_RS) fstrcat(ret1, "Response ");
00086         if (flags & NM_FLAGS_AA) fstrcat(ret1, "Authoritative ");
00087         if (flags & NM_FLAGS_TC) fstrcat(ret1, "Truncated ");
00088         if (flags & NM_FLAGS_RD) fstrcat(ret1, "Recursion_Desired ");
00089         if (flags & NM_FLAGS_RA) fstrcat(ret1, "Recursion_Available ");
00090         if (flags & NM_FLAGS_B)  fstrcat(ret1, "Broadcast ");
00091 
00092         return ret1;
00093 }

static void do_node_status ( int  fd,
const char *  name,
int  type,
struct in_addr  ip 
) [static]

nmblookup.c98 行で定義されています。

参照先 d_printf()flagsnode_status_extra::mac_addrmake_nmb_name()node_status_flags()node_status_query()pull_ascii_fstring()status.

参照元 main()query_one().

00099 {
00100         struct nmb_name nname;
00101         int count, i, j;
00102         NODE_STATUS_STRUCT *status;
00103         struct node_status_extra extra;
00104         fstring cleanname;
00105 
00106         d_printf("Looking up status of %s\n",inet_ntoa(ip));
00107         make_nmb_name(&nname, name, type);
00108         status = node_status_query(fd,&nname,ip, &count, &extra);
00109         if (status) {
00110                 for (i=0;i<count;i++) {
00111                         pull_ascii_fstring(cleanname, status[i].name);
00112                         for (j=0;cleanname[j];j++) {
00113                                 if (!isprint((int)cleanname[j])) cleanname[j] = '.';
00114                         }
00115                         d_printf("\t%-15s <%02x> - %s\n",
00116                                cleanname,status[i].type,
00117                                node_status_flags(status[i].flags));
00118                 }
00119                 d_printf("\n\tMAC Address = %02X-%02X-%02X-%02X-%02X-%02X\n",
00120                                 extra.mac_addr[0], extra.mac_addr[1],
00121                                 extra.mac_addr[2], extra.mac_addr[3],
00122                                 extra.mac_addr[4], extra.mac_addr[5]);
00123                 d_printf("\n");
00124                 SAFE_FREE(status);
00125         } else {
00126                 d_printf("No reply from %s\n\n",inet_ntoa(ip));
00127         }
00128 }

static BOOL query_one ( const char *  lookup,
unsigned int  lookup_type 
) [static]

nmblookup.c134 行で定義されています。

参照先 bcast_addrd_printf()do_node_status()find_statusflagsgive_flagsgot_bcasthostiface_count()iface_n_bcast()name_query()query_flags()recursion_desiredsafe_free()ServerFDtranslate_addressesuse_bcast.

参照元 main().

00135 {
00136         int j, count, flags = 0;
00137         struct in_addr *ip_list=NULL;
00138 
00139         if (got_bcast) {
00140                 d_printf("querying %s on %s\n", lookup, inet_ntoa(bcast_addr));
00141                 ip_list = name_query(ServerFD,lookup,lookup_type,use_bcast,
00142                                      use_bcast?True:recursion_desired,
00143                                      bcast_addr,&count, &flags, NULL);
00144         } else {
00145                 struct in_addr *bcast;
00146                 for (j=iface_count() - 1;
00147                      !ip_list && j >= 0;
00148                      j--) {
00149                         bcast = iface_n_bcast(j);
00150                         d_printf("querying %s on %s\n", 
00151                                lookup, inet_ntoa(*bcast));
00152                         ip_list = name_query(ServerFD,lookup,lookup_type,
00153                                              use_bcast,
00154                                              use_bcast?True:recursion_desired,
00155                                              *bcast,&count, &flags, NULL);
00156                 }
00157         }
00158 
00159         if (!ip_list) return False;
00160 
00161         if (give_flags)
00162           d_printf("Flags: %s\n", query_flags(flags));
00163 
00164         for (j=0;j<count;j++) {
00165                 if (translate_addresses) {
00166                         struct hostent *host = gethostbyaddr((char *)&ip_list[j], sizeof(ip_list[j]), AF_INET);
00167                         if (host) {
00168                                 d_printf("%s, ", host -> h_name);
00169                         }
00170                 }
00171                 d_printf("%s %s<%02x>\n",inet_ntoa(ip_list[j]),lookup, lookup_type);
00172                 /* We can only do find_status if the ip address returned
00173                    was valid - ie. name_query returned true.
00174                  */
00175                 if (find_status) {
00176                         do_node_status(ServerFD, lookup, lookup_type, ip_list[j]);
00177                 }
00178         }
00179 
00180         safe_free(ip_list);
00181 
00182         return (ip_list != NULL);
00183 }

int main ( int  argc,
char *  argv[] 
)

nmblookup.c189 行で定義されています。

参照先 bcast_addrd_printf()do_node_status()dyn_CONFIGFILEfind_statusfprintf()give_flagsgot_bcastinterpret_addr2()load_case_tables()load_interfaces()lookup()open_sockets()poptFreeContext()poptGetArg()poptGetContext()poptGetNextOpt()poptGetOptArg()poptPeekArg()poptPrintUsage()poptSetOtherOptionHelp()query_one()recursion_desiredRootPortServerFDsetup_logging()strchr_m()translate_addressesuse_bcast.

00190 {
00191   int opt;
00192   unsigned int lookup_type = 0x0;
00193   fstring lookup;
00194   static BOOL find_master=False;
00195   static BOOL lookup_by_ip = False;
00196   poptContext pc;
00197 
00198   struct poptOption long_options[] = {
00199           POPT_AUTOHELP
00200           { "broadcast", 'B', POPT_ARG_STRING, NULL, 'B', "Specify address to use for broadcasts", "BROADCAST-ADDRESS" },
00201           { "flags", 'f', POPT_ARG_VAL, &give_flags, True, "List the NMB flags returned" },
00202           { "unicast", 'U', POPT_ARG_STRING, NULL, 'U', "Specify address to use for unicast" },
00203           { "master-browser", 'M', POPT_ARG_VAL, &find_master, True, "Search for a master browser" },
00204           { "recursion", 'R', POPT_ARG_VAL, &recursion_desired, True, "Set recursion desired in package" },
00205           { "status", 'S', POPT_ARG_VAL, &find_status, True, "Lookup node status as well" },
00206           { "translate", 'T', POPT_ARG_NONE, NULL, 'T', "Translate IP addresses into names" },
00207           { "root-port", 'r', POPT_ARG_VAL, &RootPort, True, "Use root port 137 (Win95 only replies to this)" },
00208           { "lookup-by-ip", 'A', POPT_ARG_VAL, &lookup_by_ip, True, "Do a node status on <name> as an IP Address" },
00209           POPT_COMMON_SAMBA
00210           POPT_COMMON_CONNECTION
00211           { 0, 0, 0, 0 }
00212   };
00213         
00214   *lookup = 0;
00215 
00216   load_case_tables();
00217 
00218   setup_logging(argv[0],True);
00219 
00220   pc = poptGetContext("nmblookup", argc, (const char **)argv, long_options, 
00221                                           POPT_CONTEXT_KEEP_FIRST);
00222 
00223   poptSetOtherOptionHelp(pc, "<NODE> ...");
00224 
00225   while ((opt = poptGetNextOpt(pc)) != -1) {
00226           switch (opt) {
00227           case 'B':
00228                   bcast_addr = *interpret_addr2(poptGetOptArg(pc));
00229                   got_bcast = True;
00230                   use_bcast = True;
00231                   break;
00232           case 'U':
00233                   bcast_addr = *interpret_addr2(poptGetOptArg(pc));
00234                   got_bcast = True;
00235                   use_bcast = False;
00236                   break;
00237           case 'T':
00238                   translate_addresses = !translate_addresses;
00239                   break;
00240           }
00241   }
00242 
00243   poptGetArg(pc); /* Remove argv[0] */
00244 
00245   if(!poptPeekArg(pc)) { 
00246           poptPrintUsage(pc, stderr, 0);
00247           exit(1);
00248   }
00249 
00250   if (!lp_load(dyn_CONFIGFILE,True,False,False,True)) {
00251           fprintf(stderr, "Can't load %s - run testparm to debug it\n", dyn_CONFIGFILE);
00252   }
00253 
00254   load_interfaces();
00255   if (!open_sockets()) return(1);
00256 
00257   while(poptPeekArg(pc))
00258   {
00259           char *p;
00260           struct in_addr ip;
00261 
00262           fstrcpy(lookup,poptGetArg(pc));
00263 
00264           if(lookup_by_ip)
00265           {
00266                   ip = *interpret_addr2(lookup);
00267                   fstrcpy(lookup,"*");
00268                   do_node_status(ServerFD, lookup, lookup_type, ip);
00269                   continue;
00270           }
00271 
00272           if (find_master) {
00273                   if (*lookup == '-') {
00274                           fstrcpy(lookup,"\01\02__MSBROWSE__\02");
00275                           lookup_type = 1;
00276                   } else {
00277                           lookup_type = 0x1d;
00278                   }
00279           }
00280 
00281           p = strchr_m(lookup,'#');
00282           if (p) {
00283                   *p = '\0';
00284                   sscanf(++p,"%x",&lookup_type);
00285           }
00286 
00287           if (!query_one(lookup, lookup_type)) {
00288                   d_printf( "name_query failed to find name %s", lookup );
00289                   if( 0 != lookup_type )
00290                           d_printf( "#%02x", lookup_type );
00291                   d_printf( "\n" );
00292           }
00293   }
00294 
00295   poptFreeContext(pc);
00296 
00297   return(0);
00298 }


変数

BOOL AllowDebugChange

debug.c85 行で定義されています。

BOOL give_flags = False [static]

nmblookup.c27 行で定義されています。

参照元 main()query_one().

BOOL use_bcast = True [static]

nmblookup.c28 行で定義されています。

参照元 get_workgroups()main()query_one().

BOOL got_bcast = False [static]

nmblookup.c29 行で定義されています。

参照元 main()query_one().

struct in_addr bcast_addr [static]

nmblookup.c30 行で定義されています。

参照元 main()query_one().

BOOL recursion_desired = False [static]

nmblookup.c31 行で定義されています。

参照元 main()query_one().

BOOL translate_addresses = False [static]

nmblookup.c32 行で定義されています。

参照元 main()query_one().

int ServerFD = -1 [static]

nmblookup.c33 行で定義されています。

参照元 main()open_sockets()query_one().

int RootPort = False [static]

nmblookup.c34 行で定義されています。

参照元 main()open_sockets().

BOOL find_status = False [static]

nmblookup.c35 行で定義されています。

参照元 main()query_one().


Sambaに対してSat Aug 29 21:24:36 2009に生成されました。  doxygen 1.4.7