Changeset e4cc266 in mainline


Ignore:
Timestamp:
2024-03-10T11:40:30Z (10 months ago)
Author:
Nataliia Korop <n.corop08@…>
Children:
34aad53d, 78edb5e
Parents:
e846bec
Message:

ugly address

Location:
uspace
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • uspace/app/pcapctl/main.c

    re846bec re4cc266  
    4141#define NAME "pcapctl"
    4242
    43 pcapctl_sess_t sess;
     43pcapctl_sess_t* sess;
    4444
    45 static errno_t start_dumping(const char *drv_name, const char *name)
     45static errno_t start_dumping(const char *svc_name, const char *name)
    4646{
    47         errno_t rc = pcapctl_dump_init(&sess, drv_name);
     47        errno_t rc = pcapctl_dump_open(svc_name, &sess);
    4848        if (rc != EOK) {
    49                 //fprintf(stderr, "Error initializing ...\n");
    5049                return 1;
    5150        }
    52         pcapctl_dump_start(name, &sess);
     51        pcapctl_dump_start(name, sess);
     52        pcapctl_dump_close(sess);
    5353        return EOK;
    5454}
    5555
    5656/** Session might */
    57 static errno_t stop_dumping(const char *drv_name)
     57static errno_t stop_dumping(const char *svc_name)
    5858{
    59         errno_t rc = pcapctl_dump_init(&sess, drv_name);
     59        errno_t rc = pcapctl_dump_open(svc_name, &sess);
    6060        if (rc != EOK) {
    61                 fprintf(stderr, "Error initializing ...\n");
    6261                return 1;
    6362        }
    64         pcapctl_dump_stop(&sess);
     63
     64        pcapctl_dump_stop(sess);
     65        pcapctl_dump_close(sess);
    6566        return EOK;
    6667}
     
    7374{
    7475        fprintf(stderr, "Usage:\n");
     76        fprintf(stderr, "  %s list: List of devices\n", progname);
    7577        fprintf(stderr, "  %s start <device> <outfile>: Packets dumped from <device> will be written to <outfile>\n", progname);
    7678        fprintf(stderr, "  %s stop <device>: Dumping from <device> stops\n", progname);
    77 
    7879}
    7980
  • uspace/lib/nic/include/nic_driver.h

    re846bec re4cc266  
    4646#include <nic/nic.h>
    4747#include <async.h>
     48#include <pcapdump_iface.h>
    4849
    4950#include "nic.h"
    5051#include "nic_rx_control.h"
    5152#include "nic_wol_virtues.h"
    52 #include "pcap/include/pcapdump_iface.h"
    5353
    5454struct sw_poll_info {
  • uspace/lib/nic/src/nic_driver.c

    re846bec re4cc266  
    650650
    651651        nic_data->dev = device;
     652
    652653        errno_t pcap_rc  = pcapdump_init(nic_get_pcap_iface(nic_data));
    653 
    654654        if (pcap_rc != EOK) {
    655655                printf("Failed creating pcapdump port\n");
  • uspace/lib/pcap/include/pcapctl_dump.h

    re846bec re4cc266  
    4949} pcapctl_sess_t;
    5050
    51 extern errno_t pcapctl_dump_init(pcapctl_sess_t *, const char *);
     51extern errno_t pcapctl_dump_open(const char *svcname, pcapctl_sess_t **rsess);
     52extern errno_t pcapctl_dump_close(pcapctl_sess_t *sess);
    5253extern errno_t pcapctl_dump_start(const char *, pcapctl_sess_t *);
    5354extern errno_t pcapctl_dump_stop(pcapctl_sess_t *);
    5455extern errno_t pcapctl_list(void);
     56
    5557
    5658#endif
  • uspace/lib/pcap/src/pcapctl_dump.c

    re846bec re4cc266  
    5151}
    5252
    53 static errno_t pcapctl_cat_has_drv(const char *drv_name, service_id_t* svc) {
     53static errno_t pcapctl_cat_get_svc(const char *drv_name, service_id_t* svc) {
    5454        errno_t rc;
    5555        category_id_t pcap_cat;
     
    9090        rc = loc_category_get_id("pcap", &pcap_cat, 0);
    9191        if (rc != EOK) {
    92                 printf("Error resolving category 'pcap'.\n");
     92                printf("Error resolving category pcap.\n");
    9393                return rc;
    9494        }
     
    9797        if (rc != EOK) {
    9898                printf("Error resolving list of pcap services.\n");
     99                free(pcap_svcs);
    99100                return rc;
    100101        }
    101102
    102         assert((count > 0) && "TODO: not implemented when no services are available\n");
    103 
    104         fprintf(stdout, "Drivers:\n");
     103        fprintf(stdout, "Services:\n");
    105104        for (unsigned i = 0; i < count; ++i) {
    106105                char *name = NULL;
    107106                loc_service_get_name(pcap_svcs[i], &name);
    108 
    109                 fprintf(stdout, "driver: %s\n", name);
     107                fprintf(stdout, "service: %s\n", name);
    110108        }
     109        free(pcap_svcs);
    111110        return EOK;
    112111}
    113112
    114 errno_t pcapctl_dump_init(pcapctl_sess_t *sess, const char *drv_name)
     113
     114errno_t pcapctl_dump_open(const char *svcname, pcapctl_sess_t **rsess)
    115115{
    116116        errno_t rc;
    117117        service_id_t svc;
    118         rc  = pcapctl_cat_has_drv(drv_name, &svc);
     118        pcapctl_sess_t *sess = calloc(1, sizeof(pcapctl_sess_t));
     119        if (sess == NULL)
     120                return ENOMEM;
     121
     122        rc  = pcapctl_cat_get_svc(svcname, &svc);
    119123        if (rc != EOK) {
    120                 fprintf(stderr, "No such driver was found.\n");
    121                 return 1;
     124                goto error;
    122125        }
    123126        async_sess_t *new_session = loc_service_connect(svc, INTERFACE_PCAP_CONTROL, 0);
     
    127130                goto error;
    128131        }
     132
    129133        sess->sess = new_session;
    130         rc = EOK;
     134        *rsess = sess;
     135        return EOK;
    131136error:
     137        pcapctl_dump_close(sess);
    132138        return rc;
     139}
     140
     141errno_t pcapctl_dump_close(pcapctl_sess_t *sess)
     142{
     143        free(sess);
     144        return EOK;
    133145}
    134146
Note: See TracChangeset for help on using the changeset viewer.