OpenCores
URL https://opencores.org/ocsvn/1g_ethernet_dpi/1g_ethernet_dpi/trunk

Subversion Repositories 1g_ethernet_dpi

[/] [1g_ethernet_dpi/] [tags/] [v0.0/] [sw/] [app/] [src/] [ethlc.cpp] - Blame information for rev 3

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 3 kuzmi4
#include "ethlc.hpp"
2
 
3
/**
4
 * @brief   private: Execute Generic Shell Command
5
 *
6
 * @param[in]   command Command to execute.
7
 * @param[out]  output  Shell output.
8
 * @param[in]   mode read/write access
9
 *
10
 * @return 0 for success, 1 otherwise.
11
 *
12
*/
13
bool ethlc::exec_shell_cmd( const std::string&  command,
14
                            std::string&        output,
15
                            const std::string&  mode = "r")
16
{
17
    // Create the stringstream
18
    std::stringstream sout;
19
    // Run Popen
20
    FILE *in;
21
    char buff[512];
22
    // Test output
23
    if(!(in = popen(command.c_str(), mode.c_str()))){
24
        return 1;
25
    }
26
    // Parse output
27
    while(fgets(buff, sizeof(buff), in)!=NULL){
28
        sout << buff;
29
    }
30
    // Close
31
    int exit_code = pclose(in);
32
    // set output
33
    output = sout.str();
34
    // Return exit code
35
    return exit_code;
36
}
37
 
38
 
39
 
40
/**
41
 * @brief   public: Open-dev
42
 *
43
 * @param[in] address   dev IPv4-addr
44
 *
45
 * @return 0 for success, 1 otherwise.
46
 *
47
*/
48
bool ethlc::ethlc_open(const std::string& paddress)
49
{
50
    // 1st: record addr
51
    address = paddress.c_str();
52
    // 2nd: ARPING it
53
    std::string command = "arping -c 1 " + address + " -I tap0"+ " 2>&1"; // !!!redirecting stderr to stdout
54
    int code = exec_shell_cmd(command, details);
55
    return (code == 0);
56
}
57
 
58
/**
59
 * @brief   public: Work with dev
60
 *
61
 * @return 0 for success, 1 otherwise.
62
 *
63
*/
64
bool ethlc::ethlc_proc(void)
65
{
66
    // 1st: PING it
67
    std::string command = "ping -c 1 " + address + " 2>&1"; // !!!redirecting stderr to stdout
68
    int code = exec_shell_cmd(command, details);
69
    return (code == 0);
70
}
71
 
72
/**
73
 * @brief   public: Close-dev
74
 *
75
 * @return 0 for success, 1 otherwise.
76
 *
77
*/
78
bool ethlc::ethlc_close(void)
79
{
80
    // 1st: ARPING it
81
    std::string command = "arping -c 1 " + address + " -I tap0"+ " 2>&1"; // !!!redirecting stderr to stdout
82
    int code = exec_shell_cmd(command, details);
83
    return (code == 0);
84
    //return true;
85
}
86
 
87
/**
88
 * @brief   public: Out2usr detailes of shell output
89
 *
90
 * @param[out]  output  Shell output.
91
 *
92
*/
93
void ethlc::ethlc_gdet(std::string& pdetails)
94
{
95
    pdetails = details;
96
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.