The friendly Operating System for the Internet of Things
ipv4/addr.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2015 Martine Lenders <mlenders@inf.fu-berlin.de>
3  *
4  * This file is subject to the terms and conditions of the GNU Lesser
5  * General Public License v2.1. See the file LICENSE in the top level
6  * directory for more details.
7  */
8 
20 #ifndef IPV4_ADDR_H
21 #define IPV4_ADDR_H
22 
23 #include <stdbool.h>
24 #include <stdint.h>
25 
26 #include "byteorder.h"
27 
28 #ifdef __cplusplus
29 extern "C" {
30 #endif
31 
35 #define IPV4_ADDR_MAX_STR_LEN (sizeof("255.255.255.255"))
36 
40 typedef union {
41  uint8_t u8[4];
43 } ipv4_addr_t;
44 
54 static inline bool ipv4_addr_equal(ipv4_addr_t *a, ipv4_addr_t *b)
55 {
56  return (a->u32.u32 == b->u32.u32);
57 }
58 
71 char *ipv4_addr_to_str(char *result, const ipv4_addr_t *addr, uint8_t result_len);
72 
84 ipv4_addr_t *ipv4_addr_from_str(ipv4_addr_t *result, const char *addr);
85 
86 #ifdef __cplusplus
87 }
88 #endif
89 
90 #endif /* IPV4_ADDR_H */
91 
A 32 bit integer in big endian aka network byte order.
Definition: byteorder.h:86
uint32_t u32
32 bit representation
Definition: byteorder.h:87
network_uint32_t u32
as 32-bit unsigned integer
Definition: ipv4/addr.h:42
ipv4_addr_t * ipv4_addr_from_str(ipv4_addr_t *result, const char *addr)
Converts an IPv4 address string representation to a byte-represented IPv4 address.
static bool ipv4_addr_equal(ipv4_addr_t *a, ipv4_addr_t *b)
Checks if two IPv4 addresses are equal.
Definition: ipv4/addr.h:54
Functions to work with different byte orders.
Data type to represent an IPv4 address.
Definition: ipv4/addr.h:40
char * ipv4_addr_to_str(char *result, const ipv4_addr_t *addr, uint8_t result_len)
Converts an IPv4 address to its string representation.