can_set_rfmon_test.c 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. /*
  2. * Copyright (c) 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 2000
  3. * The Regents of the University of California. All rights reserved.
  4. *
  5. * Redistribution and use in source and binary forms, with or without
  6. * modification, are permitted provided that: (1) source code distributions
  7. * retain the above copyright notice and this paragraph in its entirety, (2)
  8. * distributions including binary code include the above copyright notice and
  9. * this paragraph in its entirety in the documentation or other materials
  10. * provided with the distribution, and (3) all advertising materials mentioning
  11. * features or use of this software display the following acknowledgement:
  12. * ``This product includes software developed by the University of California,
  13. * Lawrence Berkeley Laboratory and its contributors.'' Neither the name of
  14. * the University nor the names of its contributors may be used to endorse
  15. * or promote products derived from this software without specific prior
  16. * written permission.
  17. * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
  18. * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
  19. * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  20. */
  21. #include "varattrs.h"
  22. #ifndef lint
  23. static const char copyright[] _U_ =
  24. "@(#) Copyright (c) 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 2000\n\
  25. The Regents of the University of California. All rights reserved.\n";
  26. #endif
  27. #include <stdio.h>
  28. #include <stdlib.h>
  29. #include <string.h>
  30. #include <stdarg.h>
  31. #include <pcap.h>
  32. #include "pcap/funcattrs.h"
  33. static const char *program_name;
  34. /* Forwards */
  35. static void PCAP_NORETURN error(PCAP_FORMAT_STRING(const char *), ...) PCAP_PRINTFLIKE(1,2);
  36. int
  37. main(int argc, char **argv)
  38. {
  39. const char *cp;
  40. pcap_t *pd;
  41. char ebuf[PCAP_ERRBUF_SIZE];
  42. int status;
  43. if ((cp = strrchr(argv[0], '/')) != NULL)
  44. program_name = cp + 1;
  45. else
  46. program_name = argv[0];
  47. if (argc != 2) {
  48. fprintf(stderr, "Usage: %s <device>\n", program_name);
  49. return 2;
  50. }
  51. pd = pcap_create(argv[1], ebuf);
  52. if (pd == NULL)
  53. error("%s", ebuf);
  54. status = pcap_can_set_rfmon(pd);
  55. if (status < 0) {
  56. if (status == PCAP_ERROR)
  57. error("%s: pcap_can_set_rfmon failed: %s", argv[1],
  58. pcap_geterr(pd));
  59. else
  60. error("%s: pcap_can_set_rfmon failed: %s", argv[1],
  61. pcap_statustostr(status));
  62. return 1;
  63. }
  64. printf("%s: Monitor mode %s be set\n", argv[1], status ? "can" : "cannot");
  65. return 0;
  66. }
  67. /* VARARGS */
  68. static void
  69. error(const char *fmt, ...)
  70. {
  71. va_list ap;
  72. (void)fprintf(stderr, "%s: ", program_name);
  73. va_start(ap, fmt);
  74. (void)vfprintf(stderr, fmt, ap);
  75. va_end(ap);
  76. if (*fmt) {
  77. fmt += strlen(fmt);
  78. if (fmt[-1] != '\n')
  79. (void)fputc('\n', stderr);
  80. }
  81. exit(1);
  82. /* NOTREACHED */
  83. }