1 | /*
|
---|
2 | * TINET (TCP/IP Protocol Stack)
|
---|
3 | *
|
---|
4 | * Copyright (C) 2001-2017 by Dep. of Computer Science and Engineering
|
---|
5 | * Tomakomai National College of Technology, JAPAN
|
---|
6 | *
|
---|
7 | * ä¸è¨èä½æ¨©è
|
---|
8 | ã¯ï¼ä»¥ä¸ã® (1)ï½(4) ã®æ¡ä»¶ãï¼Free Software Foundation
|
---|
9 | * ã«ãã£ã¦å
|
---|
10 | ¬è¡¨ããã¦ãã GNU General Public License ã® Version 2 ã«è¨
|
---|
11 | * è¿°ããã¦ããæ¡ä»¶ãæºããå ´åã«éãï¼æ¬ã½ããã¦ã§ã¢ï¼æ¬ã½ããã¦ã§ã¢
|
---|
12 | * ãæ¹å¤ãããã®ãå«ãï¼ä»¥ä¸åãï¼ã使ç¨ã»è¤è£½ã»æ¹å¤ã»åé
|
---|
13 | å¸ï¼ä»¥ä¸ï¼
|
---|
14 | * å©ç¨ã¨å¼ã¶ï¼ãããã¨ãç¡åã§è¨±è«¾ããï¼
|
---|
15 | * (1) æ¬ã½ããã¦ã§ã¢ãã½ã¼ã¹ã³ã¼ãã®å½¢ã§å©ç¨ããå ´åã«ã¯ï¼ä¸è¨ã®èä½
|
---|
16 | * 権表示ï¼ãã®å©ç¨æ¡ä»¶ããã³ä¸è¨ã®ç¡ä¿è¨¼è¦å®ãï¼ãã®ã¾ã¾ã®å½¢ã§ã½ã¼
|
---|
17 | * ã¹ã³ã¼ãä¸ã«å«ã¾ãã¦ãããã¨ï¼
|
---|
18 | * (2) æ¬ã½ããã¦ã§ã¢ãï¼ã©ã¤ãã©ãªå½¢å¼ãªã©ï¼ä»ã®ã½ããã¦ã§ã¢éçºã«ä½¿
|
---|
19 | * ç¨ã§ããå½¢ã§åé
|
---|
20 | å¸ããå ´åã«ã¯ï¼åé
|
---|
21 | å¸ã«ä¼´ãããã¥ã¡ã³ãï¼å©ç¨
|
---|
22 | * è
|
---|
23 | ããã¥ã¢ã«ãªã©ï¼ã«ï¼ä¸è¨ã®èä½æ¨©è¡¨ç¤ºï¼ãã®å©ç¨æ¡ä»¶ããã³ä¸è¨
|
---|
24 | * ã®ç¡ä¿è¨¼è¦å®ãæ²è¼ãããã¨ï¼
|
---|
25 | * (3) æ¬ã½ããã¦ã§ã¢ãï¼æ©å¨ã«çµã¿è¾¼ããªã©ï¼ä»ã®ã½ããã¦ã§ã¢éçºã«ä½¿
|
---|
26 | * ç¨ã§ããªãå½¢ã§åé
|
---|
27 | å¸ããå ´åã«ã¯ï¼æ¬¡ã®æ¡ä»¶ãæºãããã¨ï¼
|
---|
28 | * (a) åé
|
---|
29 | å¸ã«ä¼´ãããã¥ã¡ã³ãï¼å©ç¨è
|
---|
30 | ããã¥ã¢ã«ãªã©ï¼ã«ï¼ä¸è¨ã®è
|
---|
31 | * ä½æ¨©è¡¨ç¤ºï¼ãã®å©ç¨æ¡ä»¶ããã³ä¸è¨ã®ç¡ä¿è¨¼è¦å®ãæ²è¼ãããã¨ï¼
|
---|
32 | * (4) æ¬ã½ããã¦ã§ã¢ã®å©ç¨ã«ããç´æ¥çã¾ãã¯éæ¥çã«çãããããªãæ
|
---|
33 | * 害ãããï¼ä¸è¨èä½æ¨©è
|
---|
34 | ããã³TOPPERSããã¸ã§ã¯ããå
|
---|
35 | 責ãããã¨ï¼
|
---|
36 | *
|
---|
37 | * æ¬ã½ããã¦ã§ã¢ã¯ï¼ç¡ä¿è¨¼ã§æä¾ããã¦ãããã®ã§ããï¼ä¸è¨èä½æ¨©è
|
---|
38 | ã
|
---|
39 | * ãã³TOPPERSããã¸ã§ã¯ãã¯ï¼æ¬ã½ããã¦ã§ã¢ã«é¢ãã¦ï¼ãã®é©ç¨å¯è½æ§ã
|
---|
40 | * å«ãã¦ï¼ãããªãä¿è¨¼ãè¡ããªãï¼ã¾ãï¼æ¬ã½ããã¦ã§ã¢ã®å©ç¨ã«ããç´
|
---|
41 | * æ¥çã¾ãã¯éæ¥çã«çãããããªãæ害ã«é¢ãã¦ãï¼ãã®è²¬ä»»ãè² ããªãï¼
|
---|
42 | *
|
---|
43 | * @(#) $Id: in_subr.c 313 2017-07-23 04:50:32Z coas-nagasima $
|
---|
44 | */
|
---|
45 |
|
---|
46 | /*
|
---|
47 | * Copyright (c) 1982, 1986, 1988, 1993
|
---|
48 | * The Regents of the University of California. All rights reserved.
|
---|
49 | *
|
---|
50 | * Redistribution and use in source and binary forms, with or without
|
---|
51 | * modification, are permitted provided that the following conditions
|
---|
52 | * are met:
|
---|
53 | * 1. Redistributions of source code must retain the above copyright
|
---|
54 | * notice, this list of conditions and the following disclaimer.
|
---|
55 | * 2. Redistributions in binary form must reproduce the above copyright
|
---|
56 | * notice, this list of conditions and the following disclaimer in the
|
---|
57 | * documentation and/or other materials provided with the distribution.
|
---|
58 | * 3. All advertising materials mentioning features or use of this software
|
---|
59 | * must display the following acknowledgement:
|
---|
60 | * This product includes software developed by the University of
|
---|
61 | * California, Berkeley and its contributors.
|
---|
62 | * 4. Neither the name of the University nor the names of its contributors
|
---|
63 | * may be used to endorse or promote products derived from this software
|
---|
64 | * without specific prior written permission.
|
---|
65 | *
|
---|
66 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
---|
67 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
---|
68 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
---|
69 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
---|
70 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
---|
71 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
---|
72 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
---|
73 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
---|
74 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
---|
75 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
---|
76 | * SUCH DAMAGE.
|
---|
77 | */
|
---|
78 |
|
---|
79 | #include <string.h>
|
---|
80 |
|
---|
81 | #ifdef TARGET_KERNEL_ASP
|
---|
82 |
|
---|
83 | #include <kernel.h>
|
---|
84 | #include <sil.h>
|
---|
85 | #include "kernel_cfg.h"
|
---|
86 |
|
---|
87 | #endif /* of #ifdef TARGET_KERNEL_ASP */
|
---|
88 |
|
---|
89 | #ifdef TARGET_KERNEL_JSP
|
---|
90 |
|
---|
91 | #include <s_services.h>
|
---|
92 | #include <t_services.h>
|
---|
93 | #include "kernel_id.h"
|
---|
94 |
|
---|
95 | #endif /* of #ifdef TARGET_KERNEL_JSP */
|
---|
96 |
|
---|
97 | #include <tinet_defs.h>
|
---|
98 | #include <tinet_config.h>
|
---|
99 |
|
---|
100 | #include <net/if.h>
|
---|
101 | #include <net/if_loop.h>
|
---|
102 | #include <net/if_ppp.h>
|
---|
103 | #include <net/ethernet.h>
|
---|
104 | #include <net/net.h>
|
---|
105 | #include <net/net_endian.h>
|
---|
106 | #include <net/net_var.h>
|
---|
107 | #include <net/net_buf.h>
|
---|
108 | #include <net/net_timer.h>
|
---|
109 |
|
---|
110 | #include <netinet/in.h>
|
---|
111 | #include <netinet/in_var.h>
|
---|
112 | #include <netinet/ip.h>
|
---|
113 | #include <netinet/ip_var.h>
|
---|
114 | #include <netinet/in_itron.h>
|
---|
115 |
|
---|
116 | #include <net/if_var.h>
|
---|
117 |
|
---|
118 | /*
|
---|
119 | * in_cksum_sum -- ãã§ãã¯ãµã ã®åè¨è¨ç®é¢æ°
|
---|
120 | *
|
---|
121 | * 注æ: data 㯠4 ãªã¯ãããåä½ã§ããã£ã³ã°ãããã¨ã
|
---|
122 | * data ã 2 ãªã¯ãããåä½ã«ã¢ã©ã¤ã³ããã¦ããªãã¨
|
---|
123 | * ä¾å¤ãçºçããå¯è½æ§ãããã
|
---|
124 | * len 㯠4 ãªã¯ãããåä½ã«ã¢ã©ã¤ã³ããã¦ãããã¨ã
|
---|
125 | *
|
---|
126 | * æ»ãå¤ã¯ãã¹ããã¤ããªã¼ã
|
---|
127 | */
|
---|
128 |
|
---|
129 | uint32_t
|
---|
130 | in_cksum_sum (void *data, uint_t len /*ãªã¯ãããåä½*/)
|
---|
131 | {
|
---|
132 | uint32_t sum = 0;
|
---|
133 |
|
---|
134 | for ( ; len > 0; len -= 2) {
|
---|
135 | sum += *((uint16_t*)data);
|
---|
136 | data = (uint8_t*)data + 2;
|
---|
137 | }
|
---|
138 |
|
---|
139 | #if _NET_CFG_BYTE_ORDER == _NET_CFG_BIG_ENDIAN
|
---|
140 | return sum;
|
---|
141 | #elif _NET_CFG_BYTE_ORDER == _NET_CFG_LITTLE_ENDIAN
|
---|
142 | return ((sum >> 8) & 0xffff) + ((sum & 0xff) << 8) + ((sum >> 24) & 0xff);
|
---|
143 | #endif /* #if _NET_CFG_BYTE_ORDER == _NET_CFG_BIG_ENDIAN */
|
---|
144 |
|
---|
145 | }
|
---|
146 |
|
---|
147 | /*
|
---|
148 | * in_cksum_carry -- ãã§ãã¯ãµã ã®æ¡ä¸ãè¨ç®é¢æ°
|
---|
149 | *
|
---|
150 | * 注æ: data 㯠4 ãªã¯ãããåä½ã§ããã£ã³ã°ãããã¨ã
|
---|
151 | * data ã 2 ãªã¯ãããåä½ã«ã¢ã©ã¤ã³ããã¦ããªãã¨
|
---|
152 | * ä¾å¤ãçºçããå¯è½æ§ãããã
|
---|
153 | * len 㯠4 ãªã¯ãããåä½ã«ã¢ã©ã¤ã³ããã¦ãããã¨ã
|
---|
154 | */
|
---|
155 |
|
---|
156 | uint32_t
|
---|
157 | in_cksum_carry (uint32_t sum)
|
---|
158 | {
|
---|
159 | uint32_t carry;
|
---|
160 |
|
---|
161 | while (sum >= 0x00010000) {
|
---|
162 | carry = sum >> 16;
|
---|
163 | sum = (sum & 0xffff) + carry;
|
---|
164 | }
|
---|
165 |
|
---|
166 | return sum;
|
---|
167 | }
|
---|
168 |
|
---|
169 | /*
|
---|
170 | * in_strtfn -- API æ©è½ã³ã¼ãã®æå表ç¾ãè¿ãã
|
---|
171 | */
|
---|
172 |
|
---|
173 | typedef struct t_strtfn {
|
---|
174 | FN fncd; /* API æ©è½ã³ã¼ã */
|
---|
175 | const char *str; /* æåè¡¨ç¾ */
|
---|
176 | } T_STRTFN;
|
---|
177 |
|
---|
178 | const T_STRTFN strtfn[] = {
|
---|
179 | { TEV_TCP_RCV_OOB, "TEV_TCP_RCV_OOB" },
|
---|
180 | { TFN_TCP_DEL_REP, "TFN_TCP_DEL_REP" },
|
---|
181 | { TFN_TCP_CRE_CEP, "TFN_TCP_CRE_CEP" },
|
---|
182 | { TFN_TCP_DEL_CEP, "TFN_TCP_DEL_CEP" },
|
---|
183 | { TFN_TCP_ACP_CEP, "TFN_TCP_ACP_CEP" },
|
---|
184 | { TFN_TCP_CON_CEP, "TFN_TCP_CON_CEP" },
|
---|
185 | { TFN_TCP_SHT_CEP, "TFN_TCP_SHT_CEP" },
|
---|
186 | { TFN_TCP_CLS_CEP, "TFN_TCP_CLS_CEP" },
|
---|
187 | { TFN_TCP_SND_DAT, "TFN_TCP_SND_DAT" },
|
---|
188 | { TFN_TCP_RCV_DAT, "TFN_TCP_RCV_DAT" },
|
---|
189 | { TFN_TCP_GET_BUF, "TFN_TCP_GET_BUF" },
|
---|
190 | { TFN_TCP_SND_BUF, "TFN_TCP_SND_BUF" },
|
---|
191 | { TFN_TCP_RCV_BUF, "TFN_TCP_RCV_BUF" },
|
---|
192 | { TFN_TCP_REL_BUF, "TFN_TCP_REL_BUF" },
|
---|
193 | { TFN_TCP_SND_OOB, "TFN_TCP_SND_OOB" },
|
---|
194 | { TFN_TCP_RCV_OOB, "TFN_TCP_RCV_OOB" },
|
---|
195 | { TFN_TCP_CAN_CEP, "TFN_TCP_CAN_CEP" },
|
---|
196 | { TFN_TCP_SET_OPT, "TFN_TCP_SET_OPT" },
|
---|
197 | { TFN_TCP_GET_OPT, "TFN_TCP_GET_OPT" },
|
---|
198 | { TFN_TCP_ALL, "TFN_TCP_ALL" },
|
---|
199 |
|
---|
200 | { TEV_UDP_RCV_DAT, "TEV_UDP_RCV_DAT" },
|
---|
201 | { TFN_UDP_DEL_CEP, "TFN_UDP_DEL_CEP" },
|
---|
202 | { TFN_UDP_SND_DAT, "TFN_UDP_SND_DAT" },
|
---|
203 | { TFN_UDP_RCV_DAT, "TFN_UDP_RCV_DAT" },
|
---|
204 | { TFN_UDP_CAN_CEP, "TFN_UDP_CAN_CEP" },
|
---|
205 | { TFN_UDP_SET_OPT, "TFN_UDP_SET_OPT" },
|
---|
206 | { TFN_UDP_GET_OPT, "TFN_UDP_GET_OPT" },
|
---|
207 | };
|
---|
208 |
|
---|
209 | const char *
|
---|
210 | in_strtfn (FN fncd)
|
---|
211 | {
|
---|
212 | int_t ix;
|
---|
213 |
|
---|
214 | for (ix = sizeof(strtfn) / sizeof(T_STRTFN); ix -- > 0; )
|
---|
215 | if (strtfn[ix].fncd == fncd)
|
---|
216 | return strtfn[ix].str;
|
---|
217 |
|
---|
218 | return "unknown TFN";
|
---|
219 | }
|
---|
220 |
|
---|
221 | #if defined(_IP4_CFG)
|
---|
222 |
|
---|
223 | /*
|
---|
224 | * ipv42str -- IPv4 ã¢ãã¬ã¹ãæååã«å¤æããã
|
---|
225 | */
|
---|
226 |
|
---|
227 | char *
|
---|
228 | ipv42str (char *buf, const T_IN4_ADDR *ipaddr)
|
---|
229 | {
|
---|
230 | static char addr_sbuf[NUM_IPV4ADDR_STR_BUFF][sizeof("123.123.123.123")];
|
---|
231 | static int_t bix = NUM_IPV4ADDR_STR_BUFF;
|
---|
232 |
|
---|
233 | char *start;
|
---|
234 |
|
---|
235 | if (buf == NULL) {
|
---|
236 | syscall(wai_sem(SEM_IP2STR_BUFF_LOCK));
|
---|
237 | buf = addr_sbuf[-- bix];
|
---|
238 | if (bix <= 0)
|
---|
239 | bix = NUM_IPV4ADDR_STR_BUFF;
|
---|
240 | syscall(sig_sem(SEM_IP2STR_BUFF_LOCK));
|
---|
241 | }
|
---|
242 |
|
---|
243 | start = buf;
|
---|
244 | buf += convert_hexdigit(buf, (uint_t)((*ipaddr >> 24) & 0xff), 10, 0, ' ');
|
---|
245 | *(buf ++) = '.';
|
---|
246 | buf += convert_hexdigit(buf, (uint_t)((*ipaddr >> 16) & 0xff), 10, 0, ' ');
|
---|
247 | *(buf ++) = '.';
|
---|
248 | buf += convert_hexdigit(buf, (uint_t)((*ipaddr >> 8) & 0xff), 10, 0, ' ');
|
---|
249 | *(buf ++) = '.';
|
---|
250 | buf += convert_hexdigit(buf, (uint_t)((*ipaddr ) & 0xff), 10, 0, ' ');
|
---|
251 | *buf = '\0';
|
---|
252 | return start;
|
---|
253 | }
|
---|
254 |
|
---|
255 | #endif /* of #if defined(_IP4_CFG) */
|
---|
256 |
|
---|
257 | /*
|
---|
258 | * in6_is_addr_ipv4mapped -- IPv4 å°å½±ã¢ãã¬ã¹ã§ããäºãæ¤æ»ããã
|
---|
259 | */
|
---|
260 |
|
---|
261 | bool_t
|
---|
262 | in6_is_addr_ipv4mapped (const T_IN6_ADDR *addr)
|
---|
263 | {
|
---|
264 | return IN6_IS_ADDR_V4MAPPED(addr);
|
---|
265 | }
|
---|
266 |
|
---|
267 | #if defined(_IP6_CFG) && defined(_IP4_CFG)
|
---|
268 |
|
---|
269 | /*
|
---|
270 | * ip_exchg_addr -- IP ã¢ãã¬ã¹ã交æããã
|
---|
271 | */
|
---|
272 |
|
---|
273 | static void
|
---|
274 | ip6_exchg_addr (T_NET_BUF *nbuf)
|
---|
275 | {
|
---|
276 | T_IP6_HDR *iph;
|
---|
277 | T_IN6_ADDR ipaddr;
|
---|
278 |
|
---|
279 | iph = GET_IP6_HDR(nbuf);
|
---|
280 |
|
---|
281 | /* IPv6 ã¢ãã¬ã¹ã交æããã*/
|
---|
282 | ipaddr = iph->src;
|
---|
283 | iph->src = iph->dst;
|
---|
284 | iph->dst = ipaddr;
|
---|
285 | }
|
---|
286 |
|
---|
287 | static void
|
---|
288 | ip4_exchg_addr (T_NET_BUF *nbuf)
|
---|
289 | {
|
---|
290 | T_IP4_HDR *iph;
|
---|
291 | T_IN4_ADDR ipaddr;
|
---|
292 |
|
---|
293 | iph = GET_IP4_HDR(nbuf);
|
---|
294 |
|
---|
295 | /* IPv4 ã¢ãã¬ã¹ã交æããã*/
|
---|
296 | ipaddr = iph->src;
|
---|
297 | iph->src = iph->dst;
|
---|
298 | iph->dst = ipaddr;
|
---|
299 | }
|
---|
300 |
|
---|
301 | void
|
---|
302 | ip_exchg_addr (T_NET_BUF *nbuf)
|
---|
303 | {
|
---|
304 | if (GET_IP_VER(nbuf) == 6)
|
---|
305 | ip6_exchg_addr(nbuf);
|
---|
306 | else
|
---|
307 | ip4_exchg_addr(nbuf);
|
---|
308 | }
|
---|
309 |
|
---|
310 | #else /* of #if defined(_IP6_CFG) && defined(_IP4_CFG) */
|
---|
311 |
|
---|
312 | /*
|
---|
313 | * ip_exchg_addr -- IP ã¢ãã¬ã¹ã交æããã
|
---|
314 | */
|
---|
315 |
|
---|
316 | void
|
---|
317 | ip_exchg_addr (T_NET_BUF *nbuf)
|
---|
318 | {
|
---|
319 | T_IP_HDR *iph;
|
---|
320 | T_IN_ADDR ipaddr;
|
---|
321 |
|
---|
322 | iph = GET_IP_HDR(nbuf);
|
---|
323 |
|
---|
324 | /* IP ã¢ãã¬ã¹ã交æããã*/
|
---|
325 | ipaddr = iph->src;
|
---|
326 | iph->src = iph->dst;
|
---|
327 | iph->dst = ipaddr;
|
---|
328 | }
|
---|
329 |
|
---|
330 | #endif /* of #if defined(_IP6_CFG) && defined(_IP4_CFG) */
|
---|
331 |
|
---|
332 | #if defined(_IP6_CFG) && defined(_IP4_CFG)
|
---|
333 |
|
---|
334 | /*
|
---|
335 | * inn_is_dstaddr_accept -- å®å
|
---|
336 | ã¢ãã¬ã¹ã¨ãã¦æ£ããããã§ãã¯ããã
|
---|
337 | */
|
---|
338 |
|
---|
339 | bool_t
|
---|
340 | inn_is_dstaddr_accept (T_IN6_ADDR *myaddr, T_NET_BUF *nbuf)
|
---|
341 | {
|
---|
342 | if (GET_IP_VER(nbuf)==IPV6_VERSION)
|
---|
343 | return INN6_IS_DSTADDR_ACCEPT(myaddr, nbuf);
|
---|
344 | else /*if (GET_IP_VER(nbuf)==IPV4_VERSION)*/ {
|
---|
345 | T_IP4_HDR *ip4h;
|
---|
346 |
|
---|
347 | ip4h = GET_IP4_HDR(nbuf);
|
---|
348 | if (IN6_IS_ADDR_UNSPECIFIED(myaddr))
|
---|
349 | return ntohl(ip4h->dst) == IF_GET_IFNET()->in4_ifaddr.addr;
|
---|
350 | else {
|
---|
351 | T_IN6_ADDR dstaddr;
|
---|
352 |
|
---|
353 | return IN6_ARE_ADDR_EQUAL(myaddr, in6_make_ipv4mapped(&dstaddr, ntohl(ip4h->dst)));
|
---|
354 | }
|
---|
355 | }
|
---|
356 | }
|
---|
357 |
|
---|
358 | /*
|
---|
359 | * inn_are_net_srcaddr_equal -- ã¢ãã¬ã¹ãåä¸ããã§ãã¯ããã
|
---|
360 | */
|
---|
361 |
|
---|
362 | bool_t
|
---|
363 | inn_are_net_srcaddr_equal (T_IN6_ADDR *ipaddr, T_NET_BUF *nbuf)
|
---|
364 | {
|
---|
365 | if (GET_IP_VER(nbuf)==IPV6_VERSION)
|
---|
366 | return IN6_ARE_ADDR_EQUAL(ipaddr, &GET_IP6_HDR(nbuf)->src);
|
---|
367 | else /*if (GET_IP_VER(nbuf)==IPV4_VERSION)*/ {
|
---|
368 |
|
---|
369 |
|
---|
370 | T_IN6_ADDR srcaddr;
|
---|
371 |
|
---|
372 | return IN6_ARE_ADDR_EQUAL(ipaddr, in6_make_ipv4mapped(&srcaddr, ntohl(GET_IP4_HDR(nbuf)->src)));
|
---|
373 | }
|
---|
374 | }
|
---|
375 |
|
---|
376 | /*
|
---|
377 | * inn_copy_to_host -- IP ããããããã¹ã表ç¾å¤æãã¦ãIP ã¢ãã¬ã¹ãã³ãã¼ããã
|
---|
378 | */
|
---|
379 |
|
---|
380 | void
|
---|
381 | inn_copy_to_host (T_IN6_ADDR *dst, T_NET_BUF *nbuf)
|
---|
382 | {
|
---|
383 | if (GET_IP_VER(nbuf)==IPV6_VERSION)
|
---|
384 | memcpy(dst, &GET_IP6_HDR(nbuf)->src, sizeof(T_IN6_ADDR));
|
---|
385 | else /*if (GET_IP_VER(nbuf)==IPV4_VERSION)*/
|
---|
386 | in6_make_ipv4mapped(dst, ntohl(GET_IP4_HDR(nbuf)->src));
|
---|
387 |
|
---|
388 | }
|
---|
389 |
|
---|
390 | /*
|
---|
391 | * inn_get_datagram -- IPv6/IPv4 ãã¼ã¿ã°ã©ã ãç²å¾ããããããè¨å®ããã
|
---|
392 | */
|
---|
393 |
|
---|
394 | ER
|
---|
395 | inn_get_datagram (T_NET_BUF **nbuf, uint_t len, uint_t maxlen,
|
---|
396 | T_IN6_ADDR *dstaddr, T_IN6_ADDR *srcaddr,
|
---|
397 | uint8_t next, uint8_t hlim, ATR nbatr, TMO tmout)
|
---|
398 | {
|
---|
399 | if (IN6_IS_ADDR_V4MAPPED(dstaddr)) {
|
---|
400 | T_IN4_ADDR ip4dstaddr, ip4srcaddr;
|
---|
401 |
|
---|
402 | ip4dstaddr = ntohl(dstaddr->s6_addr32[3]);
|
---|
403 | if (IN6_IS_ADDR_UNSPECIFIED(srcaddr))
|
---|
404 | ip4srcaddr = IF_GET_IFNET()->in4_ifaddr.addr;
|
---|
405 | else
|
---|
406 | ip4srcaddr = ntohl(srcaddr->s6_addr32[3]);
|
---|
407 |
|
---|
408 | return in4_get_datagram(nbuf, len, maxlen, &ip4dstaddr, &ip4srcaddr, next, hlim, nbatr, tmout);
|
---|
409 | }
|
---|
410 | else
|
---|
411 | return in6_get_datagram(nbuf, len, maxlen, dstaddr, srcaddr, next, hlim, nbatr, tmout);
|
---|
412 | }
|
---|
413 |
|
---|
414 | /*
|
---|
415 | * inn_addrwithifp -- å®å
|
---|
416 | ã¢ãã¬ã¹ã«ãµããããéä¿¡å
|
---|
417 | ã¢ãã¬ã¹ãã
|
---|
418 | * ãããã¯ã¼ã¯ã¤ã³ã¿ãã§ã¼ã¹ããæ¢ç´¢ããã
|
---|
419 | */
|
---|
420 |
|
---|
421 | T_IN6_ADDR *
|
---|
422 | inn_addrwithifp (T_IFNET *ifp, T_IN6_ADDR *src, T_IN6_ADDR *dst)
|
---|
423 | {
|
---|
424 | T_IN6_IFADDR *ifaddr;
|
---|
425 |
|
---|
426 | if (IN6_IS_ADDR_V4MAPPED(dst))
|
---|
427 | return in6_make_ipv4mapped (src, ifp->in4_ifaddr.addr);
|
---|
428 | else if ((ifaddr = in6_ifawithifp(ifp, dst)) == NULL)
|
---|
429 | return NULL;
|
---|
430 | else {
|
---|
431 | *src = ifaddr->addr;
|
---|
432 | return src;
|
---|
433 | }
|
---|
434 | }
|
---|
435 |
|
---|
436 | /*
|
---|
437 | * inn_is_addr_multicast -- ã¢ãã¬ã¹ããã«ããã£ã¹ãã¢ãã¬ã¹ããã§ãã¯ããã
|
---|
438 | */
|
---|
439 |
|
---|
440 | bool_t
|
---|
441 | inn_is_addr_multicast (T_IN6_ADDR *addr)
|
---|
442 | {
|
---|
443 |
|
---|
444 | if (IN6_IS_ADDR_V4MAPPED(addr))
|
---|
445 | return IN4_IS_ADDR_MULTICAST(ntohl(addr->s6_addr32[3]));
|
---|
446 | else
|
---|
447 | return IN6_IS_ADDR_MULTICAST(addr);
|
---|
448 | }
|
---|
449 |
|
---|
450 | #endif /* of #if defined(_IP6_CFG) && defined(_IP4_CFG) */
|
---|
451 |
|
---|
452 | /*
|
---|
453 | * ãã¤ããªã¼ãé¢æ°ã®å®ç¾©
|
---|
454 | *
|
---|
455 | * tinet/net/net.h ã§ããã¤ããªã¼ãã®å®ç¾©ãè¡ã£ã¦ãããã
|
---|
456 | * tinet/net/net.h ãã¤ã³ã¯ã«ã¼ãããªã
|
---|
457 | * ã¢ããªã±ã¼ã·ã§ã³ããã°ã©ã ç¨ã«
|
---|
458 | * ã¿ã¼ã²ããä¾åããªããã¤ããªã¼ãé¢æ°ãå®ç¾©ããã
|
---|
459 | */
|
---|
460 |
|
---|
461 | #if defined(_NET_CFG_BYTE_ORDER)
|
---|
462 |
|
---|
463 | #undef ntohs
|
---|
464 | #undef htons
|
---|
465 | #undef ntohl
|
---|
466 | #undef htonl
|
---|
467 |
|
---|
468 | #if _NET_CFG_BYTE_ORDER == _NET_CFG_BIG_ENDIAN
|
---|
469 |
|
---|
470 | uint16_t
|
---|
471 | ntohs (uint16_t net)
|
---|
472 | {
|
---|
473 | return net;
|
---|
474 | }
|
---|
475 |
|
---|
476 | uint16_t
|
---|
477 | htons (uint16_t host)
|
---|
478 | {
|
---|
479 | return host;
|
---|
480 | }
|
---|
481 |
|
---|
482 | uint32_t
|
---|
483 | ntohl (uint32_t net)
|
---|
484 | {
|
---|
485 | return net;
|
---|
486 | }
|
---|
487 |
|
---|
488 | uint32_t
|
---|
489 | htonl (uint32_t host)
|
---|
490 | {
|
---|
491 | return host;
|
---|
492 | }
|
---|
493 |
|
---|
494 | #elif _NET_CFG_BYTE_ORDER == _NET_CFG_LITTLE_ENDIAN /* of #if _NET_CFG_BYTE_ORDER == _NET_CFG_BIG_ENDIAN */
|
---|
495 |
|
---|
496 | uint16_t
|
---|
497 | ntohs (uint16_t net)
|
---|
498 | {
|
---|
499 | return NET_REV_ENDIAN_HWORD(net);
|
---|
500 | }
|
---|
501 |
|
---|
502 | uint16_t
|
---|
503 | htons (uint16_t host)
|
---|
504 | {
|
---|
505 | return NET_REV_ENDIAN_HWORD(host);
|
---|
506 | }
|
---|
507 |
|
---|
508 | uint32_t
|
---|
509 | ntohl (uint32_t net)
|
---|
510 | {
|
---|
511 | return NET_REV_ENDIAN_WORD(net);
|
---|
512 | }
|
---|
513 |
|
---|
514 | uint32_t
|
---|
515 | htonl (uint32_t host)
|
---|
516 | {
|
---|
517 | return NET_REV_ENDIAN_WORD(host);
|
---|
518 | }
|
---|
519 |
|
---|
520 | #else /* #if _NET_CFG_BYTE_ORDER == _NET_CFG_BIG_ENDIAN */
|
---|
521 |
|
---|
522 | #error "_NET_CFG_BYTE_ORDER expected."
|
---|
523 |
|
---|
524 | #endif /* #if _NET_CFG_BYTE_ORDER == _NET_CFG_BIG_ENDIAN */
|
---|
525 |
|
---|
526 | #endif /* of #if defined(_NET_CFG_BYTE_ORDER) */
|
---|