📄 ftswap.c
字号:
/* * Copyright (c) 2001 Mark Fullmer and The Ohio State University * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * * $Id: ftswap.c,v 1.14 2003/02/13 02:38:42 maf Exp $ */#include "ftconfig.h"#include "ftlib.h"/* * function: ftpdu_swap * * Swap bytes in any PDU structure. cur is the current * byte order of the PDU **/void ftpdu_swap(void *pdu, int cur){ struct ftpdu_header *ph; int16 i; char agg_method, agg_version; ph = pdu; i = ph->version;#if BYTE_ORDER == LITTLE_ENDIAN if (cur == BIG_ENDIAN) SWAPINT16(i);#endif /* BYTE_ORDER == LITTLE_ENDIAN */#if BYTE_ORDER == BIG_ENDIAN if (cur == LITTLE_ENDIAN) SWAPINT16(i);#endif /* BYTE_ORDER == LITTLE_ENDIAN */ switch (i) { case 1: ftpdu_v1_swap(pdu, cur); break; case 5: ftpdu_v5_swap(pdu, cur); break; case 6: ftpdu_v6_swap(pdu, cur); break; case 7: ftpdu_v7_swap(pdu, cur); break; case 8: agg_method = *((char*)pdu+22); agg_version = *((char*)pdu+23); switch (agg_method) { case 1: ftpdu_v8_1_swap(pdu, cur); break; case 2: ftpdu_v8_2_swap(pdu, cur); break; case 3: ftpdu_v8_3_swap(pdu, cur); break; case 4: ftpdu_v8_4_swap(pdu, cur); break; case 5: ftpdu_v8_5_swap(pdu, cur); break; case 6: ftpdu_v8_6_swap(pdu, cur); break; case 7: ftpdu_v8_7_swap(pdu, cur); break; case 8: ftpdu_v8_8_swap(pdu, cur); break; case 9: ftpdu_v8_9_swap(pdu, cur); break; case 10: ftpdu_v8_10_swap(pdu, cur); break; case 11: ftpdu_v8_11_swap(pdu, cur); break; case 12: ftpdu_v8_12_swap(pdu, cur); break; case 13: ftpdu_v8_13_swap(pdu, cur); break; case 14: ftpdu_v8_14_swap(pdu, cur); break; default: fterr_warnx("Internal error agg_method=%d", (int)agg_method); break; } /* switch */ break; default: fterr_warnx("Internal error i=%d", (int)i); break; } /* switch */} /* ftpdu_swap *//* * function: ftpdu_v1_swap * * Swap bytes in a V1 PDU. cur is the current * byte order of the PDU **/void ftpdu_v1_swap(struct ftpdu_v1 *pdu, int cur){ int16 i; i = pdu->count;#if BYTE_ORDER == LITTLE_ENDIAN if (cur == BIG_ENDIAN) SWAPINT16(i);#endif /* BYTE_ORDER == LITTLE_ENDIAN */#if BYTE_ORDER == BIG_ENDIAN if (cur == LITTLE_ENDIAN) SWAPINT16(i);#endif /* BYTE_ORDER == LITTLE_ENDIAN */ SWAPINT16(pdu->version); SWAPINT16(pdu->count); SWAPINT32(pdu->sysUpTime); SWAPINT32(pdu->unix_secs); SWAPINT32(pdu->unix_nsecs); for (--i; i >= 0; --i) { SWAPINT32(pdu->records[i].srcaddr); SWAPINT32(pdu->records[i].dstaddr); SWAPINT32(pdu->records[i].nexthop); SWAPINT16(pdu->records[i].input); SWAPINT16(pdu->records[i].output); SWAPINT32(pdu->records[i].dPkts); SWAPINT32(pdu->records[i].dOctets); SWAPINT32(pdu->records[i].First); SWAPINT32(pdu->records[i].Last); SWAPINT16(pdu->records[i].dstport); SWAPINT16(pdu->records[i].srcport); }} /* ftpdu_v1_swap */void ftpdu_v5_swap(struct ftpdu_v5 *pdu, int cur){ int16 i; i = pdu->count;#if BYTE_ORDER == LITTLE_ENDIAN if (cur == BIG_ENDIAN) SWAPINT16(i);#endif /* BYTE_ORDER == LITTLE_ENDIAN */#if BYTE_ORDER == BIG_ENDIAN if (cur == LITTLE_ENDIAN) SWAPINT16(i);#endif /* BYTE_ORDER == LITTLE_ENDIAN */ SWAPINT16(pdu->version); SWAPINT16(pdu->count); SWAPINT32(pdu->sysUpTime); SWAPINT32(pdu->unix_secs); SWAPINT32(pdu->unix_nsecs); SWAPINT32(pdu->flow_sequence); for (--i; i >= 0; --i) { SWAPINT32(pdu->records[i].srcaddr); SWAPINT32(pdu->records[i].dstaddr); SWAPINT32(pdu->records[i].nexthop); SWAPINT16(pdu->records[i].input) ; SWAPINT16(pdu->records[i].output); SWAPINT32(pdu->records[i].dPkts); SWAPINT32(pdu->records[i].dOctets); SWAPINT32(pdu->records[i].First); SWAPINT32(pdu->records[i].Last); SWAPINT16(pdu->records[i].dstport); SWAPINT16(pdu->records[i].srcport); SWAPINT16(pdu->records[i].src_as); SWAPINT16(pdu->records[i].dst_as); SWAPINT16(pdu->records[i].drops); }} /* ftpdu_v5_swap *//* * function: ftpdu_v6_swap * * Swap bytes in a V6 PDU. cur is the current * byte order of the PDU **/void ftpdu_v6_swap(struct ftpdu_v6 *pdu, int cur){ int16 i; i = pdu->count;#if BYTE_ORDER == LITTLE_ENDIAN if (cur == BIG_ENDIAN) SWAPINT16(i);#endif /* BYTE_ORDER == LITTLE_ENDIAN */#if BYTE_ORDER == BIG_ENDIAN if (cur == LITTLE_ENDIAN) SWAPINT16(i);#endif /* BYTE_ORDER == LITTLE_ENDIAN */ SWAPINT16(pdu->version); SWAPINT16(pdu->count); SWAPINT32(pdu->sysUpTime); SWAPINT32(pdu->unix_secs); SWAPINT32(pdu->unix_nsecs); SWAPINT32(pdu->flow_sequence); for (--i; i >= 0; --i) { SWAPINT32(pdu->records[i].srcaddr); SWAPINT32(pdu->records[i].dstaddr); SWAPINT32(pdu->records[i].nexthop); SWAPINT16(pdu->records[i].input); SWAPINT16(pdu->records[i].output); SWAPINT32(pdu->records[i].dPkts); SWAPINT32(pdu->records[i].dOctets); SWAPINT32(pdu->records[i].First); SWAPINT32(pdu->records[i].Last); SWAPINT16(pdu->records[i].dstport); SWAPINT16(pdu->records[i].srcport); SWAPINT16(pdu->records[i].src_as); SWAPINT16(pdu->records[i].dst_as); SWAPINT32(pdu->records[i].peer_nexthop); }} /* ftpdu_v6_swap *//* * function: ftpdu_v7_swap * * Swap bytes in a V7 PDU. cur is the current * byte order of the PDU **/void ftpdu_v7_swap(struct ftpdu_v7 *pdu, int cur){ int16 i; i = pdu->count;#if BYTE_ORDER == LITTLE_ENDIAN if (cur == BIG_ENDIAN) SWAPINT16(i);#endif /* BYTE_ORDER == LITTLE_ENDIAN */#if BYTE_ORDER == BIG_ENDIAN if (cur == LITTLE_ENDIAN) SWAPINT16(i);#endif /* BYTE_ORDER == LITTLE_ENDIAN */ SWAPINT16(pdu->version); SWAPINT16(pdu->count); SWAPINT32(pdu->sysUpTime); SWAPINT32(pdu->unix_secs); SWAPINT32(pdu->unix_nsecs); SWAPINT32(pdu->flow_sequence); for (--i; i >= 0; --i) { SWAPINT32(pdu->records[i].srcaddr); SWAPINT32(pdu->records[i].dstaddr); SWAPINT32(pdu->records[i].nexthop); SWAPINT16(pdu->records[i].input) ; SWAPINT16(pdu->records[i].output); SWAPINT32(pdu->records[i].dPkts); SWAPINT32(pdu->records[i].dOctets); SWAPINT32(pdu->records[i].First); SWAPINT32(pdu->records[i].Last); SWAPINT16(pdu->records[i].dstport); SWAPINT16(pdu->records[i].srcport); SWAPINT16(pdu->records[i].src_as); SWAPINT16(pdu->records[i].dst_as); SWAPINT16(pdu->records[i].drops); SWAPINT32(pdu->records[i].router_sc); }} /* ftpdu_v7_swap *//* * function: ftpdu_v8_1_swap * * Swap bytes in a V8 agg method 1 PDU. cur is the current * byte order of the PDU **/void ftpdu_v8_1_swap(struct ftpdu_v8_1 *pdu, int cur){ int16 i; i = pdu->count;#if BYTE_ORDER == LITTLE_ENDIAN if (cur == BIG_ENDIAN) SWAPINT16(i);#endif /* BYTE_ORDER == LITTLE_ENDIAN */#if BYTE_ORDER == BIG_ENDIAN if (cur == LITTLE_ENDIAN) SWAPINT16(i);#endif /* BYTE_ORDER == LITTLE_ENDIAN */ SWAPINT16(pdu->version); SWAPINT16(pdu->count); SWAPINT32(pdu->sysUpTime); SWAPINT32(pdu->unix_secs); SWAPINT32(pdu->unix_nsecs); SWAPINT32(pdu->flow_sequence); for (--i; i >= 0; --i) { SWAPINT32(pdu->records[i].dFlows); SWAPINT32(pdu->records[i].dPkts); SWAPINT32(pdu->records[i].dOctets); SWAPINT32(pdu->records[i].First); SWAPINT32(pdu->records[i].Last); SWAPINT16(pdu->records[i].src_as); SWAPINT16(pdu->records[i].dst_as); SWAPINT16(pdu->records[i].input); SWAPINT16(pdu->records[i].output); }} /* ftpdu_v8_1_swap *//* * function: ftpdu_v8_2_swap * * Swap bytes in a V8 agg method 2 PDU. cur is the current * byte order of the PDU **/void ftpdu_v8_2_swap(struct ftpdu_v8_2 *pdu, int cur){ int16 i; i = pdu->count;#if BYTE_ORDER == LITTLE_ENDIAN if (cur == BIG_ENDIAN) SWAPINT16(i);#endif /* BYTE_ORDER == LITTLE_ENDIAN */#if BYTE_ORDER == BIG_ENDIAN if (cur == LITTLE_ENDIAN) SWAPINT16(i);#endif /* BYTE_ORDER == LITTLE_ENDIAN */ SWAPINT16(pdu->version); SWAPINT16(pdu->count); SWAPINT32(pdu->sysUpTime); SWAPINT32(pdu->unix_secs); SWAPINT32(pdu->unix_nsecs); SWAPINT32(pdu->flow_sequence); for (--i; i >= 0; --i) { SWAPINT32(pdu->records[i].dFlows); SWAPINT32(pdu->records[i].dPkts); SWAPINT32(pdu->records[i].dOctets); SWAPINT32(pdu->records[i].First); SWAPINT32(pdu->records[i].Last); SWAPINT16(pdu->records[i].srcport); SWAPINT16(pdu->records[i].dstport); }} /* ftpdu_v8_2_swap *//* * function: ftpdu_v8_3_swap * * Swap bytes in a V8 agg method 3 PDU. cur is the current * byte order of the PDU **/void ftpdu_v8_3_swap(struct ftpdu_v8_3 *pdu, int cur){ int16 i; i = pdu->count;#if BYTE_ORDER == LITTLE_ENDIAN if (cur == BIG_ENDIAN) SWAPINT16(i);#endif /* BYTE_ORDER == LITTLE_ENDIAN */#if BYTE_ORDER == BIG_ENDIAN if (cur == LITTLE_ENDIAN) SWAPINT16(i);#endif /* BYTE_ORDER == LITTLE_ENDIAN */ SWAPINT16(pdu->version); SWAPINT16(pdu->count); SWAPINT32(pdu->sysUpTime); SWAPINT32(pdu->unix_secs); SWAPINT32(pdu->unix_nsecs); SWAPINT32(pdu->flow_sequence); for (--i; i >= 0; --i) { SWAPINT32(pdu->records[i].dFlows); SWAPINT32(pdu->records[i].dPkts); SWAPINT32(pdu->records[i].dOctets); SWAPINT32(pdu->records[i].First); SWAPINT32(pdu->records[i].Last); SWAPINT32(pdu->records[i].src_prefix); SWAPINT16(pdu->records[i].src_as); SWAPINT16(pdu->records[i].input); }} /* ftpdu_v8_3_swap *//* * function: ftpdu_v8_4_swap * * Swap bytes in a V8 agg method 4 PDU. cur is the current * byte order of the PDU **/void ftpdu_v8_4_swap(struct ftpdu_v8_4 *pdu, int cur){ int16 i; i = pdu->count;#if BYTE_ORDER == LITTLE_ENDIAN if (cur == BIG_ENDIAN) SWAPINT16(i);#endif /* BYTE_ORDER == LITTLE_ENDIAN */#if BYTE_ORDER == BIG_ENDIAN if (cur == LITTLE_ENDIAN) SWAPINT16(i);#endif /* BYTE_ORDER == LITTLE_ENDIAN */ SWAPINT16(pdu->version); SWAPINT16(pdu->count);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -