tcp_errs.c

来自「mcf5307实验源代码」· C语言 代码 · 共 387 行 · 第 1/2 页

C
387
字号
/* OUTPUTS																	*/
/*	Will update the value to the TCP_Avail_Index variable.					*/
/*                                                                          */
/* HISTORY                                                                  */
/*                                                                          */
/*     NAME             DATE        REMARKS                                 */
/*                                                                          */
/*                                                                          */
/****************************************************************************/

void NU_Tcp_Clear_All_Errors ()
{
#ifdef PLUS
    STATUS status;
#else
    int16 status;                        /* status of memory allocation */
#endif

	/* allocate the TCP/IP resource for blocking during this time */
#ifdef PLUS
    status = NU_Obtain_Semaphore(&TCP_Resource, NU_SUSPEND);
#else
    status = NU_Request_Resource(TCP_Resource, NU_WAIT_FOREVER);
#endif
    if (status != NU_SUCCESS)
    {
		return;
	}

	/* clear all the error by reseting the index value */
	TCP_Avail_Index = -1;

	/* deallocate the TCP/IP resource */
#ifdef PLUS
    status = NU_Release_Semaphore(&TCP_Resource);
#else
    status = NU_Release_Resource(TCP_Resource);
#endif
	if (status != NU_SUCCESS)
	{
		return;
	}
}  /* end NU_Tcp_Clear_All_Errors */

#ifdef TCP_ERR_STRS
	/*
	 * This structure array is only used and defined if the def TCP_ERR_STRS is
	 * defined.  This will allow for space saving if you do not wish to handle the
	 * printing of the static text strings explaining the actual error code.
	 */
    struct TCP_MSG_STR TCP_Error_Strings[] =
	{
		{0, "Error unknown"},
		{100, "Network jammed, probable break in wire"},
		{101, "Could not initialize hardware level network driver"},
		{102, "ERROR: The conflicting machine is using the same IP number"},
		{103, "RARP request failed, an IP number is required"},
		{300, "Bad IP checksum"},
		{301, "IP packet not for me"},
		{302, "IP packet with options received"},
		{303, "IP: unknown higher layer protocol"},
		{304, "IP: fragmented packet received, frags not supported"},
		{400, "TCP: bad checksum"},
		{401, "ACK invalid for TCP syn sent"},
		{403, "TCP in unknown state"},
		{404, "Invalid port for TCPsend"},
		{405, "TCP connection reset by other host"},
		{406, "Null port specified for ackandtrans"},
		{407, "Packet received for invalid port -- reset sent"},
		{500, "No internal TCP ports available"},
		{501, "Warning: Event queue filled, probably non-fatal"},
		{504, "Local host or gateway not responding"},
		{505, "Memory allocation error, cannot open port"},
		{506, "Not allowed to connect to broadcast address"},
		{507, "Reset received: syn sent, host is refusing connection"},
        {508, "Partition allocation error"},
        {600, "ICMP:   Echo reply"},
		{603, "ICMP:   Destination unreachable"},
		{604, "ICMP:   Source Quench"},
		{605, "ICMP:   Redirect, another gateway is more efficient"},
		{608, "ICMP:   Echo requested (ping requested)"},
		{611, "ICMP:   Time Exceeded on Packet"},
		{612, "ICMP:   Parameter problem in IP"},
		{613, "ICMP:   Timestamp request"},
		{614, "ICMP:   Timestamp reply"},
		{615, "ICMP:   Information request"},
		{616, "ICMP:   Information reply"},
		{699, "ICMP: Checksum error"},
		{700, "Bad UDP checksum"},
		{800, "Domain: Name request to server failed"},
		{801, "Domain: Using default domain"},
		{802, "Domain: name does not exist"},
		{803, "Domain: UDP name server did not resolve the name"},
		{804, "Domain: name server failed, unknown reason"},
		{805, "Host machine not in configuration file"},
		{806, "Missing IP number, requires domain lookup"},
		{900, "Session: Cannot find or open configuration file"},
		{901, "Session: Cannot allocate memory for processing"},
		{902, "Session: Invalid keyword in configuration file"},
		{903, "Session: Element too long (>200), maybe missing quote"},
        {904, "Session: Probable missing quote marks, a field must be on one line"},
		{905, "Session: 'name' field required before other machine entries"},
		{906, "Session: Syntax error, invalid IP number"},
		{907, "Session: Syntax error, Subnet mask invalid"},
		{908, "Session: Syntax error, IP address for this PC is invalid"},
		{-1, ""}
	};

/****************************************************************************/
/* FUNCTION                                                                 */
/*  NU_Tcp_Error_String ()                                                  */
/*                                                                          */
/* DESCRIPTION                                                              */
/*  This routine will handle returning the actual character string for the  */
/*  error number passed in.  This will not change the current error array   */
/*  in any way.                                                             */
/*                                                                          */
/* AUTHOR                                                                   */
/*                                                                          */
/* Craig L. Meredith                                                        */
/*                                                                          */
/* CALLED BY                                                                */
/*                                                                          */
/*                                                                          */
/* CALLS                                                                    */
/*                                                                          */
/*   NU_Request_Resource ()                                                 */
/*   NU_Release_Resource ()                                                 */
/*                                                                          */
/* INPUTS                                                                   */
/*  uint16 error_number :   Error number for which a string is wished.      */
/*                                                                          */
/* OUTPUTS                                                                  */
/*  uint8 * returned to the caller, which will point to the character str.  */
/*                                                                          */
/* HISTORY                                                                  */
/*                                                                          */
/*     NAME             DATE        REMARKS                                 */
/*                                                                          */
/*                                                                          */
/****************************************************************************/
uint8 *NU_Tcp_Error_String (uint16 error_number)
{
    struct TCP_MSG_STR *string_ptr;
#ifdef PLUS
    STATUS status;
#else
    int16 status;                        /* status of memory allocation */
#endif

		/* allocate the TCP/IP resource for blocking during this time */
#ifdef PLUS
        status = NU_Obtain_Semaphore(&TCP_Resource, NU_SUSPEND);
#else
        status = NU_Request_Resource(TCP_Resource, NU_WAIT_FOREVER);
#endif
    if (status != NU_SUCCESS)
        return ((uint8 *) NU_NULL);

    /* start at the front of the list */
    string_ptr = &TCP_Error_Strings[0];

    /*
     * search thourgh the array until the error number is found or end
     * of the list.  If the end of the list is reached, a NU_NULL will be
     * returned.
     */
    while (string_ptr->tms_err_str != (uint8 *)NU_NULL)
    {
        /* check for this is the error string we want */
        if (string_ptr->tms_err_num == error_number)
        {
            return ((uint8 *)string_ptr);
        }  /* end error string found */

        /* move to the next possible error string */
        string_ptr++;
    }

    /* deallocate the TCP/IP resource */
#ifdef PLUS
    status = NU_Release_Semaphore(&TCP_Resource);
#else
    status = NU_Release_Resource(TCP_Resource);
#endif
    if (status != NU_SUCCESS)
        return ((uint8 *) NU_NULL);
        
    /* return NU_NULL, error string not found */
    return ((uint8 *) NU_NULL);
}  /* end NU_Tcp_Error_String */
#endif	/* TCP_ERR_STRS */

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?