Changeset 78edb5e in mainline for uspace/lib/pcap/src/pcapctl_dump.c
- Timestamp:
- 2024-03-19T15:15:50Z (10 months ago)
- Children:
- 8d9217d
- Parents:
- e4cc266
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/pcap/src/pcapctl_dump.c
re4cc266 r78edb5e 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" 43 44 45 //static service_id_t *pcap_svcs = NULL; ?? 46 47 static errno_t str2num(const char* str, size_t* number) { 48 size_t num = 0; 49 if (*str == 0) 50 return ELIMIT; 51 if (!isdigit(*str)) 52 return EINVAL; 53 while (isdigit(*str)) { 54 num = num * 10 + ((*str) - '0'); 55 str++; 56 } 57 58 *number = num; 59 return EOK; 60 } 44 61 /** Finish an async exchange on the pcapctl session 45 62 * … … 105 122 char *name = NULL; 106 123 loc_service_get_name(pcap_svcs[i], &name); 107 fprintf(stdout, " service: %s\n", name);124 fprintf(stdout, "%d. %s\n", i, name); 108 125 } 109 126 free(pcap_svcs); … … 112 129 113 130 114 errno_t pcapctl_dump_open(const char *svcname, pcapctl_sess_t **rsess) 131 static errno_t pcapctl_get_name_from_number(const char* svcnum, const char** svcname) { 132 133 errno_t rc; 134 category_id_t pcap_cat; 135 size_t count; 136 service_id_t *pcap_svcs = NULL; 137 138 rc = loc_category_get_id("pcap", &pcap_cat, 0); 139 if (rc != EOK) { 140 printf("Error resolving category pcap.\n"); 141 return rc; 142 } 143 size_t num; 144 rc = str2num(svcnum, &num); 145 if (rc != EOK) { 146 printf("Error converting char* to size_t.\n"); 147 free(pcap_svcs); 148 return rc; 149 } 150 151 rc = loc_category_get_svcs(pcap_cat, &pcap_svcs, &count); 152 if (rc != EOK) { 153 printf("Error resolving list of pcap services.\n"); 154 free(pcap_svcs); 155 return rc; 156 } 157 158 if (num >= count) { 159 printf("Error finding device: no device with such number\n"); 160 free(pcap_svcs); 161 return EINVAL; 162 } 163 char *name = NULL; 164 rc = loc_service_get_name(pcap_svcs[num], &name); 165 if (rc != EOK) { 166 printf("Error resolving name"); 167 } 168 169 *svcname = name; 170 printf("%s\n", *svcname); 171 return EOK; 172 } 173 174 /** 175 * 176 */ 177 errno_t pcapctl_dump_open(const char *svcnum, pcapctl_sess_t **rsess) 115 178 { 116 179 errno_t rc; … … 119 182 if (sess == NULL) 120 183 return ENOMEM; 184 185 186 const char* svcname; 187 188 rc = pcapctl_get_name_from_number(svcnum, &svcname); 189 if (rc != EOK) { 190 return rc; 191 } 121 192 122 193 rc = pcapctl_cat_get_svc(svcname, &svc); … … 130 201 goto error; 131 202 } 132 133 203 sess->sess = new_session; 134 204 *rsess = sess; … … 139 209 } 140 210 211 /** 212 * 213 */ 141 214 errno_t pcapctl_dump_close(pcapctl_sess_t *sess) 142 215 {
Note:
See TracChangeset
for help on using the changeset viewer.