source: mainline/uspace/app/pcapctl/main.c@ 91042127

Last change on this file since 91042127 was 91042127, checked in by Nataliia Korop <n.corop08@…>, 10 months ago

long name without mapping ok

  • Property mode set to 100644
File size: 3.2 KB
Line 
1/*
2 * Copyright (c) 2023 Nataliia Korop
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * - Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * - Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * - The name of the author may not be used to endorse or promote products
15 * derived from this software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28
29/** @addtogroup pcapctl
30 * @{
31 */
32/** @file pcapctl app
33 */
34
35#include <stdio.h>
36#include <str.h>
37#include <errno.h>
38
39#include "pcapctl_dump.h"
40
41#define NAME "pcapctl"
42
43#define LOGGER(msg, ...) \
44 fprintf(stderr, \
45 "[PCAP %s:%d]: " msg "\n", \
46 __FILE__, __LINE__, \
47 ##__VA_ARGS__\
48 )
49
50pcapctl_sess_t sess;
51
52static errno_t start_dumping(const char *drv_name, const char *name)
53{
54 errno_t rc = pcapctl_dump_init(&sess, drv_name);
55 if (rc != EOK) {
56 //fprintf(stderr, "Error initializing ...\n");
57 return 1;
58 }
59 pcapctl_dump_start(name, &sess);
60 return EOK;
61}
62
63/** Session might */
64static errno_t stop_dumping(const char *drv_name)
65{
66 errno_t rc = pcapctl_dump_init(&sess, drv_name);
67 if (rc != EOK) {
68 fprintf(stderr, "Error initializing ...\n");
69 return 1;
70 }
71 pcapctl_dump_stop(&sess);
72 return EOK;
73}
74
75static void list_devs(void) {
76 pcapctl_list();
77}
78
79static void usage(const char *progname)
80{
81 fprintf(stderr, "Usage:\n");
82 fprintf(stderr, " %s start <device> <outfile>: Packets dumped from <device> will be written to <outfile>\n", progname);
83 fprintf(stderr, " %s stop <device>: Dumping from <device> stops\n", progname);
84
85}
86
87int main(int argc, char *argv[])
88{
89 if (argc < 2) {
90 usage(argv[0]);
91 return 1;
92 } else {
93 if (str_cmp(argv[1], "--help") == 0 || str_cmp(argv[1], "-h") == 0) {
94 usage(argv[0]);
95 return 0;
96 } else if (str_cmp(argv[1], "list") == 0) {
97 list_devs();
98 return 0;
99 } else if (str_cmp(argv[1], "start") == 0) {
100 if (argc != 4) {
101 usage(argv[0]);
102 return 1;
103 }
104 start_dumping(argv[2], argv[3]);
105 } else if (str_cmp(argv[1], "stop") == 0) {
106 if (argc != 3) {
107 usage(argv[0]);
108 return 1;
109 }
110 stop_dumping(argv[2]);
111 fprintf(stdout, "Dumping was stopped\n");
112 return EOK;
113 } else {
114 usage(argv[0]);
115 return 1;
116 }
117 }
118 return 0;
119}
120
121/** @}
122 */
Note: See TracBrowser for help on using the repository browser.