00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include "address-utils.h"
00021
00022 namespace ns3 {
00023
00024 void WriteTo (Buffer::Iterator &i, Ipv4Address ad)
00025 {
00026 i.WriteHtonU32 (ad.Get ());
00027 }
00028 void WriteTo (Buffer::Iterator &i, Ipv6Address ad)
00029 {
00030 uint8_t buf[16];
00031 ad.GetBytes(buf);
00032 i.Write(buf, 16);
00033 }
00034 void WriteTo (Buffer::Iterator &i, const Address &ad)
00035 {
00036 uint8_t mac[Address::MAX_SIZE];
00037 ad.CopyTo (mac);
00038 i.Write (mac, ad.GetLength ());
00039 }
00040 void WriteTo (Buffer::Iterator &i, Mac48Address ad)
00041 {
00042 uint8_t mac[6];
00043 ad.CopyTo (mac);
00044 i.Write (mac, 6);
00045 }
00046
00047 void ReadFrom (Buffer::Iterator &i, Ipv4Address &ad)
00048 {
00049 ad.Set (i.ReadNtohU32 ());
00050 }
00051 void ReadFrom (Buffer::Iterator &i, Ipv6Address &ad)
00052 {
00053 uint8_t ipv6[16];
00054 i.Read(ipv6, 16);
00055 ad.Set (ipv6);
00056 }
00057 void ReadFrom (Buffer::Iterator &i, Address &ad, uint32_t len)
00058 {
00059 uint8_t mac[Address::MAX_SIZE];
00060 i.Read (mac, len);
00061 ad.CopyFrom (mac, len);
00062 }
00063 void ReadFrom (Buffer::Iterator &i, Mac48Address &ad)
00064 {
00065 uint8_t mac[6];
00066 i.Read (mac, 6);
00067 ad.CopyFrom (mac);
00068 }
00069
00070 }