char *pData, *pStart;
char *pData, *pStart, *pEnd;
ProcessConnectionSetup (iceConn, length, swap)IceConn		iceConn;unsigned long	length;Bool		swap;{    iceConnectionSetupMsg *message;    int  myVersionCount, hisVersionCount;    int	 myVersionIndex, hisVersionIndex;    int  hisMajorVersion, hisMinorVersion;    int	 myAuthCount, hisAuthCount;    int	 found, i, j;    char *myAuthName, **hisAuthNames;    char *pData, *pStart;    char *vendor = NULL;    char *release = NULL;    int myAuthIndex = 0;    int hisAuthIndex = 0;    int accept_setup_now = 0;    char mustAuthenticate;    int	authUsableCount;    int	authUsableFlags[MAX_ICE_AUTH_NAMES];    int	authIndices[MAX_ICE_AUTH_NAMES];    CHECK_AT_LEAST_SIZE (iceConn, ICE_ConnectionSetup,	length, SIZEOF (iceConnectionSetupMsg), IceFatalToConnection);    IceReadCompleteMessage (iceConn, SIZEOF (iceConnectionSetupMsg),	iceConnectionSetupMsg, message, pStart);    if (!IceValidIO (iceConn))    {	IceDisposeCompleteMessage (iceConn, pStart);	return (0);    }    pData = pStart;    SKIP_STRING (pData, swap);				       /* vendor */    SKIP_STRING (pData, swap);				       /* release */    SKIP_LISTOF_STRING (pData, swap, (int) message->authCount);/* auth names */    pData += (message->versionCount * 4);		       /* versions */    CHECK_COMPLETE_SIZE (iceConn, ICE_ConnectionSetup,	length, pData - pStart + SIZEOF (iceConnectionSetupMsg),	pStart, IceFatalToConnection);    mustAuthenticate = message->mustAuthenticate;    if (mustAuthenticate != 0 && mustAuthenticate != 1)    {	_IceErrorBadValue (iceConn, 0,	    ICE_ConnectionSetup, 8, 1, &mustAuthenticate);	iceConn->connection_status = IceConnectRejected;	IceDisposeCompleteMessage (iceConn, pStart);	return (0);    }    pData = pStart;    EXTRACT_STRING (pData, swap, vendor);    EXTRACT_STRING (pData, swap, release);    if ((hisAuthCount = message->authCount) > 0)    {	hisAuthNames = (char **) malloc (hisAuthCount * sizeof (char *));	EXTRACT_LISTOF_STRING (pData, swap, hisAuthCount, hisAuthNames);    }    hisVersionCount = message->versionCount;    myVersionCount = _IceVersionCount;    hisVersionIndex = myVersionIndex = found = 0;    for (i = 0; i < hisVersionCount && !found; i++)    {	EXTRACT_CARD16 (pData, swap, hisMajorVersion);	EXTRACT_CARD16 (pData, swap, hisMinorVersion);	for (j = 0; j < myVersionCount && !found; j++)	{	    if (_IceVersions[j].major_version == hisMajorVersion &&		_IceVersions[j].minor_version == hisMinorVersion)	    {		hisVersionIndex = i;		myVersionIndex = j;		found = 1;	    }	}    }    if (!found)    {	_IceErrorNoVersion (iceConn, ICE_ConnectionSetup);	iceConn->connection_status = IceConnectRejected;	free (vendor);	free (release);	if (hisAuthCount > 0)	{	    for (i = 0; i < hisAuthCount; i++)		free (hisAuthNames[i]);		    free ((char *) hisAuthNames);	}	IceDisposeCompleteMessage (iceConn, pStart);	return (0);    }    _IceGetPaValidAuthIndices ("ICE", iceConn->connection_string,	_IceAuthCount, _IceAuthNames, &authUsableCount, authIndices);    for (i = 0; i < _IceAuthCount; i++)    {	authUsableFlags[i] = 0;	for (j = 0; j < authUsableCount && !authUsableFlags[i]; j++)	    authUsableFlags[i] = (authIndices[j] == i);    }    myAuthCount = _IceAuthCount;    for (i = found = 0; i < myAuthCount && !found; i++)    {	if (authUsableFlags[i])	{	    myAuthName = _IceAuthNames[i];	    for (j = 0; j < hisAuthCount && !found; j++)		if (strcmp (myAuthName, hisAuthNames[j]) == 0)		{		    myAuthIndex = i;		    hisAuthIndex = j;		    found = 1;		}	}    }    if (!found)    {	/*	 * None of the authentication methods specified by the	 * other client is supported.  If the other client requires	 * authentication, we must reject the connection now.	 * Otherwise, we can invoke the host-based authentication callback	 * to see if we can accept this connection.	 */	if (mustAuthenticate || !iceConn->listen_obj->host_based_auth_proc)	{	    _IceErrorNoAuthentication (iceConn, ICE_ConnectionSetup);	    iceConn->connection_status = IceConnectRejected;	}	else	{	    char *hostname = _IceGetPeerName (iceConn);	    if ((*iceConn->listen_obj->host_based_auth_proc) (hostname))	    {		accept_setup_now = 1;	    }	    else 	    {		_IceErrorAuthenticationRejected (iceConn,	            ICE_ConnectionSetup, "None of the authentication protocols specified are supported and host-based authentication failed");		iceConn->connection_status = IceConnectRejected;	    }	    if (hostname)		free (hostname);	}	if (iceConn->connection_status == IceConnectRejected)	{	    free (vendor);	    free (release);	}    }    else    {	IcePaAuthStatus	status;	int		authDataLen;	IcePointer	authData = NULL;	IcePointer	authState;	char		*errorString = NULL;	IcePaAuthProc	authProc = _IcePaAuthProcs[myAuthIndex];	authState = NULL;	status = (*authProc) (iceConn, &authState,	    swap, 0, NULL, &authDataLen, &authData, &errorString);	if (status == IcePaAuthContinue)	{	    _IceConnectToMeInfo *setupInfo;	    AuthRequired (iceConn, hisAuthIndex, authDataLen, authData);	    iceConn->connect_to_me = setupInfo = (_IceConnectToMeInfo *)		malloc (sizeof (_IceConnectToMeInfo));	    setupInfo->my_version_index = myVersionIndex;	    setupInfo->his_version_index = hisVersionIndex;	    setupInfo->his_vendor = vendor;	    setupInfo->his_release = release;	    setupInfo->my_auth_index = myAuthIndex;	    setupInfo->my_auth_state = authState;	    setupInfo->must_authenticate = mustAuthenticate;	}	else if (status == IcePaAuthAccepted)	{	    accept_setup_now = 1;	}	if (authData && authDataLen > 0)	    free ((char *) authData);	if (errorString)	    free (errorString);    }        if (accept_setup_now)    {	AcceptConnection (iceConn, hisVersionIndex);	iceConn->vendor = vendor;	iceConn->release = release;	iceConn->my_ice_version_index = myVersionIndex;    }    if (hisAuthCount > 0)    {	for (i = 0; i < hisAuthCount; i++)	    free (hisAuthNames[i]);		free ((char *) hisAuthNames);    }    IceDisposeCompleteMessage (iceConn, pStart);    return (0);}