Question: -Please I need help to pass the cource: Write a ( simple ) program c or c++ or java to simulate processing of a packet
-Please I need help to pass the cource:
Write a (simple) program c or c++ or java to simulate processing of a packet at a router interface with an ACL
bound to that interface. Given an ACL (standard ) bound to a router interface, your
program should accept as input a packet with a source IP address, destination IP address, source, check the ACL permit and deny statements in sequence and determine if the packet gets discarded or forwarded.
------------------------------------------------------------------------------------------------------
In order to do this, your program should read two text files:
File no. 1 contains the ACL (for example):
access-list 1 deny 172.16.4.13 0.0.0.0
access-list 1 deny 172.16.5.0 0.0.0.255
access-list 1 permit 172.16.3.0 0.0.0.255
File no.2 contains a list of packets (just source and destination addresses)
172.16.4.13 172.16.3.2
172.16.5.2 172.16.3.4
etc.
Your output should be something like this:
172.16.4.13 172.16.3.2 denied
172.16.5.2 172.16.3.4 denied
etc. etc. permitted
--------------------------------------------------------------------
I try to write the program in c++ but it does not work correctly please help me:
#include
#include
#include
int main(void)
{
unsigned int S1,S2,S3,S4,D1,D2,D3,D4,SIP1,SIP2,SIP3,SIP4,Smask1,Smask2,Smask3,Smask4;
char Interface[3],Listname[20],Commond[6];
FILE *fin=fopen("packets.txt","r");
while(fscanf(fin,"%u.%u.%u.%u %u.%u.%u.%u ", &S1, &S2, &S3, &S4, &D1, &D2, &D3, &D4)!=EOF)
{
FILE *fin1=fopen("acl.txt","r");
printf(" ");
while(fscanf(fin1, "%s %s %s %d.%d.%d.%d %d.%d.%d.%d %s ", Listname, Commond, &SIP1, &SIP2, &SIP3, &SIP4, &Smask1, &Smask2, &Smask3, &Smask4,Interface)!=EOF)
{
if(S1==SIP1 && S2==SIP2 && S3==SIP3 && S4==SIP4)
{
if(strcmp(Commond,"deny")==0)
std::cout< else std::cout< } } } return 0;} packet file: 172.16.20.163 172.16.70.5 172.16.0.0 172.16.10.0 172.16.80.0 172.16.10.0 172.16.50.75 172.16.70.2 172.16.0.0 172.16.40.89 acl file: Access-list1 deny 172.16.20.163 0.0.0.0 E0 Access-list1 permit 172.16.0.0 0.0.255.255 E0 Access-list2 deny 172.16.80.0 0.0.0.255 E1 Access-list2 permit 172.16.0.0 0.0.255.255 E1 Access-list3 deny 172.16.50.75 0.0.0.0 E0 Access-list3 deny 172.16.50.7 0.0.0.0 E0 Access-list3 permit 172.16.0.0 0.0.255.255 E0
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
