Watt-32 tcp/ip  2.2 dev-rel.10
ip6_out.c
Go to the documentation of this file.
1 
5 /*
6  * Copyright (c) 1997-2002 Gisle Vanem <gvanem@yahoo.no>
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  * 1. Redistributions of source code must retain the above copyright
12  * notice, this list of conditions and the following disclaimer.
13  * 2. Redistributions in binary form must reproduce the above copyright
14  * notice, this list of conditions and the following disclaimer in the
15  * documentation and/or other materials provided with the distribution.
16  * 3. All advertising materials mentioning features or use of this software
17  * must display the following acknowledgement:
18  * This product includes software developed by Gisle Vanem
19  * Bergen, Norway.
20  *
21  * THIS SOFTWARE IS PROVIDED BY ME (Gisle Vanem) AND CONTRIBUTORS ``AS IS''
22  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24  * ARE DISCLAIMED. IN NO EVENT SHALL I OR CONTRIBUTORS BE LIABLE FOR ANY
25  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
26  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
27  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
28  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
30  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  *
32  * Version
33  *
34  * 0.5 : Jul 29, 2002 : G. Vanem - created
35  *
36  */
37 
38 #include <stdio.h>
39 #include <stdlib.h>
40 
41 #include "wattcp.h"
42 #include "misc.h"
43 #include "chksum.h"
44 #include "pcsed.h"
45 #include "ip4_out.h"
46 #include "ip6_out.h"
47 #include "socket.h"
48 
49 /* \if USE_IPV6 */
50 #if defined(USE_IPV6)
51 
52 struct in6_addr in6addr_my_ip = {{ 0,0,0,0,0,0,0,0,
53  0,0,0,0,0,0,0,0 }};
54 
55 const struct in6_addr in6addr_loopback = {{ 0,0,0,0,0,0,0,0,
56  0,0,0,0,0,0,0,1 }};
57 const struct in6_addr in6addr_any = {{ 0,0,0,0,0,0,0,0,
58  0,0,0,0,0,0,0,0 }};
59 const struct in6_addr in6addr_all_1 = {{ 0xFF,0xFF,0xFF,0xFF,
60  0xFF,0xFF,0xFF,0xFF,
61  0xFF,0xFF,0xFF,0xFF,
62  0xFF,0xFF,0xFF,0xFF }};
63 /* all nodes multicast address */
64 const struct in6_addr in6addr_alln_mc = {{ 0xFF,2,0,0,0,0,0,0,
65  0,0,0,0,0,0,0,1 }};
66 /* all routers multicast address */
67 const struct in6_addr in6addr_allr_mc = {{ 0xFF,2,0,0,0,0,0,0,
68  0,0,0,0,0,0,0,2 }};
69 
70 const BYTE in6addr_mapped[12] = { 0,0,0,0, 0,0,0,0, 0,0,0xFF,0xFF };
71 
72 int _default6_ttl = 255; /* TTL on outgoing packets */
73 
74 int _ip6_output (in6_Header *ip, /* IPv6-structure to fill in */
75  ip6_address *src_ip, /* Source address */
76  ip6_address *dst_ip, /* Destination address */
77  BYTE protocol, /* Upper-level protocol */
78  unsigned data_len, /* Length of data after IPv6 header */
79  int hop_lim, /* Hop limit, 0 means default */
80  const void *sock, /* Which socket is this */
81  const char *file, /* Debug: from what file */
82  unsigned line) /* and line we where called */
83 {
84  unsigned total = data_len + sizeof(*ip);
85 
86  if (total > _mtu)
87  return (0);
88 
89  if (!src_ip)
90  src_ip = (ip6_address*)&in6addr_my_ip;
91 
92  ip->pri = 0;
93  ip->ver = 6;
94  ip->len = intel16 ((WORD)data_len);
95  ip->hop_limit = hop_lim ? hop_lim : _default6_ttl;
96 
97  if (protocol == 0 || data_len == 0) /* Only an IP6 header */
98  ip->next_hdr = IP6_NEXT_NONE;
99  else ip->next_hdr = protocol;
100 
101  memset (&ip->flow_lbl, 0, sizeof(ip->flow_lbl));
102 
103  if (&ip->source != src_ip) /* assumes ptr set by caller */
104  memcpy (&ip->source, src_ip, sizeof(ip->source));
105 
106  if (&ip->destination != dst_ip)
107  memcpy (&ip->destination, dst_ip, sizeof(ip->destination));
108 
109  if (IN6_IS_ADDR_LOOPBACK(&ip->destination) ||
110  IN6_IS_ADDR_MULTICAST(&ip->source))
111  return (0);
112 
115  return _eth_send (total, sock, file, line);
116 }
117 #endif /* USE_IPV6 */
118 /* \endif */
int W32_CALL _eth_send(WORD len, const void *sock, const char *file, unsigned line)
_eth_send() does the actual transmission once we are complete with filling the buffer.
Definition: pcsed.c:306
Core definitions.
Definition: in.h:153
Definition: ip.h:67
int _ip6_output(in6_Header *ip, ip6_address *src_ip, ip6_address *dst_ip, BYTE protocol, unsigned data_len, int hop_lim, const void *sock, const char *file, unsigned line)
Definition: ip6_out.c:74