Cleanup, reindent, NULL -> 0.
1.1 --- a/examples/test-ipv6.cc Tue Sep 08 07:07:58 2009 +0200
1.2 +++ b/examples/test-ipv6.cc Tue Sep 08 18:40:47 2009 +0200
1.3 @@ -20,7 +20,6 @@
1.4 */
1.5
1.6 #include "ns3/log.h"
1.7 -//#include "ns3/ipv6.h"
1.8 #include "ns3/ipv6-address.h"
1.9 #include "ns3/node.h"
1.10 #include "ns3/mac48-address.h"
1.11 @@ -38,24 +37,24 @@
1.12
1.13 Mac48Address m_addresses[10];
1.14
1.15 - m_addresses[0]=("00:00:00:00:00:01");
1.16 - m_addresses[1]=("00:00:00:00:00:02");
1.17 - m_addresses[2]=("00:00:00:00:00:03");
1.18 - m_addresses[3]=("00:00:00:00:00:04");
1.19 - m_addresses[4]=("00:00:00:00:00:05");
1.20 - m_addresses[5]=("00:00:00:00:00:06");
1.21 - m_addresses[6]=("00:00:00:00:00:07");
1.22 - m_addresses[7]=("00:00:00:00:00:08");
1.23 - m_addresses[8]=("00:00:00:00:00:09");
1.24 - m_addresses[9]=("00:00:00:00:00:10");
1.25 + m_addresses[0] = ("00:00:00:00:00:01");
1.26 + m_addresses[1] = ("00:00:00:00:00:02");
1.27 + m_addresses[2] = ("00:00:00:00:00:03");
1.28 + m_addresses[3] = ("00:00:00:00:00:04");
1.29 + m_addresses[4] = ("00:00:00:00:00:05");
1.30 + m_addresses[5] = ("00:00:00:00:00:06");
1.31 + m_addresses[6] = ("00:00:00:00:00:07");
1.32 + m_addresses[7] = ("00:00:00:00:00:08");
1.33 + m_addresses[8] = ("00:00:00:00:00:09");
1.34 + m_addresses[9] = ("00:00:00:00:00:10");
1.35
1.36 Ipv6Address prefix1 ("2001:1::");
1.37 NS_LOG_INFO ("prefix = " << prefix1);
1.38 for (uint32_t i = 0; i < 10 ; ++i)
1.39 {
1.40 - NS_LOG_INFO ("address = " <<m_addresses[i]);
1.41 - Ipv6Address ipv6address=Ipv6Address::MakeAutoconfiguredAddress(m_addresses[i], prefix1);
1.42 - NS_LOG_INFO ("address = " <<ipv6address);
1.43 + NS_LOG_INFO ("address = " << m_addresses[i]);
1.44 + Ipv6Address ipv6address = Ipv6Address::MakeAutoconfiguredAddress (m_addresses[i], prefix1);
1.45 + NS_LOG_INFO ("address = " << ipv6address);
1.46 }
1.47
1.48 Ipv6Address prefix2 ("2002:1:1::");
1.49 @@ -63,8 +62,8 @@
1.50 NS_LOG_INFO ("prefix = " << prefix2);
1.51 for (uint32_t i = 0; i < 10 ; ++i)
1.52 {
1.53 - Ipv6Address ipv6address=Ipv6Address::MakeAutoconfiguredAddress(m_addresses[i], prefix2);
1.54 - NS_LOG_INFO ("address = " <<ipv6address);
1.55 + Ipv6Address ipv6address = Ipv6Address::MakeAutoconfiguredAddress (m_addresses[i], prefix2);
1.56 + NS_LOG_INFO ("address = " << ipv6address);
1.57 }
1.58 }
1.59
2.1 --- a/src/internet-stack/icmpv4.h Tue Sep 08 07:07:58 2009 +0200
2.2 +++ b/src/internet-stack/icmpv4.h Tue Sep 08 18:40:47 2009 +0200
2.3 @@ -1,3 +1,23 @@
2.4 +/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
2.5 +/*
2.6 + * Copyright (c) 2008 INRIA
2.7 + *
2.8 + * This program is free software; you can redistribute it and/or modify
2.9 + * it under the terms of the GNU General Public License version 2 as
2.10 + * published by the Free Software Foundation;
2.11 + *
2.12 + * This program is distributed in the hope that it will be useful,
2.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
2.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2.15 + * GNU General Public License for more details.
2.16 + *
2.17 + * You should have received a copy of the GNU General Public License
2.18 + * along with this program; if not, write to the Free Software
2.19 + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
2.20 + *
2.21 + * Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
2.22 + */
2.23 +
2.24 #ifndef ICMPV4_H
2.25 #define ICMPV4_H
2.26
3.1 --- a/src/internet-stack/icmpv6-header.h Tue Sep 08 07:07:58 2009 +0200
3.2 +++ b/src/internet-stack/icmpv6-header.h Tue Sep 08 18:40:47 2009 +0200
3.3 @@ -47,7 +47,7 @@
3.4 ICMPV6_ERROR_PACKET_TOO_BIG,
3.5 ICMPV6_ERROR_TIME_EXCEEDED,
3.6 ICMPV6_ERROR_PARAMETER_ERROR,
3.7 - ICMPV6_ECHO_REQUEST=128,
3.8 + ICMPV6_ECHO_REQUEST = 128,
3.9 ICMPV6_ECHO_REPLY,
3.10 ICMPV6_SUBSCRIBE_REQUEST,
3.11 ICMPV6_SUBSCRIBE_REPORT,
4.1 --- a/src/internet-stack/icmpv6-l4-protocol.cc Tue Sep 08 07:07:58 2009 +0200
4.2 +++ b/src/internet-stack/icmpv6-l4-protocol.cc Tue Sep 08 18:40:47 2009 +0200
4.3 @@ -278,7 +278,7 @@
4.4 {
4.5 NS_LOG_FUNCTION (this << lla << src << dst << interface);
4.6 Address hardwareAddress;
4.7 - NdiscCache::Entry* entry = NULL;
4.8 + NdiscCache::Entry* entry = 0;
4.9 Ptr<NdiscCache> cache = FindCache (interface->GetDevice ());
4.10
4.11 /* check if we have this address in our cache */
4.12 @@ -347,7 +347,7 @@
4.13 packet->RemoveHeader (rsHeader);
4.14 Address hardwareAddress;
4.15 Icmpv6OptionLinkLayerAddress lla (1);
4.16 - NdiscCache::Entry* entry = NULL;
4.17 + NdiscCache::Entry* entry = 0;
4.18 Ptr<NdiscCache> cache = FindCache (interface->GetDevice ());
4.19
4.20 if (src != Ipv6Address::GetAny ())
4.21 @@ -664,7 +664,7 @@
4.22 if (hasLla)
4.23 {
4.24 /* update the cache if needed */
4.25 - NdiscCache::Entry* entry = NULL;
4.26 + NdiscCache::Entry* entry = 0;
4.27 Ptr<NdiscCache> cache = FindCache (interface->GetDevice ());
4.28
4.29 entry = cache->Lookup (redirTarget);
5.1 --- a/src/node/ipv6-address.cc Tue Sep 08 07:07:58 2009 +0200
5.2 +++ b/src/node/ipv6-address.cc Tue Sep 08 18:40:47 2009 +0200
5.3 @@ -33,119 +33,141 @@
5.4
5.5 #ifdef __cplusplus
5.6 extern "C"
5.7 -{
5.8 +{ /* } */
5.9 #endif
5.10
5.11 - /**
5.12 - * \brief Get a hash key.
5.13 - * \param k the key
5.14 - * \param length the length of the key
5.15 - * \param level the previous hash, or an arbitrary value
5.16 - * \return hash
5.17 - * \note Adpated from Jens Jakobsen implementation (chillispot).
5.18 - */
5.19 - static uint32_t lookuphash (unsigned char* k, uint32_t length, uint32_t level)
5.20 +/**
5.21 + * \brief Get a hash key.
5.22 + * \param k the key
5.23 + * \param length the length of the key
5.24 + * \param level the previous hash, or an arbitrary value
5.25 + * \return hash
5.26 + * \note Adapted from Jens Jakobsen implementation (chillispot).
5.27 + */
5.28 +static uint32_t lookuphash (unsigned char* k, uint32_t length, uint32_t level)
5.29 +{
5.30 +#define mix(a, b, c) \
5.31 +({ \
5.32 + (a) -= (b); (a) -= (c); (a) ^= ((c) >> 13); \
5.33 + (b) -= (c); (b) -= (a); (b) ^= ((a) << 8); \
5.34 + (c) -= (a); (c) -= (b); (c) ^= ((b) >> 13); \
5.35 + (a) -= (b); (a) -= (c); (a) ^= ((c) >> 12); \
5.36 + (b) -= (c); (b) -= (a); (b) ^= ((a) << 16); \
5.37 + (c) -= (a); (c) -= (b); (c) ^= ((b) >> 5); \
5.38 + (a) -= (b); (a) -= (c); (a) ^= ((c) >> 3); \
5.39 + (b) -= (c); (b) -= (a); (b) ^= ((a) << 10); \
5.40 + (c) -= (a); (c) -= (b); (c) ^= ((b) >> 15); \
5.41 +})
5.42 +
5.43 + typedef uint32_t ub4; /* unsigned 4-byte quantities */
5.44 + typedef unsigned char ub1; /* unsigned 1-byte quantities */
5.45 + uint32_t a = 0;
5.46 + uint32_t b = 0;
5.47 + uint32_t c = 0;
5.48 + uint32_t len = 0;
5.49 +
5.50 + /* Set up the internal state */
5.51 + len = length;
5.52 + a = b = 0x9e3779b9; /* the golden ratio; an arbitrary value */
5.53 + c = level; /* the previous hash value */
5.54 +
5.55 + /* handle most of the key */
5.56 + while (len >= 12)
5.57 {
5.58 -#define mix(a,b,c) \
5.59 - { \
5.60 - a -= b; a -= c; a ^= (c>>13); \
5.61 - b -= c; b -= a; b ^= (a<<8); \
5.62 - c -= a; c -= b; c ^= (b>>13); \
5.63 - a -= b; a -= c; a ^= (c>>12); \
5.64 - b -= c; b -= a; b ^= (a<<16); \
5.65 - c -= a; c -= b; c ^= (b>>5); \
5.66 - a -= b; a -= c; a ^= (c>>3); \
5.67 - b -= c; b -= a; b ^= (a<<10); \
5.68 - c -= a; c -= b; c ^= (b>>15); \
5.69 - }
5.70 + a += (k[0] + ((ub4)k[1] << 8) + ((ub4)k[2] << 16) + ((ub4)k[3] << 24));
5.71 + b += (k[4] + ((ub4)k[5] << 8) + ((ub4)k[6] << 16) + ((ub4)k[7] << 24));
5.72 + c += (k[8] + ((ub4)k[9] << 8) + ((ub4)k[10] << 16) + ((ub4)k[11] << 24));
5.73 + mix (a, b, c);
5.74 + k += 12;
5.75 + len -= 12;
5.76 + }
5.77
5.78 - typedef uint32_t ub4; /* unsigned 4-byte quantities */
5.79 - typedef unsigned char ub1; /* unsigned 1-byte quantities */
5.80 - uint32_t a,b,c,len;
5.81 + /* handle the last 11 bytes */
5.82 + c += length;
5.83 + switch (len) /* all the case statements fall through */
5.84 + {
5.85 + case 11: c += ((ub4)k[10] << 24);
5.86 + case 10: c += ((ub4)k[9] << 16);
5.87 + case 9 : c += ((ub4)k[8] << 8); /* the first byte of c is reserved for the length */
5.88 + case 8 : b += ((ub4)k[7] << 24);
5.89 + case 7 : b += ((ub4)k[6] << 16);
5.90 + case 6 : b += ((ub4)k[5] << 8);
5.91 + case 5 : b += k[4];
5.92 + case 4 : a += ((ub4)k[3] << 24);
5.93 + case 3 : a += ((ub4)k[2] << 16);
5.94 + case 2 : a += ((ub4)k[1] << 8);
5.95 + case 1 : a += k[0];
5.96 + /* case 0: nothing left to add */
5.97 + }
5.98 + mix (a, b, c);
5.99 +
5.100 +#undef mix
5.101
5.102 - /* Set up the internal state */
5.103 - len = length;
5.104 - a = b = 0x9e3779b9; /* the golden ratio; an arbitrary value */
5.105 - c = level; /* the previous hash value */
5.106 + /* report the result */
5.107 + return c;
5.108 +}
5.109
5.110 - /*---------------------------------------- handle most of the key */
5.111 - while (len >= 12)
5.112 - {
5.113 - a += (k[0] +((ub4)k[1]<<8) +((ub4)k[2]<<16) +((ub4)k[3]<<24));
5.114 - b += (k[4] +((ub4)k[5]<<8) +((ub4)k[6]<<16) +((ub4)k[7]<<24));
5.115 - c += (k[8] +((ub4)k[9]<<8) +((ub4)k[10]<<16)+((ub4)k[11]<<24));
5.116 - mix(a, b, c);
5.117 - k += 12; len -= 12;
5.118 - }
5.119 -
5.120 - /*------------------------------------- handle the last 11 bytes */
5.121 - c += length;
5.122 - switch (len) /* all the case statements fall through */
5.123 - {
5.124 - case 11: c+=((ub4)k[10]<<24);
5.125 - case 10: c+=((ub4)k[9]<<16);
5.126 - case 9 : c+=((ub4)k[8]<<8);
5.127 - /* the first byte of c is reserved for the length */
5.128 - case 8 : b+=((ub4)k[7]<<24);
5.129 - case 7 : b+=((ub4)k[6]<<16);
5.130 - case 6 : b+=((ub4)k[5]<<8);
5.131 - case 5 : b+=k[4];
5.132 - case 4 : a+=((ub4)k[3]<<24);
5.133 - case 3 : a+=((ub4)k[2]<<16);
5.134 - case 2 : a+=((ub4)k[1]<<8);
5.135 - case 1 : a+=k[0];
5.136 - /* case 0: nothing left to add */
5.137 - }
5.138 - mix(a, b, c);
5.139 - /*-------------------------------------------- report the result */
5.140 - return c;
5.141 - }
5.142 #ifdef __cplusplus
5.143 }
5.144 #endif
5.145
5.146 /**
5.147 * \brief Convert an IPv6 C-string into a 128-bit representation.
5.148 - * \return 1 if OK, 0 if failure (bad format, ...)
5.149 + * \return true if success, false otherwise (bad format, ...)
5.150 * \note This function is strongly inspired by inet_pton6() from Paul Vixie.
5.151 * \todo Handle IPv6 address with decimal value for last four bytes.
5.152 */
5.153 -static int AsciiToIpv6Host (char const *address, uint8_t addr[16])
5.154 +static bool AsciiToIpv6Host (const char *address, uint8_t addr[16])
5.155 {
5.156 - static const char xdigits_l[] = "0123456789abcdef",
5.157 - xdigits_u[] = "0123456789ABCDEF";
5.158 - unsigned char tmp[16 /*NS_IN6ADDRSZ*/], *tp, *endp, *colonp;
5.159 - const char *xdigits, *curtok;
5.160 - int ch, seen_xdigits;
5.161 - unsigned int val;
5.162 + static const char xdigits_l[] = "0123456789abcdef";
5.163 + static const char xdigits_u[] = "0123456789ABCDEF";
5.164 + unsigned char tmp[16];
5.165 + unsigned char* tp = tmp;
5.166 + unsigned char* endp = 0;
5.167 + unsigned char* colonp = 0;
5.168 + const char* xdigits = 0;
5.169 + const char* curtok = 0;
5.170 + int ch = 0;
5.171 + int seen_xdigits = 0;
5.172 + unsigned int val = 0;
5.173
5.174 - memset ((tp = tmp), '\0', 16 /* NS_IN6ADDRSZ*/);
5.175 - endp = tp + 16 /*NS_IN6ADDRSZ*/;
5.176 - colonp = NULL;
5.177 + memset (tp, 0x00, 16);
5.178 + endp = tp + 16;
5.179 +
5.180 /* Leading :: requires some special handling. */
5.181 if (*address == ':')
5.182 + {
5.183 if (*++address != ':')
5.184 + {
5.185 return (0);
5.186 + }
5.187 + }
5.188 curtok = address;
5.189 - seen_xdigits = 0;
5.190 - val = 0;
5.191 +
5.192 while ((ch = *address++) != '\0')
5.193 {
5.194 - const char *pch;
5.195 + const char *pch = 0;
5.196
5.197 - if ((pch = strchr ((xdigits = xdigits_l), ch)) == NULL)
5.198 + if ((pch = strchr ((xdigits = xdigits_l), ch)) == 0)
5.199 + {
5.200 pch = strchr ((xdigits = xdigits_u), ch);
5.201 - if (pch != NULL)
5.202 + }
5.203 +
5.204 + if (pch != 0)
5.205 {
5.206 val <<= 4;
5.207 val |= (pch - xdigits);
5.208 +
5.209 if (++seen_xdigits > 4)
5.210 + {
5.211 return (0);
5.212 + }
5.213 continue;
5.214 }
5.215 if (ch == ':')
5.216 {
5.217 curtok = address;
5.218 +
5.219 if (!seen_xdigits)
5.220 {
5.221 if (colonp)
5.222 @@ -153,8 +175,12 @@
5.223 colonp = tp;
5.224 continue;
5.225 }
5.226 - if (tp + 2 /*NS_INT16SZ*/ > endp)
5.227 +
5.228 + if (tp + 2 > endp)
5.229 + {
5.230 return (0);
5.231 + }
5.232 +
5.233 *tp++ = (unsigned char) (val >> 8) & 0xff;
5.234 *tp++ = (unsigned char) val & 0xff;
5.235 seen_xdigits = 0;
5.236 @@ -174,35 +200,45 @@
5.237 #endif
5.238 return (0);
5.239 }
5.240 +
5.241 if (seen_xdigits)
5.242 {
5.243 - if (tp + 2/* NS_INT16SZ*/ > endp)
5.244 + if (tp + 2 > endp)
5.245 + {
5.246 return (0);
5.247 + }
5.248 *tp++ = (unsigned char) (val >> 8) & 0xff;
5.249 *tp++ = (unsigned char) val & 0xff;
5.250 }
5.251 - if (colonp != NULL)
5.252 +
5.253 + if (colonp != 0)
5.254 {
5.255 /*
5.256 * Since some memmove ()'s erroneously fail to handle
5.257 * overlapping regions, we'll do the shift by hand.
5.258 */
5.259 const int n = tp - colonp;
5.260 - int i;
5.261 + int i = 0;
5.262
5.263 if (tp == endp)
5.264 + {
5.265 return (0);
5.266 + }
5.267 +
5.268 for (i = 1; i <= n; i++)
5.269 {
5.270 endp[- i] = colonp[n - i];
5.271 colonp[n - i] = 0;
5.272 }
5.273 +
5.274 tp = endp;
5.275 }
5.276 +
5.277 if (tp != endp)
5.278 + {
5.279 return (0);
5.280 + }
5.281
5.282 - /* memcpy (dst, tmp, NS_IN6ADDRSZ); */
5.283 memcpy (addr, tmp, 16);
5.284 return (1);
5.285 }
5.286 @@ -357,7 +393,7 @@
5.287 return false;
5.288 }
5.289
5.290 -Ipv6Address Ipv6Address::CombinePrefix (Ipv6Prefix const & prefix)
5.291 +Ipv6Address Ipv6Address::CombinePrefix (Ipv6Prefix const& prefix)
5.292 {
5.293 Ipv6Address ipv6;
5.294 uint8_t addr[16];
5.295 @@ -447,33 +483,21 @@
5.296 return type;
5.297 }
5.298
5.299 -Ipv6Address Ipv6Address::GetZero ()
5.300 -{
5.301 - Ipv6Address zero ("::");
5.302 - return zero;
5.303 -}
5.304 -
5.305 -Ipv6Address Ipv6Address::GetAny ()
5.306 -{
5.307 - Ipv6Address any ("::");
5.308 - return any;
5.309 -}
5.310 -
5.311 Ipv6Address Ipv6Address::GetAllNodesMulticast ()
5.312 {
5.313 - Ipv6Address nmc ("ff02::1");
5.314 + static Ipv6Address nmc ("ff02::1");
5.315 return nmc;
5.316 }
5.317
5.318 Ipv6Address Ipv6Address::GetAllRoutersMulticast ()
5.319 {
5.320 - Ipv6Address rmc ("ff02::2");
5.321 + static Ipv6Address rmc ("ff02::2");
5.322 return rmc;
5.323 }
5.324
5.325 Ipv6Address Ipv6Address::GetAllHostsMulticast ()
5.326 {
5.327 - Ipv6Address hmc ("ff02::3");
5.328 + static Ipv6Address hmc ("ff02::3");
5.329 return hmc;
5.330 }
5.331
5.332 @@ -483,6 +507,18 @@
5.333 return loopback;
5.334 }
5.335
5.336 +Ipv6Address Ipv6Address::GetZero ()
5.337 +{
5.338 + static Ipv6Address zero ("::");
5.339 + return zero;
5.340 +}
5.341 +
5.342 +Ipv6Address Ipv6Address::GetAny ()
5.343 +{
5.344 + static Ipv6Address any ("::");
5.345 + return any;
5.346 +}
5.347 +
5.348 Ipv6Address Ipv6Address::GetOnes ()
5.349 {
5.350 static Ipv6Address ones ("ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff");
5.351 @@ -629,7 +665,7 @@
5.352
5.353 Ipv6Prefix Ipv6Prefix::GetLoopback ()
5.354 {
5.355 - Ipv6Prefix prefix ((uint8_t)128);
5.356 + static Ipv6Prefix prefix ((uint8_t)128);
5.357 return prefix;
5.358 }
5.359
5.360 @@ -641,7 +677,7 @@
5.361
5.362 Ipv6Prefix Ipv6Prefix::GetZero ()
5.363 {
5.364 - Ipv6Prefix prefix ((uint8_t)0);
5.365 + static Ipv6Prefix prefix ((uint8_t)0);
5.366 return prefix;
5.367 }
5.368
5.369 @@ -665,7 +701,7 @@
5.370 prefixLength++;
5.371 }
5.372 }
5.373 -
5.374 +
5.375 return prefixLength;
5.376 }
5.377
5.378 @@ -678,7 +714,7 @@
5.379 return false;
5.380 }
5.381
5.382 -std::ostream& operator<< (std::ostream& os, Ipv6Prefix const& prefix)
5.383 +std::ostream& operator << (std::ostream& os, Ipv6Prefix const& prefix)
5.384 {
5.385 prefix.Print (os);
5.386 return os;