Changeset 325ea9c in mainline for uspace/lib/pcap/src/pcapctl_dump.c


Ignore:
Timestamp:
2024-03-04T08:47:50Z (9 months ago)
Author:
Nataliia Korop <n.corop08@…>
Children:
e846bec
Parents:
192019f
Message:

long name without mapping ok

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/pcap/src/pcapctl_dump.c

    r192019f r325ea9c  
    5151}
    5252
    53 errno_t pcapctl_dump_init(pcapctl_sess_t *sess)
    54 {
     53static errno_t pcapctl_cat_has_drv(const char *drv_name, service_id_t* svc) {
    5554        errno_t rc;
    56         char *svc_name;
    5755        category_id_t pcap_cat;
    5856        size_t count;
     
    7068                return rc;
    7169        }
     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
     83extern 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
    72102        assert((count > 0) && "TODO: not implemented when no services are available\n");
    73103
    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
     114errno_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);
    75119        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;
    78122        }
    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);
    82124        if (new_session == NULL) {
    83                 printf("Error connecting to service.\n");
     125                fprintf(stderr, "Error connecting to service.\n");
    84126                rc =  EREFUSED;
    85127                goto error;
     
    88130        rc = EOK;
    89131error:
    90         free(pcap_svcs);
    91132        return rc;
    92133}
Note: See TracChangeset for help on using the changeset viewer.