\r\n

51Degrees Device Detection C/C++  4.5

A device detection library that is used natively or by 51Degrees products

Detailed Description

Types and methods to parse IP address strings.

Introduction

IP v4 and v6 addresses can be parsed using the fiftyoneDegreesIpAddressParse and #fiftyoneDegreesIpAddressesParse methods.

Collaboration diagram for IP:

Structs

struct  fiftyoneDegreesIpAddress
The structure to hold a IP Address in byte array format. More...

Macros

#define  FIFTYONE_DEGREES_IPV4_LENGTH   4
The number of bytes in an Ipv4 Address.
#define  FIFTYONE_DEGREES_IPV6_LENGTH   16
The number of bytes in an Ipv6 Address.

Enumerations

Functions

bool  fiftyoneDegreesIpAddressParse (const char *start, const char *end, fiftyoneDegreesIpAddress *address)
Parse a single IP address string. More...
int  fiftyoneDegreesIpAddressesCompare (const unsigned char *ipAddress1, const unsigned char *ipAddress2, fiftyoneDegreesIpType type)
Compare two IP addresses in its binary form. More...

Enumeration Type Documentation

◆ fiftyoneDegreesIpType

Enum indicating the type of IP address.

Enumerator

FIFTYONE_DEGREES_IP_TYPE_INVALID 

Invalid IP address.

FIFTYONE_DEGREES_IP_TYPE_IPV4 

An IPv4 address.

FIFTYONE_DEGREES_IP_TYPE_IPV6 

An IPv6 address.

Function Documentation

◆ fiftyoneDegreesIpAddressesCompare()

int fiftyoneDegreesIpAddressesCompare ( const unsigned char *   ipAddress1,
const unsigned char *   ipAddress2,
fiftyoneDegreesIpType   type  
)

Compare two IP addresses in its binary form.

Parameters
ipAddress1 - the first IP address
ipAddress2 - the second IP address
type - the type of IP address. This determine the number of bytes to compare. IPv4 require 4 bytes and IPv6 require 16 bytes
Returns
a value indicate the result: 0 for equals

0 for ipAddress1 comes after ipAddress2

< 0 for ipAddress1 comes before ipAddress2

◆ fiftyoneDegreesIpAddressParse()

bool fiftyoneDegreesIpAddressParse ( const char *   start,
const char *   end,
fiftyoneDegreesIpAddress *   address  
)

Parse a single IP address string.

Does not modify the last 12 (out of 16) bytes when parsing IPv4.

Parameters
start - of the string containing the IP address to parse
end - the last character of the string (with IP address) to be considered for parsing
address - memory to write parsed IP address into.
Returns
true if address was parsed correctly, false otherwise