Changeset 21663 in vbox
- Timestamp:
- Jul 17, 2009 5:03:48 AM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Devices/Network/slirp/udp.c
r21049 r21663 368 368 udp_attach(PNATState pData, struct socket *so, int service_port) 369 369 { 370 struct sockaddr_in addr;370 struct sockaddr_in *addr; 371 371 struct sockaddr sa_addr; 372 372 socklen_t socklen = sizeof(struct sockaddr); 373 373 int status; 374 375 if ((so->s = socket(AF_INET, SOCK_DGRAM, 0)) != -1) 376 { 377 /* 378 * Here, we bind() the socket. Although not really needed 379 * (sendto() on an unbound socket will bind it), it's done 380 * here so that emulation of ytalk etc. don't have to do it 381 */ 382 memset(&addr, 0, sizeof(addr)); 374 int opt = 1; 375 376 if ((so->s = socket(AF_INET, SOCK_DGRAM, 0)) == -1) 377 goto error; 378 /* 379 * Here, we bind() the socket. Although not really needed 380 * (sendto() on an unbound socket will bind it), it's done 381 * here so that emulation of ytalk etc. don't have to do it 382 */ 383 memset(&sa_addr, 0, sizeof(struct sockaddr)); 384 addr = (struct sockaddr_in *)&sa_addr; 383 385 #ifdef RT_OS_DARWIN 384 addr.sin_len = sizeof(addr);386 addr->sin_len = sizeof(struct sockaddr_in); 385 387 #endif 386 addr.sin_family = AF_INET;387 addr.sin_port = service_port;388 addr.sin_addr.s_addr = pData->bindIP.s_addr;389 390 if (bind(so->s, (struct sockaddr *)&addr, sizeof(addr)) < 0)391 392 393 394 388 addr->sin_family = AF_INET; 389 addr->sin_port = service_port; 390 addr->sin_addr.s_addr = pData->bindIP.s_addr; 391 fd_nonblock(so->s); 392 if (bind(so->s, &sa_addr, sizeof(struct sockaddr_in)) < 0) 393 { 394 int lasterrno = errno; 395 closesocket(so->s); 396 so->s = -1; 395 397 #ifdef RT_OS_WINDOWS 396 398 WSASetLastError(lasterrno); 397 399 #else 398 400 errno = lasterrno; 399 401 #endif 400 } 401 else 402 { 403 int opt = 1; 404 /* success, insert in queue */ 405 so->so_expire = curtime + SO_EXPIRE; 406 /* enable broadcast for later use */ 407 setsockopt(so->s, SOL_SOCKET, SO_BROADCAST, (const char *)&opt, sizeof(opt)); 408 status = getsockname(so->s, &sa_addr, &socklen); 409 Assert(status == 0 && sa_addr.sa_family == AF_INET); 410 so->so_hlport = ((struct sockaddr_in *)&sa_addr)->sin_port; 411 so->so_hladdr.s_addr = ((struct sockaddr_in *)&sa_addr)->sin_addr.s_addr; 412 SOCKET_LOCK_CREATE(so); 413 QSOCKET_LOCK(udb); 414 insque(pData, so, &udb); 415 NSOCK_INC(); 416 QSOCKET_UNLOCK(udb); 417 } 418 } 419 else 420 { 421 LogRel(("NAT: can't create datagramm socket\n")); 422 } 402 goto error; 403 } 404 /* success, insert in queue */ 405 so->so_expire = curtime + SO_EXPIRE; 406 /* enable broadcast for later use */ 407 setsockopt(so->s, SOL_SOCKET, SO_BROADCAST, (const char *)&opt, sizeof(opt)); 408 status = getsockname(so->s, &sa_addr, &socklen); 409 Assert(status == 0 && sa_addr.sa_family == AF_INET); 410 so->so_hlport = ((struct sockaddr_in *)&sa_addr)->sin_port; 411 so->so_hladdr.s_addr = ((struct sockaddr_in *)&sa_addr)->sin_addr.s_addr; 412 SOCKET_LOCK_CREATE(so); 413 QSOCKET_LOCK(udb); 414 insque(pData, so, &udb); 415 NSOCK_INC(); 416 QSOCKET_UNLOCK(udb); 423 417 return so->s; 418 error: 419 LogRel(("NAT: can't create datagramm socket\n")); 420 return -1; 424 421 } 425 422
Note:
See TracChangeset
for help on using the changeset viewer.