Changeset 325ea9c in mainline
- Timestamp:
- 2024-03-04T08:47:50Z (10 months ago)
- Children:
- e846bec
- Parents:
- 192019f
- Location:
- uspace
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/pcapctl/main.c
r192019f r325ea9c 50 50 pcapctl_sess_t sess; 51 51 52 static void start_dumping(const char *name)52 static errno_t start_dumping(const char *drv_name, const char *name) 53 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 } 54 59 pcapctl_dump_start(name, &sess); 60 return EOK; 55 61 } 56 62 57 static void stop_dumping(void) 63 /** Session might */ 64 static errno_t stop_dumping(const char *drv_name) 58 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 } 59 71 pcapctl_dump_stop(&sess); 72 return EOK; 73 } 74 75 static void list_devs(void) { 76 pcapctl_list(); 60 77 } 61 78 … … 63 80 { 64 81 fprintf(stderr, "Usage:\n"); 65 fprintf(stderr, " %s start < outfile>: Packetswill be written to <outfile>\n", progname);66 fprintf(stderr, " %s stop : Dumpingstops\n", progname);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); 67 84 68 85 } … … 74 91 return 1; 75 92 } 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) { 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) { 82 106 if (argc != 3) { 83 107 usage(argv[0]); 84 108 return 1; 85 109 } 86 start_dumping(argv[2]); 87 } else if (str_cmp(argv[1], "stop") == 0) { 88 stop_dumping(); 110 stop_dumping(argv[2]); 89 111 fprintf(stdout, "Dumping was stopped\n"); 90 112 return EOK; -
uspace/lib/pcap/include/pcapctl_dump.h
r192019f r325ea9c 49 49 } pcapctl_sess_t; 50 50 51 extern errno_t pcapctl_dump_init(pcapctl_sess_t * );51 extern errno_t pcapctl_dump_init(pcapctl_sess_t *, const char *); 52 52 extern errno_t pcapctl_dump_start(const char *, pcapctl_sess_t *); 53 53 extern errno_t pcapctl_dump_stop(pcapctl_sess_t *); 54 extern errno_t pcapctl_list(void); 54 55 55 56 #endif -
uspace/lib/pcap/include/pcapdump_iface.h
r192019f r325ea9c 44 44 typedef enum { 45 45 PCAP_CONTROL_SET_START = IPC_FIRST_USER_METHOD, 46 PCAP_CONTROL_SET_STOP 46 PCAP_CONTROL_SET_STOP, 47 PCAP_CONTROL_GET_NAME 47 48 } pcap_request_t; 48 49 -
uspace/lib/pcap/src/pcapctl_dump.c
r192019f r325ea9c 51 51 } 52 52 53 errno_t pcapctl_dump_init(pcapctl_sess_t *sess) 54 { 53 static errno_t pcapctl_cat_has_drv(const char *drv_name, service_id_t* svc) { 55 54 errno_t rc; 56 char *svc_name;57 55 category_id_t pcap_cat; 58 56 size_t count; … … 70 68 return rc; 71 69 } 70 71 for (unsigned i = 0; i < count; ++i) { 72 char *name = NULL; 73 loc_service_get_name(pcap_svcs[i], &name); 74 if (!str_cmp(drv_name, name)) { 75 *svc = pcap_svcs[i]; 76 return EOK; 77 } 78 } 79 free(pcap_svcs); 80 return 1; 81 } 82 83 extern errno_t pcapctl_list(void) { 84 85 errno_t rc; 86 category_id_t pcap_cat; 87 size_t count; 88 service_id_t *pcap_svcs = NULL; 89 90 rc = loc_category_get_id("pcap", &pcap_cat, 0); 91 if (rc != EOK) { 92 printf("Error resolving category 'pcap'.\n"); 93 return rc; 94 } 95 96 rc = loc_category_get_svcs(pcap_cat, &pcap_svcs, &count); 97 if (rc != EOK) { 98 printf("Error resolving list of pcap services.\n"); 99 return rc; 100 } 101 72 102 assert((count > 0) && "TODO: not implemented when no services are available\n"); 73 103 74 rc = loc_service_get_name(pcap_svcs[0], &svc_name); // Note: for now [0], because only one driver is in pcap_svcs and there is no need to find particular 104 fprintf(stdout, "Drivers:\n"); 105 for (unsigned i = 0; i < count; ++i) { 106 char *name = NULL; 107 loc_service_get_name(pcap_svcs[i], &name); 108 109 fprintf(stdout, "driver: %s\n", name); 110 } 111 return EOK; 112 } 113 114 errno_t pcapctl_dump_init(pcapctl_sess_t *sess, const char *drv_name) 115 { 116 errno_t rc; 117 service_id_t svc; 118 rc = pcapctl_cat_has_drv(drv_name, &svc); 75 119 if (rc != EOK) { 76 printf("Error getting service name.\n");77 goto error;120 fprintf(stderr, "No such driver was found.\n"); 121 return 1; 78 122 } 79 printf("Using device: %s\n", svc_name); 80 81 async_sess_t *new_session = loc_service_connect(pcap_svcs[0], INTERFACE_PCAP_CONTROL, 0); 123 async_sess_t *new_session = loc_service_connect(svc, INTERFACE_PCAP_CONTROL, 0); 82 124 if (new_session == NULL) { 83 printf("Error connecting to service.\n");125 fprintf(stderr, "Error connecting to service.\n"); 84 126 rc = EREFUSED; 85 127 goto error; … … 88 130 rc = EOK; 89 131 error: 90 free(pcap_svcs);91 132 return rc; 92 133 }
Note:
See TracChangeset
for help on using the changeset viewer.