BOOL LWIP_SOCKETS_Driver::Uninitialize() { NATIVE_PROFILE_PAL_NETWORK(); PostAddressChangedContinuation.Abort(); PostAvailabilityOnContinuation.Abort(); PostAvailabilityOffContinuation.Abort(); for(int i=0; i<g_NetworkConfig.NetworkInterfaceCount; i++) { Network_Interface_Close(i); } tcpip_shutdown(); return TRUE; }
static int tcpip_connect2(struct sockaddr_in server) { int fd; DEB((D_INFO, "tcpip_connect2: trying \"%s\" at port %d", inet_ntoa(server.sin_addr), (int)ntohs(server.sin_port))); if( (fd = socket(AF_INET, SOCK_STREAM, 0)) < 0 ) { logerr("can't create socket"); return(1); } /* make new fd == stdin if it isn't already */ if( fd > 0 ) { (void)close(0); if( dup(fd) != 0 ) { logerr("cannot dup socket to stdin"); return(1); } } /* make stdout and stderr, too */ (void)close(1); (void)close(2); if( dup(0) != 1 ) { logerr("cannot dup stdin to stdout"); return(1); } if( dup(0) != 2 ) { logerr("cannot dup stdin to stderr"); return(1); } if( fd > 2 ) (void)close(fd); /* switch off stdio buffering */ setbuf(stdin, (char *)NULL); setbuf(stdout, (char *)NULL); setbuf(stderr, (char *)NULL); clearerr(stdin); clearerr(stdout); clearerr(stderr); if( connect(0, (struct sockaddr*)&server, sizeof(server)) == -1 ) { logerr("can't connect to %s", inet_ntoa(server.sin_addr)); close(0); close(1); close(2); return 1; } if( tcpip_init() ) { tcpip_shutdown(); return 1; } log("TCP/IP connect to %s on port %d", inet_ntoa(server.sin_addr), (int)ntohs(server.sin_port)); return(0); }