Changeset 325ea9c in mainline for uspace/lib/pcap/src/pcapctl_dump.c
- Timestamp:
- 2024-03-04T08:47:50Z (9 months ago)
- Children:
- e846bec
- Parents:
- 192019f
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/pcap/src/pcapctl_dump.c
r192019f r325ea9c 51 51 } 52 52 53 errno_t pcapctl_dump_init(pcapctl_sess_t *sess) 54 { 53 static errno_t pcapctl_cat_has_drv(const char *drv_name, service_id_t* svc) { 55 54 errno_t rc; 56 char *svc_name;57 55 category_id_t pcap_cat; 58 56 size_t count; … … 70 68 return rc; 71 69 } 70 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 } 78 } 79 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 return rc; 100 } 101 72 102 assert((count > 0) && "TODO: not implemented when no services are available\n"); 73 103 74 rc = loc_service_get_name(pcap_svcs[0], &svc_name); // Note: for now [0], because only one driver is in pcap_svcs and there is no need to find particular 104 fprintf(stdout, "Drivers:\n"); 105 for (unsigned i = 0; i < count; ++i) { 106 char *name = NULL; 107 loc_service_get_name(pcap_svcs[i], &name); 108 109 fprintf(stdout, "driver: %s\n", name); 110 } 111 return EOK; 112 } 113 114 errno_t pcapctl_dump_init(pcapctl_sess_t *sess, const char *drv_name) 115 { 116 errno_t rc; 117 service_id_t svc; 118 rc = pcapctl_cat_has_drv(drv_name, &svc); 75 119 if (rc != EOK) { 76 printf("Error getting service name.\n");77 goto error;120 fprintf(stderr, "No such driver was found.\n"); 121 return 1; 78 122 } 79 printf("Using device: %s\n", svc_name); 80 81 async_sess_t *new_session = loc_service_connect(pcap_svcs[0], INTERFACE_PCAP_CONTROL, 0); 123 async_sess_t *new_session = loc_service_connect(svc, INTERFACE_PCAP_CONTROL, 0); 82 124 if (new_session == NULL) { 83 printf("Error connecting to service.\n");125 fprintf(stderr, "Error connecting to service.\n"); 84 126 rc = EREFUSED; 85 127 goto error; … … 88 130 rc = EOK; 89 131 error: 90 free(pcap_svcs);91 132 return rc; 92 133 }
Note:
See TracChangeset
for help on using the changeset viewer.