int cmd_lookup(int argc, char *argv[]) { struct nb_ctx *ctx; struct sockaddr *sap; char *hostname; int error, opt; if (argc < 2) lookup_usage(); error = nb_ctx_create(&ctx); if (error) { smb_error("unable to create nbcontext", error); exit(1); } if (smb_open_rcfile() == 0) { if (nb_ctx_readrcsection(smb_rc, ctx, "default", 0) != 0) exit(1); rc_close(smb_rc); } while ((opt = getopt(argc, argv, "w:")) != EOF) { switch(opt) { case 'w': nb_ctx_setns(ctx, optarg); break; default: lookup_usage(); /*NOTREACHED*/ } } if (optind >= argc) lookup_usage(); if (nb_ctx_resolve(ctx) != 0) exit(1); hostname = argv[argc - 1]; /* printf("Looking for %s...\n", hostname);*/ error = nbns_resolvename(hostname, ctx, &sap); if (error) { smb_error("unable to resolve %s", error, hostname); exit(1); } printf("Got response from %s\n", inet_ntoa(ctx->nb_lastns.sin_addr)); printf("IP address of %s: %s\n", hostname, inet_ntoa(((struct sockaddr_in*)sap)->sin_addr)); return 0; }
/* * used level values: * 0 - default * 1 - server */ int nb_ctx_readrcsection(struct rcfile *rcfile, struct nb_ctx *ctx, const char *sname, int level) { char *p; int error; if (level > 1) return EINVAL; rc_getint(rcfile, sname, "nbtimeout", &ctx->nb_timo); rc_getstringptr(rcfile, sname, "nbns", &p); if (p) { error = nb_ctx_setns(ctx, p); if (error) { smb_error("invalid address specified in the section %s", 0, sname); return error; } } rc_getstringptr(rcfile, sname, "nbscope", &p); if (p) nb_ctx_setscope(ctx, p); return 0; }