儲存庫 vbox 的更動 39801
- 時間撮記:
- 2012-1-18 下午06:01:11 (13 年 以前)
- 位置:
- trunk/src/VBox/Runtime
- 檔案:
-
- 修改 7 筆資料
圖例:
- 未更動
- 新增
- 刪除
-
trunk/src/VBox/Runtime/include/internal/socket.h
r32131 r39801 30 30 #include <iprt/cdefs.h> 31 31 #include <iprt/types.h> 32 #include <iprt/net.h> 32 33 /* Currently requires a bunch of socket headers. */ 33 34 … … 54 55 int rtSocketCreateForNative(RTSOCKETINT **ppSocket, RTSOCKETNATIVE hNative); 55 56 int rtSocketCreate(PRTSOCKET phSocket, int iDomain, int iType, int iProtocol); 56 int rtSocketBind(RTSOCKET hSocket, const struct sockaddr *pAddr, int cbAddr);57 int rtSocketBind(RTSOCKET hSocket, PCRTNETADDR pAddr); 57 58 int rtSocketListen(RTSOCKET hSocket, int cMaxPending); 58 59 int rtSocketAccept(RTSOCKET hSocket, PRTSOCKET phClient, struct sockaddr *pAddr, size_t *pcbAddr); 59 int rtSocketConnect(RTSOCKET hSocket, const struct sockaddr *pAddr, int cbAddr);60 int rtSocketConnect(RTSOCKET hSocket, PCRTNETADDR pAddr); 60 61 int rtSocketSetOpt(RTSOCKET hSocket, int iLevel, int iOption, void const *pvValue, int cbValue); 61 62 #endif /* IPRT_INTERNAL_SOCKET_POLLING_ONLY */ -
trunk/src/VBox/Runtime/r3/posix/process-posix.cpp
r33602 r39801 131 131 RTR3DECL(int) RTProcTerminate(RTPROCESS Process) 132 132 { 133 if (Process == NIL_RTPROCESS) 134 return VINF_SUCCESS; 135 133 136 if (!kill(Process, SIGKILL)) 134 137 return VINF_SUCCESS; -
trunk/src/VBox/Runtime/r3/socket.cpp
r39032 r39801 55 55 #include <iprt/asm.h> 56 56 #include <iprt/assert.h> 57 #include <iprt/ctype.h> 57 58 #include <iprt/err.h> 58 59 #include <iprt/mempool.h> … … 157 158 { 158 159 struct sockaddr Addr; 159 struct sockaddr_in I pv4;160 struct sockaddr_in IPv4; 160 161 #ifdef IPRT_WITH_TCPIP_V6 161 struct sockaddr_in6 I pv6;162 struct sockaddr_in6 IPv6; 162 163 #endif 163 164 } RTSOCKADDRUNION; … … 239 240 RT_ZERO(*pAddr); 240 241 pAddr->enmType = RTNETADDRTYPE_IPV4; 241 pAddr->uPort = RT_N2H_U16(pSrc->I pv4.sin_port);242 pAddr->uAddr.IPv4.u = pSrc->I pv4.sin_addr.s_addr;242 pAddr->uPort = RT_N2H_U16(pSrc->IPv4.sin_port); 243 pAddr->uAddr.IPv4.u = pSrc->IPv4.sin_addr.s_addr; 243 244 } 244 245 #ifdef IPRT_WITH_TCPIP_V6 … … 248 249 RT_ZERO(*pAddr); 249 250 pAddr->enmType = RTNETADDRTYPE_IPV6; 250 pAddr->uPort = RT_N2H_U16(pSrc->I pv6.sin6_port);251 pAddr->uAddr.IPv6.au32[0] = pSrc->I pv6.sin6_addr.s6_addr32[0];252 pAddr->uAddr.IPv6.au32[1] = pSrc->I pv6.sin6_addr.s6_addr32[1];253 pAddr->uAddr.IPv6.au32[2] = pSrc->I pv6.sin6_addr.s6_addr32[2];254 pAddr->uAddr.IPv6.au32[3] = pSrc->I pv6.sin6_addr.s6_addr32[3];251 pAddr->uPort = RT_N2H_U16(pSrc->IPv6.sin6_port); 252 pAddr->uAddr.IPv6.au32[0] = pSrc->IPv6.sin6_addr.s6_addr32[0]; 253 pAddr->uAddr.IPv6.au32[1] = pSrc->IPv6.sin6_addr.s6_addr32[1]; 254 pAddr->uAddr.IPv6.au32[2] = pSrc->IPv6.sin6_addr.s6_addr32[2]; 255 pAddr->uAddr.IPv6.au32[3] = pSrc->IPv6.sin6_addr.s6_addr32[3]; 255 256 } 256 257 #endif … … 268 269 * @param pDst The source address. 269 270 * @param cbSrc The size of the source address. 270 */ 271 static int rtSocketAddrFromNetAddr(PCRTNETADDR pAddr, RTSOCKADDRUNION *pDst, size_t cbDst) 271 * @param pcbAddr Where to store the size of the returned address. 272 * Optional 273 */ 274 static int rtSocketAddrFromNetAddr(PCRTNETADDR pAddr, RTSOCKADDRUNION *pDst, size_t cbDst, int *pcbAddr) 272 275 { 273 276 RT_BZERO(pDst, cbDst); … … 276 279 { 277 280 pDst->Addr.sa_family = AF_INET; 278 pDst->Ipv4.sin_port = RT_H2N_U16(pAddr->uPort); 279 pDst->Ipv4.sin_addr.s_addr = pAddr->uAddr.IPv4.u; 281 pDst->IPv4.sin_port = RT_H2N_U16(pAddr->uPort); 282 pDst->IPv4.sin_addr.s_addr = pAddr->uAddr.IPv4.u; 283 if (pcbAddr) 284 *pcbAddr = sizeof(pDst->IPv4); 280 285 } 281 286 #ifdef IPRT_WITH_TCPIP_V6 … … 284 289 { 285 290 pDst->Addr.sa_family = AF_INET6; 286 pDst->Ipv6.sin6_port = RT_H2N_U16(pAddr->uPort); 287 pSrc->Ipv6.sin6_addr.s6_addr32[0] = pAddr->uAddr.IPv6.au32[0]; 288 pSrc->Ipv6.sin6_addr.s6_addr32[1] = pAddr->uAddr.IPv6.au32[1]; 289 pSrc->Ipv6.sin6_addr.s6_addr32[2] = pAddr->uAddr.IPv6.au32[2]; 290 pSrc->Ipv6.sin6_addr.s6_addr32[3] = pAddr->uAddr.IPv6.au32[3]; 291 pDst->IPv6.sin6_port = RT_H2N_U16(pAddr->uPort); 292 pSrc->IPv6.sin6_addr.s6_addr32[0] = pAddr->uAddr.IPv6.au32[0]; 293 pSrc->IPv6.sin6_addr.s6_addr32[1] = pAddr->uAddr.IPv6.au32[1]; 294 pSrc->IPv6.sin6_addr.s6_addr32[2] = pAddr->uAddr.IPv6.au32[2]; 295 pSrc->IPv6.sin6_addr.s6_addr32[3] = pAddr->uAddr.IPv6.au32[3]; 296 if (pcbAddr) 297 *pcbAddr = sizeof(pDst->IPv6); 291 298 } 292 299 #endif … … 580 587 } 581 588 589 static bool rtSocketIsIPv4Numerical(const char *pszAddress, PRTNETADDRIPV4 pAddr) 590 { 591 592 /* Empty address resolves to the INADDR_ANY address (good for bind). */ 593 if (!*pszAddress) 594 { 595 pAddr->u = INADDR_ANY; 596 return true; 597 } 598 599 /* Four quads? */ 600 char *psz = (char *)pszAddress; 601 for (int i = 0; i < 4; i++) 602 { 603 uint8_t u8; 604 int rc = RTStrToUInt8Ex(psz, &psz, 0, &u8); 605 if (rc != VINF_SUCCESS) 606 return false; 607 if (*psz != (i < 3 ? '.' : '\0')) 608 return false; 609 psz++; 610 611 pAddr->au8[i] = u8; /* big endian */ 612 } 613 614 return true; 615 } 582 616 583 617 RTDECL(int) RTSocketParseInetAddress(const char *pszAddress, unsigned uPort, PRTNETADDR pAddr) … … 606 640 607 641 /* 608 * Resolve the address. 642 * Resolve the address. Pretty crude at the moment, but we have to make 643 * sure to not ask the NT 4 gethostbyname about an IPv4 address as it may 644 * give a wrong answer. 609 645 */ 610 646 /** @todo this only supports IPv4, and IPv6 support needs to be added. 611 * It probably needs to be converted to getnameinfo(). */ 612 struct hostent *pHostEnt = NULL; 647 * It probably needs to be converted to getaddrinfo(). */ 648 RTNETADDRIPV4 IPv4Quad; 649 if (rtSocketIsIPv4Numerical(pszAddress, &IPv4Quad)) 650 { 651 RT_ZERO(*pAddr); 652 pAddr->enmType = RTNETADDRTYPE_IPV4; 653 pAddr->uPort = uPort; 654 pAddr->uAddr.IPv4 = IPv4Quad; 655 return VINF_SUCCESS; 656 } 657 658 struct hostent *pHostEnt; 613 659 pHostEnt = gethostbyname(pszAddress); 614 660 if (!pHostEnt) 615 661 { 616 struct in_addr InAddr; 617 InAddr.s_addr = inet_addr(pszAddress); 618 pHostEnt = gethostbyaddr((char *)&InAddr, 4, AF_INET); 619 if (!pHostEnt) 620 { 621 rc = rtSocketResolverError(); 622 AssertMsgFailed(("Could not resolve '%s', rc=%Rrc\n", pszAddress, rc)); 623 return rc; 624 } 662 rc = rtSocketResolverError(); 663 AssertMsgFailed(("Could not resolve '%s', rc=%Rrc\n", pszAddress, rc)); 664 return rc; 625 665 } 626 666 … … 857 897 if (pAddr) 858 898 { 859 rc = rtSocketAddrFromNetAddr(pAddr, &u, sizeof(u) );899 rc = rtSocketAddrFromNetAddr(pAddr, &u, sizeof(u), NULL); 860 900 if (RT_FAILURE(rc)) 861 901 return rc; … … 1393 1433 * @returns IPRT status code. 1394 1434 * @param hSocket The socket handle. 1395 * @param pAddr The socket address to bind to. 1396 * @param cbAddr The size of the address structure @a pAddr 1397 * points to. 1398 */ 1399 int rtSocketBind(RTSOCKET hSocket, const struct sockaddr *pAddr, int cbAddr) 1435 * @param pAddr The address to bind to. 1436 */ 1437 int rtSocketBind(RTSOCKET hSocket, PCRTNETADDR pAddr) 1400 1438 { 1401 1439 /* … … 1407 1445 AssertReturn(rtSocketTryLock(pThis), VERR_CONCURRENT_ACCESS); 1408 1446 1409 int rc = VINF_SUCCESS; 1410 if (bind(pThis->hNative, pAddr, cbAddr) != 0) 1411 rc = rtSocketError(); 1447 RTSOCKADDRUNION u; 1448 int cbAddr; 1449 int rc = rtSocketAddrFromNetAddr(pAddr, &u, sizeof(u), &cbAddr); 1450 if (RT_SUCCESS(rc)) 1451 { 1452 if (bind(pThis->hNative, &u.Addr, cbAddr) != 0) 1453 rc = rtSocketError(); 1454 } 1412 1455 1413 1456 rtSocketUnlock(pThis); … … 1508 1551 * @param hSocket The socket handle. 1509 1552 * @param pAddr The socket address to connect to. 1510 * @param cbAddr The size of the address structure @a pAddr 1511 * points to. 1512 */ 1513 int rtSocketConnect(RTSOCKET hSocket, const struct sockaddr *pAddr, int cbAddr) 1553 */ 1554 int rtSocketConnect(RTSOCKET hSocket, PCRTNETADDR pAddr) 1514 1555 { 1515 1556 /* … … 1521 1562 AssertReturn(rtSocketTryLock(pThis), VERR_CONCURRENT_ACCESS); 1522 1563 1523 int rc = VINF_SUCCESS; 1524 if (connect(pThis->hNative, pAddr, cbAddr) != 0) 1525 rc = rtSocketError(); 1564 RTSOCKADDRUNION u; 1565 int cbAddr; 1566 int rc = rtSocketAddrFromNetAddr(pAddr, &u, sizeof(u), &cbAddr); 1567 if (RT_SUCCESS(rc)) 1568 { 1569 Log(("Calling connect()...\n%.*Rhxs\n", cbAddr, &u)); 1570 if (connect(pThis->hNative, &u.Addr, cbAddr) != 0) 1571 rc = rtSocketError(); 1572 } 1526 1573 1527 1574 rtSocketUnlock(pThis); -
trunk/src/VBox/Runtime/r3/tcp.cpp
r39083 r39801 51 51 #include <iprt/assert.h> 52 52 #include <iprt/err.h> 53 #include <iprt/log.h> 53 54 #include <iprt/mempool.h> 54 55 #include <iprt/mem.h> … … 303 304 RTR3DECL(int) RTTcpServerCreateEx(const char *pszAddress, uint32_t uPort, PPRTTCPSERVER ppServer) 304 305 { 305 int rc;306 307 306 /* 308 307 * Validate input. … … 311 310 AssertPtrReturn(ppServer, VERR_INVALID_PARAMETER); 312 311 313 #ifdef RT_OS_WINDOWS 314 /* 315 * Initialize WinSock and check version. 316 */ 317 WORD wVersionRequested = MAKEWORD(1, 1); 318 WSADATA wsaData; 319 rc = WSAStartup(wVersionRequested, &wsaData); 320 if (wsaData.wVersion != wVersionRequested) 321 { 322 AssertMsgFailed(("Wrong winsock version\n")); 323 return VERR_NOT_SUPPORTED; 324 } 325 #endif 326 327 /* 328 * Get host listening address. 329 */ 330 struct hostent *pHostEnt = NULL; 331 if (pszAddress != NULL && *pszAddress) 332 { 333 pHostEnt = gethostbyname(pszAddress); 334 if (!pHostEnt) 335 { 336 struct in_addr InAddr; 337 InAddr.s_addr = inet_addr(pszAddress); 338 pHostEnt = gethostbyaddr((char *)&InAddr, 4, AF_INET); 339 if (!pHostEnt) 340 { 341 rc = rtSocketResolverError(); 342 return rc; 343 } 344 } 345 } 312 /* 313 * Resolve the address. 314 */ 315 RTNETADDR LocalAddr; 316 int rc = RTSocketParseInetAddress(pszAddress, uPort, &LocalAddr); 317 if (RT_FAILURE(rc)) 318 return rc; 346 319 347 320 /* … … 360 333 if (!rtSocketSetOpt(WaitSock, SOL_SOCKET, SO_REUSEADDR, &fFlag, sizeof(fFlag))) 361 334 { 362 /*363 * Set socket family, address and port.364 */365 struct sockaddr_in LocalAddr;366 RT_ZERO(LocalAddr);367 LocalAddr.sin_family = AF_INET;368 LocalAddr.sin_port = htons(uPort);369 /* if address not specified, use INADDR_ANY. */370 if (!pHostEnt)371 LocalAddr.sin_addr.s_addr = INADDR_ANY;372 else373 LocalAddr.sin_addr = *((struct in_addr *)pHostEnt->h_addr);374 335 375 336 /* 376 337 * Bind a name to a socket and set it listening for connections. 377 338 */ 378 rc = rtSocketBind(WaitSock, (struct sockaddr *)&LocalAddr, sizeof(LocalAddr));339 rc = rtSocketBind(WaitSock, &LocalAddr); 379 340 if (RT_SUCCESS(rc)) 380 341 rc = rtSocketListen(WaitSock, RTTCP_SERVER_BACKLOG); … … 845 806 RTR3DECL(int) RTTcpClientConnect(const char *pszAddress, uint32_t uPort, PRTSOCKET pSock) 846 807 { 847 int rc;848 849 808 /* 850 809 * Validate input. … … 853 812 AssertPtrReturn(pszAddress, VERR_INVALID_POINTER); 854 813 855 #ifdef RT_OS_WINDOWS856 /*857 * Initialize WinSock and check version.858 */859 WORD wVersionRequested = MAKEWORD(1, 1);860 WSADATA wsaData;861 rc = WSAStartup(wVersionRequested, &wsaData);862 if (wsaData.wVersion != wVersionRequested)863 {864 AssertMsgFailed(("Wrong winsock version\n"));865 return VERR_NOT_SUPPORTED;866 }867 #endif868 869 814 /* 870 815 * Resolve the address. 871 816 */ 872 struct hostent *pHostEnt = NULL; 873 pHostEnt = gethostbyname(pszAddress); 874 if (!pHostEnt) 875 { 876 struct in_addr InAddr; 877 InAddr.s_addr = inet_addr(pszAddress); 878 pHostEnt = gethostbyaddr((char *)&InAddr, 4, AF_INET); 879 if (!pHostEnt) 880 { 881 rc = rtSocketResolverError(); 882 AssertMsgFailed(("Could not resolve '%s', rc=%Rrc\n", pszAddress, rc)); 883 return rc; 884 } 885 } 817 RTNETADDR Addr; 818 int rc = RTSocketParseInetAddress(pszAddress, uPort, &Addr); 819 if (RT_FAILURE(rc)) 820 return rc; 886 821 887 822 /* … … 889 824 */ 890 825 RTSOCKET Sock; 826 Log(("Calling rtSocketCreate\n")); 891 827 rc = rtSocketCreate(&Sock, PF_INET, SOCK_STREAM, 0); 892 828 if (RT_SUCCESS(rc)) … … 894 830 RTSocketSetInheritance(Sock, false /*fInheritable*/); 895 831 896 struct sockaddr_in InAddr; 897 RT_ZERO(InAddr); 898 InAddr.sin_family = AF_INET; 899 InAddr.sin_port = htons(uPort); 900 InAddr.sin_addr = *((struct in_addr *)pHostEnt->h_addr); 901 rc = rtSocketConnect(Sock, (struct sockaddr *)&InAddr, sizeof(InAddr)); 832 Log(("Calling rtSocketConnect\n")); 833 rc = rtSocketConnect(Sock, &Addr); 834 Log(("rtSocketConnect returned\n")); 902 835 if (RT_SUCCESS(rc)) 903 836 { -
trunk/src/VBox/Runtime/r3/udp.cpp
r39083 r39801 274 274 RTR3DECL(int) RTUdpServerCreateEx(const char *pszAddress, uint32_t uPort, PPRTUDPSERVER ppServer) 275 275 { 276 int rc;277 276 278 277 /* … … 282 281 AssertPtrReturn(ppServer, VERR_INVALID_PARAMETER); 283 282 284 #ifdef RT_OS_WINDOWS 285 /* 286 * Initialize WinSock and check version. 287 */ 288 WORD wVersionRequested = MAKEWORD(1, 1); 289 WSADATA wsaData; 290 rc = WSAStartup(wVersionRequested, &wsaData); 291 if (wsaData.wVersion != wVersionRequested) 292 { 293 AssertMsgFailed(("Wrong winsock version\n")); 294 return VERR_NOT_SUPPORTED; 295 } 296 #endif 297 298 /* 299 * Get host listening address. 300 */ 301 struct hostent *pHostEnt = NULL; 302 if (pszAddress != NULL && *pszAddress) 303 { 304 pHostEnt = gethostbyname(pszAddress); 305 if (!pHostEnt) 306 { 307 struct in_addr InAddr; 308 InAddr.s_addr = inet_addr(pszAddress); 309 pHostEnt = gethostbyaddr((char *)&InAddr, 4, AF_INET); 310 if (!pHostEnt) 311 { 312 rc = rtSocketResolverError(); 313 return rc; 314 } 315 } 316 } 283 /* 284 * Resolve the address. 285 */ 286 RTNETADDR LocalAddr; 287 int rc = RTSocketParseInetAddress(pszAddress, uPort, &LocalAddr); 288 if (RT_FAILURE(rc)) 289 return rc; 317 290 318 291 /* … … 332 305 { 333 306 /* 334 * Set socket family, address and port.335 */336 struct sockaddr_in LocalAddr;337 RT_ZERO(LocalAddr);338 LocalAddr.sin_family = AF_INET;339 LocalAddr.sin_port = htons(uPort);340 /* if address not specified, use INADDR_ANY. */341 if (!pHostEnt)342 LocalAddr.sin_addr.s_addr = INADDR_ANY;343 else344 LocalAddr.sin_addr = *((struct in_addr *)pHostEnt->h_addr);345 346 /*347 307 * Bind a name to the socket. 348 308 */ 349 rc = rtSocketBind(Sock, (struct sockaddr *)&LocalAddr, sizeof(LocalAddr));309 rc = rtSocketBind(Sock, &LocalAddr); 350 310 if (RT_SUCCESS(rc)) 351 311 { -
trunk/src/VBox/Runtime/r3/win/process-win.cpp
r38618 r39801 1276 1276 RTR3DECL(int) RTProcTerminate(RTPROCESS Process) 1277 1277 { 1278 if (Process == NIL_RTPROCESS) 1279 return VINF_SUCCESS; 1280 1278 1281 int rc = RTOnce(&g_rtProcWinInitOnce, rtProcWinInitOnce, NULL, NULL); 1279 1282 AssertRCReturn(rc, rc); -
trunk/src/VBox/Runtime/win/RTErrConvertFromWin32.cpp
r33437 r39801 392 392 //case WSANOTINITIALISED (WSABASEERR+93) 393 393 394 //case WSAHOST_NOT_FOUND (WSABASEERR+1001) 395 //case WSATRY_AGAIN (WSABASEERR+1002) 396 //case WSANO_RECOVERY (WSABASEERR+1003) 397 //case WSANO_DATA (WSABASEERR+1004) 394 #ifdef WSAHOST_NOT_FOUND 395 case WSAHOST_NOT_FOUND: return VERR_NET_HOST_NOT_FOUND; 396 #endif 397 #ifdef WSATRY_AGAIN 398 case WSATRY_AGAIN: return VERR_TRY_AGAIN; 399 #endif 400 #ifndef WSANO_RECOVERY 401 case WSANO_RECOVERY: return VERR_IO_GEN_FAILURE; 402 #endif 403 #ifdef WSANO_DATA 404 case WSANO_DATA: return VERR_NET_ADDRESS_NOT_AVAILABLE; 405 #endif 398 406 399 407
注意:
瀏覽 TracChangeset
來幫助您使用更動檢視器