|
From: <nor...@us...> - 2007-05-10 13:44:22
|
Revision: 20
http://opencalea.svn.sourceforge.net/opencalea/?rev=20&view=rev
Author: norm_brandinger
Date: 2007-05-10 06:44:23 -0700 (Thu, 10 May 2007)
Log Message:
-----------
Only write data to a file if an error is returned from sendto.
Modified Paths:
--------------
src/df_collector.c
Modified: src/df_collector.c
===================================================================
--- src/df_collector.c 2007-05-10 11:53:58 UTC (rev 19)
+++ src/df_collector.c 2007-05-10 13:44:23 UTC (rev 20)
@@ -319,7 +319,7 @@
strcat(filename,"/");
strcat(filename,(char *)ctrlmsg->ctrlh.intercept.CaseID);
strcat(filename,".CmII");
- if (!(route[id].cmii_fp = fopen(filename, "wb"))) {
+ if (!(route[id].cmii_fp = fopen(filename, "ab"))) {
debug_5("df_collector: CmII_fp open failed for %s", filename);
pdie("df_collector: CmII_fp fopen");
}
@@ -334,7 +334,7 @@
strcat(filename,"/");
strcat(filename,(char *)ctrlmsg->ctrlh.intercept.CaseID);
strcat(filename,".CmC");
- if (!(route[id].cmc_fp = fopen(filename, "wb"))) {
+ if (!(route[id].cmc_fp = fopen(filename, "ab"))) {
debug_5("df_collector: CmC_fp open failed for %s", filename);
pdie("df_collector: CmC_fp fopen");
}
@@ -349,7 +349,7 @@
strcat(filename,"/");
strcat(filename,(char *)ctrlmsg->ctrlh.intercept.CaseID);
strcat(filename,".LOG");
- if (!(route[id].log_fp = fopen(filename, "w"))) {
+ if (!(route[id].log_fp = fopen(filename, "a"))) {
debug_5("df_collector: Surveillance log file open failed for %s", filename);
pdie("df_collector: Surveillance log fopen");
}
@@ -440,18 +440,6 @@
id = ntohs(msg->msgh.routeid);
inet_ntop (route[id].lea_addr.sin_family, &route[id].lea_addr.sin_addr.s_addr, addrstr, sizeof(addrstr));
- /**************************/
- /* Write packet to a file */
- /**************************/
- if (route[id].cmii_fp) {
- ret = fwrite(((char *)msg + msg_len), msg->msgh.msglen, 1, route[id].cmii_fp);
- if (ret != 1) {
- debug_5("df_collector: error writing to CmII file");
- }
- } else {
- debug_5("df_collector: Warning CmII capture file is not available");
- }
-
num_sent = sendto (route[id].lea_fd,
((char *)msg + msg_len),
msg->msgh.msglen,
@@ -459,13 +447,34 @@
(struct sockaddr *)&route[id].lea_addr,
sizeof(route[id].lea_addr));
+ /****************************************************************************/
+ /* If there was an error sending the data to the other end of the route[id] */
+ /* then save the data locally for future transmission. */
+ /* Note that for UDP transmissions, an error will only be indicated if the */
+ /* the socket to the route[id] is in an error state. For UDP, there IS NO */
+ /* GUARANTEE that the data was actually received at the remote end. */
+ /****************************************************************************/
if (num_sent == -1) {
- debug_5("df_collector: CmII packet -> route[%d] %s:%d failed",
+ debug_5("df_collector: CmII packet -> route[%d] %s:%d failed saving to file",
id,
addrstr,
ntohs(route[id].lea_addr.sin_port));
socklen = sizeof(sockval);
Getsockopt(route[id].lea_fd, SOL_SOCKET, SO_ERROR, &sockval, &socklen);
+
+ /**************************/
+ /* Write packet to a file */
+ /**************************/
+ if (route[id].cmii_fp) {
+ ret = fwrite(((char *)msg + msg_len), msg->msgh.msglen, 1, route[id].cmii_fp);
+ if (ret != 1) {
+ debug_5("df_collector: Error writing to CmII file");
+ } else {
+ debug_5("df_collector: Wrote %d bytes to CmII file", (ret * msg->msgh.msglen));
+ }
+ } else {
+ debug_5("df_collector: Warning CmII capture file is not available");
+ }
} else {
debug_5("df_collector: CmII packet -> route[%d] %s:%d %d bytes sent ",
id,
@@ -488,15 +497,6 @@
id = ntohs(msg->msgh.routeid);
inet_ntop (route[id].lea_addr.sin_family, &route[id].lea_addr.sin_addr.s_addr, addrstr, sizeof(addrstr));
- if (route[id].cmc_fp) {
- ret = fwrite(((char *)msg + msg_len), msg->msgh.msglen, 1, route[id].cmc_fp);
- if (ret != 1) {
- debug_5("df_collector: error writing to CmC file");
- }
- } else {
- debug_5("df_collector: Warning CmC capture file is not available");
- }
-
num_sent = sendto (route[id].lea_fd,
((char *)msg + msg_len),
msg->msgh.msglen,
@@ -504,13 +504,34 @@
(struct sockaddr *)&route[id].lea_addr,
sizeof(route[id].lea_addr));
+ /****************************************************************************/
+ /* If there was an error sending the data to the other end of the route[id] */
+ /* then save the data locally for future transmission. */
+ /* Note that for UDP transmissions, an error will only be indicated if the */
+ /* the socket to the route[id] is in an error state. For UDP, there IS NO */
+ /* GUARANTEE that the data was actually received at the remote end. */
+ /****************************************************************************/
if (num_sent == -1) {
- debug_5("df_collector: CmC packet -> route[%d] %s:%d failed",
+ debug_5("df_collector: CmC packet -> route[%d] %s:%d failed saving to file",
id,
addrstr,
ntohs(route[id].lea_addr.sin_port));
socklen = sizeof(sockval);
Getsockopt(route[id].lea_fd, SOL_SOCKET, SO_ERROR, &sockval, &socklen);
+ /**************************/
+ /* Write packet to a file */
+ /**************************/
+ if (route[id].cmc_fp) {
+ ret = fwrite(((char *)msg + msg_len), msg->msgh.msglen, 1, route[id].cmc_fp);
+ if (ret != 1) {
+ debug_5("df_collector: Error writing to CmC file");
+ } else {
+ debug_5("df_collector: Wrote %d bytes to CmC file", (ret * msg->msgh.msglen));
+ }
+ } else {
+ debug_5("df_collector: Warning CmC capture file is not available");
+ }
+
} else {
debug_5("df_collector: CmC packet -> route[%d] %s:%d %d bytes sent ",
id,
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|