Use a linked list to simulate 3 TCP/IP packest. Each packet should have source I
ID: 3836324 • Letter: U
Question
Use a linked list to simulate 3 TCP/IP packest. Each packet should have source IP, destination IP, and data (20 characters).
Search each packet for suspicious IP that starts with 000. Also check data for cypher, subtract 1 from ASCII of first 8 to see if "JOHN JAY" is the data. Your program should simulate processing six packest in 2 groups of 3. Check 3 packets (nodes) then change IP and data in each and check again. Use a QUEUE for this instead of a LINKED LIST. But the QUEUE must have the same data.
Please make sure this works and Ill definetly give you a thumbs up. Thank you in advance
Explanation / Answer
#include <iostream>
#include <queue>
#include<stdbool.h>
using namespace std;
struct node
{
string source;
string destination;
string dat;
};
node* newNode(string s,string d,string data)
{
node* newnode= new node();
newnode->source = s;
newnode->destination = d;
newnode->dat = data;
return newnode;
}
int main()
{
queue<node*> q;
int i=0;
string s,d,data;
bool flag = true;
string suspicious = "000";
while(flag)
{
while(i<3)
{
cout << "Enter source IP , destination IP and data" << endl;
//cin.ignore();
getline(cin, s, ' ');
getline(cin, d, ' ');
getline(cin, data, ' ');
//cin >> s >> d >> data;
struct node *n = newNode(s,d,data);
q.push(n);
i++;
}
int j=0;
while(j<i && !q.empty())
{
node *front = q.front();
q.pop();
if(suspicious.compare(front->source) == 0)
cout << "This is suspicious IP from source at packet " << i+1 << endl;
if(suspicious.compare(front->destination) == 0)
cout << "This is suspicious IP from destination" << i+1 <<endl;
cout << front->source << " " << front->destination <<" " << front->dat <<endl;
j++;
}
cout << "want to enter next three packet then please enter Y or y"<< endl;
char ch;
cin >> ch ;
if(ch == 'y' || ch == 'Y')
flag = true;
else
flag = false;
}
return 0;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.