libpcap  1.10.1
About: libpcap is a packet filter library used by tools like tcpdump.
  Fossies Dox: libpcap-1.10.1.tar.gz  ("unofficial" and yet experimental doxygen-generated source code documentation)  

can_set_rfmon_test.c
Go to the documentation of this file.
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 
22 #include "varattrs.h"
23 
24 #ifndef lint
25 static const char copyright[] _U_ =
26  "@(#) Copyright (c) 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 2000\n\
27 The Regents of the University of California. All rights reserved.\n";
28 #endif
29 
30 #include <stdio.h>
31 #include <stdlib.h>
32 #include <string.h>
33 #include <stdarg.h>
34 
35 #include <pcap.h>
36 
37 #include "pcap/funcattrs.h"
38 
39 static const char *program_name;
40 
41 /* Forwards */
42 static void PCAP_NORETURN error(PCAP_FORMAT_STRING(const char *), ...) PCAP_PRINTFLIKE(1,2);
43 
44 int
45 main(int argc, char **argv)
46 {
47  const char *cp;
48  pcap_t *pd;
49  char ebuf[PCAP_ERRBUF_SIZE];
50  int status;
51 
52  if ((cp = strrchr(argv[0], '/')) != NULL)
53  program_name = cp + 1;
54  else
55  program_name = argv[0];
56 
57  if (argc != 2) {
58  fprintf(stderr, "Usage: %s <device>\n", program_name);
59  return 2;
60  }
61 
62  pd = pcap_create(argv[1], ebuf);
63  if (pd == NULL)
64  error("%s", ebuf);
65  status = pcap_can_set_rfmon(pd);
66  if (status < 0) {
67  if (status == PCAP_ERROR)
68  error("%s: pcap_can_set_rfmon failed: %s", argv[1],
69  pcap_geterr(pd));
70  else
71  error("%s: pcap_can_set_rfmon failed: %s", argv[1],
72  pcap_statustostr(status));
73  }
74  printf("%s: Monitor mode %s be set\n", argv[1], status ? "can" : "cannot");
75  return 0;
76 }
77 
78 /* VARARGS */
79 static void
80 error(const char *fmt, ...)
81 {
82  va_list ap;
83 
84  (void)fprintf(stderr, "%s: ", program_name);
85  va_start(ap, fmt);
86  (void)vfprintf(stderr, fmt, ap);
87  va_end(ap);
88  if (*fmt) {
89  fmt += strlen(fmt);
90  if (fmt[-1] != '\n')
91  (void)fputc('\n', stderr);
92  }
93  exit(1);
94  /* NOTREACHED */
95 }
static void error(const char *,...)
static const char copyright[]
int main(int argc, char **argv)
static const char * program_name
static pcap_t * pd
Definition: capturetest.c:63
#define PCAP_FORMAT_STRING(p)
Definition: funcattrs.h:322
#define PCAP_NORETURN
Definition: funcattrs.h:248
#define PCAP_PRINTFLIKE(x, y)
Definition: funcattrs.h:270
int printf(const char *,...)
#define _U_
Definition: pcap-dos.h:93
#define PCAP_ERRBUF_SIZE
Definition: pcap.h:152
#define PCAP_ERROR
Definition: pcap.h:339
char * pcap_geterr(pcap_t *p)
Definition: pcap.c:3505
const char * pcap_statustostr(int errnum)
Definition: pcap.c:3610
int pcap_can_set_rfmon(pcap_t *p)
Definition: pcap.c:500
pcap_t * pcap_create(const char *device, char *errbuf)
Definition: pcap.c:2252
Definition: pcap-int.h:200