Skip to content

Commit

Permalink
Added isgreater_ipv4 and isless_ipv4
Browse files Browse the repository at this point in the history
  • Loading branch information
jacopodl committed Jul 12, 2017
1 parent 5eb9901 commit b6763fb
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 2 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ cmake_minimum_required(VERSION 2.8)
project(LibSpark)

set (VERSION_MAJOR 2)
set(VERSION_MINOR 3)
set(VERSION_MINOR 4)
set(VERSION_PATCH 0)

set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} --std=gnu11 --pedantic -DUSE_DEPRECATED")
Expand Down
2 changes: 1 addition & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
.. image:: https://img.shields.io/badge/license-MIT-blue.svg
:alt: MIT License

.. image:: https://img.shields.io/badge/version-2.2.0-green.svg
.. image:: https://img.shields.io/badge/version-2.4.0-green.svg

.. image:: https://travis-ci.org/jacopodl/Spark.svg?branch=master

Expand Down
16 changes: 16 additions & 0 deletions include/ipv4.h
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,22 @@ bool isbcast2_ipv4(struct netaddr_ip *ip, struct netaddr_ip *netmask);
*/
bool isempty_ipv4(struct netaddr_ip *ip);

/**
* @brief Checks if ip1 is greater than ip2.
* @param ip1 Pointer to netaddr_ip structure contains ip address.
* @param ip2 Pointer to netaddr_ip structure contains ip address.
* @return Function returns true if ip1 is greater than ip2, false otherwise.
*/
bool isgreater_ipv4(struct netaddr_ip *ip1, struct netaddr_ip *ip2);

/**
* @brief Checks if ip1 is less than ip2.
* @param ip1 Pointer to netaddr_ip structure contains ip address.
* @param ip2 Pointer to netaddr_ip structure contains ip address.
* @return Function returns true if ip1 is less than ip2, false otherwise.
*/
bool isless_ipv4(struct netaddr_ip *ip1, struct netaddr_ip *ip2);

/**
* @brief Checks if is a multicast(class D) IPv4 address.
* @param ip Pointer to netaddr_ip structure contains ip address.
Expand Down
14 changes: 14 additions & 0 deletions src/ipv4.c
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,20 @@ inline bool isempty_ipv4(struct netaddr_ip *ip) {
return ip->ip == 0x00;
}

bool isgreater_ipv4(struct netaddr_ip *ip1, struct netaddr_ip *ip2) {
return ((ip1->ip & 0xFF) << 24 | (ip1->ip >> 8 & 0xFF) << 16 | (ip1->ip >> 16 & 0xFF) << 8 |
(ip1->ip >> 24 & 0xFF)) >
((ip2->ip & 0xFF) << 24 | (ip2->ip >> 8 & 0xFF) << 16 | (ip2->ip >> 16 & 0xFF) << 8 |
(ip2->ip >> 24 & 0xFF));
}

bool isless_ipv4(struct netaddr_ip *ip1, struct netaddr_ip *ip2) {
return ((ip1->ip & 0xFF) << 24 | (ip1->ip >> 8 & 0xFF) << 16 | (ip1->ip >> 16 & 0xFF) << 8 |
(ip1->ip >> 24 & 0xFF)) <
((ip2->ip & 0xFF) << 24 | (ip2->ip >> 8 & 0xFF) << 16 | (ip2->ip >> 16 & 0xFF) << 8 |
(ip2->ip >> 24 & 0xFF));
}

inline bool ismcast_ipv4(struct netaddr_ip *ip) {
unsigned char fbyte = *(((unsigned char *) (&ip->ip)));
return ((fbyte >= 0xE0) && (fbyte <= 0xEF));
Expand Down

0 comments on commit b6763fb

Please sign in to comment.