source: EcnlProtoTool/trunk/asp3_dcre/tinet/netinet/in.h@ 321

Last change on this file since 321 was 321, checked in by coas-nagasima, 7 years ago

文字コードを設定

  • Property svn:eol-style set to native
  • Property svn:mime-type set to text/x-chdr;charset=UTF-8
File size: 10.1 KB
Line 
1/*
2 * TINET (TCP/IP Protocol Stack)
3 *
4 * Copyright (C) 2001-2009 by Dep. of Computer Science and Engineering
5 * Tomakomai National College of Technology, JAPAN
6 *
7 * 上記著作権者は,以下の (1)~(4) の条件か,Free Software Foundation
8 * によって公表されている GNU General Public License の Version 2 に記
9 * 述されている条件を満たす場合に限り,本ソフトウェア(本ソフトウェア
10 * を改変したものを含む.以下同じ)を使用・複製・改変・再配布(以下,
11 * 利用と呼ぶ)することを無償で許諾する.
12 * (1) 本ソフトウェアをソースコードの形で利用する場合には,上記の著作
13 * 権表示,この利用条件および下記の無保証規定が,そのままの形でソー
14 * スコード中に含まれていること.
15 * (2) 本ソフトウェアを,ライブラリ形式など,他のソフトウェア開発に使
16 * 用できる形で再配布する場合には,再配布に伴うドキュメント(利用
17 * 者マニュアルなど)に,上記の著作権表示,この利用条件および下記
18 * の無保証規定を掲載すること.
19 * (3) 本ソフトウェアを,機器に組み込むなど,他のソフトウェア開発に使
20 * 用できない形で再配布する場合には,次の条件を満たすこと.
21 * (a) 再配布に伴うドキュメント(利用者マニュアルなど)に,上記の著
22 * 作権表示,この利用条件および下記の無保証規定を掲載すること.
23 * (4) 本ソフトウェアの利用により直接的または間接的に生じるいかなる損
24 * 害からも,上記著作権者およびTOPPERSプロジェクトを免責すること.
25 *
26 * 本ソフトウェアは,無保証で提供されているものである.上記著作権者お
27 * よびTOPPERSプロジェクトは,本ソフトウェアに関して,その適用可能性も
28 * 含めて,いかなる保証も行わない.また,本ソフトウェアの利用により直
29 * 接的または間接的に生じたいかなる損害に関しても,その責任を負わない.
30 *
31 * @(#) $Id$
32 */
33
34/*
35 * Copyright (c) 1982, 1986, 1990, 1993
36 * The Regents of the University of California. All rights reserved.
37 *
38 * Redistribution and use in source and binary forms, with or without
39 * modification, are permitted provided that the following conditions
40 * are met:
41 * 1. Redistributions of source code must retain the above copyright
42 * notice, this list of conditions and the following disclaimer.
43 * 2. Redistributions in binary form must reproduce the above copyright
44 * notice, this list of conditions and the following disclaimer in the
45 * documentation and/or other materials provided with the distribution.
46 * 3. All advertising materials mentioning features or use of this software
47 * must display the following acknowledgement:
48 * This product includes software developed by the University of
49 * California, Berkeley and its contributors.
50 * 4. Neither the name of the University nor the names of its contributors
51 * may be used to endorse or promote products derived from this software
52 * without specific prior written permission.
53 *
54 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
55 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
56 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
57 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
58 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
59 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
60 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
61 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
62 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
63 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
64 * SUCH DAMAGE.
65 *
66 * @(#)in.h 8.3 (Berkeley) 1/3/94
67 * $FreeBSD: src/sys/netinet/in.h,v 1.38.2.3 1999/08/29 16:29:34 peter Exp $
68 */
69
70#ifndef _IN_H_
71#define _IN_H_
72
73#include <tinet_kernel_defs.h>
74
75#include <netinet6/in6.h>
76
77/*
78 * TINET のバージョン情報
79 */
80
81#define TINET_PRVER UINT_C(0x1054) /* TINET のバージョン番号 */
82
83/*
84 * インターネットシステムの定義、RFC790 参照
85 */
86
87/*
88 * プロトコル (RFC1700)
89 */
90
91#define IPPROTO_IP UINT_C(0) /* IP のダミー */
92#define IPPROTO_HOPOPTS UINT_C(0) /* IPv6 中継点 (Hop-by-Hop) オプション */
93#define IPPROTO_ICMP UINT_C(1) /* ICMP */
94#define IPPROTO_TCP UINT_C(6) /* TCP */
95#define IPPROTO_UDP UINT_C(17) /* UDP */
96#define IPPROTO_IPV6 UINT_C(41) /* IPv6 */
97#define IPPROTO_ROUTING UINT_C(43) /* 経路制御オプション */
98#define IPPROTO_FRAGMENT UINT_C(44) /* 断片化オプション */
99#define IPPROTO_RSVP UINT_C(46) /* RSVP */
100#define IPPROTO_ESP UINT_C(50) /* IPv6 暗号化オプション */
101#define IPPROTO_AH UINT_C(51) /* IPv6 認証オプション */
102#define IPPROTO_ICMPV6 UINT_C(58) /* ICMPv6 */
103#define IPPROTO_NONE UINT_C(59) /* IPv6 次ヘッダ無し */
104#define IPPROTO_DSTOPTS UINT_C(60) /* IPv6 終点オプション */
105#define IPPROTO_IPCOMP UINT_C(108) /* ペイロード圧縮 */
106#define IPPROTO_DONE UINT_C(257) /* IPv6 で上位プロトコル入力終了 */
107
108/*
109 * IPv4 アドレス
110 */
111
112/* 前方参照 */
113
114#ifndef T_IN4_ADDR_DEFINED
115
116typedef uint32_t T_IN4_ADDR;
117
118#define T_IN4_ADDR_DEFINED
119
120#endif /* of #ifndef T_IN4_ADDR_DEFINED */
121
122/*
123 * ITRON TCP/IPv4 アドレス/ポート番号の定義
124 */
125
126typedef struct t_ipv4ep {
127 uint32_t ipaddr; /* IPv4 アドレス */
128 uint16_t portno; /* ポート番号 */
129 } T_IPV4EP;
130
131/*
132 * アドレス/ポートの長さ
133 */
134
135#define IPV4_ADDR_LEN 4
136#define PORT_NUM_LEN 2
137
138/*
139 * ポート番号の定義
140 */
141
142#define TCP_PORTANY UINT_C(0x0000) /* ITRON TCP/IP 標準 */
143#define UDP_PORTANY UINT_C(0x0000) /* ITRON TCP/IP 標準 */
144
145#define TCP_PORT_LAST_WELL_KNOWN UINT_C(1023) /* Well Known 終了番号 */
146#define TCP_PORT_FIRST_AUTO UINT_C(1024) /* 自動割り当て開始番号 */
147#define TCP_PORT_LAST_AUTO UINT_C(4999) /* 自動割り当て終了番号 */
148
149#define UDP_PORT_LAST_WELL_KNOWN UINT_C(1023) /* Well Known 終了番号 */
150#define UDP_PORT_FIRST_AUTO UINT_C(1024) /* 自動割り当て開始番号 */
151#define UDP_PORT_LAST_AUTO UINT_C(4999) /* 自動割り当て終了番号 */
152
153/*
154 * IP アドレスの定義
155 */
156
157#define IPV4_ADDRANY ULONG_C(0x00000000) /* ITRON TCP/IP 標準 */
158
159#define IPV4_ADDR_LOOPBACK ULONG_C(0x7f000001)
160#define IPV4_ADDR_LOOPBACK_MASK IPV4_CLASS_A_MASK
161#define IPV4_ADDR_BROADCAST ULONG_C(0xffffffff)
162
163#define IPV4_CLASS_A(i) (((i) & ULONG_C(0x80000000)) == 0)
164#define IPV4_CLASS_A_NET ULONG_C(0xff000000)
165#define IPV4_CLASS_A_MASK ULONG_C(0xff000000)
166#define IPV4_CLASS_A_HOST ULONG_C(0x00ffffff)
167
168#define IPV4_CLASS_B(i) (((i) & ULONG_C(0xc0000000)) == ULONG_C(0x80000000))
169#define IPV4_CLASS_B_NET ULONG_C(0xffff0000)
170#define IPV4_CLASS_B_MASK ULONG_C(0xffff0000)
171#define IPV4_CLASS_B_HOST ULONG_C(0x0000ffff)
172
173#define IPV4_CLASS_C(i) (((i) & ULONG_C(0xe0000000)) == ULONG_C(0xc0000000))
174#define IPV4_CLASS_C_NET ULONG_C(0xffffff00)
175#define IPV4_CLASS_C_MASK ULONG_C(0xffffff00)
176#define IPV4_CLASS_C_HOST ULONG_C(0x000000ff)
177
178#define IPV4_CLASS_D(i) (((i) & ULONG_C(0xf0000000)) == ULONG_C(0xe0000000))
179
180#define IN4_IS_ADDR_MULTICAST(i) IPV4_CLASS_D(i)
181
182#define MAKE_IPV4_LOCAL_BROADCAST(i) (IPV4_CLASS_A(i)?((i)|IPV4_CLASS_A_HOST):\
183 IPV4_CLASS_B(i)?((i)|IPV4_CLASS_B_HOST):\
184 IPV4_CLASS_C(i)?((i)|IPV4_CLASS_C_HOST):\
185 IPV4_ADDR_BROADCAST)
186
187#define MAKE_IPV4_LOCAL_MASK(i) (IPV4_CLASS_A(i)?IPV4_CLASS_A_MASK:\
188 IPV4_CLASS_B(i)?IPV4_CLASS_B_MASK:\
189 IPV4_CLASS_C(i)?IPV4_CLASS_C_MASK:\
190 IPV4_ADDRANY)
191
192#define MAKE_IPV4_ADDR(a,b,c,d) ((T_IN4_ADDR)(((uint32_t)(a)<<24)|((uint32_t)(b)<<16)|((uint32_t)(c)<<8)|(d)))
193
194/*
195 * 動的生成用 TCP 通信端点
196 */
197
198typedef struct t_tcp_ccep {
199 /* 標準 */
200 ATR cepatr; /* 通信端点属性 */
201 void *sbuf; /* 送信用ウィンドバッファ */
202 int_t sbufsz; /* 送信用ウィンドバッファサイズ */
203 void *rbuf; /* 受信用ウィンドバッファ */
204 int_t rbufsz; /* 受信用ウィンドバッファサイズ */
205 FP callback; /* コールバック */
206 /* 実装依存 */
207 } T_TCP_CCEP;
208
209/*
210 * 動的生成用 TCP 受付口
211 */
212
213#if defined(SUPPORT_INET4)
214
215typedef struct t_tcp_crep {
216 /* 標準 */
217 ATR repatr; /* 受付口属性 */
218 T_IPV4EP myaddr; /* 自分のアドレス */
219 /* 実装依存 */
220 } T_TCP_CREP;
221
222#endif /* of #if defined(SUPPORT_INET4) */
223
224/*
225 * 動的生成用 UDP 通信端点
226 */
227
228#if defined(SUPPORT_INET4)
229
230typedef struct t_udp_ccep {
231 /* 標準 */
232 ATR cepatr; /* UDP 通信端点属性 */
233 T_IPV4EP myaddr; /* 自分のアドレス */
234 FP callback; /* コールバック関数 */
235 /* 実装依存 */
236 } T_UDP_CCEP;
237
238#endif /* of #if defined(SUPPORT_INET4) */
239
240/*
241 * IPv4 と IPv6 をコンパイル時に選択するためのマクロ
242 */
243
244#if defined(SUPPORT_INET4)
245
246#define T_IN_ADDR T_IN4_ADDR
247#define T_IPEP T_IPV4EP
248#define IP_ADDRANY IPV4_ADDRANY
249
250#define IN_ARE_ADDR_EQUAL(n,h) (*(n)==*(h))
251#define IN_ARE_NET_ADDR_EQUAL(n,h) (ntohl(*(n))==*(h))
252#define IN_COPY_TO_NET(d,s) (*(d)=htonl(*(s)))
253#define IN_COPY_TO_HOST(d,s) (*(d)=ntohl(*(s)))
254#define IN_IS_ADDR_MULTICAST(a) IN4_IS_ADDR_MULTICAST(*(a))
255#define IN_IS_NET_ADDR_MULTICAST(a) IN4_IS_ADDR_MULTICAST(ntohl(*(a)))
256#define IN_IS_ADDR_ANY(a) (*(a)==IPV4_ADDRANY)
257
258#endif /* of #if defined(SUPPORT_INET4) */
259
260/*
261 * TINET 独自 API
262 */
263
264extern const char *in_strtfn (FN fncd);
265
266#if defined(SUPPORT_INET4)
267
268extern ER in4_add_ifaddr (T_IN4_ADDR addr, T_IN4_ADDR mask);
269extern ER in4_add_route (int_t index, T_IN4_ADDR target,
270 T_IN4_ADDR mask, T_IN4_ADDR gateway);
271extern char *ip2str (char *buf, const T_IN4_ADDR *p_ipaddr);
272extern const T_IN4_ADDR *in4_get_ifaddr (int_t index);
273
274#endif /* of #if defined(SUPPORT_INET4) */
275
276#endif /* of #ifndef _IN_H_ */
Note: See TracBrowser for help on using the repository browser.