Changes in / [34aad53d:c37c24c] in mainline
- Location:
- uspace
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/pcapctl/main.c
r34aad53d rc37c24c 36 36 #include <str.h> 37 37 #include <errno.h> 38 #include <arg_parse.h> 39 #include <getopt.h> 38 40 39 41 #include "pcapctl_dump.h" 40 42 41 43 #define NAME "pcapctl" 44 #define DEFAULT_DEV_NUM 0 42 45 43 pcapctl_sess_t* sess; 44 45 static errno_t start_dumping(const char *svc_name, const char *name) 46 static errno_t start_dumping(int *dev_number, const char *name) 46 47 { 47 errno_t rc = pcapctl_dump_open(svc_name, &sess); 48 pcapctl_sess_t *sess = NULL; 49 errno_t rc = pcapctl_dump_open(dev_number, &sess); 48 50 if (rc != EOK) { 49 51 return 1; 50 52 } 53 51 54 pcapctl_dump_start(name, sess); 52 55 pcapctl_dump_close(sess); … … 54 57 } 55 58 56 /** Session might */ 57 static errno_t stop_dumping(const char *svc_name) 59 static errno_t stop_dumping(int *dev_number) 58 60 { 59 errno_t rc = pcapctl_dump_open(svc_name, &sess); 61 pcapctl_sess_t *sess = NULL; 62 errno_t rc = pcapctl_dump_open(dev_number, &sess); 60 63 if (rc != EOK) { 61 64 return 1; 62 65 } 63 64 66 pcapctl_dump_stop(sess); 65 67 pcapctl_dump_close(sess); … … 67 69 } 68 70 69 static void list_devs(void) { 71 static void list_devs(void) 72 { 70 73 pcapctl_list(); 71 74 } 72 75 73 static void usage(const char *progname) 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) 74 90 { 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); 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"); 79 102 } 80 103 81 104 int main(int argc, char *argv[]) 82 105 { 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) { 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); 126 return 1; 127 } 128 break; 129 case 'l': 91 130 list_devs(); 92 131 return 0; 93 } else if (str_cmp(argv[1], "start") == 0) { 94 if (argc != 4) { 95 usage(argv[0]); 96 return 1; 97 } 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; 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; 110 144 } 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..name 151 start_dumping(&dev_number, output_file_name); 152 } else if (stop) { 153 //stop with dev number 154 stop_dumping(&dev_number); 111 155 } 112 156 return 0; -
uspace/drv/nic/e1k/e1k.c
r34aad53d rc37c24c 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"); 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); 2209 2214 if (rc != EOK) { 2210 ddf_msg(LVL_ERROR, "Failed adding function to category pcap"); 2211 goto err_add_to_cat; 2212 } 2213 2215 ddf_msg(LVL_ERROR, "Failed adding function to categories"); 2216 return rc; 2217 } 2214 2218 return EOK; 2215 2219 2216 err_add_to_cat:2217 ddf_fun_unbind(fun);2220 // err_add_to_cat: 2221 // ddf_fun_unbind(fun); 2218 2222 err_fun_bind: 2219 2223 err_rx_structure: -
uspace/drv/nic/ne2k/ne2k.c
r34aad53d rc37c24c 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 } 451 458 452 459 return EOK; -
uspace/drv/nic/rtl8139/driver.c
r34aad53d rc37c24c 42 42 #include <stdio.h> 43 43 #include <str.h> 44 #include <pcapdump_iface.h> 44 45 45 46 #include "defs.h" … … 1313 1314 } 1314 1315 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 1315 1322 ddf_msg(LVL_NOTE, "The %s device has been successfully initialized.", 1316 1323 ddf_dev_get_name(dev)); -
uspace/lib/nic/include/nic.h
r34aad53d rc37c24c 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 284 286 #endif // __NIC_H__ 285 287 -
uspace/lib/nic/src/nic_impl.c
r34aad53d rc37c24c 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 846 865 /** @} 847 866 */ -
uspace/lib/pcap/include/pcapctl_dump.h
r34aad53d rc37c24c 49 49 } pcapctl_sess_t; 50 50 51 extern errno_t pcapctl_dump_open( const char *svcname, pcapctl_sess_t **rsess);51 extern errno_t pcapctl_dump_open(int *, 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 56 extern errno_t pcapctl_is_valid_device(int *); 57 57 58 58 #endif -
uspace/lib/pcap/src/pcapctl_dump.c
r34aad53d rc37c24c 38 38 #include <str.h> 39 39 #include <stdlib.h> 40 40 #include <stdio.h> 41 #include <ctype.h> 41 42 #include "pcapctl_dump.h" 42 43 #include "pcapdump_iface.h" … … 51 52 } 52 53 53 static errno_t pcapctl_cat_get_svc(const char *drv_name, service_id_t* svc) { 54 static errno_t pcapctl_cat_get_svc(int *index, service_id_t *svc) 55 { 54 56 errno_t rc; 55 57 category_id_t pcap_cat; … … 66 68 if (rc != EOK) { 67 69 printf("Error resolving list of pcap services.\n"); 68 return rc; 69 } 70 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 return rc; 93 } 94 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; 100 } 101 if (*index + 1 > (int)count || *index < 0) { 102 return EINVAL; 103 } 104 return EOK; 105 } 106 107 /** 108 * 109 */ 110 errno_t pcapctl_list(void) 111 { 112 errno_t rc; 113 category_id_t pcap_cat; 114 size_t count; 115 service_id_t *pcap_svcs = NULL; 116 117 rc = loc_category_get_id("pcap", &pcap_cat, 0); 118 if (rc != EOK) { 119 printf("Error resolving category pcap.\n"); 120 return rc; 121 } 122 123 rc = loc_category_get_svcs(pcap_cat, &pcap_svcs, &count); 124 if (rc != EOK) { 125 printf("Error resolving list of pcap services.\n"); 126 free(pcap_svcs); 127 return rc; 128 } 129 130 fprintf(stdout, "Devices:\n"); 71 131 for (unsigned i = 0; i < count; ++i) { 72 132 char *name = NULL; 73 133 loc_service_get_name(pcap_svcs[i], &name); 74 if (!str_cmp(drv_name, name)) { 75 *svc = pcap_svcs[i]; 76 return EOK; 77 } 134 fprintf(stdout, "%d. %s\n", i, name); 78 135 } 79 136 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 free(pcap_svcs); 100 return rc; 101 } 102 103 fprintf(stdout, "Services:\n"); 104 for (unsigned i = 0; i < count; ++i) { 105 char *name = NULL; 106 loc_service_get_name(pcap_svcs[i], &name); 107 fprintf(stdout, "service: %s\n", name); 108 } 109 free(pcap_svcs); 110 return EOK; 111 } 112 113 114 errno_t pcapctl_dump_open(const char *svcname, pcapctl_sess_t **rsess) 137 return EOK; 138 } 139 140 /** 141 * 142 */ 143 errno_t pcapctl_dump_open(int *index, pcapctl_sess_t **rsess) 115 144 { 116 145 errno_t rc; … … 120 149 return ENOMEM; 121 150 122 rc = pcapctl_cat_get_svc(svcname, &svc); 123 if (rc != EOK) { 151 rc = pcapctl_cat_get_svc(index, &svc); 152 if (rc != EOK) { 153 printf("Error finding the device with index: %d\n", *index); 124 154 goto error; 125 155 } 156 126 157 async_sess_t *new_session = loc_service_connect(svc, INTERFACE_PCAP_CONTROL, 0); 127 158 if (new_session == NULL) { … … 130 161 goto error; 131 162 } 132 133 163 sess->sess = new_session; 134 164 *rsess = sess; … … 139 169 } 140 170 171 /** 172 * 173 */ 141 174 errno_t pcapctl_dump_close(pcapctl_sess_t *sess) 142 175 {
Note:
See TracChangeset
for help on using the changeset viewer.