BOOL ConnectAuthSocket ( SOCKET *s, CredHandle *hCred, struct _SecHandle *hcText) { unsigned long ulAddress; struct hostent *pHost; SOCKADDR_IN sin; //-------------------------------------------------------------------- // Lookup the server's address. ulAddress = inet_addr (ServerName); if (INADDR_NONE == ulAddress) { pHost = gethostbyname (ServerName); if (NULL == pHost) { MyHandleError("Unable to resolve host name "); } memcpy((char FAR *)&ulAddress, pHost->h_addr, pHost->h_length); } //-------------------------------------------------------------------- // Create the socket. *s = socket ( PF_INET, SOCK_STREAM, 0); if (INVALID_SOCKET == *s) { MyHandleError("Unable to create socket"); } else { printf("Socket created.\n"); } sin.sin_family = AF_INET; sin.sin_addr.s_addr = ulAddress; sin.sin_port = htons (g_usPort); //-------------------------------------------------------------------- // Connect to the server. if (connect (*s, (LPSOCKADDR) &sin, sizeof (sin))) { closesocket (*s); MyHandleError( "Connect failed "); } //-------------------------------------------------------------------- // Authenticate the connection. if (!DoAuthentication (*s)) { closesocket (*s); MyHandleError("Authentication "); } return(TRUE); } // end ConnectAuthSocket
void main () { DoAuthentication(); }