-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
94 lines (80 loc) · 1.97 KB
/
main.cpp
File metadata and controls
94 lines (80 loc) · 1.97 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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#include <iostream>
#include <fstream>
#include <string.h>
#include <sys/socket.h>
#include <sys/types.h>
#include <arpa/inet.h>
#include <unistd.h>
#include <netdb.h>
#include "AppLayer.h"
#include "LinkLayer.h"
using namespace std;
const string DEFAULT_IP = "127.0.0.1";
int main (int argc, char** argv){
ifstream myReader;
char* fileName = argv[1];
myReader.open(fileName);
cout << "The file name is " << fileName << endl;
string line = "";
string fileInfo[128];
int count = 0;
while(getline(myReader,line)) {
char *pch;
char *linecopy = new char[line.length() + 1];
strcpy(linecopy,line.c_str());
pch = strtok(linecopy, ": ");
while(pch != NULL) {
string str = pch;
fileInfo[count] = str;
// cout << pch << endl;
pch = strtok(NULL, " : ");
cout << "The string info " << count << " is " << fileInfo[count] << endl;
count++;
}
}
if(fileInfo[0].compare("localhost") == 0){
fileInfo[0] = DEFAULT_IP;
}
vector<itf_info> nodeItfs;
for(int i = 2; i < count;){
if(fileInfo[i].compare("localhost") == 0){
fileInfo[i] = DEFAULT_IP;
}
itf_info newItf;
phy_info newPhy;
newPhy.ipAddr = const_cast<char* >(fileInfo[i].c_str());
i++;
newPhy.port = const_cast<char* >(fileInfo[i].c_str());
i++;
newItf.rmtPhy = newPhy;
newItf.locAddr = const_cast<char* >(fileInfo[i].c_str());
i++;
newItf.rmtAddr = const_cast<char* >(fileInfo[i].c_str());
i++;
nodeItfs.push_back(newItf);
}
phy_info myPhyInfo;
myPhyInfo.ipAddr = const_cast<char* >(fileInfo[0].c_str());
myPhyInfo.port = const_cast<char* >(fileInfo[1].c_str());
LinkLayer nodeLink(myPhyInfo, nodeItfs);
string input = "";
AppLayer myApp;
while(1){
cin >> input;
myApp.runningApp(input);
}
return 0;
}
/*
IPLayer createIPLayer(string config) {
char *pch;
char *linecopy = new char[config.length() + 1];
strcpy(linecopy, config.c_str());
pch = strtok(linecopy, ": ");
while(pch != NULL) {
newPS.ip = inet_addr(pch);
pch = strtok(NULL, " : ");
}
return 0;
}
*/