|
|
| 233 |
{ |
233 |
{ |
| 234 |
NS_LOG_FUNCTION_NOARGS (); |
234 |
NS_LOG_FUNCTION_NOARGS (); |
| 235 |
m_endPoint = m_udp->Allocate (); |
235 |
m_endPoint = m_udp->Allocate (); |
|
|
236 |
if (m_boundnetdevice) |
| 237 |
{ |
| 238 |
m_endPoint->BindToNetDevice (m_boundnetdevice); |
| 239 |
} |
| 236 |
return FinishBind (); |
240 |
return FinishBind (); |
| 237 |
} |
241 |
} |
| 238 |
|
242 |
|
|
|
| 241 |
{ |
245 |
{ |
| 242 |
NS_LOG_FUNCTION_NOARGS (); |
246 |
NS_LOG_FUNCTION_NOARGS (); |
| 243 |
m_endPoint6 = m_udp->Allocate6 (); |
247 |
m_endPoint6 = m_udp->Allocate6 (); |
|
|
248 |
if (m_boundnetdevice) |
| 249 |
{ |
| 250 |
m_endPoint6->BindToNetDevice (m_boundnetdevice); |
| 251 |
} |
| 244 |
return FinishBind (); |
252 |
return FinishBind (); |
| 245 |
} |
253 |
} |
| 246 |
|
254 |
|
|
|
| 251 |
|
259 |
|
| 252 |
if (InetSocketAddress::IsMatchingType (address)) |
260 |
if (InetSocketAddress::IsMatchingType (address)) |
| 253 |
{ |
261 |
{ |
| 254 |
NS_ASSERT_MSG (m_endPoint == 0, "Endpoint already allocated (maybe you used BindToNetDevice before Bind)."); |
262 |
NS_ASSERT_MSG (m_endPoint == 0, "Endpoint already allocated."); |
| 255 |
|
263 |
|
| 256 |
InetSocketAddress transport = InetSocketAddress::ConvertFrom (address); |
264 |
InetSocketAddress transport = InetSocketAddress::ConvertFrom (address); |
| 257 |
Ipv4Address ipv4 = transport.GetIpv4 (); |
265 |
Ipv4Address ipv4 = transport.GetIpv4 (); |
|
|
| 263 |
} |
271 |
} |
| 264 |
else if (ipv4 == Ipv4Address::GetAny () && port != 0) |
272 |
else if (ipv4 == Ipv4Address::GetAny () && port != 0) |
| 265 |
{ |
273 |
{ |
| 266 |
m_endPoint = m_udp->Allocate (port); |
274 |
m_endPoint = m_udp->Allocate (GetBoundNetDevice (), port); |
| 267 |
} |
275 |
} |
| 268 |
else if (ipv4 != Ipv4Address::GetAny () && port == 0) |
276 |
else if (ipv4 != Ipv4Address::GetAny () && port == 0) |
| 269 |
{ |
277 |
{ |
|
|
| 271 |
} |
279 |
} |
| 272 |
else if (ipv4 != Ipv4Address::GetAny () && port != 0) |
280 |
else if (ipv4 != Ipv4Address::GetAny () && port != 0) |
| 273 |
{ |
281 |
{ |
| 274 |
m_endPoint = m_udp->Allocate (ipv4, port); |
282 |
m_endPoint = m_udp->Allocate (GetBoundNetDevice (), ipv4, port); |
| 275 |
} |
283 |
} |
| 276 |
if (0 == m_endPoint) |
284 |
if (0 == m_endPoint) |
| 277 |
{ |
285 |
{ |
| 278 |
m_errno = port ? ERROR_ADDRINUSE : ERROR_ADDRNOTAVAIL; |
286 |
m_errno = port ? ERROR_ADDRINUSE : ERROR_ADDRNOTAVAIL; |
| 279 |
return -1; |
287 |
return -1; |
| 280 |
} |
288 |
} |
|
|
289 |
if (m_boundnetdevice) |
| 290 |
{ |
| 291 |
m_endPoint->BindToNetDevice (m_boundnetdevice); |
| 292 |
} |
| 293 |
|
| 281 |
} |
294 |
} |
| 282 |
else if (Inet6SocketAddress::IsMatchingType (address)) |
295 |
else if (Inet6SocketAddress::IsMatchingType (address)) |
| 283 |
{ |
296 |
{ |
| 284 |
NS_ASSERT_MSG (m_endPoint == 0, "Endpoint already allocated (maybe you used BindToNetDevice before Bind)."); |
297 |
NS_ASSERT_MSG (m_endPoint == 0, "Endpoint already allocated."); |
| 285 |
|
298 |
|
| 286 |
Inet6SocketAddress transport = Inet6SocketAddress::ConvertFrom (address); |
299 |
Inet6SocketAddress transport = Inet6SocketAddress::ConvertFrom (address); |
| 287 |
Ipv6Address ipv6 = transport.GetIpv6 (); |
300 |
Ipv6Address ipv6 = transport.GetIpv6 (); |
|
|
| 292 |
} |
305 |
} |
| 293 |
else if (ipv6 == Ipv6Address::GetAny () && port != 0) |
306 |
else if (ipv6 == Ipv6Address::GetAny () && port != 0) |
| 294 |
{ |
307 |
{ |
| 295 |
m_endPoint6 = m_udp->Allocate6 (port); |
308 |
m_endPoint6 = m_udp->Allocate6 (GetBoundNetDevice (), port); |
| 296 |
} |
309 |
} |
| 297 |
else if (ipv6 != Ipv6Address::GetAny () && port == 0) |
310 |
else if (ipv6 != Ipv6Address::GetAny () && port == 0) |
| 298 |
{ |
311 |
{ |
|
|
| 300 |
} |
313 |
} |
| 301 |
else if (ipv6 != Ipv6Address::GetAny () && port != 0) |
314 |
else if (ipv6 != Ipv6Address::GetAny () && port != 0) |
| 302 |
{ |
315 |
{ |
| 303 |
m_endPoint6 = m_udp->Allocate6 (ipv6, port); |
316 |
m_endPoint6 = m_udp->Allocate6 (GetBoundNetDevice (), ipv6, port); |
| 304 |
} |
317 |
} |
| 305 |
if (0 == m_endPoint6) |
318 |
if (0 == m_endPoint6) |
| 306 |
{ |
319 |
{ |
| 307 |
m_errno = port ? ERROR_ADDRINUSE : ERROR_ADDRNOTAVAIL; |
320 |
m_errno = port ? ERROR_ADDRINUSE : ERROR_ADDRNOTAVAIL; |
| 308 |
return -1; |
321 |
return -1; |
| 309 |
} |
322 |
} |
|
|
323 |
if (m_boundnetdevice) |
| 324 |
{ |
| 325 |
m_endPoint6->BindToNetDevice (m_boundnetdevice); |
| 326 |
} |
| 327 |
|
| 310 |
if (ipv6.IsMulticast ()) |
328 |
if (ipv6.IsMulticast ()) |
| 311 |
{ |
329 |
{ |
| 312 |
Ptr<Ipv6L3Protocol> ipv6l3 = m_node->GetObject <Ipv6L3Protocol> (); |
330 |
Ptr<Ipv6L3Protocol> ipv6l3 = m_node->GetObject <Ipv6L3Protocol> (); |
| 313 |
if (ipv6l3) |
331 |
if (ipv6l3) |
| 314 |
{ |
332 |
{ |
| 315 |
ipv6l3->AddMulticastAddress (ipv6); |
333 |
if (m_boundnetdevice == 0) |
|
|
334 |
{ |
| 335 |
ipv6l3->AddMulticastAddress (ipv6); |
| 336 |
} |
| 337 |
else |
| 338 |
{ |
| 339 |
uint32_t index = ipv6l3->GetInterfaceForDevice (m_boundnetdevice); |
| 340 |
ipv6l3->AddMulticastAddress (m_endPoint6->GetLocalAddress (), index); |
| 341 |
} |
| 316 |
} |
342 |
} |
| 317 |
} |
343 |
} |
| 318 |
} |
344 |
} |
|
|
| 928 |
{ |
954 |
{ |
| 929 |
NS_LOG_FUNCTION (netdevice); |
955 |
NS_LOG_FUNCTION (netdevice); |
| 930 |
|
956 |
|
|
|
957 |
Ptr<NetDevice> oldBoundNetDevice = m_boundnetdevice; |
| 958 |
|
| 931 |
Socket::BindToNetDevice (netdevice); // Includes sanity check |
959 |
Socket::BindToNetDevice (netdevice); // Includes sanity check |
| 932 |
if (m_endPoint == 0) |
960 |
if (m_endPoint != 0) |
| 933 |
{ |
961 |
{ |
| 934 |
if (Bind () == -1) |
962 |
m_endPoint->BindToNetDevice (netdevice); |
| 935 |
{ |
|
|
| 936 |
NS_ASSERT (m_endPoint == 0); |
| 937 |
return; |
| 938 |
} |
| 939 |
NS_ASSERT (m_endPoint != 0); |
| 940 |
} |
963 |
} |
| 941 |
m_endPoint->BindToNetDevice (netdevice); |
|
|
| 942 |
|
964 |
|
| 943 |
if (m_endPoint6 == 0) |
965 |
if (m_endPoint6 != 0) |
| 944 |
{ |
966 |
{ |
| 945 |
if (Bind6 () == -1) |
967 |
m_endPoint6->BindToNetDevice (netdevice); |
|
|
968 |
|
| 969 |
// The following is to fix the multicast distribution inside the node |
| 970 |
// and to upgrade it to the actual bound NetDevice. |
| 971 |
if (m_endPoint6->GetLocalAddress ().IsMulticast ()) |
| 946 |
{ |
972 |
{ |
| 947 |
NS_ASSERT (m_endPoint6 == 0); |
973 |
Ptr<Ipv6L3Protocol> ipv6l3 = m_node->GetObject <Ipv6L3Protocol> (); |
| 948 |
return; |
974 |
if (ipv6l3) |
| 949 |
} |
975 |
{ |
| 950 |
NS_ASSERT (m_endPoint6 != 0); |
976 |
// Cleanup old one |
| 951 |
} |
977 |
if (oldBoundNetDevice) |
| 952 |
m_endPoint6->BindToNetDevice (netdevice); |
978 |
{ |
| 953 |
|
979 |
uint32_t index = ipv6l3->GetInterfaceForDevice (oldBoundNetDevice); |
| 954 |
if (m_endPoint6->GetLocalAddress ().IsMulticast ()) |
980 |
ipv6l3->RemoveMulticastAddress (m_endPoint6->GetLocalAddress (), index); |
| 955 |
{ |
981 |
} |
| 956 |
Ptr<Ipv6L3Protocol> ipv6l3 = m_node->GetObject <Ipv6L3Protocol> (); |
982 |
else |
| 957 |
if (ipv6l3) |
983 |
{ |
| 958 |
{ |
984 |
ipv6l3->RemoveMulticastAddress (m_endPoint6->GetLocalAddress ()); |
| 959 |
uint32_t index = ipv6l3->GetInterfaceForDevice (netdevice); |
985 |
} |
| 960 |
ipv6l3->RemoveMulticastAddress (m_endPoint6->GetLocalAddress ()); |
986 |
// add new one |
| 961 |
ipv6l3->AddMulticastAddress (m_endPoint6->GetLocalAddress (), index); |
987 |
if (netdevice) |
|
|
988 |
{ |
| 989 |
uint32_t index = ipv6l3->GetInterfaceForDevice (netdevice); |
| 990 |
ipv6l3->AddMulticastAddress (m_endPoint6->GetLocalAddress (), index); |
| 991 |
} |
| 992 |
else |
| 993 |
{ |
| 994 |
ipv6l3->AddMulticastAddress (m_endPoint6->GetLocalAddress ()); |
| 995 |
} |
| 996 |
} |
| 962 |
} |
997 |
} |
| 963 |
} |
998 |
} |
| 964 |
|
999 |
|