137 return ERROR_INVAL; |
137 return ERROR_INVAL; |
138 } |
138 } |
139 InetSocketAddress transport = InetSocketAddress::ConvertFrom (address); |
139 InetSocketAddress transport = InetSocketAddress::ConvertFrom (address); |
140 Ipv4Address ipv4 = transport.GetIpv4 (); |
140 Ipv4Address ipv4 = transport.GetIpv4 (); |
141 uint16_t port = transport.GetPort (); |
141 uint16_t port = transport.GetPort (); |
142 |
|
143 Ipv4Address localInterface = Ipv4Address::GetAny (); |
|
144 if (ipv4 != Ipv4Address::GetAny ()) |
|
145 { |
|
146 Ptr<Ipv4> ipv4_api = m_node->GetObject<Ipv4> (); |
|
147 // Assert that the given address matches an existing local interface |
|
148 NS_ASSERT (ipv4_api->FindInterfaceForAddr (ipv4) != 0); |
|
149 localInterface = ipv4; |
|
150 } |
|
151 |
|
152 if (ipv4 == Ipv4Address::GetAny () && port == 0) |
142 if (ipv4 == Ipv4Address::GetAny () && port == 0) |
153 { |
143 { |
154 m_endPoint = m_udp->Allocate (); |
144 m_endPoint = m_udp->Allocate (); |
155 } |
145 } |
156 else if (ipv4 == Ipv4Address::GetAny () && port != 0) |
146 else if (ipv4 == Ipv4Address::GetAny () && port != 0) |
157 { |
147 { |
158 m_endPoint = m_udp->Allocate (port); |
148 m_endPoint = m_udp->Allocate (port); |
159 } |
149 } |
160 else if (ipv4 != Ipv4Address::GetAny () && port == 0) |
150 else if (ipv4 != Ipv4Address::GetAny () && port == 0) |
161 { |
151 { |
162 m_endPoint = m_udp->Allocate (ipv4, localInterface); |
152 m_endPoint = m_udp->Allocate (ipv4); |
163 } |
153 } |
164 else if (ipv4 != Ipv4Address::GetAny () && port != 0) |
154 else if (ipv4 != Ipv4Address::GetAny () && port != 0) |
165 { |
155 { |
166 m_endPoint = m_udp->Allocate (ipv4, port, localInterface); |
156 m_endPoint = m_udp->Allocate (ipv4, port); |
167 } |
157 } |
168 |
158 |
169 return FinishBind (); |
159 return FinishBind (); |
170 } |
160 } |
171 |
161 |