1 #include "daq/slc/readout/IOInfo.h"
12 int IOInfo::checkTCP(
IOInfo& info)
14 std::vector<IOInfo> info_v;
15 info_v.push_back(info);
16 int ret = checkTCP(info_v);
21 int IOInfo::checkTCP(std::vector<IOInfo>& info)
24 for (
size_t i = 0; i < info.size(); i++) {
26 info[i].setTXQueue(0);
27 info[i].setRXQueue(0);
32 std::string sl, local_address, rem_address, st, queue;
33 std::ifstream fin(
"/proc/net/tcp");
35 while (fin && getline(fin, line)) {
38 ss >> sl >> local_address >> rem_address >> st >> queue;
39 unsigned int addr = strtoul(local_address.substr(0, 8).c_str(), NULL, 16);
40 int port = strtoul(local_address.substr(9).c_str(), NULL, 16);
41 unsigned int raddr = strtoul(rem_address.substr(0, 8).c_str(), NULL, 16);
42 int rport = strtoul(rem_address.substr(9).c_str(), NULL, 16);
43 for (
size_t i = 0; i < info.size(); i++) {
44 if (info[i].getState() > 0)
continue;
45 int sti = strtoul(st.substr(0).c_str(), NULL, 16);
47 port == info[i].getLocalPort() && sti == 1) {
48 info[i].setRemoteAddress(raddr);
49 info[i].setRemotePort(rport);
50 info[i].setState(sti);
51 info[i].setTXQueue(strtoul(queue.substr(0, 8).c_str(), NULL, 16));
52 info[i].setRXQueue(strtoul(queue.substr(9).c_str(), NULL, 16));
54 }
else if (raddr == info[i].getRemoteAddress() &&
55 rport == info[i].getRemotePort() && sti == 1) {
56 info[i].setLocalAddress(addr);
57 info[i].setLocalPort(port);
58 info[i].setState(sti);
59 info[i].setTXQueue(strtoul(queue.substr(0, 8).c_str(), NULL, 16));
60 info[i].setRXQueue(strtoul(queue.substr(9).c_str(), NULL, 16));
63 if (count == info.size())
return count;
69 const char* IOInfo::getLocalIP()
const
72 addr.sin_addr.s_addr = m_local_addr;
73 return inet_ntoa(addr.sin_addr);
76 const char* IOInfo::getRemoteIP()
const
79 addr.sin_addr.s_addr = m_remote_addr;
80 return inet_ntoa(addr.sin_addr);