lookup.c 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. //---------------------------------------------------------------------------
  2. // __________________ _________ _____ _____ .__ ._.
  3. // \______ \______ \ / _____/ / \ / _ \ |__| ____ | |
  4. // | | _/| | \ \_____ \ / \ / \ / /_\ \| _/ __ \ | |
  5. // | | \| ` \/ / Y \ / | | \ ___/ \|
  6. // |______ /_______ /_______ \____|__ / /\ \____|__ |__|\___ | __
  7. // \/ \/ \/ \/ )/ \/ \/ \/
  8. //
  9. // This file is part of libdsm. Copyright © 2014 VideoLabs SAS
  10. //
  11. // Author: Julien 'Lta' BALLET <contact@lta.io>
  12. //
  13. // This program is free software. It comes without any warranty, to the extent
  14. // permitted by applicable law. You can redistribute it and/or modify it under
  15. // the terms of the Do What The Fuck You Want To Public License, Version 2, as
  16. // published by Sam Hocevar. See the COPYING file for more details.
  17. //----------------------------------------------------------------------------
  18. #include <stdlib.h>
  19. #include <stdio.h>
  20. #include <string.h>
  21. #include <assert.h>
  22. #include <sys/socket.h>
  23. #include <netinet/in.h>
  24. #include <arpa/inet.h>
  25. #include "bdsm.h"
  26. int main(int ac, char **av)
  27. {
  28. netbios_ns *ns;
  29. struct in_addr addr;
  30. ns = netbios_ns_new();
  31. if (ac != 2)
  32. {
  33. fprintf(stderr, "%s usage: %s NBT_NAME\n", av[0], av[0]);
  34. fprintf(stderr, "Print the ip for this netbios name\n");
  35. exit(1);
  36. }
  37. if (!netbios_ns_resolve(ns, av[1], NETBIOS_FILESERVER, &addr.s_addr)) {
  38. exit(-1);
  39. }
  40. if (!addr.s_addr)
  41. {
  42. fprintf(stderr, "Unable to perform name resolution for %s\n", av[1]);
  43. exit(42);
  44. }
  45. printf("%s's IP address is : %s\n", av[1], inet_ntoa(addr));
  46. netbios_ns_destroy(ns);
  47. return (0);
  48. }