-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbcast.cpp
More file actions
71 lines (70 loc) · 1.53 KB
/
Copy pathbcast.cpp
File metadata and controls
71 lines (70 loc) · 1.53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#include "bcast.h"
//send data plus identifying info to host at host port
bool bcast (string line,string id,string &hostip, unsigned short destport) {
try {
string data = line + "," + id;
sock.sendTo(data.c_str(),data.size(), hostip, destport);
//cout << ":" << sock.getLocalPort() << endl;
}
catch (SocketException &e) {
cerr << endl << e.what() << endl;
return false;
}
sock.disconnect();
return true;
}
vector<string> updateip (string data) {
vector<string> v;
istringstream ss(data);
string x;
while(ss >> x) {
//cout << x << "\n";
v.push_back(x);
}
/*
cout << "v 0 " << v[0] << "\n";
cout << "v 1 " << v[1] << "\n";
cout << "v 2 " << v[2] << "\n";
*/
return v;
}
vector<unsigned short> updateport (string data) {
//cout << "\nUpdating port\n";
istringstream ss(data);
vector<unsigned short> v;
string x;
while(ss >> x) {
//cout << x << endl;
stringstream str(x);
unsigned short portshort;
str >> portshort;
//cout << portshort << "\n";
v.push_back(portshort);
}
/*
for (int i = 0; i < 3; ++i) {
cout << "V[" << i << "]: " << v[i] << "\n";
}
*/
return v;
}
void checkinternet() {
bool notworking = true;
char s[81];
sprintf(s, "ping -c 1 -s 1 %s > /dev/null", pingip.c_str());
while(notworking) {
int ping = system(s);
if (ping > 0) {
cerr << "\nNetwork misconfigured. Trying to recover...\n";
if(system("timeout 10 ifdown eth2") >= 0) {
sleep(2);
}
system("timeout 10 ifup eth2");
sleep(1);
}
else {
notworking = false;
//cout << "\nNetwork is operational\n";
}
}
}