Changeset 7038
- Timestamp:
- Dec 8, 2009, 5:28:53 PM (15 years ago)
- Location:
- source/ariba/utility/transport/tcpip/protlib
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
source/ariba/utility/transport/tcpip/protlib/tp_over_tcp.cpp
r5284 r7038 61 61 const unsigned int max_listen_queue_size= 10; 62 62 63 #define IPV6_ADDR_INT32_SMP 0x0000ffff 64 63 65 namespace protlib { 66 67 void v6_to_v4(struct sockaddr_in *sin, struct sockaddr_in6 *sin6) { 68 bzero(sin, sizeof(*sin)); 69 sin->sin_family = AF_INET; 70 sin->sin_port = sin6->sin6_port; 71 memcpy(&sin->sin_addr, &sin6->sin6_addr.s6_addr[12], sizeof(struct in_addr)); 72 } 73 74 /* Convert sockaddr_in to sockaddr_in6 in v4 mapped addr format. */ 75 void v4_to_v6(struct sockaddr_in *sin, struct sockaddr_in6 *sin6) { 76 bzero(sin6, sizeof(*sin6)); 77 sin6->sin6_family = AF_INET6; 78 sin6->sin6_port = sin->sin_port; 79 *(uint32_t *)&sin6->sin6_addr.s6_addr[0] = 0; 80 *(uint32_t *)&sin6->sin6_addr.s6_addr[4] = 0; 81 *(uint32_t *)&sin6->sin6_addr.s6_addr[8] = IPV6_ADDR_INT32_SMP; 82 *(uint32_t *)&sin6->sin6_addr.s6_addr[12] = sin->sin_addr.s_addr; 83 } 64 84 65 85 using namespace log; … … 129 149 130 150 // no connection found, create a new one 131 new_socket = socket( AF_INET6, SOCK_STREAM, IPPROTO_TCP);151 new_socket = socket( v4_mode ? AF_INET : AF_INET6, SOCK_STREAM, IPPROTO_TCP); 132 152 if (new_socket == -1) 133 153 { … … 161 181 } 162 182 163 struct sockaddr_in6 dest_address; 164 dest_address.sin6_flowinfo= 0; 165 dest_address.sin6_scope_id= 0; 166 addr.get_sockaddr(dest_address); 183 struct sockaddr_in6 dest_address; 184 dest_address.sin6_flowinfo= 0; 185 dest_address.sin6_scope_id= 0; 186 addr.get_sockaddr(dest_address); 187 188 // connect the socket to the destination address 189 int connect_status = 0; 190 if (v4_mode) { 191 struct sockaddr_in dest_address_v4; 192 v6_to_v4( &dest_address_v4, &dest_address ); 193 connect_status = connect(new_socket, 194 reinterpret_cast<const struct sockaddr*>(&dest_address_v4), 195 sizeof(dest_address)); 196 } else { 197 connect_status = connect(new_socket, 198 reinterpret_cast<const struct sockaddr*>(&dest_address), 199 sizeof(dest_address)); 200 } 167 201 168 // connect the socket to the destination address169 int connect_status = connect(new_socket,170 reinterpret_cast<const struct sockaddr*>(&dest_address),171 sizeof(dest_address));172 173 202 // connects to the listening_port of the peer's masterthread 174 203 if (connect_status != 0) … … 180 209 } 181 210 182 211 183 212 struct sockaddr_in6 own_address; 184 213 socklen_t own_address_len= sizeof(own_address); 185 getsockname(new_socket, reinterpret_cast<struct sockaddr*>(&own_address), &own_address_len); 186 187 214 getsockname(new_socket, reinterpret_cast<struct sockaddr*>(&own_address), &own_address_len); 188 215 189 216 Log(DEBUG_LOG,LOG_UNIMP, tpparam.name,">>--Connect-->> to " << addr.get_ip_str() << " port #" << addr.get_port() 190 217 << " from " << inet_ntop(AF_INET6,&own_address.sin6_addr,in6_addrstr,INET6_ADDRSTRLEN) 191 218 << " port #" << ntohs(own_address.sin6_port)); 192 193 194 219 195 220 … … 1422 1447 { 1423 1448 // create a new address-structure for the listening masterthread 1424 struct sockaddr_in6 own_address ;1425 own_address .sin6_family = AF_INET6;1426 own_address .sin6_flowinfo= 0;1427 own_address .sin6_port = htons(tpparam.port); // use port number in param structure1449 struct sockaddr_in6 own_address_v6; 1450 own_address_v6.sin6_family = AF_INET6; 1451 own_address_v6.sin6_flowinfo= 0; 1452 own_address_v6.sin6_port = htons(tpparam.port); // use port number in param structure 1428 1453 // accept incoming connections on all interfaces 1429 own_address.sin6_addr = in6addr_any; 1430 own_address.sin6_scope_id= 0; 1454 own_address_v6.sin6_addr = in6addr_any; 1455 own_address_v6.sin6_scope_id= 0; 1456 1457 // create a new address-structure for the listening masterthread 1458 struct sockaddr_in own_address_v4; 1459 own_address_v4.sin_family = AF_INET; 1460 own_address_v4.sin_port = htons(tpparam.port); // use port number in param structure 1461 // accept incoming connections on all interfaces 1462 own_address_v4.sin_addr.s_addr = INADDR_ANY; 1431 1463 1432 1464 // create a listening socket 1433 int master_listener_socket= socket(AF_INET6, SOCK_STREAM, IPPROTO_TCP); 1465 int master_listener_socket= socket( AF_INET6, SOCK_STREAM, IPPROTO_TCP); 1466 if (master_listener_socket!=-1) v4_mode = false; 1467 if (master_listener_socket == -1) { 1468 master_listener_socket= socket( AF_INET, SOCK_STREAM, IPPROTO_TCP); 1469 if (master_listener_socket!=-1) v4_mode = true; 1470 } 1434 1471 if (master_listener_socket == -1) 1435 1472 { … … 1464 1501 1465 1502 // bind the newly created socket to a specific address 1466 int bind_status = bind(master_listener_socket, 1467 reinterpret_cast<struct sockaddr *>(&own_address), 1468 sizeof(own_address)); 1503 int bind_status = bind(master_listener_socket, v4_mode ? 1504 reinterpret_cast<struct sockaddr *>(&own_address_v4) : 1505 reinterpret_cast<struct sockaddr *>(&own_address_v6), 1506 v4_mode ? sizeof(own_address_v4) : sizeof(own_address_v6)); 1469 1507 if (bind_status) 1470 1508 { 1471 1509 Log(ERROR_LOG,LOG_CRIT, tpparam.name, "Binding to " 1472 << inet_ntop(AF_INET6, &own_address.sin6_addr, in6_addrstr, INET6_ADDRSTRLEN) 1510 << (v4_mode ? inet_ntop(AF_INET, &own_address_v4.sin_addr, in_addrstr, INET_ADDRSTRLEN) : 1511 inet_ntop(AF_INET6, &own_address_v6.sin6_addr, in6_addrstr, INET6_ADDRSTRLEN)) 1473 1512 << " port " << tpparam.port << " failed, error: " << strerror(errno)); 1474 1513 return; … … 1598 1637 1599 1638 struct sockaddr_in6 own_address; 1600 socklen_t own_address_len= sizeof(own_address); 1601 getsockname(conn_socket, reinterpret_cast<struct sockaddr*>(&own_address), &own_address_len); 1639 if (v4_mode) { 1640 struct sockaddr_in own_address_v4; 1641 socklen_t own_address_len_v4 = sizeof(own_address_v4); 1642 getsockname(conn_socket, reinterpret_cast<struct sockaddr*>(&own_address_v4), &own_address_len_v4); 1643 v4_to_v6(&own_address_v4, &own_address); 1644 } else { 1645 socklen_t own_address_len= sizeof(own_address); 1646 getsockname(conn_socket, reinterpret_cast<struct sockaddr*>(&own_address), &own_address_len); 1647 } 1602 1648 1603 1649 // AssocData will copy addr content into its own structure -
source/ariba/utility/transport/tcpip/protlib/tp_over_tcp.h
r6922 r7038 218 218 219 219 bool debug_pdu; 220 bool v4_mode; 220 221 }; // end class TPoverTCP 221 222
Note:
See TracChangeset
for help on using the changeset viewer.