So guys here are some coding assignment based on what you have studied in this module
So this module the major part of this module was IP address mathematics. So here are few programming questions for you on
IP address mathematics. so prerequisite of doing this assignment is that you should be familiar with the bit-wise, AND, OR
Operations in C. And you must be familiar with the left and right shift operations in C
And of course, you must have a thorough understanding of this module in order to do this assignment
After doing all your assignments you should upload all your assignments and codes on your github account
So in the very first lecture of this course I have introduced you to the github account
If for some reason you have skipped that lecture please revisit it. It is very important to maintain
Github account nowadays to prove your competence in the job market
and
The relevance of this assignment is that it will prepare you to use bitwise manipulation to achieve network related operations
Not knowing bitwise operations in C is a great put off for interviewers. Please note that if you are appearing
For system programming jobs in the market you should be thorough with the bitwise operations
So let's go ahead
So you have to create a file called IP_maths.c and you have to write the C functions
to accomplish the following functionality
so in question 1 you have to write a function get broadcast address the input to the function is the
IP address as a string and
the mask value and
The output pointers, this is the pointer and
This is the output buffer in which you will get the result back out of this function
So you can see the usage of this function, right?
so
Declare the array then initialize the array
So this is actually your output array where the result will be stored
and
You have an IP address 192.168.2.10 and the mask value 20. So you just call this API get_broadcast _address
and the first argument is the pointer to the string which denotes the IP address 192.168.2.10
The second argument is the mask value and
the third argument is a pointer to the buffer that
Is the empty buffer in which the result will be obtained
right and
when this function
Returns you should print the broadcast address that is returned in the output buffer
So here is a test case, let's say your input is
192.168.2.10 and the mask value is 24
so the broadcast address of this IP address and the mask combination is
192.168.2.255. So this is the expected output. Similarly, you can test your function with the test case 2. Supply the input ip address and the
mask value and the expected broadcast address should be 10.1.31.255
Right and you can use link 2 for result verification
I have provided here two very good links link 1 and Link 2 if you visit this link
so this is the link 1 you can type here the IP address in A.B.C.D format or
You can also type the IP address in the integer form. So let's say
Let us take this example you type out the IP address 192.168.2.10
and just convert so it will give you the result
So this website will print the integer equivalent of this IP address, the hexadecimal representation of the same ip address
Right and the octal representation of the same IP address in the second link
Second link is even more helpful
let us say let
Us suppose you type out
192.168.0.2 and the mask value is 24 just calculate and
this website will give you the network ID, which is
192.168.0.0/24
So this is the network ID
for this IP address and mask value and the broadcast address will be
192.168.0.255 and
In this subnet the maximum number of machines that could be present is
254 so you can use these two links to
verify the output of your function for this assignment
Right
So going forward in the second question you have to write a function
Get IP integral equivalent, so this function simply returns the equivalent integer for the IP address
So for example, if your input is 192.168.0.10
then this function should return the
equivalent integer for this IP address
So you can see in the test case for this IP address, You should get integer equivalent value
Right. And in the second test case for this IP address you should get
integer equivalent value for this IP address. you can
verify this test cases using link 1
Right
Then in the third function
That in the third question you have to write a function get ABCD IP format
That is you have to return the IP address in ABCD format. So the input to the function is
the IP address which is in the unsigned form and
The and the function must return an array which is filled with the IP address in ABCD format
So you can see the usage of this function
Take the integer value. So this integer value actually represents this IP address and
Take the buffer memory. Just call this function
Pass the integer IP address as the first argument which is input and pass the empty buffer
which should be filled with the correct IP address in A.B.C.D format and
simply print the IP address that is
returned or calculated by function
right, so
Basically, it should print 122.172.178.53, right?
Then in the next question
You have to write a function in C to get the network ID and the input to the function is
the IP address and the mask value and the output
Should be and the function should return an output in the output
buffer
Right so you can see the usage of this function take the empty buffer then take the input IP address take the mask value
call the function and
The network ID should be returned in the output buffer
Just print that buffer. So this function should
compute the network ID from the IP address and mask value combination
Of course, you can use link 2 to verify your result
Then you have to write question number 5 you have to write a function
Get subnet cardinality. So to compute the cardinality of a subnet, you only need a mask value
so cardinality of the subnet means
maximum number of assignable IP addresses
right
So the usage is very simple just take the mask value 24 and
Just call the API and this API should return the cardinality of the subnet based on mask value
For example in our course, we have studied how to compute the cardinality for subnet mask value
24 and the cardinality is
254 so you can use link 2 for verification of your
result
then the last question is the question number 6 and this question you have to write a function which return an int value.
int value means if it returns zero it means true if it returns -1 then it is false
so this function actually
checks membership of an IP address in a subnet
the first argument to this function is the network ID and
The second argument to this function is the mask value so first and second argument of the function is the input
So first and second argument to the function forms the subnet ID
right and
the last argument to this function is the IP address and
This function should check the membership of this IP address
into this subnet
so it should return zero if the
IP address is a member of the subnet and it should return -1 if
This IP address is not a member of the subnet. so you can check the usage of this API
The network ID, Let's say is
192.168.0.0 the mask value is 24. So these two values put together forms a subnet
so you can compute a subnet from these two values and the test IP address is
192.168.0.13
Now call this API
Right and pause the argument. So this API should check the membership of this IP address into the subnet
Right. So result is 0 it means
that the IP address
is a member of this subnet and
If it (correction) return minus 1 it means that the IP address is not a member of the subnet
Right. So these are the six questions and you should write a C function for all of these functions and and you should test the
correctness of your functions
Using link 1 and Link two that I have provided. You should run your
functions with good enough number of test cases
So this is your coding assignment
and
of course to do this assignment to use GCC compiler and
Do this assignment Preferably on Linux only that is inside your virtual machine. I
Would suggest develop a habit to do all your assignments and development work in Linux environment only
right and
you can simply Google how to compile the C program and
Run the executable. If you are not aware with the steps. These are very simple steps. You can easily find on google
Right. So good luck with your assignment guys. Hope you will enjoy them