⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 m2tcplib.c

📁 VXWORKS源代码
💻 C
📖 第 1 页 / 共 2 页
字号:
** RETURNS: 0 = equal, 1 > greater than, and -1 < less than.** SEE ALSO: N/A*/LOCAL int tcpConnCmp    (    M2_TCPCONNTBL * pConnVal1,	/* pointer to control block (Compare againts) */    M2_TCPCONNTBL * pConnVal2	/* pointer to control block (Second entry) */    )    {    int result;	/* Comparison of two unsigned values */        if (pConnVal1->tcpConnLocalAddress > pConnVal2->tcpConnLocalAddress)            {            return 1;                   /* First Entry is Greater */            }         if (pConnVal1->tcpConnLocalAddress < pConnVal2->tcpConnLocalAddress)            {            return -1;                  /* First Entry is Smaller */            }	/* Comparison of two signed values */        result = pConnVal1->tcpConnLocalPort - pConnVal2->tcpConnLocalPort;         if (result != 0)            return (result);		/* Value > 0 or < 0 */ 	/* Comparison of two unsigned values */        if (pConnVal1->tcpConnRemAddress > pConnVal2->tcpConnRemAddress)            {            return 1;                   /* First Entry is Greater */            }         if (pConnVal1->tcpConnRemAddress < pConnVal2->tcpConnRemAddress)            {            return -1;                  /* First Entry is Smaller */            }         /* Result will determine Equal, Less than or Greater than */         return (pConnVal1->tcpConnRemPort - pConnVal2->tcpConnRemPort);    }/******************************************************************************** m2TcpConnEntryGet - get a MIB-II TCP connection table entry** This routine traverses the TCP table of users and does an* M2_EXACT_VALUE or a M2_NEXT_VALUE search based on the* <search> parameter (see m2Lib).  The calling routine is responsible* for supplying a valid MIB-II entry index in the input structure* <pReqTcpConnEntry>.  The index is made up of the local IP address,* the local port number, the remote IP address, and the remote port.* The first entry in the table is retrieved by doing a M2_NEXT_VALUE* search with the index fields set to zero.** RETURNS: * OK, or ERROR if the input parameter is not specified or a* match is not found.** ERRNO:*  S_m2Lib_INVALID_PARAMETER*  S_m2Lib_ENTRY_NOT_FOUND** SEE ALSO:* m2Lib, m2TcpInit(), m2TcpGroupInfoGet(), m2TcpConnEntrySet(), m2TcpDelete()*/STATUS m2TcpConnEntryGet    (    int             search,             /* M2_EXACT_VALUE or M2_NEXT_VALUE */    M2_TCPCONNTBL * pReqTcpConnEntry    /* input = Index, Output = Entry */    )    {    M2_TCPCONNTBL   savedEntry; /* Use to save the table entry to return */    M2_TCPCONNTBL   tableEntry; /* Use to test an entry in the table */    int              netLock;   /* Use to secure the Network Code Access */    struct inpcb   * pPcb;      /* Pointer to an entry in TCP Connection List */     /* Validate Pointer to TCP Table Entry structure */     if (pReqTcpConnEntry == NULL)	{	errnoSet (S_m2Lib_INVALID_PARAMETER);        return (ERROR);	}    /* Setup structure used in the search for the requested TCP entry */    savedEntry.tcpConnState        =  TCP_NSTATES;  /* Invalid TCP State */    savedEntry.tcpConnLocalAddress = -1;	    /* Largest local IP Addr */    savedEntry.tcpConnLocalPort    = -1;	    /* Largest local port */     savedEntry.tcpConnRemAddress   = -1;	    /* Largest Remote IP Addr */    savedEntry.tcpConnRemPort      = -1;	    /* Largest Remote Port */     netLock = splnet ();        /* Get exclusive access to Network Code */    /*      * Traverse the circular list of TCP control blocks.  The first item in the     * list is a dummy header, skip it and used it as the loop exit condition.     */#ifdef VIRTUAL_STACK    /*     * To avoid introducing a conflict with the "tcpcb" structure tag,     * virtual stacks do not alias the head of the pcb list.     */    for (pPcb = tcb.lh_first; pPcb != NULL; pPcb = pPcb->inp_list.le_next)#else    for (pPcb = tcpcb.lh_first; pPcb != NULL; pPcb = pPcb->inp_list.le_next)#endif        { 	/* Convert control block format into a more convenient format */        tableEntry.tcpConnLocalAddress = ntohl(pPcb->inp_laddr.s_addr);        tableEntry.tcpConnLocalPort    = ntohs(pPcb->inp_lport);        tableEntry.tcpConnRemAddress   = ntohl(pPcb->inp_faddr.s_addr);        tableEntry.tcpConnRemPort      = ntohs(pPcb->inp_fport);         if (search == M2_EXACT_VALUE &&	    (tcpConnCmp(&tableEntry, pReqTcpConnEntry) == 0))            {	    /* Match, map the connection state to MIB-II format and exit */            pReqTcpConnEntry->tcpConnState =		    m2TcpStates [((struct tcpcb *) pPcb->inp_ppcb)->t_state];             splx (netLock);      /* Give up exclusive access to Network Code */            return (OK);            }        else            {            /*             * A NEXT search is satisfied by an entry that is lexicographicaly             * greater than the input TCP connection entry.  Because the TCP 	     * connection list is not in order, the list must be traverse 	     * completly before a selection is made.  The rules for a 	     * lexicographicaly comparison are built in the routine tcpConnCmp.             */              if ((tcpConnCmp(&tableEntry, pReqTcpConnEntry) >= 0) &&                (tcpConnCmp(&tableEntry, &savedEntry) < 0))                {                savedEntry.tcpConnLocalAddress = ntohl(pPcb->inp_laddr.s_addr);                savedEntry.tcpConnLocalPort    = ntohs(pPcb->inp_lport);                savedEntry.tcpConnRemAddress   = ntohl(pPcb->inp_faddr.s_addr);                savedEntry.tcpConnRemPort      = ntohs(pPcb->inp_fport);		/* Save the connection state in BSD format */                savedEntry.tcpConnState =                        ((struct tcpcb *) pPcb->inp_ppcb)->t_state;                }            }        }     splx (netLock);             /* Give up exclusive access to Network Code */     if (savedEntry.tcpConnState == TCP_NSTATES)	{	errnoSet (S_m2Lib_ENTRY_NOT_FOUND);        return (ERROR);                 /* Requested Entry Not Found */	}     pReqTcpConnEntry->tcpConnState      = m2TcpStates [savedEntry.tcpConnState];    pReqTcpConnEntry->tcpConnLocalAddress = savedEntry.tcpConnLocalAddress;    pReqTcpConnEntry->tcpConnLocalPort    = savedEntry.tcpConnLocalPort;    pReqTcpConnEntry->tcpConnRemAddress   = savedEntry.tcpConnRemAddress;    pReqTcpConnEntry->tcpConnRemPort      = savedEntry.tcpConnRemPort;     return (OK);    }/******************************************************************************** m2TcpConnEntrySet -  set a TCP connection to the closed state** This routine traverses the TCP connection table and searches for the* connection specified by the input parameter <pReqTcpConnEntry>. The* calling routine is responsible for providing a valid index as the* input parameter <pReqTcpConnEntry>.  The index is made up of the* local IP address, the local port number, the remote IP address, and* the remote port.  This call can only succeed if the connection is in* the MIB-II state "deleteTCB" (12).  If a match is found, the socket* associated with the TCP connection is closed.** RETURNS: * OK, or ERROR if the input parameter is invalid, the state of the* connection specified at <pReqTcpConnEntry> is not "closed,"* the specified connection is not found, a socket is not associated* with the connection, or the close() call fails.** SEE ALSO: * m2TcpInit(), m2TcpGroupInfoGet(), m2TcpConnEntryGet(), m2TcpDelete()*/STATUS m2TcpConnEntrySet    (    M2_TCPCONNTBL * pReqTcpConnEntry  /* pointer to TCP connection  to close */    )    {    int               fdToClose;     /* Selected File Descriptor to close */    int               netLock;       /* Use to secure the Network Code Access */    struct inpcb    * pInp;	     /* Pointer to BSD PCB list */    struct in_addr    loc_addr;	     /* Local IP Address structure */    struct in_addr    rem_addr;      /* Remote IP Address structure */    unsigned short    locPort;    unsigned short    remPort;     /* Validate Pointer to TCP Table Entry structure and operation  */     if (pReqTcpConnEntry == NULL ||        pReqTcpConnEntry->tcpConnState != M2TCP_DELETETCB)	{	errnoSet (S_m2Lib_INVALID_PARAMETER);        return (ERROR);	}     /* Look for the Internet Control Block which maps to the TCP Entry */    locPort         = pReqTcpConnEntry->tcpConnLocalPort;    remPort         = pReqTcpConnEntry->tcpConnRemPort;     loc_addr.s_addr = htonl(pReqTcpConnEntry->tcpConnLocalAddress);    locPort         = htons(locPort);    rem_addr.s_addr = htonl(pReqTcpConnEntry->tcpConnRemAddress);    remPort         = htons(remPort);     netLock = splnet ();        /* Get exclusive access to Network Code */     if ((pInp = in_pcblookup (&tcbinfo, rem_addr,		      remPort, loc_addr, locPort, 0)) == NULL)        {        splx (netLock);         /* Give up exclusive access to Network Code */	errnoSet (S_m2Lib_ENTRY_NOT_FOUND);        return (ERROR);		/* Entry not found */        }     splx (netLock);             /* Give up exclusive access to Network Code */     /* Look for the FD to issue close in the File Descriptor Table */     for (fdToClose = 0; fdToClose < maxFiles ; fdToClose++)        {#ifdef _WRS_VXWORKS_5_X            if (fdTable [fdToClose].value == (int) pInp->inp_socket)#else            if (fdTable [fdToClose] &&                fdTable [fdToClose]->value == (int) pInp->inp_socket)#endif /* _WRS_VXWORKS_5_X */                            break;        }     if (fdToClose >= maxFiles)	{	errnoSet (S_m2Lib_TCPCONN_FD_NOT_FOUND);        return (ERROR);	}     /* Issue Close */    fdToClose = STD_FIX(fdToClose);     return (close (fdToClose));    }/********************************************************************************* m2TcpDelete - delete all resources used to access the TCP group** This routine frees all the resources allocated at the time the group was* initialized.  The TCP group should not be accessed after this routine has been* called.** RETURNS: OK, always.** SEE ALSO: * m2TcpInit(), m2TcpGroupInfoGet(), m2TcpConnEntryGet(), m2TcpConnEntrySet() */STATUS m2TcpDelete (void)    {    return (OK);    }

⌨️ 快捷键说明

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