Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Do the following in C++: Implement a Firewall class, whose interface contains two items: 1. A constructor, taking a single string argument, which is a

Do the following in C++:

Implement a Firewall class, whose interface contains two items: 1. A constructor, taking a single string argument, which is a file path to a CSV file whose contents are as described above, e.g, in Ruby, this would be Firewall.new(/path/to/fw.csv). o Note that you do not need to define a static new method simply use the constructor syntax. o Remember that you may assume that all content in the input file is valid.

2 A function, accept_packet, that takes exactly four arguments and returns a boolean: true, if there exists a rule in the file that this object was initialized with that allows traffic with these particular properties, and false otherwise. o direction (string): inbound or outbound o protocol (string): exactly one of tcp or udp, all lowercase o port (integer) an integer in the range [1, 65535] o ip_address (string):

Either (a) an IPv4 address in dotted notation, consisting of 4 octets, each an integer in the range [0, 255], separated by periods or (b) an IP range containing two IPv4 addresses, separated by a dash (no spaces). Like port ranges, IP ranges are inclusive. Given an IP range, you may assume that the range is well-formed i.e. when viewed as a number, the starting address is strictly less than the ending address.

Examples:

> fw = Firewall.new("/path/to/fw.csv") > fw.accept_packet("inbound", "tcp", 80, "192.168.1.2") # matches first rule true > fw.accept_packet("inbound", "udp", 53, "192.168.2.1") # matches third rule true > fw.accept_packet("outbound", "tcp", 10234, "192.168.10.11") # matches second rule true > fw.accept_packet("inbound", "tcp", 81, "192.168.1.2") false > fw.accept_packet("inbound", "udp", 24, "52.12.48.92") false

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Concepts Of Database Management

Authors: Joy L. Starks, Philip J. Pratt, Mary Z. Last

9th Edition

1337093424, 978-1337093422

More Books

Students also viewed these Databases questions