Changes in uspace/lib/pcap/src/pcapctl_dump.c [384f081:e4cc266] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/pcap/src/pcapctl_dump.c
r384f081 re4cc266 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.