fork download
  1. */
  2.  
  3. /*
  4.  * $Id: fang.c,v 1.00 2003/04/20 13:00:00 ollie Exp $
  5.  */
  6.  
  7. #include <stdio.h>
  8. #include <stdlib.h>
  9. #include <unistd.h>
  10. #include <string.h>
  11. #include <signal.h>
  12. #include <fcntl.h>
  13. #include <errno.h>
  14. #include <ctype.h>
  15.  
  16. #include <termios.h>
  17. #include <fcntl.h>
  18. #include <getopt.h>
  19. #include <sys/ioctl.h>
  20. #include <sys/socket.h>
  21. #include <asm/types.h>
  22. #include <netinet/in.h>
  23.  
  24. #include <bluetooth/bluetooth.h>
  25. #include <bluetooth/hci.h>
  26. #include <bluetooth/hci_lib.h>
  27.  
  28. extern int optind,opterr,optopt;
  29. extern char *optarg;
  30.  
  31. #define for_each_opt(opt, long, short) while ((opt=getopt_long(argc, argv, short ? short:"+", long, NULL)) != -1)
  32.  
  33. static void usage(void);
  34.  
  35. static struct option hunt_options[] = {
  36.   {"help", 0,0, 'h'},
  37.   {0, 0, 0, 0}
  38. };
  39.  
  40. static char *hunt_help =
  41.   "Usage:\n"
  42.   "\thunt <timeout>\n";
  43.  
  44. static void cmd_hunt(int dev_id, int argc, char **argv)
  45. {
  46.   bdaddr_t bdaddr;
  47.   char name[248];
  48.   
  49.   int opt, dd, num=0, num2=0, num3=0, num4=0, num5=0, num6=0;
  50.   int btout=50000;
  51.  
  52.   unsigned char lame[16][2] = {"0","1","2","3","4","5","6","7","8","9","A","B","C","D","E","F", };
  53.  
  54.   char addtobrute[248];
  55.  
  56.   printf("redfang - the bluetooth hunter ver 1.00.alpha\n");
  57.   printf("(c)2003 \@stake Inc\n");
  58.   printf("author: Ollie Whitehouse (ollie@atstake.com)\n");
  59.  
  60.   argc -= optind;
  61.         argv += optind;
  62.  
  63.   if (argc < 2) {
  64.     printf(hunt_help);
  65.     exit(1);
  66.   }
  67.  
  68.   if (argc >= 1) {
  69.     btout=atoi(argv[1]);
  70.   }
  71.  
  72.   printf("timeout: %d\n", btout);
  73.  
  74.   printf("starting...\n");
  75.  
  76.   while (num <= 15)
  77.   {
  78.     while(num2 <= 15)
  79.     {
  80.       while(num3 <= 15)
  81.       {
  82.         while(num4 <= 15)
  83.         {
  84.           while(num5 <= 15)
  85.           {
  86.             while(num6 <= 15)
  87.             {
  88.               strcpy(addtobrute,"00:80:98:");
  89.               strcat(addtobrute,lame[num]);
  90.               strcat(addtobrute,lame[num2]);
  91.               strcat(addtobrute,":");
  92.               strcat(addtobrute,lame[num3]);
  93.               strcat(addtobrute,lame[num4]);
  94.               strcat(addtobrute,":");
  95.               strcat(addtobrute,lame[num5]);
  96.               strcat(addtobrute,lame[num6]);
  97.             
  98.               /* debug purposes */
  99.               printf("%s\n",addtobrute);
  100.  
  101.               baswap(&bdaddr, strtoba(addtobrute));
  102.                       
  103.               dev_id = hci_get_route(&bdaddr);
  104.               if (dev_id < 0) {
  105.                 fprintf(stderr,"Device not availible");
  106.                 exit(1);
  107.               }
  108.               
  109.  
  110.               
  111.               dd = hci_open_dev(dev_id);
  112.               if (dd < 0) {
  113.                 fprintf(stderr,"HCI device open failed");
  114.                 exit(1);
  115.               }
  116.               
  117.               
  118.               /* try to get name of remote device - timeout is the int) */
  119.               if (hci_read_remote_name(dd,&bdaddr,sizeof(name), name, btout) == 0)
  120.                 printf("\n.start--->\naddress :- %s\nname :- %s\n<.end-----\n",batostr(&bdaddr),name);
  121.               
  122.               close(dd);
  123.  
  124.               num6++;
  125.               }
  126.               num6=0;
  127.               num5++;
  128.  
  129.             }
  130.             num5=0;
  131.             num4++;
  132.           }
  133.           num4=0;
  134.           num3++;
  135.       }
  136.       num3=0;
  137.       num2++;
  138.     }
  139.     num2=0;
  140.     num++;
  141.   }
  142. }
  143.  
  144. struct {
  145.   char *cmd;
  146.   void (*func)(int dev_id, int argc, char **argv);
  147.   char *doc;
  148. } command[] = {
  149.   { "hunt", cmd_hunt, "Get name from remote device" },
  150.   { NULL, NULL, 0}
  151. };
  152.  
  153. static void usage(void)
  154. {
  155.   int i;
  156.  
  157.   printf("redfang - the bluetooth hunter ver 1.00.alpha\n");
  158.   printf("usage:\n"
  159.     "\tfang [options] <command> [command parameters]\n");
  160.   printf("options:\n"
  161.     "\t--help\tDisplay help\n"
  162.     "\t-i dev\tHCI device\n");
  163.   printf("commands:\n");
  164.   for (i=0; command[i].cmd; i++)
  165.     printf("\t%-4s\t%s\n", command[i].cmd,
  166.     command[i].doc);
  167.   printf("\n"
  168.     "For more information on the usage of each command use:\n"
  169.     "\tfang <command> --help\n" );
  170. }
  171.  
  172. static struct option main_options[] = {
  173.   {"help", 0,0, 'h'},
  174.   {"device", 1,0, 'i'},
  175.   {0, 0, 0, 0}
  176. };
  177.  
  178. int main(int argc, char **argv)
  179. {
  180.   int opt, i, dev_id = -1;
  181.   bdaddr_t ba;
  182.  
  183.   while ((opt=getopt_long(argc, argv, "+i:h", main_options, NULL)) != -1) {
  184.     switch(opt) {
  185.     case 'i':
  186.       dev_id = hci_devid(optarg);
  187.       if (dev_id < 0) {
  188.         perror("Invalid device");
  189.         exit(1);
  190.       }
  191.       break;
  192.  
  193.     case 'h':
  194.     default:
  195.       usage();
  196.       exit(0);
  197.     }
  198.   }
  199.  
  200.   argc -= optind;
  201.   argv += optind;
  202.   optind = 0;
  203.  
  204.   if (argc < 1) {
  205.     usage();
  206.     exit(0);
  207.   }
  208.  
  209.   if (dev_id != -1 && hci_devba(dev_id, &ba) < 0) {
  210.     perror("Device is not available");
  211.     exit(1);
  212.   }
  213.  
  214.   for (i=0; command[i].cmd; i++) {
  215.     if (strncmp(command[i].cmd, argv[0], 3))
  216.       continue;
  217.     command[i].func(dev_id, argc, argv);
  218.     break;
  219.   }
  220.   return 0;
  221. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.nim(3, 0) Error: expression expected, but found '[same indentation]'
stdout
Standard output is empty