|
From: <jn...@us...> - 2007-05-11 22:53:47
|
Revision: 31
http://opencalea.svn.sourceforge.net/opencalea/?rev=31&view=rev
Author: jnorell
Date: 2007-05-11 15:53:48 -0700 (Fri, 11 May 2007)
Log Message:
-----------
Moved process_packet() function to packet_processing.c,
and copied to support a separate function per output content type.
Currently every function, no matter what the name, is exactly what
process_packet used to be, and content_option = 1 is hardcoded.
You need to specify "Content_Type" in config file or -c on the command line.
Modified Paths:
--------------
trunk/man/tap.8
trunk/src/Makefile.am
trunk/src/Makefile.in
trunk/src/calea.c
trunk/src/calea.h
trunk/src/log_debug.c
trunk/src/msg.h
trunk/src/packet_data_header_report.c
trunk/src/tap.c
trunk/src/tap.h
Added Paths:
-----------
trunk/src/packet_data_header_report.h
trunk/src/packet_processing.c
Modified: trunk/man/tap.8
===================================================================
--- trunk/man/tap.8 2007-05-11 16:58:30 UTC (rev 30)
+++ trunk/man/tap.8 2007-05-11 22:53:48 UTC (rev 31)
@@ -57,7 +57,7 @@
.LP
This program is a network tap (packet sniffer) from the OpenCALEA project. It can be invoked to collect CACmII (Content Associated Communications Identifying Information) and CmC (Communication Content) for an intercept subject, which is sent to a running \fBdf_collector\fR(8) program somewhere in the network.
.LP
-We currently use the same content format for an Internet data tap (T1.IAS standard) and a Voice intercept (T1.678 standard), ie. a \fICC\-APDU\fR structure. More formats will likely be added in the future. The \fB\-c\fR switch will parse other formats, but they're not there yet.
+We currently use the same content format for an Internet data tap (T1.I AS standard) and a Voice intercept (T1.678 standard), ie. a \fICC\-APDU\fR structure. More formats will likely be added in the future. The \fB\-c\fR switch will parse other formats, but they're not there yet.
.LP
\fBtap\fR(8) can be invoked by itself, but is normally started by the \fBtap_controller\fR(8) program. See \fBtap_controller\fR(8) for more information.
.SH "OPTIONS"
@@ -123,7 +123,7 @@
.br
\fBraw\fR Send captured packets, sans link layer headers (no formatting).
.br
-\fBraw\-full\fR Send captured packets with link layer headers (no formatting).
+\fBpcap\fR Send captured packets with link layer headers in pcap format.
.br
Default: \fBContent_Type\fR from config file.
Modified: trunk/src/Makefile.am
===================================================================
--- trunk/src/Makefile.am 2007-05-11 16:58:30 UTC (rev 30)
+++ trunk/src/Makefile.am 2007-05-11 22:53:48 UTC (rev 31)
@@ -10,7 +10,7 @@
controllerd_CFLAGS = $(AM_CFLAGS) $(GLIB_CFLAGS)
controllerd_LDADD = -lpthread $(GLIB_LIBS)
-tap_SOURCES = tap.c tap.h common.h calea.c calea.h log_debug.c log_debug.h cc_apdu.c packet_data_header_report.c directsignalreporting.c util.h util.c
+tap_SOURCES = tap.c tap.h common.h calea.c calea.h log_debug.c log_debug.h cc_apdu.c packet_data_header_report.c directsignalreporting.c util.h util.c packet_processing.c
tap_CFLAGS = $(AM_CFLAGS) $(GLIB_CFLAGS)
tap_LDADD = -lpcap -Lasn.1/T1.678/CCDeliveryHeader -lCCDeliveryHeader -Lasn.1/T1.IAS/CmII -lCmII -Lasn.1/T1.678/VoP -lVoP $(GLIB_LIBS)
Modified: trunk/src/Makefile.in
===================================================================
--- trunk/src/Makefile.in 2007-05-11 16:58:30 UTC (rev 30)
+++ trunk/src/Makefile.in 2007-05-11 22:53:48 UTC (rev 31)
@@ -79,7 +79,8 @@
am_tap_OBJECTS = tap-tap.$(OBJEXT) tap-calea.$(OBJEXT) \
tap-log_debug.$(OBJEXT) tap-cc_apdu.$(OBJEXT) \
tap-packet_data_header_report.$(OBJEXT) \
- tap-directsignalreporting.$(OBJEXT) tap-util.$(OBJEXT)
+ tap-directsignalreporting.$(OBJEXT) tap-util.$(OBJEXT) \
+ tap-packet_processing.$(OBJEXT)
tap_OBJECTS = $(am_tap_OBJECTS)
tap_DEPENDENCIES = $(am__DEPENDENCIES_1)
tap_LINK = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) \
@@ -221,7 +222,7 @@
controllerd_SOURCES = controllerd.c log_debug.c util.c
controllerd_CFLAGS = $(AM_CFLAGS) $(GLIB_CFLAGS)
controllerd_LDADD = -lpthread $(GLIB_LIBS)
-tap_SOURCES = tap.c tap.h common.h calea.c calea.h log_debug.c log_debug.h cc_apdu.c packet_data_header_report.c directsignalreporting.c util.h util.c
+tap_SOURCES = tap.c tap.h common.h calea.c calea.h log_debug.c log_debug.h cc_apdu.c packet_data_header_report.c directsignalreporting.c util.h util.c packet_processing.c
tap_CFLAGS = $(AM_CFLAGS) $(GLIB_CFLAGS)
tap_LDADD = -lpcap -Lasn.1/T1.678/CCDeliveryHeader -lCCDeliveryHeader -Lasn.1/T1.IAS/CmII -lCmII -Lasn.1/T1.678/VoP -lVoP $(GLIB_LIBS)
df_collector_SOURCES = df_collector.c common.h log_debug.c log_debug.h util.h calea.c util.c
@@ -332,6 +333,7 @@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/tap-directsignalreporting.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/tap-log_debug.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/tap-packet_data_header_report.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/tap-packet_processing.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/tap-tap.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/tap-util.Po@am__quote@
@@ -650,6 +652,20 @@
@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
@am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(tap_CFLAGS) $(CFLAGS) -c -o tap-util.obj `if test -f 'util.c'; then $(CYGPATH_W) 'util.c'; else $(CYGPATH_W) '$(srcdir)/util.c'; fi`
+tap-packet_processing.o: packet_processing.c
+@am__fastdepCC_TRUE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(tap_CFLAGS) $(CFLAGS) -MT tap-packet_processing.o -MD -MP -MF $(DEPDIR)/tap-packet_processing.Tpo -c -o tap-packet_processing.o `test -f 'packet_processing.c' || echo '$(srcdir)/'`packet_processing.c
+@am__fastdepCC_TRUE@ mv -f $(DEPDIR)/tap-packet_processing.Tpo $(DEPDIR)/tap-packet_processing.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='packet_processing.c' object='tap-packet_processing.o' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(tap_CFLAGS) $(CFLAGS) -c -o tap-packet_processing.o `test -f 'packet_processing.c' || echo '$(srcdir)/'`packet_processing.c
+
+tap-packet_processing.obj: packet_processing.c
+@am__fastdepCC_TRUE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(tap_CFLAGS) $(CFLAGS) -MT tap-packet_processing.obj -MD -MP -MF $(DEPDIR)/tap-packet_processing.Tpo -c -o tap-packet_processing.obj `if test -f 'packet_processing.c'; then $(CYGPATH_W) 'packet_processing.c'; else $(CYGPATH_W) '$(srcdir)/packet_processing.c'; fi`
+@am__fastdepCC_TRUE@ mv -f $(DEPDIR)/tap-packet_processing.Tpo $(DEPDIR)/tap-packet_processing.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='packet_processing.c' object='tap-packet_processing.obj' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(tap_CFLAGS) $(CFLAGS) -c -o tap-packet_processing.obj `if test -f 'packet_processing.c'; then $(CYGPATH_W) 'packet_processing.c'; else $(CYGPATH_W) '$(srcdir)/packet_processing.c'; fi`
+
mostlyclean-libtool:
-rm -f *.lo
Modified: trunk/src/calea.c
===================================================================
--- trunk/src/calea.c 2007-05-11 16:58:30 UTC (rev 30)
+++ trunk/src/calea.c 2007-05-11 22:53:48 UTC (rev 31)
@@ -14,10 +14,10 @@
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
- * THIS SOFTWARE IS PROVIDED BY MERIT NETWORK, INC. ``AS IS'' AND ANY
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR OR 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 MERIT NETWORK, INC. BE LIABLE FOR ANY
+ * 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
@@ -45,17 +45,13 @@
mytm->tm_sec, (int) usec/1000 );
}
-
Msg *CmCPacketBuild (HEADER *dfheader) {
Msg *msg;
size_t msg_len;
msg_len = sizeof(Msg);
- if (! ( msg = (Msg *) malloc ( msg_len + dfheader->encoded_size ) ) ) {
- perror("malloc");
- exit ( -1 );
- }
+ msg = (Msg *) Calloc(msg_len + dfheader->encoded_size);
msg->msgh.msgtype = MSGTYPE_CMC;
msg->msgh.format = MSGFMT_BER;
@@ -70,10 +66,7 @@
Msg *msg;
- if (! ( msg = (Msg *) malloc ( sizeof(Msg) + dfheader->encoded_size ) ) ) {
- perror("malloc");
- exit ( -1 );
- }
+ msg = (Msg *) Calloc(sizeof(Msg) + dfheader->encoded_size);
msg->msgh.msgtype = MSGTYPE_CMII;
msg->msgh.format = MSGFMT_BER;
@@ -85,7 +78,6 @@
}
void PacketFree ( Msg *msg ) {
-
free ( msg );
}
@@ -94,10 +86,7 @@
Msg *msg;
CtrlMsg *ctrlmsg;
- if ( !(msg = (Msg *)malloc(sizeof(Msg) + sizeof(CtrlMsg) ) ) ) {
- perror("CtrlMsgBuild: malloc");
- exit(-1);
- }
+ msg = (Msg *)Calloc(sizeof(Msg) + sizeof(CtrlMsg));
ctrlmsg = (CtrlMsg *)((char *)msg + sizeof(Msg));
@@ -148,4 +137,3 @@
return bytes_sent;
}
-/* */
Modified: trunk/src/calea.h
===================================================================
--- trunk/src/calea.h 2007-05-11 16:58:30 UTC (rev 30)
+++ trunk/src/calea.h 2007-05-11 22:53:48 UTC (rev 31)
@@ -57,4 +57,13 @@
} header_t;
#define HEADER header_t
+/* function declarations */
+void get_calea_time ( time_t sec, time_t usec, char *buf );
+Msg *CmCPacketBuild (HEADER *dfheader);
+Msg *CmIIPacketBuild (HEADER *dfheader);
+void PacketFree ( Msg *msg );
+int PacketSend (Msg *packet, int length, int *send_socket);
+Msg *CtrlMsgBuild (HEADER *dfheader);
+
#endif
+
Modified: trunk/src/log_debug.c
===================================================================
--- trunk/src/log_debug.c 2007-05-11 16:58:30 UTC (rev 30)
+++ trunk/src/log_debug.c 2007-05-11 22:53:48 UTC (rev 31)
@@ -10,9 +10,6 @@
* * 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.
- * * Neither the name of Merit Network, Inc. nor the names of its
- * contributors may be used to endorse or promote products derived
- * from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR OR CONTRIBUTORS ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
Modified: trunk/src/msg.h
===================================================================
--- trunk/src/msg.h 2007-05-11 16:58:30 UTC (rev 30)
+++ trunk/src/msg.h 2007-05-11 22:53:48 UTC (rev 31)
@@ -10,9 +10,6 @@
* * 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.
- * * Neither the name of Merit Network, Inc. nor the names of its
- * contributors may be used to endorse or promote products derived
- * from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR OR CONTRIBUTORS ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
Modified: trunk/src/packet_data_header_report.c
===================================================================
--- trunk/src/packet_data_header_report.c 2007-05-11 16:58:30 UTC (rev 30)
+++ trunk/src/packet_data_header_report.c 2007-05-11 22:53:48 UTC (rev 31)
@@ -33,6 +33,7 @@
#include "common.h"
#include "calea.h"
+#include "packet_data_header_report.h"
int encode_ias_protocol(HEADER *dfheader, IasProtocol_t *IasProtocol) {
Added: trunk/src/packet_data_header_report.h
===================================================================
--- trunk/src/packet_data_header_report.h (rev 0)
+++ trunk/src/packet_data_header_report.h 2007-05-11 22:53:48 UTC (rev 31)
@@ -0,0 +1,36 @@
+/*
+ * Copyright (c) 2007, Jesse Norell <je...@kc...>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * 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 OR 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.
+ */
+
+#ifndef _PACKET_DATA_HEADER_REPORT_H
+#define _PACKET_DATA_HEADER_REPORT_H
+
+#include "IasProtocol.h"
+
+/* function declarations */
+int encode_ias_protocol(HEADER *dfheader, IasProtocol_t *IasProtocol);
+int packet_data_header_report(HEADER *dfheader);
+
+#endif
+
Added: trunk/src/packet_processing.c
===================================================================
--- trunk/src/packet_processing.c (rev 0)
+++ trunk/src/packet_processing.c 2007-05-11 22:53:48 UTC (rev 31)
@@ -0,0 +1,1163 @@
+/*
+ * Copyright (c) 2007, Jesse Norell <je...@kc...>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * 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 OR 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.
+ */
+
+#include "common.h"
+#include "calea.h"
+#include "tap.h"
+#include "packet_data_header_report.h"
+
+#include <pcap.h>
+#include <net/ethernet.h>
+
+/* function declarations */
+char *cc_apdu(HEADER *dfheader);
+char *directsignalreporting(HEADER *dfheader);
+
+extern int datalink_hdr_len;
+extern int send_df_socket;
+extern struct sockaddr_in send_df_addr;
+
+
+// tmp ... need to clean up / write all the functions below
+int content_option = 1;
+
+/*
+ * process_packet_cc_apdu: sends CC-APDU structures for VoP CC
+ */
+void process_packet_cc_apdu( u_char *args, const struct pcap_pkthdr *header, const u_char *packet ) {
+
+ struct ether_header *ethernet;
+ struct ip *ip;
+ struct udphdr *udp;
+ struct tcphdr *tcp;
+ Msg *cmc_pkt;
+ Msg *cmii_pkt;
+ int total_pkt_length;
+ int ip_size;
+ int tcp_size;
+ int udp_size;
+ int payload_size;
+ int ip_size_total;
+ const char *payload; /* Packet Payload */
+ HEADER *dfheader;
+ char calea_time[TS_LENGTH];
+
+ dfheader = (HEADER *)args;
+
+#ifdef DEBUG_PKTS
+ char msg[ MAX_LOG_DEBUG_MSG_LEN ];
+ memset ( msg, '\0', MAX_LOG_DEBUG_MSG_LEN );
+#endif
+
+ get_calea_time ( header->ts.tv_sec, header->ts.tv_usec, &calea_time[0] );
+
+ dfheader->sec = header->ts.tv_sec;
+ dfheader->usec = header->ts.tv_usec/100;
+
+ /* Ethernet Packet */
+ ethernet = (struct ether_header *)(packet);
+
+ /* IP Header Offset */
+ ip = ( struct ip* )( (char *)ethernet + datalink_hdr_len );
+ ip_size_total = (int)ntohs(ip->ip_len);
+ ip_size = ip->ip_hl * 4;
+ if (ip_size < 20) {
+ log_5("Packet has invalid IP header length: %u bytes", ip_size);
+ debug_3("Packet has invalid IP header length: %u bytes", ip_size);
+ return;
+ }
+
+ dfheader->srcIP = htonl(ip->ip_src.s_addr);
+ dfheader->dstIP = htonl(ip->ip_dst.s_addr);
+
+ if (inet_ntop(AF_INET, &ip->ip_src.s_addr, dfheader->src_ip, sizeof(dfheader->src_ip)) == NULL ) {
+ pdie("inet_ntop");
+ }
+ if (inet_ntop(AF_INET, &ip->ip_dst.s_addr, dfheader->dst_ip, sizeof(dfheader->dst_ip)) == NULL ) {
+ pdie("inet_ntop");
+ }
+
+ if ( ip->ip_p == IPPROTO_UDP ) {
+ /* UDP Header */
+ udp = ( struct udphdr* ) ( (u_char *)ip + ip_size );
+
+ udp_size = sizeof(struct udphdr);
+ if (ntohs(udp->uh_ulen) <= 12) {
+ log_5("Packet has invalid UDP header length: %u bytes", udp_size);
+ debug_3("Packet has invalid UDP header length: %u bytes", udp_size);
+ return;
+ }
+
+ /* UDP Payload */
+ payload = (char *)((u_char *)udp + udp_size);
+
+ /* UDP Payload size */
+ payload_size = ntohs(udp->uh_ulen) - udp_size;
+
+#ifdef DEBUG_PKTS
+ if (payload_size > 0) {
+ debug_5("Payload (%d bytes):", payload_size);
+ print_hex(payload, payload_size);
+ }
+#endif
+
+ //format_vop_payload(dfheader);
+
+ dfheader->srcPort = ntohs(udp->uh_sport);
+ dfheader->dstPort = ntohs(udp->uh_dport);
+
+ } else if ( ip->ip_p == IPPROTO_TCP ) {
+
+ /* TCP Header */
+ tcp = ( struct tcphdr* ) ( (u_char *)ip + ip_size);
+
+ tcp_size = tcp->th_off * 4;
+ if (tcp_size < 20) {
+ log_5("Packet has invalid TCP header length: %u bytes", tcp_size);
+ debug_3("Packet has invalid TCP header length: %u bytes", tcp_size);
+ return;
+ }
+
+ /* TCP Payload */
+ payload = (char *)((u_char *)tcp + tcp_size);
+
+ /* TCP Payload size */
+ payload_size = ntohs(ip->ip_len) - (ip_size + tcp_size);
+
+ dfheader->srcPort = ntohs(tcp->th_sport);
+ dfheader->dstPort = ntohs(tcp->th_dport);
+
+ } else {
+ debug_4("Packet is neither UDP or TCP");
+ dfheader->srcPort = 0;
+ dfheader->dstPort = 0;
+ }
+
+ /*------------------------------------------------------------------------*/
+ /* only send Communications Content CmC msg if requested */
+ /*------------------------------------------------------------------------*/
+ if ( content_option == 1 ) {
+
+ //debug_5("IP (%d bytes):", ip_size_total);
+ //print_hex((const u_char *)ip, (size_t)ip_size_total);
+
+ dfheader->sequenceNumber++;
+ dfheader->payload = (const char *)ip;
+ dfheader->payload_size = (size_t)ip_size_total;
+ /*------------------------------------------------------------------------*/
+ /* WARNING: cc_apdu will allocate space for the BER encoded message. */
+ /* This space MUST be freed when it is no longer needed or a */
+ /* memory leak will occur. */
+ /* */
+ /* The address of the allocated memory is dfheader->encoded. */
+ /* The size of the allocated memory is dfheader->encoded_size. */
+ /* If cc_apdu does not return 0, no deallocation is needed. */
+ /*------------------------------------------------------------------------*/
+ if ( cc_apdu(dfheader) == 0) {
+ debug_5("Encoded addr(size): %p(%Zd)", dfheader->encoded_size, dfheader->encoded);
+ } else {
+ debug_5("cc_apdu returned nonzero");
+ return;
+ }
+
+ total_pkt_length = sizeof(Msg) + dfheader->encoded_size;
+ debug_5 ( "building CmC packet size: %d", total_pkt_length );
+ cmc_pkt = CmCPacketBuild ( dfheader );
+ debug_5 ( "sending CmC packet size: %d", total_pkt_length );
+ PacketSend ( cmc_pkt, total_pkt_length, &send_df_socket );
+ PacketFree ( cmc_pkt );
+
+ free(dfheader->encoded);
+
+ }
+
+ if (packet_data_header_report(dfheader) == 0) {
+ debug_5("Packet_Data_Header_Report encoded addr: %p, size: %Zd", dfheader->encoded, dfheader->encoded_size);
+ //print_hex((const u_char *)dfheader->encoded, (size_t)dfheader->encoded_size);
+ } else {
+ return;
+ }
+
+ total_pkt_length = sizeof(Msg) + dfheader->encoded_size;
+ debug_5 ( "building T1.IAS CmII packet size: %d", total_pkt_length);
+ cmii_pkt = CmIIPacketBuild ( dfheader );
+ debug_5 ( "sending T1.IAS CmII packet size: %d", total_pkt_length );
+ //print_hex((const u_char *)cmii_pkt, (size_t)total_pkt_length);
+ PacketSend ( cmii_pkt, total_pkt_length, &send_df_socket );
+ PacketFree ( cmii_pkt );
+
+ free(dfheader->encoded);
+
+ if (directsignalreporting(dfheader) == 0) {
+ debug_5("Direct Signal Reporting encoded addr: %p, size: %Zd", dfheader->encoded, dfheader->encoded_size);
+ //print_hex((const u_char *)dfheader->encoded, (size_t)dfheader->encoded_size);
+ } else {
+ return;
+ }
+
+ total_pkt_length = sizeof(Msg) + dfheader->encoded_size;
+ debug_5 ( "building T1.678 CmII packet size: %d", total_pkt_length);
+ cmii_pkt = CmIIPacketBuild ( dfheader );
+ debug_5 ( "sending T1.678 CmII packet size: %d", total_pkt_length );
+ //print_hex((const u_char *)cmii_pkt, (size_t)total_pkt_length);
+ PacketSend ( cmii_pkt, total_pkt_length, &send_df_socket );
+ PacketFree ( cmii_pkt );
+
+ free(dfheader->encoded);
+}
+
+
+/*
+ * process_packet_cmii_pdhr: sends PacketDataHeaderReport structures for IAS CACmII
+ */
+void process_packet_cmii_pdhr( u_char *args, const struct pcap_pkthdr *header, const u_char *packet ) {
+
+ struct ether_header *ethernet;
+ struct ip *ip;
+ struct udphdr *udp;
+ struct tcphdr *tcp;
+ Msg *cmc_pkt;
+ Msg *cmii_pkt;
+ int total_pkt_length;
+ int ip_size;
+ int tcp_size;
+ int udp_size;
+ int payload_size;
+ int ip_size_total;
+ const char *payload; /* Packet Payload */
+ HEADER *dfheader;
+ char calea_time[TS_LENGTH];
+
+ dfheader = (HEADER *)args;
+
+#ifdef DEBUG_PKTS
+ char msg[ MAX_LOG_DEBUG_MSG_LEN ];
+ memset ( msg, '\0', MAX_LOG_DEBUG_MSG_LEN );
+#endif
+
+ get_calea_time ( header->ts.tv_sec, header->ts.tv_usec, &calea_time[0] );
+
+ dfheader->sec = header->ts.tv_sec;
+ dfheader->usec = header->ts.tv_usec/100;
+
+ /* Ethernet Packet */
+ ethernet = (struct ether_header *)(packet);
+
+ /* IP Header Offset */
+ ip = ( struct ip* )( (char *)ethernet + datalink_hdr_len );
+ ip_size_total = (int)ntohs(ip->ip_len);
+ ip_size = ip->ip_hl * 4;
+ if (ip_size < 20) {
+ log_5("Packet has invalid IP header length: %u bytes", ip_size);
+ debug_3("Packet has invalid IP header length: %u bytes", ip_size);
+ return;
+ }
+
+ dfheader->srcIP = htonl(ip->ip_src.s_addr);
+ dfheader->dstIP = htonl(ip->ip_dst.s_addr);
+
+ if (inet_ntop(AF_INET, &ip->ip_src.s_addr, dfheader->src_ip, sizeof(dfheader->src_ip)) == NULL ) {
+ pdie("inet_ntop");
+ }
+ if (inet_ntop(AF_INET, &ip->ip_dst.s_addr, dfheader->dst_ip, sizeof(dfheader->dst_ip)) == NULL ) {
+ pdie("inet_ntop");
+ }
+
+ if ( ip->ip_p == IPPROTO_UDP ) {
+ /* UDP Header */
+ udp = ( struct udphdr* ) ( (u_char *)ip + ip_size );
+
+ udp_size = sizeof(struct udphdr);
+ if (ntohs(udp->uh_ulen) <= 12) {
+ log_5("Packet has invalid UDP header length: %u bytes", udp_size);
+ debug_3("Packet has invalid UDP header length: %u bytes", udp_size);
+ return;
+ }
+
+ /* UDP Payload */
+ payload = (char *)((u_char *)udp + udp_size);
+
+ /* UDP Payload size */
+ payload_size = ntohs(udp->uh_ulen) - udp_size;
+
+#ifdef DEBUG_PKTS
+ if (payload_size > 0) {
+ debug_5("Payload (%d bytes):", payload_size);
+ print_hex(payload, payload_size);
+ }
+#endif
+
+ //format_vop_payload(dfheader);
+
+ dfheader->srcPort = ntohs(udp->uh_sport);
+ dfheader->dstPort = ntohs(udp->uh_dport);
+
+ } else if ( ip->ip_p == IPPROTO_TCP ) {
+
+ /* TCP Header */
+ tcp = ( struct tcphdr* ) ( (u_char *)ip + ip_size);
+
+ tcp_size = tcp->th_off * 4;
+ if (tcp_size < 20) {
+ log_5("Packet has invalid TCP header length: %u bytes", tcp_size);
+ debug_3("Packet has invalid TCP header length: %u bytes", tcp_size);
+ return;
+ }
+
+ /* TCP Payload */
+ payload = (char *)((u_char *)tcp + tcp_size);
+
+ /* TCP Payload size */
+ payload_size = ntohs(ip->ip_len) - (ip_size + tcp_size);
+
+ dfheader->srcPort = ntohs(tcp->th_sport);
+ dfheader->dstPort = ntohs(tcp->th_dport);
+
+ } else {
+ debug_4("Packet is neither UDP or TCP");
+ dfheader->srcPort = 0;
+ dfheader->dstPort = 0;
+ }
+
+ /*------------------------------------------------------------------------*/
+ /* only send Communications Content CmC msg if requested */
+ /*------------------------------------------------------------------------*/
+ if ( content_option == 1 ) {
+
+ //debug_5("IP (%d bytes):", ip_size_total);
+ //print_hex((const u_char *)ip, (size_t)ip_size_total);
+
+ dfheader->sequenceNumber++;
+ dfheader->payload = (const char *)ip;
+ dfheader->payload_size = (size_t)ip_size_total;
+ /*------------------------------------------------------------------------*/
+ /* WARNING: cc_apdu will allocate space for the BER encoded message. */
+ /* This space MUST be freed when it is no longer needed or a */
+ /* memory leak will occur. */
+ /* */
+ /* The address of the allocated memory is dfheader->encoded. */
+ /* The size of the allocated memory is dfheader->encoded_size. */
+ /* If cc_apdu does not return 0, no deallocation is needed. */
+ /*------------------------------------------------------------------------*/
+ if ( cc_apdu(dfheader) == 0) {
+ debug_5("Encoded addr(size): %p(%Zd)", dfheader->encoded_size, dfheader->encoded);
+ } else {
+ debug_5("cc_apdu returned nonzero");
+ return;
+ }
+
+ total_pkt_length = sizeof(Msg) + dfheader->encoded_size;
+ debug_5 ( "building CmC packet size: %d", total_pkt_length );
+ cmc_pkt = CmCPacketBuild ( dfheader );
+ debug_5 ( "sending CmC packet size: %d", total_pkt_length );
+ PacketSend ( cmc_pkt, total_pkt_length, &send_df_socket );
+ PacketFree ( cmc_pkt );
+
+ free(dfheader->encoded);
+
+ }
+
+ if (packet_data_header_report(dfheader) == 0) {
+ debug_5("Packet_Data_Header_Report encoded addr: %p, size: %Zd", dfheader->encoded, dfheader->encoded_size);
+ //print_hex((const u_char *)dfheader->encoded, (size_t)dfheader->encoded_size);
+ } else {
+ return;
+ }
+
+ total_pkt_length = sizeof(Msg) + dfheader->encoded_size;
+ debug_5 ( "building T1.IAS CmII packet size: %d", total_pkt_length);
+ cmii_pkt = CmIIPacketBuild ( dfheader );
+ debug_5 ( "sending T1.IAS CmII packet size: %d", total_pkt_length );
+ //print_hex((const u_char *)cmii_pkt, (size_t)total_pkt_length);
+ PacketSend ( cmii_pkt, total_pkt_length, &send_df_socket );
+ PacketFree ( cmii_pkt );
+
+ free(dfheader->encoded);
+
+ if (directsignalreporting(dfheader) == 0) {
+ debug_5("Direct Signal Reporting encoded addr: %p, size: %Zd", dfheader->encoded, dfheader->encoded_size);
+ //print_hex((const u_char *)dfheader->encoded, (size_t)dfheader->encoded_size);
+ } else {
+ return;
+ }
+
+ total_pkt_length = sizeof(Msg) + dfheader->encoded_size;
+ debug_5 ( "building T1.678 CmII packet size: %d", total_pkt_length);
+ cmii_pkt = CmIIPacketBuild ( dfheader );
+ debug_5 ( "sending T1.678 CmII packet size: %d", total_pkt_length );
+ //print_hex((const u_char *)cmii_pkt, (size_t)total_pkt_length);
+ PacketSend ( cmii_pkt, total_pkt_length, &send_df_socket );
+ PacketFree ( cmii_pkt );
+
+ free(dfheader->encoded);
+}
+
+
+/*
+ * process_packet_cmc_pdhr: sends PacketDataHeaderReport structures for IAS CACmII,
+ * and IAS-CC-APDU structures for IAS CmC
+ */
+void process_packet_cmc_pdhr( u_char *args, const struct pcap_pkthdr *header, const u_char *packet ) {
+
+ struct ether_header *ethernet;
+ struct ip *ip;
+ struct udphdr *udp;
+ struct tcphdr *tcp;
+ Msg *cmc_pkt;
+ Msg *cmii_pkt;
+ int total_pkt_length;
+ int ip_size;
+ int tcp_size;
+ int udp_size;
+ int payload_size;
+ int ip_size_total;
+ const char *payload; /* Packet Payload */
+ HEADER *dfheader;
+ char calea_time[TS_LENGTH];
+
+ dfheader = (HEADER *)args;
+
+#ifdef DEBUG_PKTS
+ char msg[ MAX_LOG_DEBUG_MSG_LEN ];
+ memset ( msg, '\0', MAX_LOG_DEBUG_MSG_LEN );
+#endif
+
+ get_calea_time ( header->ts.tv_sec, header->ts.tv_usec, &calea_time[0] );
+
+ dfheader->sec = header->ts.tv_sec;
+ dfheader->usec = header->ts.tv_usec/100;
+
+ /* Ethernet Packet */
+ ethernet = (struct ether_header *)(packet);
+
+ /* IP Header Offset */
+ ip = ( struct ip* )( (char *)ethernet + datalink_hdr_len );
+ ip_size_total = (int)ntohs(ip->ip_len);
+ ip_size = ip->ip_hl * 4;
+ if (ip_size < 20) {
+ log_5("Packet has invalid IP header length: %u bytes", ip_size);
+ debug_3("Packet has invalid IP header length: %u bytes", ip_size);
+ return;
+ }
+
+ dfheader->srcIP = htonl(ip->ip_src.s_addr);
+ dfheader->dstIP = htonl(ip->ip_dst.s_addr);
+
+ if (inet_ntop(AF_INET, &ip->ip_src.s_addr, dfheader->src_ip, sizeof(dfheader->src_ip)) == NULL ) {
+ pdie("inet_ntop");
+ }
+ if (inet_ntop(AF_INET, &ip->ip_dst.s_addr, dfheader->dst_ip, sizeof(dfheader->dst_ip)) == NULL ) {
+ pdie("inet_ntop");
+ }
+
+ if ( ip->ip_p == IPPROTO_UDP ) {
+ /* UDP Header */
+ udp = ( struct udphdr* ) ( (u_char *)ip + ip_size );
+
+ udp_size = sizeof(struct udphdr);
+ if (ntohs(udp->uh_ulen) <= 12) {
+ log_5("Packet has invalid UDP header length: %u bytes", udp_size);
+ debug_3("Packet has invalid UDP header length: %u bytes", udp_size);
+ return;
+ }
+
+ /* UDP Payload */
+ payload = (char *)((u_char *)udp + udp_size);
+
+ /* UDP Payload size */
+ payload_size = ntohs(udp->uh_ulen) - udp_size;
+
+#ifdef DEBUG_PKTS
+ if (payload_size > 0) {
+ debug_5("Payload (%d bytes):", payload_size);
+ print_hex(payload, payload_size);
+ }
+#endif
+
+ //format_vop_payload(dfheader);
+
+ dfheader->srcPort = ntohs(udp->uh_sport);
+ dfheader->dstPort = ntohs(udp->uh_dport);
+
+ } else if ( ip->ip_p == IPPROTO_TCP ) {
+
+ /* TCP Header */
+ tcp = ( struct tcphdr* ) ( (u_char *)ip + ip_size);
+
+ tcp_size = tcp->th_off * 4;
+ if (tcp_size < 20) {
+ log_5("Packet has invalid TCP header length: %u bytes", tcp_size);
+ debug_3("Packet has invalid TCP header length: %u bytes", tcp_size);
+ return;
+ }
+
+ /* TCP Payload */
+ payload = (char *)((u_char *)tcp + tcp_size);
+
+ /* TCP Payload size */
+ payload_size = ntohs(ip->ip_len) - (ip_size + tcp_size);
+
+ dfheader->srcPort = ntohs(tcp->th_sport);
+ dfheader->dstPort = ntohs(tcp->th_dport);
+
+ } else {
+ debug_4("Packet is neither UDP or TCP");
+ dfheader->srcPort = 0;
+ dfheader->dstPort = 0;
+ }
+
+ /*------------------------------------------------------------------------*/
+ /* only send Communications Content CmC msg if requested */
+ /*------------------------------------------------------------------------*/
+ if ( content_option == 1 ) {
+
+ //debug_5("IP (%d bytes):", ip_size_total);
+ //print_hex((const u_char *)ip, (size_t)ip_size_total);
+
+ dfheader->sequenceNumber++;
+ dfheader->payload = (const char *)ip;
+ dfheader->payload_size = (size_t)ip_size_total;
+ /*------------------------------------------------------------------------*/
+ /* WARNING: cc_apdu will allocate space for the BER encoded message. */
+ /* This space MUST be freed when it is no longer needed or a */
+ /* memory leak will occur. */
+ /* */
+ /* The address of the allocated memory is dfheader->encoded. */
+ /* The size of the allocated memory is dfheader->encoded_size. */
+ /* If cc_apdu does not return 0, no deallocation is needed. */
+ /*------------------------------------------------------------------------*/
+ if ( cc_apdu(dfheader) == 0) {
+ debug_5("Encoded addr(size): %p(%Zd)", dfheader->encoded_size, dfheader->encoded);
+ } else {
+ debug_5("cc_apdu returned nonzero");
+ return;
+ }
+
+ total_pkt_length = sizeof(Msg) + dfheader->encoded_size;
+ debug_5 ( "building CmC packet size: %d", total_pkt_length );
+ cmc_pkt = CmCPacketBuild ( dfheader );
+ debug_5 ( "sending CmC packet size: %d", total_pkt_length );
+ PacketSend ( cmc_pkt, total_pkt_length, &send_df_socket );
+ PacketFree ( cmc_pkt );
+
+ free(dfheader->encoded);
+
+ }
+
+ if (packet_data_header_report(dfheader) == 0) {
+ debug_5("Packet_Data_Header_Report encoded addr: %p, size: %Zd", dfheader->encoded, dfheader->encoded_size);
+ //print_hex((const u_char *)dfheader->encoded, (size_t)dfheader->encoded_size);
+ } else {
+ return;
+ }
+
+ total_pkt_length = sizeof(Msg) + dfheader->encoded_size;
+ debug_5 ( "building T1.IAS CmII packet size: %d", total_pkt_length);
+ cmii_pkt = CmIIPacketBuild ( dfheader );
+ debug_5 ( "sending T1.IAS CmII packet size: %d", total_pkt_length );
+ //print_hex((const u_char *)cmii_pkt, (size_t)total_pkt_length);
+ PacketSend ( cmii_pkt, total_pkt_length, &send_df_socket );
+ PacketFree ( cmii_pkt );
+
+ free(dfheader->encoded);
+
+ if (directsignalreporting(dfheader) == 0) {
+ debug_5("Direct Signal Reporting encoded addr: %p, size: %Zd", dfheader->encoded, dfheader->encoded_size);
+ //print_hex((const u_char *)dfheader->encoded, (size_t)dfheader->encoded_size);
+ } else {
+ return;
+ }
+
+ total_pkt_length = sizeof(Msg) + dfheader->encoded_size;
+ debug_5 ( "building T1.678 CmII packet size: %d", total_pkt_length);
+ cmii_pkt = CmIIPacketBuild ( dfheader );
+ debug_5 ( "sending T1.678 CmII packet size: %d", total_pkt_length );
+ //print_hex((const u_char *)cmii_pkt, (size_t)total_pkt_length);
+ PacketSend ( cmii_pkt, total_pkt_length, &send_df_socket );
+ PacketFree ( cmii_pkt );
+
+ free(dfheader->encoded);
+}
+
+
+/*
+ * process_packet_cmc_udp: sends PacketDataHeaderReport structures for IAS CACmII,
+ * and UDP encapsulated IAS CmC (per IAS D.3.1)
+ */
+void process_packet_cmc_udp( u_char *args, const struct pcap_pkthdr *header, const u_char *packet ) {
+
+ struct ether_header *ethernet;
+ struct ip *ip;
+ struct udphdr *udp;
+ struct tcphdr *tcp;
+ Msg *cmc_pkt;
+ Msg *cmii_pkt;
+ int total_pkt_length;
+ int ip_size;
+ int tcp_size;
+ int udp_size;
+ int payload_size;
+ int ip_size_total;
+ const char *payload; /* Packet Payload */
+ HEADER *dfheader;
+ char calea_time[TS_LENGTH];
+
+ dfheader = (HEADER *)args;
+
+#ifdef DEBUG_PKTS
+ char msg[ MAX_LOG_DEBUG_MSG_LEN ];
+ memset ( msg, '\0', MAX_LOG_DEBUG_MSG_LEN );
+#endif
+
+ get_calea_time ( header->ts.tv_sec, header->ts.tv_usec, &calea_time[0] );
+
+ dfheader->sec = header->ts.tv_sec;
+ dfheader->usec = header->ts.tv_usec/100;
+
+ /* Ethernet Packet */
+ ethernet = (struct ether_header *)(packet);
+
+ /* IP Header Offset */
+ ip = ( struct ip* )( (char *)ethernet + datalink_hdr_len );
+ ip_size_total = (int)ntohs(ip->ip_len);
+ ip_size = ip->ip_hl * 4;
+ if (ip_size < 20) {
+ log_5("Packet has invalid IP header length: %u bytes", ip_size);
+ debug_3("Packet has invalid IP header length: %u bytes", ip_size);
+ return;
+ }
+
+ dfheader->srcIP = htonl(ip->ip_src.s_addr);
+ dfheader->dstIP = htonl(ip->ip_dst.s_addr);
+
+ if (inet_ntop(AF_INET, &ip->ip_src.s_addr, dfheader->src_ip, sizeof(dfheader->src_ip)) == NULL ) {
+ pdie("inet_ntop");
+ }
+ if (inet_ntop(AF_INET, &ip->ip_dst.s_addr, dfheader->dst_ip, sizeof(dfheader->dst_ip)) == NULL ) {
+ pdie("inet_ntop");
+ }
+
+ if ( ip->ip_p == IPPROTO_UDP ) {
+ /* UDP Header */
+ udp = ( struct udphdr* ) ( (u_char *)ip + ip_size );
+
+ udp_size = sizeof(struct udphdr);
+ if (ntohs(udp->uh_ulen) <= 12) {
+ log_5("Packet has invalid UDP header length: %u bytes", udp_size);
+ debug_3("Packet has invalid UDP header length: %u bytes", udp_size);
+ return;
+ }
+
+ /* UDP Payload */
+ payload = (char *)((u_char *)udp + udp_size);
+
+ /* UDP Payload size */
+ payload_size = ntohs(udp->uh_ulen) - udp_size;
+
+#ifdef DEBUG_PKTS
+ if (payload_size > 0) {
+ debug_5("Payload (%d bytes):", payload_size);
+ print_hex(payload, payload_size);
+ }
+#endif
+
+ //format_vop_payload(dfheader);
+
+ dfheader->srcPort = ntohs(udp->uh_sport);
+ dfheader->dstPort = ntohs(udp->uh_dport);
+
+ } else if ( ip->ip_p == IPPROTO_TCP ) {
+
+ /* TCP Header */
+ tcp = ( struct tcphdr* ) ( (u_char *)ip + ip_size);
+
+ tcp_size = tcp->th_off * 4;
+ if (tcp_size < 20) {
+ log_5("Packet has invalid TCP header length: %u bytes", tcp_size);
+ debug_3("Packet has invalid TCP header length: %u bytes", tcp_size);
+ return;
+ }
+
+ /* TCP Payload */
+ payload = (char *)((u_char *)tcp + tcp_size);
+
+ /* TCP Payload size */
+ payload_size = ntohs(ip->ip_len) - (ip_size + tcp_size);
+
+ dfheader->srcPort = ntohs(tcp->th_sport);
+ dfheader->dstPort = ntohs(tcp->th_dport);
+
+ } else {
+ debug_4("Packet is neither UDP or TCP");
+ dfheader->srcPort = 0;
+ dfheader->dstPort = 0;
+ }
+
+ /*------------------------------------------------------------------------*/
+ /* only send Communications Content CmC msg if requested */
+ /*------------------------------------------------------------------------*/
+ if ( content_option == 1 ) {
+
+ //debug_5("IP (%d bytes):", ip_size_total);
+ //print_hex((const u_char *)ip, (size_t)ip_size_total);
+
+ dfheader->sequenceNumber++;
+ dfheader->payload = (const char *)ip;
+ dfheader->payload_size = (size_t)ip_size_total;
+ /*------------------------------------------------------------------------*/
+ /* WARNING: cc_apdu will allocate space for the BER encoded message. */
+ /* This space MUST be freed when it is no longer needed or a */
+ /* memory leak will occur. */
+ /* */
+ /* The address of the allocated memory is dfheader->encoded. */
+ /* The size of the allocated memory is dfheader->encoded_size. */
+ /* If cc_apdu does not return 0, no deallocation is needed. */
+ /*------------------------------------------------------------------------*/
+ if ( cc_apdu(dfheader) == 0) {
+ debug_5("Encoded addr(size): %p(%Zd)", dfheader->encoded_size, dfheader->encoded);
+ } else {
+ debug_5("cc_apdu returned nonzero");
+ return;
+ }
+
+ total_pkt_length = sizeof(Msg) + dfheader->encoded_size;
+ debug_5 ( "building CmC packet size: %d", total_pkt_length );
+ cmc_pkt = CmCPacketBuild ( dfheader );
+ debug_5 ( "sending CmC packet size: %d", total_pkt_length );
+ PacketSend ( cmc_pkt, total_pkt_length, &send_df_socket );
+ PacketFree ( cmc_pkt );
+
+ free(dfheader->encoded);
+
+ }
+
+ if (packet_data_header_report(dfheader) == 0) {
+ debug_5("Packet_Data_Header_Report encoded addr: %p, size: %Zd", dfheader->encoded, dfheader->encoded_size);
+ //print_hex((const u_char *)dfheader->encoded, (size_t)dfheader->encoded_size);
+ } else {
+ return;
+ }
+
+ total_pkt_length = sizeof(Msg) + dfheader->encoded_size;
+ debug_5 ( "building T1.IAS CmII packet size: %d", total_pkt_length);
+ cmii_pkt = CmIIPacketBuild ( dfheader );
+ debug_5 ( "sending T1.IAS CmII packet size: %d", total_pkt_length );
+ //print_hex((const u_char *)cmii_pkt, (size_t)total_pkt_length);
+ PacketSend ( cmii_pkt, total_pkt_length, &send_df_socket );
+ PacketFree ( cmii_pkt );
+
+ free(dfheader->encoded);
+
+ if (directsignalreporting(dfheader) == 0) {
+ debug_5("Direct Signal Reporting encoded addr: %p, size: %Zd", dfheader->encoded, dfheader->encoded_size);
+ //print_hex((const u_char *)dfheader->encoded, (size_t)dfheader->encoded_size);
+ } else {
+ return;
+ }
+
+ total_pkt_length = sizeof(Msg) + dfheader->encoded_size;
+ debug_5 ( "building T1.678 CmII packet size: %d", total_pkt_length);
+ cmii_pkt = CmIIPacketBuild ( dfheader );
+ debug_5 ( "sending T1.678 CmII packet size: %d", total_pkt_length );
+ //print_hex((const u_char *)cmii_pkt, (size_t)total_pkt_length);
+ PacketSend ( cmii_pkt, total_pkt_length, &send_df_socket );
+ PacketFree ( cmii_pkt );
+
+ free(dfheader->encoded);
+}
+
+
+/*
+ * process_packet_raw: sends content raw with no formatting
+ */
+void process_packet_raw( u_char *args, const struct pcap_pkthdr *header, const u_char *packet ) {
+
+ struct ether_header *ethernet;
+ struct ip *ip;
+ struct udphdr *udp;
+ struct tcphdr *tcp;
+ Msg *cmc_pkt;
+ Msg *cmii_pkt;
+ int total_pkt_length;
+ int ip_size;
+ int tcp_size;
+ int udp_size;
+ int payload_size;
+ int ip_size_total;
+ const char *payload; /* Packet Payload */
+ HEADER *dfheader;
+ char calea_time[TS_LENGTH];
+
+ dfheader = (HEADER *)args;
+
+#ifdef DEBUG_PKTS
+ char msg[ MAX_LOG_DEBUG_MSG_LEN ];
+ memset ( msg, '\0', MAX_LOG_DEBUG_MSG_LEN );
+#endif
+
+ get_calea_time ( header->ts.tv_sec, header->ts.tv_usec, &calea_time[0] );
+
+ dfheader->sec = header->ts.tv_sec;
+ dfheader->usec = header->ts.tv_usec/100;
+
+ /* Ethernet Packet */
+ ethernet = (struct ether_header *)(packet);
+
+ /* IP Header Offset */
+ ip = ( struct ip* )( (char *)ethernet + datalink_hdr_len );
+ ip_size_total = (int)ntohs(ip->ip_len);
+ ip_size = ip->ip_hl * 4;
+ if (ip_size < 20) {
+ log_5("Packet has invalid IP header length: %u bytes", ip_size);
+ debug_3("Packet has invalid IP header length: %u bytes", ip_size);
+ return;
+ }
+
+ dfheader->srcIP = htonl(ip->ip_src.s_addr);
+ dfheader->dstIP = htonl(ip->ip_dst.s_addr);
+
+ if (inet_ntop(AF_INET, &ip->ip_src.s_addr, dfheader->src_ip, sizeof(dfheader->src_ip)) == NULL ) {
+ pdie("inet_ntop");
+ }
+ if (inet_ntop(AF_INET, &ip->ip_dst.s_addr, dfheader->dst_ip, sizeof(dfheader->dst_ip)) == NULL ) {
+ pdie("inet_ntop");
+ }
+
+ if ( ip->ip_p == IPPROTO_UDP ) {
+ /* UDP Header */
+ udp = ( struct udphdr* ) ( (u_char *)ip + ip_size );
+
+ udp_size = sizeof(struct udphdr);
+ if (ntohs(udp->uh_ulen) <= 12) {
+ log_5("Packet has invalid UDP header length: %u bytes", udp_size);
+ debug_3("Packet has invalid UDP header length: %u bytes", udp_size);
+ return;
+ }
+
+ /* UDP Payload */
+ payload = (char *)((u_char *)udp + udp_size);
+
+ /* UDP Payload size */
+ payload_size = ntohs(udp->uh_ulen) - udp_size;
+
+#ifdef DEBUG_PKTS
+ if (payload_size > 0) {
+ debug_5("Payload (%d bytes):", payload_size);
+ print_hex(payload, payload_size);
+ }
+#endif
+
+ //format_vop_payload(dfheader);
+
+ dfheader->srcPort = ntohs(udp->uh_sport);
+ dfheader->dstPort = ntohs(udp->uh_dport);
+
+ } else if ( ip->ip_p == IPPROTO_TCP ) {
+
+ /* TCP Header */
+ tcp = ( struct tcphdr* ) ( (u_char *)ip + ip_size);
+
+ tcp_size = tcp->th_off * 4;
+ if (tcp_size < 20) {
+ log_5("Packet has invalid TCP header length: %u bytes", tcp_size);
+ debug_3("Packet has invalid TCP header length: %u bytes", tcp_size);
+ return;
+ }
+
+ /* TCP Payload */
+ payload = (char *)((u_char *)tcp + tcp_size);
+
+ /* TCP Payload size */
+ payload_size = ntohs(ip->ip_len) - (ip_size + tcp_size);
+
+ dfheader->srcPort = ntohs(tcp->th_sport);
+ dfheader->dstPort = ntohs(tcp->th_dport);
+
+ } else {
+ debug_4("Packet is neither UDP or TCP");
+ dfheader->srcPort = 0;
+ dfheader->dstPort = 0;
+ }
+
+ /*------------------------------------------------------------------------*/
+ /* only send Communications Content CmC msg if requested */
+ /*------------------------------------------------------------------------*/
+ if ( content_option == 1 ) {
+
+ //debug_5("IP (%d bytes):", ip_size_total);
+ //print_hex((const u_char *)ip, (size_t)ip_size_total);
+
+ dfheader->sequenceNumber++;
+ dfheader->payload = (const char *)ip;
+ dfheader->payload_size = (size_t)ip_size_total;
+ /*------------------------------------------------------------------------*/
+ /* WARNING: cc_apdu will allocate space for the BER encoded message. */
+ /* This space MUST be freed when it is no longer needed or a */
+ /* memory leak will occur. */
+ /* */
+ /* The address of the allocated memory is dfheader->encoded. */
+ /* The size of the allocated memory is dfheader->encoded_size. */
+ /* If cc_apdu does not return 0, no deallocation is needed. */
+ /*------------------------------------------------------------------------*/
+ if ( cc_apdu(dfheader) == 0) {
+ debug_5("Encoded addr(size): %p(%Zd)", dfheader->encoded_size, dfheader->encoded);
+ } else {
+ debug_5("cc_apdu returned nonzero");
+ return;
+ }
+
+ total_pkt_length = sizeof(Msg) + dfheader->encoded_size;
+ debug_5 ( "building CmC packet size: %d", total_pkt_length );
+ cmc_pkt = CmCPacketBuild ( dfheader );
+ debug_5 ( "sending CmC packet size: %d", total_pkt_length );
+ PacketSend ( cmc_pkt, total_pkt_length, &send_df_socket );
+ PacketFree ( cmc_pkt );
+
+ free(dfheader->encoded);
+
+ }
+
+ if (packet_data_header_report(dfheader) == 0) {
+ debug_5("Packet_Data_Header_Report encoded addr: %p, size: %Zd", dfheader->encoded, dfheader->encoded_size);
+ //print_hex((const u_char *)dfheader->encoded, (size_t)dfheader->encoded_size);
+ } else {
+ return;
+ }
+
+ total_pkt_length = sizeof(Msg) + dfheader->encoded_size;
+ debug_5 ( "building T1.IAS CmII packet size: %d", total_pkt_length);
+ cmii_pkt = CmIIPacketBuild ( dfheader );
+ debug_5 ( "sending T1.IAS CmII packet size: %d", total_pkt_length );
+ //print_hex((const u_char *)cmii_pkt, (size_t)total_pkt_length);
+ PacketSend ( cmii_pkt, total_pkt_length, &send_df_socket );
+ PacketFree ( cmii_pkt );
+
+ free(dfheader->encoded);
+
+ if (directsignalreporting(dfheader) == 0) {
+ debug_5("Direct Signal Reporting encoded addr: %p, size: %Zd", dfheader->encoded, dfheader->encoded_size);
+ //print_hex((const u_char *)dfheader->encoded, (size_t)dfheader->encoded_size);
+ } else {
+ return;
+ }
+
+ total_pkt_length = sizeof(Msg) + dfheader->encoded_size;
+ debug_5 ( "building T1.678 CmII packet size: %d", total_pkt_length);
+ cmii_pkt = CmIIPacketBuild ( dfheader );
+ debug_5 ( "sending T1.678 CmII packet size: %d", total_pkt_length );
+ //print_hex((const u_char *)cmii_pkt, (size_t)total_pkt_length);
+ PacketSend ( cmii_pkt, total_pkt_length, &send_df_socket );
+ PacketFree ( cmii_pkt );
+
+ free(dfheader->encoded);
+}
+
+
+/*
+ * process_packet_pcap: sends content, with link headers, in pcap packets
+ */
+void process_packet_pcap( u_char *args, const struct pcap_pkthdr *header, const u_char *packet ) {
+
+ struct ether_header *ethernet;
+ struct ip *ip;
+ struct udphdr *udp;
+ struct tcphdr *tcp;
+ Msg *cmc_pkt;
+ Msg *cmii_pkt;
+ int total_pkt_length;
+ int ip_size;
+ int tcp_size;
+ int udp_size;
+ int payload_size;
+ int ip_size_total;
+ const char *payload; /* Packet Payload */
+ HEADER *dfheader;
+ char calea_time[TS_LENGTH];
+
+ dfheader = (HEADER *)args;
+
+#ifdef DEBUG_PKTS
+ char msg[ MAX_LOG_DEBUG_MSG_LEN ];
+ memset ( msg, '\0', MAX_LOG_DEBUG_MSG_LEN );
+#endif
+
+ get_calea_time ( header->ts.tv_sec, header->ts.tv_usec, &calea_time[0] );
+
+ dfheader->sec = header->ts.tv_sec;
+ dfheader->usec = header->ts.tv_usec/100;
+
+ /* Ethernet Packet */
+ ethernet = (struct ether_header *)(packet);
+
+ /* IP Header Offset */
+ ip = ( struct ip* )( (char *)ethernet + datalink_hdr_len );
+ ip_size_total = (int)ntohs(ip->ip_len);
+ ip_size = ip->ip_hl * 4;
+ if (ip_size < 20) {
+ log_5("Packet has invalid IP header length: %u bytes", ip_size);
+ debug_3("Packet has invalid IP header length: %u bytes", ip_size);
+ return;
+ }
+
+ dfheader->srcIP = htonl(ip->ip_src.s_addr);
+ dfheader->dstIP = htonl(ip->ip_dst.s_addr);
+
+ if (inet_ntop(AF_INET, &ip->ip_src.s_addr, dfheader->src_ip, sizeof(dfheader->src_ip)) == NULL ) {
+ pdie("inet_ntop");
+ }
+ if (inet_ntop(AF_INET, &ip->ip_dst.s_addr, dfheader->dst_ip, sizeof(dfheader->dst_ip)) == NULL ) {
+ pdie("inet_ntop");
+ }
+
+ if ( ip->ip_p == IPPROTO_UDP ) {
+ /* UDP Header */
+ udp = ( struct udphdr* ) ( (u_char *)ip + ip_size );
+
+ udp_size = sizeof(struct udphdr);
+ if (ntohs(udp->uh_ulen) <= 12) {
+ log_5("Packet has invalid UDP header length: %u bytes", udp_size);
+ debug_3("Packet has invalid UDP header length: %u bytes", udp_size);
+ return;
+ }
+
+ /* UDP Payload */
+ payload = (char *)((u_char *)udp + udp_size);
+
+ /* UDP Payload size */
+ payload_size = ntohs(udp->uh_ulen) - udp_size;
+
+#ifdef DEBUG_PKTS
+ if (payload_size > 0) {
+ debug_5("Payload (%d bytes):", payload_size);
+ print_hex(payload, payload_size);
+ }
+#endif
+
+ //format_vop_payload(dfheader);
+
+ dfheader->srcPort = ntohs(udp->uh_sport);
+ dfheader->dstPort = ntohs(udp->uh_dport);
+
+ } else if ( ip->ip_p == IPPROTO_TCP ) {
+
+ /* TCP Header */
+ tcp = ( struct tcphdr* ) ( (u_char *)ip + ip_size);
+
+ tcp_size = tcp->th_off * 4;
+ if (tcp_size < 20) {
+ log_5("Packet has invalid TCP header length: %u bytes", tcp_size);
+ debug_3("Packet has invalid TCP header length: %u bytes", tcp_size);
+ return;
+ }
+
+ /* TCP Payload */
+ payload = (char *)((u_char *)tcp + tcp_size);
+
+ /* TCP Payload size */
+ payload_size = ntohs(ip->ip_len) - (ip_size + tcp_size);
+
+ dfheader->srcPort = ntohs(tcp->th_sport);
+ dfheader->dstPort = ntohs(tcp->th_dport);
+
+ } else {
+ debug_4("Packet is neither UDP or TCP");
+ dfheader->srcPort = 0;
+ dfheader->dstPort = 0;
+ }
+
+ /*------------------------------------------------------------------------*/
+ /* only send Communications Content CmC msg if requested */
+ /*------------------------------------------------------------------------*/
+ if ( content_option == 1 ) {
+
+ //debug_5("IP (%d bytes):", ip_size_total);
+ //print_hex((const u_char *)ip, (size_t)ip_size_total);
+
+ dfheader->sequenceNumber++;
+ dfheader->payload = (const char *)ip;
+ dfheader->payload_size = (size_t)ip_size_total;
+ /*------------------------------------------------------------------------*/
+ /* WARNING: cc_apdu will allocate space for the BER encoded message. */
+ /* This space MUST be freed when it is no longer needed or a */
+ /* memory leak will occur. */
+ /* */
+ /* The address of the allocated memory is dfheader->encoded. */
+ /* The size of the allocated memory is dfheader->encoded_size. */
+ /* If cc_apdu does not return 0, no deallocation is needed. */
+ /*------------------------------------------------------------------------*/
+ if ( cc_apdu(dfheader) == 0) {
+ debug_5("Encoded addr(size): %p(%Zd)", dfheader->encoded_size, dfheader->encoded);
+ } else {
+ debug_5("cc_apdu returned nonzero");
+ return;
+ }
+
+ total_pkt_length = sizeof(Msg) + dfheader->encoded_size;
+ debug_5 ( "building CmC packet size: %d", total_pkt_length );
+ cmc_pkt = CmCPacketBuild ( dfheader );
+ debug_5 ( "sending CmC packet size: %d", total_pkt_length );
+ PacketSend ( cmc_pkt, total_pkt_length, &send_df_socket );
+ PacketFree ( cmc_pkt );
+
+ free(dfheader->encoded);
+
+ }
+
+ if (packet_data_header_report(dfheader) == 0) {
+ debug_5("Packet_Data_Header_Report encoded addr: %p, size: %Zd", dfheader->encoded, dfheader->encoded_size);
+ //print_hex((const u_char *)dfheader->encoded, (size_t)dfheader->encoded_size);
+ } else {
+ return;
+ }
+
+ total_pkt_length = sizeof(Msg) + dfheader->encoded_size;
+ debug_5 ( "building T1.IAS CmII packet size: %d", total_pkt_length);
+ cmii_pkt = CmIIPacketBuild ( dfheader );
+ debug_5 ( "sending T1.IAS CmII packet size: %d", total_pkt_length );
+ //print_hex((const u_char *)cmii_pkt, (size_t)total_pkt_length);
+ PacketSend ( cmii_pkt, total_pkt_length, &send_df_socket );
+ PacketFree ( cmii_pkt );
+
+ free(dfheader->encoded);
+
+ if (directsignalreporting(dfheader) == 0) {
+ debug_5("Direct Signal Reporting encoded addr: %p, size: %Zd", dfheader->encoded, dfheader->encoded_size);
+ //print_hex((const u_char *)dfheader->encoded, (size_t)dfheader->encoded_size);
+ } else {
+ return;
+ }
+
+ total_pkt_length = sizeof(Msg) + dfheader->encoded_size;
+ debug_5 ( "building T1.678 CmII packet size: %d", total_pkt_length);
+ cmii_pkt = CmIIPacketBuild ( dfheader );
+ debug_5 ( "sending T1.678 CmII packet size: %d", total_pkt_length );
+ //print_hex((const u_char *)cmii_pkt, (size_t)total_pkt_length);
+ PacketSend ( cmii_pkt, total_pkt_length, &send_df_socket );
+ PacketFree ( cmii_pkt );
+
+ free(dfheader->encoded);
+}
+
+
Modified: trunk/src/tap.c
===================================================================
--- trunk/src/tap.c 2007-05-11 16:58:30 UTC (rev 30)
+++ trunk/src/tap.c 2007-05-11 22:53:48 UTC (rev 31)
@@ -29,217 +29,31 @@
#include "common.h"
#include "calea.h"
#include "tap.h"
+#include "packet_data_header_report.h"
#include <pcap.h>
#include <net/ethernet.h>
/* function declarations */
-char *cc_apdu(HEADER *);
-char *packet_data_header_report(HEADER *);
-char *directsignalreporting(HEADER *);
-void get_calea_time (time_t, time_t, char *);
-Msg *CmCPacketBuild (HEADER *);
-Msg *CmIIPacketBuild (HEADER *);
-int PacketSend ( Msg *, int, int * );
-void PacketFree (Msg *);
-Msg *CtrlMsgBuild (HEADER *);
-ssize_t tcp_write(int, const void *, size_t);
-ssize_t tcp_read(int, void *, size_t);
+void process_packet_cc_apdu( u_char *args, const struct pcap_pkthdr *header, const u_char *packet );
+void process_packet_cmii_pdhr( u_char *args, const struct pcap_pkthdr *header, const u_char *packet );
+void process_packet_cmc_pdhr( u_char *args, const struct pcap_pkthdr *header, const u_char *packet );
+void process_packet_cmc_udp( u_char *args, const struct pcap_pkthdr *header, const u_char *packet );
+void process_packet_raw( u_char *args, const struct pcap_pkthdr *header, const u_char *packet );
+void process_packet_pcap( u_char *args, const struct pcap_pkthdr *header, const u_char *packet );
+
char *prog_name = "tap";
int syslog_facility = DEF_SYSLOG_FACILITY;
char contentID[MAX_CONTENT_ID_LENGTH];
char caseID[MAX_CASE_ID_LENGTH];
char iapID[MAX_IAP_SYSTEM_ID_LENGTH];
-int datalink_hdr_len;
+int datalink_hdr_len;
int send_df_socket;
struct sockaddr_in send_df_addr;
-int content_option = 0;
-void process_packet( u_char *args, const struct pcap_pkthdr *header, const u_char *packet ) {
-
- struct ether_header *ethernet;
- struct ip *ip;
- struct udphdr *udp;
- struct tcphdr *tcp;
- Msg *cmc_pkt;
- Msg *cmii_pkt;
- int total_pkt_length;
- int ip_size;
- int tcp_size;
- int udp_size;
- int payload_size;
- int ip_size_total;
- const char *payload; /* Packet Payload */
- HEADER *dfheader;
- char calea_time[TS_LENGTH];
-
- dfheader = (HEADER *)args;
-
-#ifdef DEBUG_PKTS
- char msg[ MAX_LOG_DEBUG_MSG_LEN ];
- memset ( msg, '\0', MAX_LOG_DEBUG_MSG_LEN );
-#endif
-
- get_calea_time ( header->ts.tv_sec, header->ts.tv_usec, &calea_time[0] );
-
- dfheader->sec = header->ts.tv_sec;
- dfheader->usec = header->ts.tv_usec/100;
-
- /* Ethernet Packet */
- ethernet = (struct ether_header *)(packet);
-
- /* IP Header Offset */
- ip = ( struct ip* )( (char *)ethernet + datalink_hdr_len );
- ip_size_total = (int)ntohs(ip->ip_len);
- ip_size = ip->ip_hl * 4;
- if (ip_size < 20) {
- log_5("Packet has invalid IP header length: %u bytes", ip_size);
- debug_3("Packet has invalid IP header length: %u bytes", ip_size);
- return;
- }
-
- dfheader->srcIP = htonl(ip->ip_src.s_addr);
- dfheader->dstIP = htonl(ip->ip_dst....
[truncated message content] |