inverse.c 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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. netbios_ns_entry_t ns_entry;
  30. ctx = bdsm_context_new();
  31. assert(ctx);
  32. if (ac != 2)
  33. {
  34. fprintf(stderr, "%s usage: %s a.b.c.d\n", av[0], av[0]);
  35. fprintf(stderr, "Print the netbios name for this IP address\n");
  36. exit(1);
  37. }
  38. inet_aton(av[1], &ns_entry.address);
  39. if (!netbios_ns_inverse(ctx->ns, &ns_entry))
  40. {
  41. fprintf(stderr, "Unable to perform inverse name resolution for %s\n", av[1]);
  42. exit(42);
  43. }
  44. printf("%s\n", ns_entry.name);
  45. return (0);
  46. }