src/node/address-utils.cc
author vincent@clarinet.u-strasbg.fr
Fri Nov 07 11:36:15 2008 -0800 (2008-11-07)
changeset 3852 9cf7ad0cac85
parent 3179 1763f7ac8e80
child 4472 e20a31541404
permissions -rw-r--r--
Initial IPv6 capability
mathieu@242
     1
/* -*-  Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
mathieu@242
     2
/*
mathieu@242
     3
 * Copyright (c) 2006 INRIA
mathieu@242
     4
 *
mathieu@242
     5
 * This program is free software; you can redistribute it and/or modify
mathieu@242
     6
 * it under the terms of the GNU General Public License version 2 as
mathieu@242
     7
 * published by the Free Software Foundation;
mathieu@242
     8
 *
mathieu@242
     9
 * This program is distributed in the hope that it will be useful,
mathieu@242
    10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
mathieu@242
    11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
mathieu@242
    12
 * GNU General Public License for more details.
mathieu@242
    13
 *
mathieu@242
    14
 * You should have received a copy of the GNU General Public License
mathieu@242
    15
 * along with this program; if not, write to the Free Software
mathieu@242
    16
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
mathieu@242
    17
 *
mathieu@242
    18
 * Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
mathieu@242
    19
 */
emmanuelle@976
    20
#include "address-utils.h"
mathieu@242
    21
mathieu@242
    22
namespace ns3 {
mathieu@242
    23
mathieu@242
    24
void WriteTo (Buffer::Iterator &i, Ipv4Address ad)
mathieu@242
    25
{
mathieu@3179
    26
  i.WriteHtonU32 (ad.Get ());
mathieu@242
    27
}
vincent@3852
    28
void WriteTo (Buffer::Iterator &i, Ipv6Address ad)
vincent@3852
    29
{
vincent@3852
    30
  uint8_t buf[16];
vincent@3852
    31
  ad.GetBytes(buf);
vincent@3852
    32
  i.Write(buf, 16);
vincent@3852
    33
}
mathieu@1167
    34
void WriteTo (Buffer::Iterator &i, const Address &ad)
mathieu@242
    35
{
mathieu@1167
    36
  uint8_t mac[Address::MAX_SIZE];
mathieu@1167
    37
  ad.CopyTo (mac);
mathieu@247
    38
  i.Write (mac, ad.GetLength ());
mathieu@242
    39
}
mathieu@1494
    40
void WriteTo (Buffer::Iterator &i, Mac48Address ad)
mathieu@1167
    41
{
mathieu@1167
    42
  uint8_t mac[6];
mathieu@1167
    43
  ad.CopyTo (mac);
mathieu@1167
    44
  i.Write (mac, 6);
mathieu@1167
    45
}
mathieu@242
    46
mathieu@242
    47
void ReadFrom (Buffer::Iterator &i, Ipv4Address &ad)
mathieu@242
    48
{
mathieu@3179
    49
  ad.Set (i.ReadNtohU32 ());
mathieu@242
    50
}
vincent@3852
    51
void ReadFrom (Buffer::Iterator &i, Ipv6Address &ad)
vincent@3852
    52
{
vincent@3852
    53
  uint8_t ipv6[16];
vincent@3852
    54
  i.Read(ipv6, 16);
vincent@3852
    55
  ad.Set (ipv6);
vincent@3852
    56
}
mathieu@1167
    57
void ReadFrom (Buffer::Iterator &i, Address &ad, uint32_t len)
mathieu@242
    58
{
mathieu@1167
    59
  uint8_t mac[Address::MAX_SIZE];
mathieu@242
    60
  i.Read (mac, len);
mathieu@1167
    61
  ad.CopyFrom (mac, len);
mathieu@1167
    62
}
mathieu@1494
    63
void ReadFrom (Buffer::Iterator &i, Mac48Address &ad)
mathieu@1167
    64
{
mathieu@1167
    65
  uint8_t mac[6];
mathieu@1167
    66
  i.Read (mac, 6);
mathieu@1167
    67
  ad.CopyFrom (mac);
mathieu@242
    68
}
mathieu@242
    69
mathieu@1167
    70
} // namespace ns3