Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extend sharkd to load data from URLs #3

Closed
lmangani opened this issue Jun 2, 2019 · 3 comments
Closed

Extend sharkd to load data from URLs #3

lmangani opened this issue Jun 2, 2019 · 3 comments
Assignees
Labels
enhancement New feature or request help wanted Extra attention is needed

Comments

@lmangani
Copy link
Member

lmangani commented Jun 2, 2019

Currently sharkd only supports loading from files it can directly access through function sharkd_session_process_load in turn calling load_cap_file

In order to support a broader scope of scenarios, it should be extended to support loading data from web APIs, ad-hoc interfaces and/or through piping other system commands.

This issue is just an intention pointer to track design elements and input from other devs.

@lmangani lmangani added enhancement New feature or request help wanted Extra attention is needed labels Jun 2, 2019
@lmangani
Copy link
Member Author

lmangani commented Nov 22, 2020

rebooting attempt!

A potential lightweight route could be adding URL path detection (^http.*) in filenames passed to the cf_open function by the application, and using a sidekick curl function to fetch the file before passing it to the load_cap_file function again.

#include <stdio.h>
#include <curl/curl.h>
#include <curl/types.h>
#include <curl/easy.h>
#include <string>

size_t write_data(void *ptr, size_t size, size_t nmemb, FILE *stream) {
    size_t written = fwrite(ptr, size, nmemb, stream);
    return written;
}

int main(void) {
    CURL *curl;
    FILE *fp;
    CURLcode res;
    char *url = "http://localhost/some.pcap";
    char outfilename[FILENAME_MAX] = "/capture/some.pcap";
    curl = curl_easy_init();
    if (curl) {
        fp = fopen(outfilename,"wb");
        curl_easy_setopt(curl, CURLOPT_URL, "http://localhost/some.pcap");
        curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_data);
        curl_easy_setopt(curl, CURLOPT_WRITEDATA, fp);
        res = curl_easy_perform(curl);
        /* always cleanup */
        curl_easy_cleanup(curl);
        fclose(fp);
    }
    return 0;
}

@lmangani lmangani changed the title Extend sharkd to load data from APIs Extend sharkd to load data from URLs Nov 22, 2020
@kYroL01 kYroL01 self-assigned this Nov 23, 2020
@kYroL01
Copy link
Collaborator

kYroL01 commented Nov 24, 2020

This is the standalone test to be converted in a function and called to the correct position in sharkd
https://gist.github.com/kYroL01/b92fa0d7664b92a17575227239c17076

./curl_pcap "http://www.example/file.pcap" -> download the pcap

@lmangani
Copy link
Member Author

Completed in JS for now to simplify the asynchronous aspect. Thanks @kYroL01 feel free to think about this long range :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants