|
1 /* -*- Mode:C; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
|
2 /* |
|
3 * Copyright (c) 2008 Liu Jian |
|
4 * |
|
5 * This program is free software; you can redistribute it and/or modify |
|
6 * it under the terms of the GNU General Public License version 2 as |
|
7 * published by the Free Software Foundation; |
|
8 * |
|
9 * This program is distributed in the hope that it will be useful, |
|
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 * GNU General Public License for more details. |
|
13 * |
|
14 * You should have received a copy of the GNU General Public License |
|
15 * along with this program; if not, write to the Free Software |
|
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|
17 * |
|
18 * Author: Liu Jian <liujatp@gmail.com> |
|
19 * Hajime Tazaki <tazaki@sfc.wide.ad.jp> |
|
20 */ |
|
21 |
|
22 #include "netlink-socket-address.h" |
|
23 |
|
24 namespace ns3 { |
|
25 |
|
26 NetlinkSocketAddress::NetlinkSocketAddress (uint32_t pid, uint32_t groups) |
|
27 : m_pid(pid), |
|
28 m_groups(groups) |
|
29 {} |
|
30 |
|
31 NetlinkSocketAddress::NetlinkSocketAddress () |
|
32 : m_pid (0), |
|
33 m_groups (0) |
|
34 {} |
|
35 |
|
36 NetlinkSocketAddress::~NetlinkSocketAddress () |
|
37 {} |
|
38 |
|
39 void NetlinkSocketAddress::SetProcessID (uint32_t pid) |
|
40 { |
|
41 m_pid = pid; |
|
42 } |
|
43 |
|
44 void NetlinkSocketAddress::SetGroupsMask (uint32_t mask) |
|
45 { |
|
46 m_groups = mask; |
|
47 } |
|
48 |
|
49 uint32_t NetlinkSocketAddress::GetProcessID (void) const |
|
50 { |
|
51 return m_pid; |
|
52 } |
|
53 |
|
54 uint32_t NetlinkSocketAddress::GetGroupsMask (void) const |
|
55 { |
|
56 return m_groups; |
|
57 } |
|
58 |
|
59 NetlinkSocketAddress::operator Address (void) const |
|
60 { |
|
61 return ConvertTo (); |
|
62 } |
|
63 |
|
64 Address NetlinkSocketAddress::ConvertTo (void) const |
|
65 { |
|
66 uint8_t buffer[8]; |
|
67 |
|
68 buffer[0] = (m_pid >> 24) & 0xff; |
|
69 buffer[1] = (m_pid >> 16) & 0xff; |
|
70 buffer[2] = (m_pid >> 8) & 0xff; |
|
71 buffer[3] = (m_pid >> 0) & 0xff; |
|
72 buffer[4] = (m_groups >> 24) & 0xff; |
|
73 buffer[5] = (m_groups >> 16) & 0xff; |
|
74 buffer[6] = (m_groups >> 8) & 0xff; |
|
75 buffer[7] = (m_groups >> 0) & 0xff; |
|
76 |
|
77 return Address (GetType (), buffer, 8); |
|
78 } |
|
79 |
|
80 NetlinkSocketAddress NetlinkSocketAddress::ConvertFrom (const Address &address) |
|
81 { |
|
82 NS_ASSERT (IsMatchingType (address)); |
|
83 |
|
84 NetlinkSocketAddress nl; |
|
85 uint8_t buf[8]; |
|
86 |
|
87 address.CopyTo (buf); |
|
88 |
|
89 nl.m_pid = 0; |
|
90 nl.m_pid |= buf[0]; |
|
91 nl.m_pid <<= 8; |
|
92 nl.m_pid |= buf[1]; |
|
93 nl.m_pid <<= 8; |
|
94 nl.m_pid |= buf[2]; |
|
95 nl.m_pid <<= 8; |
|
96 nl.m_pid |= buf[3]; |
|
97 |
|
98 nl.m_groups = 0; |
|
99 nl.m_groups |= buf[4]; |
|
100 nl.m_groups <<= 8; |
|
101 nl.m_groups |= buf[5]; |
|
102 nl.m_groups <<= 8; |
|
103 nl.m_groups |= buf[6]; |
|
104 nl.m_groups <<= 8; |
|
105 nl.m_groups |= buf[7]; |
|
106 |
|
107 return nl; |
|
108 } |
|
109 |
|
110 bool NetlinkSocketAddress::IsMatchingType (const Address &address) |
|
111 { |
|
112 return address.IsMatchingType (GetType ()); |
|
113 } |
|
114 |
|
115 uint8_t NetlinkSocketAddress::GetType (void) |
|
116 { |
|
117 static uint8_t type = Address::Register (); |
|
118 return type; |
|
119 } |
|
120 |
|
121 } // namespace ns3 |