51Degrees Common C/C++  4.1

A shared functionality library that is used by 51Degrees products

ip.h

1 /* *********************************************************************
2  * This Source Code Form 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 Source Code Form is subject to the terms of the Mozilla Public
7  * License, v. 2.0.
8  *
9  * If a copy of the MPL was not distributed with this file, You can obtain
10  * one at http://mozilla.org/MPL/2.0/.
11  *
12  * This Source Code Form is "Incompatible With Secondary Licenses", as
13  * defined by the Mozilla Public License, v. 2.0.
14  * ******************************************************************** */
15 
16 #ifndef FIFTYONE_DEGREES_IP_H_INCLUDED
17 #define FIFTYONE_DEGREES_IP_H_INCLUDED
18 
33 #include <stdint.h>
34 #include <stdbool.h>
35 #include <stdlib.h>
36 #include "data.h"
37 
38 #ifdef __cplusplus
39 #define EXTERNAL extern "C"
40 #else
41 #define EXTERNAL
42 #endif
43 
47 typedef enum e_fiftyone_degrees_evidence_ip_type {
52 
54 typedef struct fiftyone_degrees_evidence_ip_address
63 typedef struct fiftyone_degrees_evidence_ip_address {
65  byte *address;
66  byte *current;
69  byte bytesPresent;
71  // const char *originalStart; // The first character for the IP address
72  // const char *originalEnd; // The last character for the IP addresses
74 
81 EXTERNAL void fiftyoneDegreesIpFreeAddresses(
82  void(*free)(void*),
84 
93  void*(*malloc)(size_t),
94  const char *start,
95  const char *end);
96 
104  void*(*malloc)(size_t),
105  const char *start);
106 
111 #endif
An IPv4 address.
Definition: ip.h:48
IP address structure containing the bytes of a v4 or v6 IP address.
Definition: ip.h:63
EXTERNAL fiftyoneDegreesEvidenceIpAddress * fiftyoneDegreesIpParseAddress(void *(*malloc)(size_t), const char *start, const char *end)
Parse a single IP address string.
Definition: ip.c:158
Invalid IP address.
Definition: ip.h:50
EXTERNAL void fiftyoneDegreesIpFreeAddresses(void(*free)(void *), fiftyoneDegreesEvidenceIpAddress *addresses)
Free a linked list of IP addresses.
Definition: ip.c:146
fiftyoneDegreesEvidenceIpType type
The type of address (v4 or v6)
Definition: ip.h:64
fiftyoneDegreesEvidenceIpAddress * next
Next address in the list or NULL.
Definition: ip.h:67
fiftyoneDegreesEvidenceIpType
Enum indicating the type of IP address.
Definition: ip.h:47
An IPv6 address.
Definition: ip.h:49
EXTERNAL fiftyoneDegreesEvidenceIpAddress * fiftyoneDegreesIpParseAddresses(void *(*malloc)(size_t), const char *start)
Parse a list of IP addresses and return as a linked list.
Definition: ip.c:192
byte * current
When building the address the next byte to update.
Definition: ip.h:66
byte * address
The first byte of the address.
Definition: ip.h:65
byte bytesPresent
Number of bytes in the original string which are not abbreviated.
Definition: ip.h:69