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

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

nic, drvs, pcapctl

  • Property mode set to 100644
File size: 3.6 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"
[2ebbe9b]42#define DEFAULT_DEV_NUM 0
[17a8fcf]43
[7924f82]44//pcapctl_sess_t* sess = NULL;
[17a8fcf]45
[8765039]46static errno_t start_dumping(const char *svc_name, const char *name)
[17a8fcf]47{
[2ebbe9b]48 pcapctl_sess_t *sess = NULL;
[8765039]49 errno_t rc = pcapctl_dump_open(svc_name, &sess);
[91042127]50 if (rc != EOK) {
51 return 1;
52 }
[7924f82]53
[8765039]54 pcapctl_dump_start(name, sess);
55 pcapctl_dump_close(sess);
[91042127]56 return EOK;
[17a8fcf]57}
58
[91042127]59/** Session might */
[8765039]60static errno_t stop_dumping(const char *svc_name)
[17a8fcf]61{
[2ebbe9b]62 pcapctl_sess_t *sess = NULL;
[8765039]63 errno_t rc = pcapctl_dump_open(svc_name, &sess);
[91042127]64 if (rc != EOK) {
65 return 1;
66 }
[8765039]67 pcapctl_dump_stop(sess);
68 pcapctl_dump_close(sess);
[91042127]69 return EOK;
70}
71
[2ebbe9b]72static void list_devs(void)
73{
[91042127]74 pcapctl_list();
[17a8fcf]75}
76
[7924f82]77static void usage(void)
[17a8fcf]78{
[7924f82]79 printf("Usage:\n"
[2ebbe9b]80 NAME " list \n"
81 "\tList of devices\n"
82 NAME " start --device= | -d <device number from list> <outfile>\n"
83 "\tPackets dumped from device will be written to <outfile>\n"
84 NAME " stop --device= | -d <device>\n"
85 "\tDumping from <device> stops\n"
86 NAME " start <outfile>\n"
87 "\tPackets dumped from the 1st device from the list will be written to <outfile>\n"
88 NAME " --help | -h\n"
89 "\tShow this application help.\n");
[17a8fcf]90}
91
92int main(int argc, char *argv[])
93{
94 if (argc < 2) {
[7924f82]95 usage();
[17a8fcf]96 return 1;
97 } else {
[2ebbe9b]98 /** help */
[91042127]99 if (str_cmp(argv[1], "--help") == 0 || str_cmp(argv[1], "-h") == 0) {
[7924f82]100 usage();
[91042127]101 return 0;
[2ebbe9b]102 /** list */
[91042127]103 } else if (str_cmp(argv[1], "list") == 0) {
104 list_devs();
105 return 0;
[2ebbe9b]106 /** start with/out devnum */
[91042127]107 } else if (str_cmp(argv[1], "start") == 0) {
[7924f82]108 if (argc == 3) {
109 start_dumping((char *)"0", argv[2]);
110 return 0;
[2ebbe9b]111 } else if (argc == 4) {
[7924f82]112 start_dumping(argv[2], argv[3]);
113 return 0;
114 } else {
115 usage();
[17a8fcf]116 return 1;
117 }
[2ebbe9b]118 /** Stop with/out devnum */
[17a8fcf]119 } else if (str_cmp(argv[1], "stop") == 0) {
[7924f82]120 if (argc == 2) {
121 stop_dumping((char *)"0");
122 fprintf(stdout, "Dumping was stopped\n");
123 return 0;
[2ebbe9b]124 } else if (argc == 3) {
[7924f82]125
126 stop_dumping(argv[2]);
127 fprintf(stdout, "Dumping was stopped\n");
128 } else {
129 usage();
[91042127]130 return 1;
131 }
[17a8fcf]132 } else {
[7924f82]133 usage();
[17a8fcf]134 return 1;
135 }
136 }
137 return 0;
138}
139
140/** @}
141 */
Note: See TracBrowser for help on using the repository browser.