\r\n

51Degrees Device Detection C/C++  4.2Newer Version 4.4

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

ip.h

1 /* *********************************************************************
2  * This Original Work is copyright of 51 Degrees Mobile Experts Limited.
3  * Copyright 2019 51 Degrees Mobile Experts Limited, 5 Charlotte Close,
4  * Caversham, Reading, Berkshire, United Kingdom RG4 7BY.
5  *
6  * This Original Work is licensed under the European Union Public Licence (EUPL)
7  * v.1.2 and is subject to its terms as set out below.
8  *
9  * If a copy of the EUPL was not distributed with this file, You can obtain
10  * one at https://opensource.org/licenses/EUPL-1.2.
11  *
12  * The 'Compatible Licences' set out in the Appendix to the EUPL (as may be
13  * amended by the European Commission) shall be deemed incompatible for
14  * the purposes of the Work and the provisions of the compatibility
15  * clause in Article 5 of the EUPL shall not apply.
16  *
17  * If using the Work as, or as part of, a network application, by
18  * including the attribution notice(s) required under Article 5 of the EUPL
19  * in the end user terms of the application under an appropriate heading,
20  * such notice(s) shall fulfill the requirements of that article.
21  * ********************************************************************* */
22 
23 #ifndef FIFTYONE_DEGREES_IP_H_INCLUDED
24 #define FIFTYONE_DEGREES_IP_H_INCLUDED
25 
40 #include <stdint.h>
41 #include <stdbool.h>
42 #include <stdlib.h>
43 #include "data.h"
44 
45 #ifdef __cplusplus
46 #define EXTERNAL extern "C"
47 #else
48 #define EXTERNAL
49 #endif
50 
54 #define FIFTYONE_DEGREES_IPV4_LENGTH 4
55 
59 #define FIFTYONE_DEGREES_IPV6_LENGTH 16
60 
64 typedef enum e_fiftyone_degrees_evidence_ip_type {
69 
71 typedef struct fiftyone_degrees_evidence_ip_address
80 typedef struct fiftyone_degrees_evidence_ip_address {
82  byte *address;
83  byte *current;
86  byte bytesPresent;
88  // const char *originalStart; // The first character for the IP address
89  // const char *originalEnd; // The last character for the IP addresses
91 
98 EXTERNAL void fiftyoneDegreesIpFreeAddresses(
99  void(*free)(void*),
101 
110  void*(*malloc)(size_t),
111  const char *start,
112  const char *end);
113 
121  void*(*malloc)(size_t),
122  const char *start);
123 
137  const unsigned char *ipAddress1,
138  const unsigned char *ipAddress2,
140 
145 #endif
An IPv4 address.
Definition: ip.h:65
IP address structure containing the bytes of a v4 or v6 IP address.
Definition: ip.h:80
Invalid IP address.
Definition: ip.h:67
fiftyoneDegreesEvidenceIpAddress * fiftyoneDegreesIpParseAddress(void *(*malloc)(size_t), const char *start, const char *end)
Parse a single IP address string.
int fiftyoneDegreesCompareIpAddresses(const unsigned char *ipAddress1, const unsigned char *ipAddress2, fiftyoneDegreesEvidenceIpType type)
Compare two IP addresses in its binary form.
fiftyoneDegreesEvidenceIpType type
The type of address (v4 or v6)
Definition: ip.h:81
fiftyoneDegreesEvidenceIpAddress * next
Next address in the list or NULL.
Definition: ip.h:84
fiftyoneDegreesEvidenceIpType
Enum indicating the type of IP address.
Definition: ip.h:64
void fiftyoneDegreesIpFreeAddresses(void(*free)(void *), fiftyoneDegreesEvidenceIpAddress *addresses)
Free a linked list of IP addresses.
An IPv6 address.
Definition: ip.h:66
fiftyoneDegreesEvidenceIpAddress * fiftyoneDegreesIpParseAddresses(void *(*malloc)(size_t), const char *start)
Parse a list of IP addresses and return as a linked list.
byte * current
When building the address the next byte to update.
Definition: ip.h:83
byte * address
The first byte of the address.
Definition: ip.h:82
byte bytesPresent
Number of bytes in the original string which are not abbreviated.
Definition: ip.h:86