sdk-core v2026.11.05
PS2 SDK - core tier (build-critical EE/IOP modules)
Loading...
Searching...
No Matches
ip4.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_PROT_IP4_H
39#define LWIP_HDR_PROT_IP4_H
40
41#include "lwip/arch.h"
42#include "lwip/ip4_addr.h"
43
44#ifdef __cplusplus
45extern "C" {
46#endif
47
50#ifdef PACK_STRUCT_USE_INCLUDES
51# include "arch/bpstruct.h"
52#endif
53PACK_STRUCT_BEGIN
55 PACK_STRUCT_FIELD(u32_t addr);
56} PACK_STRUCT_STRUCT;
57PACK_STRUCT_END
58#ifdef PACK_STRUCT_USE_INCLUDES
59# include "arch/epstruct.h"
60#endif
61
62typedef struct ip4_addr_packed ip4_addr_p_t;
63
64/* Size of the IPv4 header. Same as 'sizeof(struct ip_hdr)'. */
65#define IP_HLEN 20
66/* Maximum size of the IPv4 header with options. */
67#define IP_HLEN_MAX 60
68
69#ifdef PACK_STRUCT_USE_INCLUDES
70# include "arch/bpstruct.h"
71#endif
72PACK_STRUCT_BEGIN
73/* The IPv4 header */
74struct ip_hdr {
75 /* version / header length */
76 PACK_STRUCT_FLD_8(u8_t _v_hl);
77 /* type of service */
78 PACK_STRUCT_FLD_8(u8_t _tos);
79 /* total length */
80 PACK_STRUCT_FIELD(u16_t _len);
81 /* identification */
82 PACK_STRUCT_FIELD(u16_t _id);
83 /* fragment offset field */
84 PACK_STRUCT_FIELD(u16_t _offset);
85#define IP_RF 0x8000U /* reserved fragment flag */
86#define IP_DF 0x4000U /* don't fragment flag */
87#define IP_MF 0x2000U /* more fragments flag */
88#define IP_OFFMASK 0x1fffU /* mask for fragmenting bits */
89 /* time to live */
90 PACK_STRUCT_FLD_8(u8_t _ttl);
91 /* protocol*/
92 PACK_STRUCT_FLD_8(u8_t _proto);
93 /* checksum */
94 PACK_STRUCT_FIELD(u16_t _chksum);
95 /* source and destination IP addresses */
96 PACK_STRUCT_FLD_S(ip4_addr_p_t src);
97 PACK_STRUCT_FLD_S(ip4_addr_p_t dest);
98} PACK_STRUCT_STRUCT;
99PACK_STRUCT_END
100#ifdef PACK_STRUCT_USE_INCLUDES
101# include "arch/epstruct.h"
102#endif
103
104/* Macros to get struct ip_hdr fields: */
105#define IPH_V(hdr) ((hdr)->_v_hl >> 4)
106#define IPH_HL(hdr) ((hdr)->_v_hl & 0x0f)
107#define IPH_HL_BYTES(hdr) ((u8_t)(IPH_HL(hdr) * 4))
108#define IPH_TOS(hdr) ((hdr)->_tos)
109#define IPH_LEN(hdr) ((hdr)->_len)
110#define IPH_ID(hdr) ((hdr)->_id)
111#define IPH_OFFSET(hdr) ((hdr)->_offset)
112#define IPH_OFFSET_BYTES(hdr) ((u16_t)((lwip_ntohs(IPH_OFFSET(hdr)) & IP_OFFMASK) * 8U))
113#define IPH_TTL(hdr) ((hdr)->_ttl)
114#define IPH_PROTO(hdr) ((hdr)->_proto)
115#define IPH_CHKSUM(hdr) ((hdr)->_chksum)
116
117/* Macros to set struct ip_hdr fields: */
118#define IPH_VHL_SET(hdr, v, hl) (hdr)->_v_hl = (u8_t)((((v) << 4) | (hl)))
119#define IPH_TOS_SET(hdr, tos) (hdr)->_tos = (tos)
120#define IPH_LEN_SET(hdr, len) (hdr)->_len = (len)
121#define IPH_ID_SET(hdr, id) (hdr)->_id = (id)
122#define IPH_OFFSET_SET(hdr, off) (hdr)->_offset = (off)
123#define IPH_TTL_SET(hdr, ttl) (hdr)->_ttl = (u8_t)(ttl)
124#define IPH_PROTO_SET(hdr, proto) (hdr)->_proto = (u8_t)(proto)
125#define IPH_CHKSUM_SET(hdr, chksum) (hdr)->_chksum = (chksum)
126
127
128#ifdef __cplusplus
129}
130#endif
131
132#endif /* LWIP_HDR_PROT_IP4_H */
Definition ip4.h:74