rthdr.c (333fc21e3cd79bca0c94d7722c5a56cb5ad078d1) rthdr.c (88ff5695c1e53c3398142ea10e3f041ff4b5a03f)
1/* $KAME: rthdr.c,v 1.8 2001/08/20 02:32:40 itojun Exp $ */
2
1/*
2 * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 212 unchanged lines hidden (view full) ---

221 fprintf(stderr, "inet6_rthdr_segments: unknown type(%d)\n",
222 rthdr->ip6r_type);
223#endif
224 return -1;
225 }
226}
227
228struct in6_addr *
3/*
4 * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright

--- 212 unchanged lines hidden (view full) ---

223 fprintf(stderr, "inet6_rthdr_segments: unknown type(%d)\n",
224 rthdr->ip6r_type);
225#endif
226 return -1;
227 }
228}
229
230struct in6_addr *
229inet6_rthdr_getaddr(cmsg, index)
231inet6_rthdr_getaddr(cmsg, idx)
230 struct cmsghdr *cmsg;
232 struct cmsghdr *cmsg;
231 int index;
233 int idx;
232{
233 struct ip6_rthdr *rthdr;
234
235 rthdr = (struct ip6_rthdr *)CMSG_DATA(cmsg);
236
237 switch(rthdr->ip6r_type) {
238 case IPV6_RTHDR_TYPE_0:
239 {
240 struct ip6_rthdr0 *rt0 = (struct ip6_rthdr0 *)rthdr;
241 int naddr;
242
243 if (rt0->ip6r0_len % 2 || 46 < rt0->ip6r0_len) {
244#ifdef DEBUG
245 fprintf(stderr, "inet6_rthdr_getaddr: invalid size(%d)\n",
246 rt0->ip6r0_len);
247#endif
248 return NULL;
249 }
250 naddr = (rt0->ip6r0_len * 8) / sizeof(struct in6_addr);
234{
235 struct ip6_rthdr *rthdr;
236
237 rthdr = (struct ip6_rthdr *)CMSG_DATA(cmsg);
238
239 switch(rthdr->ip6r_type) {
240 case IPV6_RTHDR_TYPE_0:
241 {
242 struct ip6_rthdr0 *rt0 = (struct ip6_rthdr0 *)rthdr;
243 int naddr;
244
245 if (rt0->ip6r0_len % 2 || 46 < rt0->ip6r0_len) {
246#ifdef DEBUG
247 fprintf(stderr, "inet6_rthdr_getaddr: invalid size(%d)\n",
248 rt0->ip6r0_len);
249#endif
250 return NULL;
251 }
252 naddr = (rt0->ip6r0_len * 8) / sizeof(struct in6_addr);
251 if (index <= 0 || naddr < index) {
253 if (idx <= 0 || naddr < idx) {
252#ifdef DEBUG
254#ifdef DEBUG
253 fprintf(stderr, "inet6_rthdr_getaddr: invalid index(%d)\n", index);
255 fprintf(stderr, "inet6_rthdr_getaddr: invalid idx(%d)\n", idx);
254#endif
255 return NULL;
256 }
256#endif
257 return NULL;
258 }
257 return &rt0->ip6r0_addr[index - 1];
259 return &rt0->ip6r0_addr[idx - 1];
258 }
259
260 default:
261#ifdef DEBUG
262 fprintf(stderr, "inet6_rthdr_getaddr: unknown type(%d)\n",
263 rthdr->ip6r_type);
264#endif
265 return NULL;
266 }
267}
268
269int
260 }
261
262 default:
263#ifdef DEBUG
264 fprintf(stderr, "inet6_rthdr_getaddr: unknown type(%d)\n",
265 rthdr->ip6r_type);
266#endif
267 return NULL;
268 }
269}
270
271int
270inet6_rthdr_getflags(cmsg, index)
272inet6_rthdr_getflags(cmsg, idx)
271 const struct cmsghdr *cmsg;
273 const struct cmsghdr *cmsg;
272 int index;
274 int idx;
273{
274 struct ip6_rthdr *rthdr;
275
276 rthdr = (struct ip6_rthdr *)CMSG_DATA(cmsg);
277
278 switch(rthdr->ip6r_type) {
279 case IPV6_RTHDR_TYPE_0:
280 {
281 struct ip6_rthdr0 *rt0 = (struct ip6_rthdr0 *)rthdr;
282 int naddr;
283
284 if (rt0->ip6r0_len % 2 || 46 < rt0->ip6r0_len) {
285#ifdef DEBUG
286 fprintf(stderr, "inet6_rthdr_getflags: invalid size(%d)\n",
287 rt0->ip6r0_len);
288#endif
289 return -1;
290 }
291 naddr = (rt0->ip6r0_len * 8) / sizeof(struct in6_addr);
275{
276 struct ip6_rthdr *rthdr;
277
278 rthdr = (struct ip6_rthdr *)CMSG_DATA(cmsg);
279
280 switch(rthdr->ip6r_type) {
281 case IPV6_RTHDR_TYPE_0:
282 {
283 struct ip6_rthdr0 *rt0 = (struct ip6_rthdr0 *)rthdr;
284 int naddr;
285
286 if (rt0->ip6r0_len % 2 || 46 < rt0->ip6r0_len) {
287#ifdef DEBUG
288 fprintf(stderr, "inet6_rthdr_getflags: invalid size(%d)\n",
289 rt0->ip6r0_len);
290#endif
291 return -1;
292 }
293 naddr = (rt0->ip6r0_len * 8) / sizeof(struct in6_addr);
292 if (index < 0 || naddr < index) {
294 if (idx < 0 || naddr < idx) {
293#ifdef DEBUG
295#ifdef DEBUG
294 fprintf(stderr, "inet6_rthdr_getflags: invalid index(%d)\n", index);
296 fprintf(stderr, "inet6_rthdr_getflags: invalid idx(%d)\n", idx);
295#endif
296 return -1;
297 }
297#endif
298 return -1;
299 }
298 if (rt0->ip6r0_slmap[index / 8] & (0x80 >> (index % 8)))
300 if (rt0->ip6r0_slmap[idx / 8] & (0x80 >> (idx % 8)))
299 return IPV6_RTHDR_STRICT;
300 else
301 return IPV6_RTHDR_LOOSE;
302 }
303
304 default:
305#ifdef DEBUG
306 fprintf(stderr, "inet6_rthdr_getflags: unknown type(%d)\n",
307 rthdr->ip6r_type);
308#endif
309 return -1;
310 }
311}
301 return IPV6_RTHDR_STRICT;
302 else
303 return IPV6_RTHDR_LOOSE;
304 }
305
306 default:
307#ifdef DEBUG
308 fprintf(stderr, "inet6_rthdr_getflags: unknown type(%d)\n",
309 rthdr->ip6r_type);
310#endif
311 return -1;
312 }
313}