sdk-core v2026.11.05
PS2 SDK - core tier (build-critical EE/IOP modules)
Loading...
Searching...
No Matches
ip4_addr.h
Go to the documentation of this file.
1
6
7/*
8 * Copyright (c) 2001-2004 Swedish Institute of Computer Science.
9 * All rights reserved.
10 *
11 * Redistribution and use in source and binary forms, with or without modification,
12 * are permitted provided that the following conditions are met:
13 *
14 * 1. Redistributions of source code must retain the above copyright notice,
15 * this list of conditions and the following disclaimer.
16 * 2. Redistributions in binary form must reproduce the above copyright notice,
17 * this list of conditions and the following disclaimer in the documentation
18 * and/or other materials provided with the distribution.
19 * 3. The name of the author may not be used to endorse or promote products
20 * derived from this software without specific prior written permission.
21 *
22 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
23 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
24 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
25 * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
26 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
27 * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
30 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
31 * OF SUCH DAMAGE.
32 *
33 * This file is part of the lwIP TCP/IP stack.
34 *
35 * Author: Adam Dunkels <adam@sics.se>
36 *
37 */
38#ifndef LWIP_HDR_IP4_ADDR_H
39#define LWIP_HDR_IP4_ADDR_H
40
41#include "lwip/opt.h"
42#include "lwip/def.h"
43
44#if LWIP_IPV4
45
46#ifdef __cplusplus
47extern "C" {
48#endif
49
52struct ip4_addr {
53 u32_t addr;
54};
55
58typedef struct ip4_addr ip4_addr_t;
59
60/* Forward declaration to not include netif.h */
61struct netif;
62
64#define IPADDR_NONE ((u32_t)0xffffffffUL)
66#define IPADDR_LOOPBACK ((u32_t)0x7f000001UL)
68#define IPADDR_ANY ((u32_t)0x00000000UL)
70#define IPADDR_BROADCAST ((u32_t)0xffffffffUL)
71
72/* Definitions of the bits in an Internet address integer.
73
74 On subnets, host and network parts are found according to
75 the subnet mask, not these masks. */
76#define IP_CLASSA(a) ((((u32_t)(a)) & 0x80000000UL) == 0)
77#define IP_CLASSA_NET 0xff000000
78#define IP_CLASSA_NSHIFT 24
79#define IP_CLASSA_HOST (0xffffffff & ~IP_CLASSA_NET)
80#define IP_CLASSA_MAX 128
81
82#define IP_CLASSB(a) ((((u32_t)(a)) & 0xc0000000UL) == 0x80000000UL)
83#define IP_CLASSB_NET 0xffff0000
84#define IP_CLASSB_NSHIFT 16
85#define IP_CLASSB_HOST (0xffffffff & ~IP_CLASSB_NET)
86#define IP_CLASSB_MAX 65536
87
88#define IP_CLASSC(a) ((((u32_t)(a)) & 0xe0000000UL) == 0xc0000000UL)
89#define IP_CLASSC_NET 0xffffff00
90#define IP_CLASSC_NSHIFT 8
91#define IP_CLASSC_HOST (0xffffffff & ~IP_CLASSC_NET)
92
93#define IP_CLASSD(a) (((u32_t)(a) & 0xf0000000UL) == 0xe0000000UL)
94#define IP_CLASSD_NET 0xf0000000 /* These ones aren't really */
95#define IP_CLASSD_NSHIFT 28 /* net and host fields, but */
96#define IP_CLASSD_HOST 0x0fffffff /* routing needn't know. */
97#define IP_MULTICAST(a) IP_CLASSD(a)
98
99#define IP_EXPERIMENTAL(a) (((u32_t)(a) & 0xf0000000UL) == 0xf0000000UL)
100#define IP_BADCLASS(a) (((u32_t)(a) & 0xf0000000UL) == 0xf0000000UL)
101
102#define IP_LOOPBACKNET 127 /* official! */
103
105#define IP4_ADDR(ipaddr, a,b,c,d) (ipaddr)->addr = PP_HTONL(LWIP_MAKEU32(a,b,c,d))
106
108#define ip4_addr_copy(dest, src) ((dest).addr = (src).addr)
110#define ip4_addr_set(dest, src) ((dest)->addr = \
111 ((src) == NULL ? 0 : \
112 (src)->addr))
114#define ip4_addr_set_zero(ipaddr) ((ipaddr)->addr = 0)
116#define ip4_addr_set_any(ipaddr) ((ipaddr)->addr = IPADDR_ANY)
118#define ip4_addr_set_loopback(ipaddr) ((ipaddr)->addr = PP_HTONL(IPADDR_LOOPBACK))
120#define ip4_addr_isloopback(ipaddr) (((ipaddr)->addr & PP_HTONL(IP_CLASSA_NET)) == PP_HTONL(((u32_t)IP_LOOPBACKNET) << 24))
123#define ip4_addr_set_hton(dest, src) ((dest)->addr = \
124 ((src) == NULL ? 0:\
125 lwip_htonl((src)->addr)))
127#define ip4_addr_set_u32(dest_ipaddr, src_u32) ((dest_ipaddr)->addr = (src_u32))
129#define ip4_addr_get_u32(src_ipaddr) ((src_ipaddr)->addr)
130
132#define ip4_addr_get_network(target, host, netmask) do { ((target)->addr = ((host)->addr) & ((netmask)->addr)); } while(0)
133
138#define ip4_addr_netcmp(addr1, addr2, mask) ip4_addr_net_eq(addr1, addr2, mask)
147#define ip4_addr_net_eq(addr1, addr2, mask) (((addr1)->addr & \
148 (mask)->addr) == \
149 ((addr2)->addr & \
150 (mask)->addr))
154#define ip4_addr_cmp(addr1, addr2) ip4_addr_eq(addr1, addr2)
155#define ip4_addr_eq(addr1, addr2) ((addr1)->addr == (addr2)->addr)
156
157#define ip4_addr_isany_val(addr1) ((addr1).addr == IPADDR_ANY)
158#define ip4_addr_isany(addr1) ((addr1) == NULL || ip4_addr_isany_val(*(addr1)))
159
160#define ip4_addr_isbroadcast(addr1, netif) ip4_addr_isbroadcast_u32((addr1)->addr, netif)
161u8_t ip4_addr_isbroadcast_u32(u32_t addr, const struct netif *netif);
162
163#define ip_addr_netmask_valid(netmask) ip4_addr_netmask_valid((netmask)->addr)
164u8_t ip4_addr_netmask_valid(u32_t netmask);
165
166#define ip4_addr_ismulticast(addr1) (((addr1)->addr & PP_HTONL(0xf0000000UL)) == PP_HTONL(0xe0000000UL))
167
168#define ip4_addr_islinklocal(addr1) (((addr1)->addr & PP_HTONL(0xffff0000UL)) == PP_HTONL(0xa9fe0000UL))
169
170#define ip4_addr_debug_print_parts(debug, a, b, c, d) \
171 LWIP_DEBUGF(debug, ("%" U16_F ".%" U16_F ".%" U16_F ".%" U16_F, a, b, c, d))
172#define ip4_addr_debug_print(debug, ipaddr) \
173 ip4_addr_debug_print_parts(debug, \
174 (u16_t)((ipaddr) != NULL ? ip4_addr1_16(ipaddr) : 0), \
175 (u16_t)((ipaddr) != NULL ? ip4_addr2_16(ipaddr) : 0), \
176 (u16_t)((ipaddr) != NULL ? ip4_addr3_16(ipaddr) : 0), \
177 (u16_t)((ipaddr) != NULL ? ip4_addr4_16(ipaddr) : 0))
178#define ip4_addr_debug_print_val(debug, ipaddr) \
179 ip4_addr_debug_print_parts(debug, \
180 ip4_addr1_16_val(ipaddr), \
181 ip4_addr2_16_val(ipaddr), \
182 ip4_addr3_16_val(ipaddr), \
183 ip4_addr4_16_val(ipaddr))
184
185/* Get one byte from the 4-byte address */
186#define ip4_addr_get_byte(ipaddr, idx) (((const u8_t*)(&(ipaddr)->addr))[idx])
187#define ip4_addr1(ipaddr) ip4_addr_get_byte(ipaddr, 0)
188#define ip4_addr2(ipaddr) ip4_addr_get_byte(ipaddr, 1)
189#define ip4_addr3(ipaddr) ip4_addr_get_byte(ipaddr, 2)
190#define ip4_addr4(ipaddr) ip4_addr_get_byte(ipaddr, 3)
191/* Get one byte from the 4-byte address, but argument is 'ip4_addr_t',
192 * not a pointer */
193#define ip4_addr_get_byte_val(ipaddr, idx) ((u8_t)(((ipaddr).addr >> (idx * 8)) & 0xff))
194#define ip4_addr1_val(ipaddr) ip4_addr_get_byte_val(ipaddr, 0)
195#define ip4_addr2_val(ipaddr) ip4_addr_get_byte_val(ipaddr, 1)
196#define ip4_addr3_val(ipaddr) ip4_addr_get_byte_val(ipaddr, 2)
197#define ip4_addr4_val(ipaddr) ip4_addr_get_byte_val(ipaddr, 3)
198/* These are cast to u16_t, with the intent that they are often arguments
199 * to printf using the U16_F format from cc.h. */
200#define ip4_addr1_16(ipaddr) ((u16_t)ip4_addr1(ipaddr))
201#define ip4_addr2_16(ipaddr) ((u16_t)ip4_addr2(ipaddr))
202#define ip4_addr3_16(ipaddr) ((u16_t)ip4_addr3(ipaddr))
203#define ip4_addr4_16(ipaddr) ((u16_t)ip4_addr4(ipaddr))
204#define ip4_addr1_16_val(ipaddr) ((u16_t)ip4_addr1_val(ipaddr))
205#define ip4_addr2_16_val(ipaddr) ((u16_t)ip4_addr2_val(ipaddr))
206#define ip4_addr3_16_val(ipaddr) ((u16_t)ip4_addr3_val(ipaddr))
207#define ip4_addr4_16_val(ipaddr) ((u16_t)ip4_addr4_val(ipaddr))
208
209#define IP4ADDR_STRLEN_MAX 16
210
212#define ip_ntoa(ipaddr) ipaddr_ntoa(ipaddr)
213
214u32_t ipaddr_addr(const char *cp);
215int ip4addr_aton(const char *cp, ip4_addr_t *addr);
217char *ip4addr_ntoa(const ip4_addr_t *addr);
218char *ip4addr_ntoa_r(const ip4_addr_t *addr, char *buf, int buflen);
219
220#ifdef __cplusplus
221}
222#endif
223
224#endif /* LWIP_IPV4 */
225
226#endif /* LWIP_HDR_IP_ADDR_H */
char * ip4addr_ntoa(const ip4_addr_t *addr)
struct ip4_addr ip4_addr_t
Definition ps2ip_rpc.h:41