Changeset 384f081 in mainline for uspace/lib/pcap/src/pcapctl_dump.c
- Timestamp:
- 2024-04-07T09:32:59Z (8 months ago)
- Children:
- 6c1e7c0
- Parents:
- 8d9217d
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/pcap/src/pcapctl_dump.c
r8d9217d r384f081 43 43 #include "pcapdump_iface.h" 44 44 45 //static service_id_t *pcap_svcs = NULL; ??46 47 static errno_t str2num(const char *str, size_t *number)48 {49 size_t num = 0;50 if (*str == 0)51 return ELIMIT;52 if (!isdigit(*str))53 return EINVAL;54 while (isdigit(*str)) {55 num = num * 10 + ((*str) - '0');56 str++;57 }58 59 *number = num;60 return EOK;61 }62 45 /** Finish an async exchange on the pcapctl session 63 46 * … … 69 52 } 70 53 71 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) 72 55 { 73 56 errno_t rc; … … 85 68 if (rc != EOK) { 86 69 printf("Error resolving list of pcap services.\n"); 87 return rc; 88 } 89 90 for (unsigned i = 0; i < count; ++i) { 91 char *name = NULL; 92 loc_service_get_name(pcap_svcs[i], &name); 93 if (!str_cmp(drv_name, name)) { 94 *svc = pcap_svcs[i]; 95 return EOK; 96 } 97 } 98 free(pcap_svcs); 99 return 1; 100 } 101 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 */ 102 110 errno_t pcapctl_list(void) 103 111 { … … 130 138 } 131 139 132 static errno_t pcapctl_get_name_from_number(const char *svcnum, const char **svcname)133 {134 errno_t rc;135 category_id_t pcap_cat;136 size_t count;137 service_id_t *pcap_svcs = NULL;138 139 rc = loc_category_get_id("pcap", &pcap_cat, 0);140 if (rc != EOK) {141 printf("Error resolving category pcap.\n");142 return rc;143 }144 size_t num;145 rc = str2num(svcnum, &num);146 if (rc != EOK) {147 printf("Error converting char* to size_t.\n");148 free(pcap_svcs);149 return rc;150 }151 152 rc = loc_category_get_svcs(pcap_cat, &pcap_svcs, &count);153 if (rc != EOK) {154 printf("Error resolving list of pcap services.\n");155 free(pcap_svcs);156 return rc;157 }158 159 if (num >= count) {160 printf("Error finding device: no device with such number\n");161 free(pcap_svcs);162 return EINVAL;163 }164 char *name = NULL;165 rc = loc_service_get_name(pcap_svcs[num], &name);166 if (rc != EOK) {167 printf("Error resolving name");168 }169 170 *svcname = name;171 printf("%s\n", *svcname);172 return EOK;173 }174 175 140 /** 176 141 * 177 142 */ 178 errno_t pcapctl_dump_open( const char *svcnum, pcapctl_sess_t **rsess)143 errno_t pcapctl_dump_open(int *index, pcapctl_sess_t **rsess) 179 144 { 180 145 errno_t rc; … … 184 149 return ENOMEM; 185 150 186 const char *svcname; 187 188 rc = pcapctl_get_name_from_number(svcnum, &svcname); 189 if (rc != EOK) { 190 return rc; 191 } 192 193 rc = pcapctl_cat_get_svc(svcname, &svc); 194 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); 195 154 goto error; 196 155 } 156 197 157 async_sess_t *new_session = loc_service_connect(svc, INTERFACE_PCAP_CONTROL, 0); 198 158 if (new_session == NULL) {
Note:
See TracChangeset
for help on using the changeset viewer.