lookup.c 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. /*****************************************************************************
  2. * __________________ _________ _____ _____ .__ ._.
  3. * \______ \______ \ / _____/ / \ / _ \ |__| ____ | |
  4. * | | _/| | \ \_____ \ / \ / \ / /_\ \| _/ __ \ | |
  5. * | | \| ` \/ / Y \ / | | \ ___/ \|
  6. * |______ /_______ /_______ \____|__ / /\ \____|__ |__|\___ | __
  7. * \/ \/ \/ \/ )/ \/ \/ \/
  8. *
  9. * This file is part of liBDSM. Copyright © 2014-2015 VideoLabs SAS
  10. *
  11. * Author: Julien 'Lta' BALLET <contact@lta.io>
  12. *
  13. * liBDSM is released under LGPLv2.1 (or later) and is also available
  14. * under a commercial license.
  15. *****************************************************************************
  16. * This program is free software; you can redistribute it and/or modify it
  17. * under the terms of the GNU Lesser General Public License as published by
  18. * the Free Software Foundation; either version 2.1 of the License, or
  19. * (at your option) any later version.
  20. *
  21. * This program is distributed in the hope that it will be useful,
  22. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  23. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  24. * GNU Lesser General Public License for more details.
  25. *
  26. * You should have received a copy of the GNU Lesser General Public License
  27. * along with this program; if not, write to the Free Software Foundation,
  28. * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
  29. *****************************************************************************/
  30. #include <stdlib.h>
  31. #include <stdio.h>
  32. #include <string.h>
  33. #include <assert.h>
  34. #if !defined( _WIN32 )
  35. # include <arpa/inet.h>
  36. #else
  37. # include <winsock2.h>
  38. #endif
  39. #include "bdsm.h"
  40. int main(int ac, char **av)
  41. {
  42. netbios_ns *ns;
  43. struct in_addr addr;
  44. ns = netbios_ns_new();
  45. if (ac != 2)
  46. {
  47. fprintf(stderr, "%s usage: %s NBT_NAME\n", av[0], av[0]);
  48. fprintf(stderr, "Print the ip for this netbios name\n");
  49. exit(1);
  50. }
  51. if (netbios_ns_resolve(ns, av[1], NETBIOS_FILESERVER, &addr.s_addr)) {
  52. exit(-1);
  53. }
  54. if (!addr.s_addr)
  55. {
  56. fprintf(stderr, "Unable to perform name resolution for %s\n", av[1]);
  57. exit(42);
  58. }
  59. printf("%s's IP address is : %s\n", av[1], inet_ntoa(addr));
  60. netbios_ns_destroy(ns);
  61. return 0;
  62. }