📄 wvnetlib.c
字号:
/* * Convert the offset to an array index based on the number of * bytes in the bitmap. */ byteIndex = WVNET_MASKSIZE - 1 - byteOffset; /* * Set event map so WV_NET_EVENT_TEST macro will accept the * specified event. */ mask = 1 << (offset % 8); wvNetEventMap [index].bitmap [byteIndex] |= mask; } return (result); }/********************************************************************************* wvNetEventDisable - deactivate specific network events** This routine prevents reporting of a single event within the priority equal * to <level>. The activation is overridden if the setting for the entire * priority level changes. The available priority values are:** WV_NET_EMERGENCY (1)* WV_NET_ALERT (2)* WV_NET_CRITICAL (3)* WV_NET_ERROR (4)* WV_NET_WARNING (5)* WV_NET_NOTICE (6)* WV_NET_INFO (7)* WV_NET_VERBOSE (8)* * Offset values for individual events are listed in the documentation.** RETURNS: OK, or ERROR for unknown event.** ERRNO: N/A*/STATUS wvNetEventDisable ( int priority, /* priority level of event */ int offset /* identifier within priority level */ ) { STATUS result = OK; int index; UCHAR mask; int byteOffset; int byteIndex; switch (priority) { case WV_NET_EMERGENCY: if (offset > maxEmergencyOffset) result = ERROR; break; case WV_NET_ALERT: if (offset > maxAlertOffset) result = ERROR; break; case WV_NET_CRITICAL: if (offset > maxCriticalOffset) result = ERROR; break; case WV_NET_ERROR: if (offset > maxErrorOffset) result = ERROR; break; case WV_NET_WARNING: if (offset > maxWarningOffset) result = ERROR; break; case WV_NET_NOTICE: if (offset > maxNoticeOffset) result = ERROR; break; case WV_NET_INFO: if (offset > maxInfoOffset) result = ERROR; break; case WV_NET_VERBOSE: if (offset > maxVerboseOffset) result = ERROR; break; default: /* Unknown priority level */ result = ERROR; break; } /* * Because of array indexing, the index into the event map is one * less than the value assigned to the priority level. */ index = priority - 1; if (result == OK) { byteOffset = offset / 8; /* * Convert the offset to an array index based on the number of * bytes in the bitmap. */ byteIndex = WVNET_MASKSIZE - 1 - byteOffset; /* * Set event map so WV_NET_EVENT_TEST macro will reject the * specified event. */ mask = ~ (1 << (offset % 8)); wvNetEventMap [index].bitmap [byteIndex] &= mask; } return (result); }/********************************************************************************* wvNetAddressFilterSet - specify an address filter for events** This routine activates an additional test that disables certain events* that do not match the specified IP address. The <pAddress> parameter* provides the test value in dotted-decimal format. The <type> parameter* indicates whether that address is compared against the source or* destination values, and the <direction> value identifies whether the * <type> is interpreted from the perspective of incoming or outgoing traffic.* The <pMask> parameter provides a network mask to support testing for a* group of events.** RETURNS: OK if filter set, or ERROR otherwise.** ERRNO: N/A**/STATUS wvNetAddressFilterSet ( char * pAddress, /* target address for event comparisons */ char * pMask, /* mask value applied to data fields */ int type, /* 0 for source, 1 for destination */ int direction /* 0 for input, 1 for output */ ) { int targetAddr; int targetMask; STATUS result = OK; targetAddr = inet_addr (pAddress); targetMask = inet_addr (pMask); if (targetAddr == ERROR) /* targetMask of 255.255.255.255 is OK. */ return (ERROR); if (direction == 0 && type == 0) { wvNetInputSrcAddr = targetAddr; wvNetInputSrcMask = targetMask; wvNetInputSrcAddrFlag = TRUE; } else if (direction == 0 && type == 1) { wvNetInputDstAddr = targetAddr; wvNetInputDstMask = targetMask; wvNetInputDstAddrFlag = TRUE; } else if (direction == 1 && type == 0) { wvNetOutputSrcAddr = targetAddr; wvNetOutputSrcMask = targetMask; wvNetOutputSrcAddrFlag = TRUE; } else if (direction == 1 && type == 1) { wvNetOutputDstAddr = targetAddr; wvNetOutputDstMask = targetMask; wvNetOutputDstAddrFlag = TRUE; } else result = ERROR; return (result); }/********************************************************************************* wvNetAddressFilterClear - remove the address filter for events** This routine removes any active address filter test indicated by* the <type> and <direction> parameters used to enable it. Affected* events will be reported unconditionally.** RETURNS: N/A** ERRNO: N/A*/void wvNetAddressFilterClear ( int type, /* 0 for source, 1 for destination */ int direction /* 0 for input, 1 for output */ ) { if (direction == 0 && type == 0) wvNetInputSrcAddrFlag = FALSE; else if (direction == 0 && type == 1) wvNetInputDstAddrFlag = FALSE; else if (direction == 1 && type == 0) wvNetOutputSrcAddrFlag = FALSE; else if (direction == 1 && type == 1) wvNetOutputDstAddrFlag = FALSE; return; }/********************************************************************************* wvNetPortFilterSet - specify an address filter for events** This routine activates an additional filter, which disables certain events * that do not match the specified port value. The <port> parameter provides * the test value and the <type> parameter indicates whether that value is * compared against the source or destination fields. The <direction> setting * identifies whether the <type> is interpreted from the perspective of * incoming or outgoing traffic.** RETURNS: OK if filter set, or ERROR otherwise.** ERRNO: N/A*/STATUS wvNetPortFilterSet ( int port, /* target port for event comparisons */ int type, /* 0 for source, 1 for destination */ int direction /* 0 for input, 1 for output */ ) { STATUS result = OK; if (direction == 0 && type == 0) { wvNetInputSrcPort = port; wvNetInputSrcPortFlag = TRUE; } else if (direction == 0 && type == 1) { wvNetInputDstPort = port; wvNetInputDstPortFlag = TRUE; } else if (direction == 1 && type == 0) { wvNetOutputSrcPort = port; wvNetOutputSrcPortFlag = TRUE; } else if (direction == 1 && type == 1) { wvNetOutputDstPort = port; wvNetOutputDstPortFlag = TRUE; } else result = ERROR; return (result); }/********************************************************************************* wvNetPortFilterClear - remove the port number filter for events** This routine removes any active port filter test indicated by* the <type> and <direction> parameters used to enable it. Affected* events will be reported unconditionally.** RETURNS: N/A** ERRNO: N/A*/void wvNetPortFilterClear ( int type, /* 0 for source, 1 for destination */ int direction /* 0 for input, 1 for output */ ) { if (direction == 0 && type == 0) wvNetInputSrcPortFlag = FALSE; else if (direction == 0 && type == 1) wvNetInputDstPortFlag = FALSE; else if (direction == 1 && type == 0) wvNetOutputSrcPortFlag = FALSE; else if (direction == 1 && type == 1) wvNetOutputDstPortFlag = FALSE; return; }/********************************************************************************* wvNetAddressFilterTest - compare the given addresses with filter values** This routine is invoked by the WV_NET_ADDR_FILTER_TEST macro within* an event block. It returns TRUE if no filters are in effect or if the* target values for each filter match the given addresses.** RETURNS: TRUE if filter passes, or FALSE otherwise.** ERRNO: N/A** NOMANUAL*/BOOL wvNetAddressFilterTest ( int filterType, /* 0 for input filter or 1 for output filter */ int targetType, /* 1 for dst only, 2 for src only, or 3 for both */ ULONG srcAddr, /* current source address for event block */ ULONG dstAddr /* current destination address for event block */ ) { BOOL result = TRUE; if (filterType == 0) /* Compare given addresses to input values. */ { if (wvNetInputSrcAddrFlag && targetType != 1) result = ((srcAddr & wvNetInputSrcMask) == wvNetInputSrcAddr); /* Only test the destination address if any source test passed. */ if (result && wvNetInputDstAddrFlag && targetType != 2) result = ((dstAddr & wvNetInputDstMask) == wvNetInputDstAddr); } if (filterType == 1) /* Compare given addresses to output values. */ { if (wvNetOutputSrcAddrFlag && targetType != 1) result = ((srcAddr & wvNetOutputSrcMask) == wvNetOutputSrcAddr); /* Only test the destination address if any source test passed. */ if (result && wvNetOutputDstAddrFlag && targetType != 2) result = ((dstAddr & wvNetOutputDstMask) == wvNetOutputDstAddr); } /* if (!result) /@ XXX - for testing, include if desired. @/ logMsg ("Address filter ignoring event.\n", 0, 0, 0, 0, 0, 0); */ return (result); }/********************************************************************************* wvNetPortFilterTest - compare the given port numbers with filter values** This routine is invoked by the WV_NET_PORT_FILTER_TEST macro within* an event block. It returns TRUE if no filters are in effect or if the* target values for each filter match the given port numbers.** INTERNAL* Unlike the address filter tests, both the source and destination ports* are always available for the filtered events, so the <targetType> * parameter is not needed.** RETURNS: TRUE if filter passes, or FALSE otherwise.** ERRNO: N/A** NOMANUAL*/BOOL wvNetPortFilterTest ( int filterType, /* 0 for input filter or 1 for output filter */ USHORT srcPort, /* current source port for event block */ USHORT dstPort /* current destination port for event block */ ) { BOOL result = TRUE; if (filterType == 0) /* Compare given ports to input values. */ { if (wvNetInputSrcPortFlag) result = (srcPort == wvNetInputSrcPort); /* Only test the destination port if any source test passed. */ if (result && wvNetInputDstPortFlag) result = (dstPort == wvNetInputDstPort); } if (filterType == 1) /* Compare given addresses to output values. */ { if (wvNetOutputSrcPortFlag) result = (srcPort == wvNetOutputSrcPort); /* Only test the destination address if any source test passed. */ if (result && wvNetOutputDstPortFlag) result = (dstPort == wvNetOutputDstPort); } return (result); }#if 0/********************************************************************************* wvNetEventTest - check if event is enabled** This routine duplicates the WV_NET_EVENT_TEST macro. It checks the bitmap* for an event to determine if it should be reported to the host-side of the * WindView tool. It is never called, and is present only to illustrate the * macro behavior.** RETURNS: TRUE if event is selected, or FALSE otherwise.** ERRNO: N/A** NOMANUAL*/BOOL wvNetEventTest ( int priority, /* priority level of event */ int offset /* identifier within priority level */ ) { BOOL result; int index; UCHAR mask; int byteOffset; int byteIndex; /* * Because of array indexing, the index into the event map is one * less than the value assigned to the priority level. */ index = priority - 1; byteOffset = offset / 8; /* * Convert the offset to an array index based on the number of * bytes in the bitmap. */ byteIndex = WVNET_MASKSIZE - 1 - byteOffset; /* Check the flag in the bitmap for the specified event. */ mask = 1 << (offset % 8); result = (wvNetEventMap [index].bitmap [byteIndex] & mask); return (result); }#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -