Changeset e4cc266 in mainline
- Timestamp:
- 2024-03-10T11:40:30Z (10 months ago)
- Children:
- 34aad53d, 78edb5e
- Parents:
- e846bec
- Location:
- uspace
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/pcapctl/main.c
re846bec re4cc266 41 41 #define NAME "pcapctl" 42 42 43 pcapctl_sess_t sess;43 pcapctl_sess_t* sess; 44 44 45 static errno_t start_dumping(const char * drv_name, const char *name)45 static errno_t start_dumping(const char *svc_name, const char *name) 46 46 { 47 errno_t rc = pcapctl_dump_ init(&sess, drv_name);47 errno_t rc = pcapctl_dump_open(svc_name, &sess); 48 48 if (rc != EOK) { 49 //fprintf(stderr, "Error initializing ...\n");50 49 return 1; 51 50 } 52 pcapctl_dump_start(name, &sess); 51 pcapctl_dump_start(name, sess); 52 pcapctl_dump_close(sess); 53 53 return EOK; 54 54 } 55 55 56 56 /** Session might */ 57 static errno_t stop_dumping(const char * drv_name)57 static errno_t stop_dumping(const char *svc_name) 58 58 { 59 errno_t rc = pcapctl_dump_ init(&sess, drv_name);59 errno_t rc = pcapctl_dump_open(svc_name, &sess); 60 60 if (rc != EOK) { 61 fprintf(stderr, "Error initializing ...\n");62 61 return 1; 63 62 } 64 pcapctl_dump_stop(&sess); 63 64 pcapctl_dump_stop(sess); 65 pcapctl_dump_close(sess); 65 66 return EOK; 66 67 } … … 73 74 { 74 75 fprintf(stderr, "Usage:\n"); 76 fprintf(stderr, " %s list: List of devices\n", progname); 75 77 fprintf(stderr, " %s start <device> <outfile>: Packets dumped from <device> will be written to <outfile>\n", progname); 76 78 fprintf(stderr, " %s stop <device>: Dumping from <device> stops\n", progname); 77 78 79 } 79 80 -
uspace/lib/nic/include/nic_driver.h
re846bec re4cc266 46 46 #include <nic/nic.h> 47 47 #include <async.h> 48 #include <pcapdump_iface.h> 48 49 49 50 #include "nic.h" 50 51 #include "nic_rx_control.h" 51 52 #include "nic_wol_virtues.h" 52 #include "pcap/include/pcapdump_iface.h"53 53 54 54 struct sw_poll_info { -
uspace/lib/nic/src/nic_driver.c
re846bec re4cc266 650 650 651 651 nic_data->dev = device; 652 652 653 errno_t pcap_rc = pcapdump_init(nic_get_pcap_iface(nic_data)); 653 654 654 if (pcap_rc != EOK) { 655 655 printf("Failed creating pcapdump port\n"); -
uspace/lib/pcap/include/pcapctl_dump.h
re846bec re4cc266 49 49 } pcapctl_sess_t; 50 50 51 extern errno_t pcapctl_dump_init(pcapctl_sess_t *, const char *); 51 extern errno_t pcapctl_dump_open(const char *svcname, pcapctl_sess_t **rsess); 52 extern errno_t pcapctl_dump_close(pcapctl_sess_t *sess); 52 53 extern errno_t pcapctl_dump_start(const char *, pcapctl_sess_t *); 53 54 extern errno_t pcapctl_dump_stop(pcapctl_sess_t *); 54 55 extern errno_t pcapctl_list(void); 56 55 57 56 58 #endif -
uspace/lib/pcap/src/pcapctl_dump.c
re846bec re4cc266 51 51 } 52 52 53 static errno_t pcapctl_cat_ has_drv(const char *drv_name, service_id_t* svc) {53 static errno_t pcapctl_cat_get_svc(const char *drv_name, service_id_t* svc) { 54 54 errno_t rc; 55 55 category_id_t pcap_cat; … … 90 90 rc = loc_category_get_id("pcap", &pcap_cat, 0); 91 91 if (rc != EOK) { 92 printf("Error resolving category 'pcap'.\n");92 printf("Error resolving category pcap.\n"); 93 93 return rc; 94 94 } … … 97 97 if (rc != EOK) { 98 98 printf("Error resolving list of pcap services.\n"); 99 free(pcap_svcs); 99 100 return rc; 100 101 } 101 102 102 assert((count > 0) && "TODO: not implemented when no services are available\n"); 103 104 fprintf(stdout, "Drivers:\n"); 103 fprintf(stdout, "Services:\n"); 105 104 for (unsigned i = 0; i < count; ++i) { 106 105 char *name = NULL; 107 106 loc_service_get_name(pcap_svcs[i], &name); 108 109 fprintf(stdout, "driver: %s\n", name); 107 fprintf(stdout, "service: %s\n", name); 110 108 } 109 free(pcap_svcs); 111 110 return EOK; 112 111 } 113 112 114 errno_t pcapctl_dump_init(pcapctl_sess_t *sess, const char *drv_name) 113 114 errno_t pcapctl_dump_open(const char *svcname, pcapctl_sess_t **rsess) 115 115 { 116 116 errno_t rc; 117 117 service_id_t svc; 118 rc = pcapctl_cat_has_drv(drv_name, &svc); 118 pcapctl_sess_t *sess = calloc(1, sizeof(pcapctl_sess_t)); 119 if (sess == NULL) 120 return ENOMEM; 121 122 rc = pcapctl_cat_get_svc(svcname, &svc); 119 123 if (rc != EOK) { 120 fprintf(stderr, "No such driver was found.\n"); 121 return 1; 124 goto error; 122 125 } 123 126 async_sess_t *new_session = loc_service_connect(svc, INTERFACE_PCAP_CONTROL, 0); … … 127 130 goto error; 128 131 } 132 129 133 sess->sess = new_session; 130 rc = EOK; 134 *rsess = sess; 135 return EOK; 131 136 error: 137 pcapctl_dump_close(sess); 132 138 return rc; 139 } 140 141 errno_t pcapctl_dump_close(pcapctl_sess_t *sess) 142 { 143 free(sess); 144 return EOK; 133 145 } 134 146
Note:
See TracChangeset
for help on using the changeset viewer.