Changes in / [c37c24c:34aad53d] in mainline
- Location:
- uspace
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/pcapctl/main.c
rc37c24c r34aad53d 36 36 #include <str.h> 37 37 #include <errno.h> 38 #include <arg_parse.h>39 #include <getopt.h>40 38 41 39 #include "pcapctl_dump.h" 42 40 43 41 #define NAME "pcapctl" 44 #define DEFAULT_DEV_NUM 045 42 46 static errno_t start_dumping(int *dev_number, const char *name) 43 pcapctl_sess_t* sess; 44 45 static errno_t start_dumping(const char *svc_name, const char *name) 47 46 { 48 pcapctl_sess_t *sess = NULL; 49 errno_t rc = pcapctl_dump_open(dev_number, &sess); 47 errno_t rc = pcapctl_dump_open(svc_name, &sess); 50 48 if (rc != EOK) { 51 49 return 1; 52 50 } 53 54 51 pcapctl_dump_start(name, sess); 55 52 pcapctl_dump_close(sess); … … 57 54 } 58 55 59 static errno_t stop_dumping(int *dev_number) 56 /** Session might */ 57 static errno_t stop_dumping(const char *svc_name) 60 58 { 61 pcapctl_sess_t *sess = NULL; 62 errno_t rc = pcapctl_dump_open(dev_number, &sess); 59 errno_t rc = pcapctl_dump_open(svc_name, &sess); 63 60 if (rc != EOK) { 64 61 return 1; 65 62 } 63 66 64 pcapctl_dump_stop(sess); 67 65 pcapctl_dump_close(sess); … … 69 67 } 70 68 71 static void list_devs(void) 72 { 69 static void list_devs(void) { 73 70 pcapctl_list(); 74 71 } 75 72 76 /** 77 * Array of supported commandline options 78 */ 79 static const struct option opts[] = { 80 { "device", required_argument, 0, 'd' }, 81 { "list", no_argument, 0, 'l' }, 82 { "help", no_argument, 0, 'h' }, 83 { "outfile", required_argument, 0, 'f' }, 84 { "start", no_argument, 0, 'r' }, 85 { "stop", no_argument, 0, 't' }, 86 { 0, 0, 0, 0 } 87 }; 88 89 static void usage(void) 73 static void usage(const char *progname) 90 74 { 91 printf("Usage:\n" 92 NAME " --list | -l \n" 93 "\tList of devices\n" 94 NAME " --start | -r --device= | -d <device number from list> --outfile= | -f <outfile>\n" 95 "\tPackets dumped from device will be written to <outfile>\n" 96 NAME " --stop | -t --device= | -d <device>\n" 97 "\tDumping from <device> stops\n" 98 NAME " --start | -s --outfile= | -f <outfile>\n" 99 "\tPackets dumped from the 0. device from the list will be written to <outfile>\n" 100 NAME " --help | -h\n" 101 "\tShow this application help.\n"); 75 fprintf(stderr, "Usage:\n"); 76 fprintf(stderr, " %s list: List of devices\n", progname); 77 fprintf(stderr, " %s start <device> <outfile>: Packets dumped from <device> will be written to <outfile>\n", progname); 78 fprintf(stderr, " %s stop <device>: Dumping from <device> stops\n", progname); 102 79 } 103 80 104 81 int main(int argc, char *argv[]) 105 82 { 106 bool start = false; 107 bool stop = false; 108 int dev_number = DEFAULT_DEV_NUM; 109 const char *output_file_name; 110 int idx = 0; 111 int ret = 0; 112 if (argc == 1) { 113 usage(); 114 return 0; 115 } 116 while (ret != -1) { 117 ret = getopt_long(argc, argv, "d:lhf:rt", opts, &idx); 118 switch (ret) { 119 case 'd': 120 char *rest; 121 long result = strtol(optarg, &rest, 10); 122 dev_number = (int)result; 123 errno_t rc = pcapctl_is_valid_device(&dev_number); 124 if (rc != EOK) { 125 printf("Device with index %d not found\n", dev_number); 83 if (argc < 2) { 84 usage(argv[0]); 85 return 1; 86 } else { 87 if (str_cmp(argv[1], "--help") == 0 || str_cmp(argv[1], "-h") == 0) { 88 usage(argv[0]); 89 return 0; 90 } else if (str_cmp(argv[1], "list") == 0) { 91 list_devs(); 92 return 0; 93 } else if (str_cmp(argv[1], "start") == 0) { 94 if (argc != 4) { 95 usage(argv[0]); 126 96 return 1; 127 97 } 128 break; 129 case 'l': 130 list_devs(); 131 return 0; 132 case 'h': 133 usage(); 134 return 0; 135 case 'f': 136 output_file_name = optarg; 137 break; 138 case 'r': 139 start = true; 140 break; 141 case 't': 142 stop = true; 143 break; 98 start_dumping(argv[2], argv[3]); 99 } else if (str_cmp(argv[1], "stop") == 0) { 100 if (argc != 3) { 101 usage(argv[0]); 102 return 1; 103 } 104 stop_dumping(argv[2]); 105 fprintf(stdout, "Dumping was stopped\n"); 106 return EOK; 107 } else { 108 usage(argv[0]); 109 return 1; 144 110 } 145 }146 147 printf("%s: HelenOS Packet Dumping utility: device - %d\n", NAME, dev_number);148 149 if (start) {150 // start with dev number and optional..name151 start_dumping(&dev_number, output_file_name);152 } else if (stop) {153 //stop with dev number154 stop_dumping(&dev_number);155 111 } 156 112 return 0; -
uspace/drv/nic/e1k/e1k.c
rc37c24c r34aad53d 2202 2202 goto err_fun_bind; 2203 2203 2204 // rc = ddf_fun_add_to_category(fun, DEVICE_CATEGORY_NIC); 2205 // if (rc != EOK) 2206 // goto err_add_to_cat; 2207 2208 // rc = ddf_fun_add_to_category(fun, "pcap"); 2209 // if (rc != EOK) { 2210 // ddf_msg(LVL_ERROR, "Failed adding function to category pcap"); 2211 // goto err_add_to_cat; 2212 // } 2213 rc = nic_fun_add_to_cats(fun); 2204 rc = ddf_fun_add_to_category(fun, DEVICE_CATEGORY_NIC); 2205 if (rc != EOK) 2206 goto err_add_to_cat; 2207 2208 rc = ddf_fun_add_to_category(fun, "pcap"); 2214 2209 if (rc != EOK) { 2215 ddf_msg(LVL_ERROR, "Failed adding function to categories"); 2216 return rc; 2217 } 2210 ddf_msg(LVL_ERROR, "Failed adding function to category pcap"); 2211 goto err_add_to_cat; 2212 } 2213 2218 2214 return EOK; 2219 2215 2220 //err_add_to_cat:2221 //ddf_fun_unbind(fun);2216 err_add_to_cat: 2217 ddf_fun_unbind(fun); 2222 2218 err_fun_bind: 2223 2219 err_rx_structure: -
uspace/drv/nic/ne2k/ne2k.c
rc37c24c r34aad53d 449 449 return rc; 450 450 } 451 rc = ddf_fun_add_to_category(fun, "pcap");452 if (rc != EOK) {453 //ddf_msg(LVL_ERROR, "Failed adding function to category pcap");454 ddf_fun_unbind(fun);455 ddf_fun_destroy(fun);456 return rc;457 }458 451 459 452 return EOK; -
uspace/drv/nic/rtl8139/driver.c
rc37c24c r34aad53d 42 42 #include <stdio.h> 43 43 #include <str.h> 44 #include <pcapdump_iface.h>45 44 46 45 #include "defs.h" … … 1314 1313 } 1315 1314 1316 rc = ddf_fun_add_to_category(fun, "pcap");1317 if (rc != EOK) {1318 ddf_msg(LVL_ERROR, "Failed adding function to category pcap");1319 goto err_fun_bind;1320 }1321 1322 1315 ddf_msg(LVL_NOTE, "The %s device has been successfully initialized.", 1323 1316 ddf_dev_get_name(dev)); -
uspace/lib/nic/include/nic.h
rc37c24c r34aad53d 282 282 extern pcap_iface_t *nic_get_pcap_iface(nic_t *); 283 283 284 extern errno_t nic_fun_add_to_cats(ddf_fun_t *fun);285 286 284 #endif // __NIC_H__ 287 285 -
uspace/lib/nic/src/nic_impl.c
rc37c24c r34aad53d 844 844 } 845 845 846 errno_t nic_fun_add_to_cats(ddf_fun_t *fun)847 {848 errno_t rc;849 rc = ddf_fun_add_to_category(fun, DEVICE_CATEGORY_NIC);850 if (rc != EOK)851 goto err_add_to_cat;852 853 rc = ddf_fun_add_to_category(fun, "pcap");854 if (rc != EOK) {855 //ddf_msg(LVL_ERROR, "Failed adding function to category pcap");856 goto err_add_to_cat;857 }858 return EOK;859 860 err_add_to_cat:861 ddf_fun_unbind(fun);862 return rc;863 }864 865 846 /** @} 866 847 */ -
uspace/lib/pcap/include/pcapctl_dump.h
rc37c24c r34aad53d 49 49 } pcapctl_sess_t; 50 50 51 extern errno_t pcapctl_dump_open( int *, pcapctl_sess_t **rsess);51 extern errno_t pcapctl_dump_open(const char *svcname, pcapctl_sess_t **rsess); 52 52 extern errno_t pcapctl_dump_close(pcapctl_sess_t *sess); 53 53 extern errno_t pcapctl_dump_start(const char *, pcapctl_sess_t *); 54 54 extern errno_t pcapctl_dump_stop(pcapctl_sess_t *); 55 55 extern errno_t pcapctl_list(void); 56 extern errno_t pcapctl_is_valid_device(int *); 56 57 57 58 58 #endif -
uspace/lib/pcap/src/pcapctl_dump.c
rc37c24c r34aad53d 38 38 #include <str.h> 39 39 #include <stdlib.h> 40 #include <stdio.h> 41 #include <ctype.h> 40 42 41 #include "pcapctl_dump.h" 43 42 #include "pcapdump_iface.h" … … 52 51 } 53 52 54 static errno_t pcapctl_cat_get_svc(int *index, service_id_t *svc) 55 { 53 static errno_t pcapctl_cat_get_svc(const char *drv_name, service_id_t* svc) { 56 54 errno_t rc; 57 55 category_id_t pcap_cat; … … 68 66 if (rc != EOK) { 69 67 printf("Error resolving list of pcap services.\n"); 70 free(pcap_svcs);71 return rc;72 }73 if (*index < (int)count) {74 *svc = pcap_svcs[*index];75 free(pcap_svcs);76 return EOK;77 }78 79 return ENOENT;80 }81 82 errno_t pcapctl_is_valid_device(int *index)83 {84 errno_t rc;85 category_id_t pcap_cat;86 size_t count;87 service_id_t *pcap_svcs = NULL;88 89 rc = loc_category_get_id("pcap", &pcap_cat, 0);90 if (rc != EOK) {91 printf("Error resolving category pcap.\n");92 68 return rc; 93 69 } 94 70 95 rc = loc_category_get_svcs(pcap_cat, &pcap_svcs, &count); 96 if (rc != EOK) { 97 printf("Error resolving list of pcap services.\n"); 98 free(pcap_svcs); 99 return rc; 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 } 100 78 } 101 if (*index + 1 > (int)count || *index < 0) { 102 return EINVAL; 103 } 104 return EOK; 79 free(pcap_svcs); 80 return 1; 105 81 } 106 82 107 /** 108 * 109 */ 110 errno_t pcapctl_list(void) 111 { 83 extern errno_t pcapctl_list(void) { 84 112 85 errno_t rc; 113 86 category_id_t pcap_cat; … … 128 101 } 129 102 130 fprintf(stdout, " Devices:\n");103 fprintf(stdout, "Services:\n"); 131 104 for (unsigned i = 0; i < count; ++i) { 132 105 char *name = NULL; 133 106 loc_service_get_name(pcap_svcs[i], &name); 134 fprintf(stdout, " %d. %s\n", i, name);107 fprintf(stdout, "service: %s\n", name); 135 108 } 136 109 free(pcap_svcs); … … 138 111 } 139 112 140 /** 141 * 142 */ 143 errno_t pcapctl_dump_open(int *index, pcapctl_sess_t **rsess) 113 114 errno_t pcapctl_dump_open(const char *svcname, pcapctl_sess_t **rsess) 144 115 { 145 116 errno_t rc; … … 149 120 return ENOMEM; 150 121 151 rc = pcapctl_cat_get_svc( index, &svc);122 rc = pcapctl_cat_get_svc(svcname, &svc); 152 123 if (rc != EOK) { 153 printf("Error finding the device with index: %d\n", *index);154 124 goto error; 155 125 } 156 157 126 async_sess_t *new_session = loc_service_connect(svc, INTERFACE_PCAP_CONTROL, 0); 158 127 if (new_session == NULL) { … … 161 130 goto error; 162 131 } 132 163 133 sess->sess = new_session; 164 134 *rsess = sess; … … 169 139 } 170 140 171 /**172 *173 */174 141 errno_t pcapctl_dump_close(pcapctl_sess_t *sess) 175 142 {
Note:
See TracChangeset
for help on using the changeset viewer.