source: mainline/uspace/app/pcapctl/main.c@ 2dac5a9

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

Packet capture prototype

  • Property mode set to 100644
File size: 2.7 KB
RevLine 
[17a8fcf]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 void start_dumping(const char *name)
53{
54 pcapctl_dump_start(name, &sess);
55}
56
57static void stop_dumping(void)
58{
59 pcapctl_dump_stop(&sess);
60}
61
62static void usage(const char *progname)
63{
64 fprintf(stderr, "Usage:\n");
65 fprintf(stderr, " %s start <outfile>: Packets will be written to <outfile>\n", progname);
66 fprintf(stderr, " %s stop: Dumping stops\n", progname);
67
68}
69
70int main(int argc, char *argv[])
71{
72 if (argc < 2) {
73 usage(argv[0]);
74 return 1;
75 } else {
76 errno_t rc = pcapctl_dump_init(&sess);
77 if (rc != EOK) {
78 fprintf(stderr, "Error initializing ...\n");
79 return 1;
80 }
81 if (str_cmp(argv[1], "start") == 0) {
82 if (argc != 3) {
83 usage(argv[0]);
84 return 1;
85 }
86 start_dumping(argv[2]);
87 } else if (str_cmp(argv[1], "stop") == 0) {
88 stop_dumping();
89 fprintf(stdout, "Dumping was stopped\n");
90 return EOK;
91 } else {
92 usage(argv[0]);
93 return 1;
94 }
95 }
96 return 0;
97}
98
99/** @}
100 */
Note: See TracBrowser for help on using the repository browser.