Ignore:
File:
1 edited

Legend:

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

    r384f081 re4cc266  
    3838#include <str.h>
    3939#include <stdlib.h>
    40 #include <stdio.h>
    41 #include <ctype.h>
     40
    4241#include "pcapctl_dump.h"
    4342#include "pcapdump_iface.h"
     
    5251}
    5352
    54 static errno_t pcapctl_cat_get_svc(int *index, service_id_t *svc)
    55 {
     53static errno_t pcapctl_cat_get_svc(const char *drv_name, service_id_t* svc) {
    5654        errno_t rc;
    5755        category_id_t pcap_cat;
     
    6866        if (rc != EOK) {
    6967                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");
    9268                return rc;
    9369        }
    9470
    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                }
    10078        }
    101         if (*index + 1 > (int)count || *index < 0) {
    102                 return EINVAL;
    103         }
    104         return EOK;
     79        free(pcap_svcs);
     80        return 1;
    10581}
    10682
    107 /**
    108  *
    109  */
    110 errno_t pcapctl_list(void)
    111 {
     83extern errno_t pcapctl_list(void) {
     84
    11285        errno_t rc;
    11386        category_id_t pcap_cat;
     
    128101        }
    129102
    130         fprintf(stdout, "Devices:\n");
     103        fprintf(stdout, "Services:\n");
    131104        for (unsigned i = 0; i < count; ++i) {
    132105                char *name = NULL;
    133106                loc_service_get_name(pcap_svcs[i], &name);
    134                 fprintf(stdout, "%d. %s\n", i, name);
     107                fprintf(stdout, "service: %s\n", name);
    135108        }
    136109        free(pcap_svcs);
     
    138111}
    139112
    140 /**
    141  *
    142  */
    143 errno_t pcapctl_dump_open(int *index, pcapctl_sess_t **rsess)
     113
     114errno_t pcapctl_dump_open(const char *svcname, pcapctl_sess_t **rsess)
    144115{
    145116        errno_t rc;
     
    149120                return ENOMEM;
    150121
    151         rc  = pcapctl_cat_get_svc(index, &svc);
     122        rc  = pcapctl_cat_get_svc(svcname, &svc);
    152123        if (rc != EOK) {
    153                 printf("Error finding the device with index: %d\n", *index);
    154124                goto error;
    155125        }
    156 
    157126        async_sess_t *new_session = loc_service_connect(svc, INTERFACE_PCAP_CONTROL, 0);
    158127        if (new_session == NULL) {
     
    161130                goto error;
    162131        }
     132
    163133        sess->sess = new_session;
    164134        *rsess = sess;
     
    169139}
    170140
    171 /**
    172  *
    173  */
    174141errno_t pcapctl_dump_close(pcapctl_sess_t *sess)
    175142{
Note: See TracChangeset for help on using the changeset viewer.