-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added doxygen code documentation, Updated Markdown README with
build information, API data and its use. gtest has been updated with more test cases for IPv4 and IPv6.
- Loading branch information
1 parent
8abb5d1
commit a15d867
Showing
8 changed files
with
296 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,46 @@ | ||
# miniIPutils | ||
# miniIPutils <img src="images/ip_address.png" width="30"> | ||
|
||
Ip Utility tools wrapper read, process and manipulate Ethernet interfaces. | ||
[![Build Status](https://travis-ci.com/arunkumar-mourougappane/miniIPutils.svg?branch=master)](https://travis-ci.com/arunkumar-mourougappane/miniIPutils) | ||
|
||
An advanced self managing IP Address Utility tool capable of managing both managing IPv4 and IPv6 Address. | ||
|
||
[CIPAddress](https://github.com/arunkumar-mourougappane/miniIPutils/blob/master/src/lib/ip_address/ip_address.cpp "Source Code for CIPAddress API") | ||
|
||
CIPAddress wrapper library can process any IP address format from one among the following: | ||
|
||
- std::string | ||
- const char* | ||
- struct in_addr_t | ||
- struct in_addr | ||
- struct in6_addr | ||
- struct sockaddr_storage | ||
|
||
**APIs:** | ||
|
||
- GetIPFamily() returns the IP Address family. | ||
- IsValidIP() returns if IP is valid or not. | ||
- GetString() returns a string for the IP Address. | ||
- GetIPAddressBytes() returns a sockaddr_storage structure. | ||
- GetIPAddress(struct in_addr & byteAddress ) returns 0 on success with valid IPv4 address populated to byte address. | ||
- GetIPAddress(struct in6_addr & byteAddress ) returns 0 on success with valid IPv6 address populated to byte address. | ||
- Compare(const CIPAddress& IpAddress) compare a CIPAddress instance with current insance. | ||
- to_string() provides a string representation of a class. | ||
|
||
**Example of Use:** | ||
|
||
Here are some examples of the use for CIPAddress class implementation. | ||
|
||
```cpp | ||
#include <CIPAddress.h> | ||
|
||
CIPAddress obj("127.0.01"); | ||
// Checking for validty | ||
if (obj) // Also obj.IsValidIP() can be use to check validity. | ||
{ | ||
std::cout << "Valid IP Address"; | ||
} | ||
// to print ip Address string or send it to stream | ||
stream_obj << obj; | ||
// to get string value; | ||
std::cout << obj.GetString(); | ||
``` |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,38 @@ | ||
#include <gtest_ip_address.h> | ||
#include <ip_address.h> | ||
|
||
TEST_F(TestCIPAddress, CheckifValidIPIsAccepted) | ||
TEST_F(TestCIPAddress, CheckifValidIPv4IsAccepted) | ||
{ | ||
mini_ip_utilities::CIPAddress ipAddressObj(ipAddressString); | ||
EXPECT_EQ(true, ipAddressObj.IsValidIP()) << "Failed to accept valid IP Addres argument, IsValidIP() returned false."; | ||
EXPECT_EQ(std::string("127.0.0.1"), ipAddressObj.GetString()) << "Failed to accept valid IP Addres argument, ipAddr.GetString() returned empty string."; | ||
EXPECT_EQ(AF_INET, ipAddressObj.GetIPFamily()) << "Failed to accept valid IP Addres argument, ipAddr.GetIPFamily() returned AF_UNSPEC"; | ||
} | ||
mini_ip_utilities::CIPAddress ipAddressObj(ipv4AddressString); | ||
ASSERT_EQ(true, ipAddressObj.IsValidIP()) << "Failed to accept valid IP Address argument, IsValidIP() returned false."; | ||
EXPECT_EQ(std::string("127.0.0.1"), ipAddressObj.GetString()) << "Failed to accept valid IPv4 Address argument, ipAddr.GetString() returned empty string."; | ||
EXPECT_EQ(AF_INET, ipAddressObj.GetIPFamily()) << "Failed to accept valid IPv4 Address argument, ipAddr.GetIPFamily() returned AF_UNSPEC"; | ||
EXPECT_TRUE(ipAddressObj) << "Failed to overload bool operator valid IPv4 Address argument,it returned false."; | ||
} | ||
|
||
TEST_F(TestCIPAddress, CheckifInvalidIPv4IsAccepted) | ||
{ | ||
mini_ip_utilities::CIPAddress ipAddressObj(invalidIPv4AddressString); | ||
ASSERT_EQ(false, ipAddressObj.IsValidIP()) << "Failed to accept invalid IPv4 Address argument, IsValidIP() returned true."; | ||
EXPECT_EQ(std::string(""), ipAddressObj.GetString()) << "Failed to accept invalid IPv4 Addres argument, ipAddr.GetString() returned a string."; | ||
EXPECT_EQ(AF_UNSPEC, ipAddressObj.GetIPFamily()) << "Failed to accept valid IPv4 Address argument, ipAddr.GetIPFamily() returned AF_INET"; | ||
EXPECT_FALSE(ipAddressObj) << "Failed to overload bool operator invalid IPv4 Address argument, it returned false."; | ||
} | ||
|
||
TEST_F(TestCIPAddress, CheckifValidIPv6IsAccepted) | ||
{ | ||
mini_ip_utilities::CIPAddress ipAddressObj(ipv6AddressString); | ||
ASSERT_EQ(true, ipAddressObj.IsValidIP()) << "Failed to accept valid IPv6 Address argument, IsValidIP() returned false."; | ||
EXPECT_EQ(ipv6AddressString, ipAddressObj.GetString()) << "Failed to accept valid IPv6 Address argument, ipAddr.GetString() returned empty string."; | ||
EXPECT_EQ(AF_INET6, ipAddressObj.GetIPFamily()) << "Failed to accept valid IPv6 Address argument, ipAddr.GetIPFamily() returned AF_UNSPEC or AF_INET"; | ||
EXPECT_TRUE(ipAddressObj) << "Failed to overload bool operator valid IPv6 Address argument,it returned false."; | ||
} | ||
|
||
TEST_F(TestCIPAddress, CheckifInvalidIPv6IsAccepted) | ||
{ | ||
mini_ip_utilities::CIPAddress ipAddressObj(invalidIPv6AddressString); | ||
ASSERT_EQ(false, ipAddressObj.IsValidIP()) << "Failed to accept invalid IPv6 Address argument, IsValidIP() returned true."; | ||
EXPECT_EQ(std::string(""), ipAddressObj.GetString()) << "Failed to accept invalid IPv6 Address argument, ipAddr.GetString() returned a string."; | ||
EXPECT_EQ(AF_UNSPEC, ipAddressObj.GetIPFamily()) << "Failed to accept valid IPv6 Address argument, ipAddr.GetIPFamily() returned AF_INET6 or AF_INET"; | ||
EXPECT_FALSE(ipAddressObj) << "Failed to overload bool operator invalid IPv6 Address argument, it returned false."; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.