lookup.c 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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. bdsm_context_t *ctx;
  29. char name[NETBIOS_NAME_LENGTH + 2];
  30. struct in_addr addr;
  31. ctx = bdsm_context_new();
  32. assert(ctx);
  33. if (ac != 2)
  34. {
  35. fprintf(stderr, "%s usage: %s NBT_NAME\n", av[0], av[0]);
  36. fprintf(stderr, "Print the ip for this netbios name\n");
  37. exit(1);
  38. }
  39. if (0 != netbios_ns_resolve(ctx->ns, av[1], NETBIOS_FILESERVER, &addr.s_addr)) {
  40. exit(-1);
  41. }
  42. if (!addr.s_addr)
  43. {
  44. fprintf(stderr, "Unable to perform name resolution for %s\n", av[1]);
  45. exit(42);
  46. }
  47. printf("%s's IP address is : %s\n", av[1], inet_ntoa(addr));
  48. return (0);
  49. }