I have to read the status of the ethernet interface in embedded linux using C++
I attempt to open and read the file /sys/class/net/eth0/operstate
, but i observed that fail() member function always returns true and the errno is permission denied.
My application permission indicator is 755, i also tried set it 777, but the error is still there.
Below is my code:
int main(int argc, char* argv[])
{
std::string word, filename;
std::fstream ethfile;
ethfile.open("/sys/class/net/eth0/operstate");
if (ethfile.fail())
{
std::cout << "Error: " << strerror(errno) << '\n';
return -1;
}
ethfile>>word;
std::cout<<"word is"<<word<<std::endl;
return 0;
}
EDIT: Additional info: this is yocto on beaglebone.