aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorDavid M. Syzdek <david.syzdek@acsalaska.com>2022-07-21 15:50:41 -0800
committerDavid M. Syzdek <david.syzdek@acsalaska.com>2022-07-21 15:50:41 -0800
commite5104afe0610d5d602338377f87f8b5c85eef0a3 (patch)
tree29215a4c3d32d6d6822d341cdfbf1e2bd2fe22e8
parentce55636db15589413d28b706b706b4ff2f535a5e (diff)
downloadakcom-udpecho-e5104afe0610d5d602338377f87f8b5c85eef0a3.tar.gz
akcom-udpecho-e5104afe0610d5d602338377f87f8b5c85eef0a3.tar.bz2
akcom-udpecho-e5104afe0610d5d602338377f87f8b5c85eef0a3.tar.xz
akcom-udpecho-e5104afe0610d5d602338377f87f8b5c85eef0a3.zip
akcom-udpechod: adding global variable for tracking state
-rw-r--r--src/akcom-udpechod.c18
1 files changed, 14 insertions, 4 deletions
diff --git a/src/akcom-udpechod.c b/src/akcom-udpechod.c
index 701bc47..892e6ba 100644
--- a/src/akcom-udpechod.c
+++ b/src/akcom-udpechod.c
@@ -162,6 +162,15 @@ static const char * cnf_listen = NULL; // IP a
162static uid_t cnf_uid = 0; // setuid 162static uid_t cnf_uid = 0; // setuid
163static gid_t cnf_gid = 0; // setgid 163static gid_t cnf_gid = 0; // setgid
164 164
165static struct udp_echo_plus state =
166{
167 .req_sn = 0,
168 .res_sn = 0,
169 .recv_time = 0,
170 .reply_time = 0,
171 .failures = 0
172};
173
165 174
166////////////////// 175//////////////////
167// // 176// //
@@ -833,6 +842,7 @@ int my_loop(int s, size_t * connp)
833 return(0); 842 return(0);
834 843
835 // increment connection counter 844 // increment connection counter
845 state.req_sn++;
836 (*connp)++; 846 (*connp)++;
837 847
838 // read data 848 // read data
@@ -847,13 +857,9 @@ int my_loop(int s, size_t * connp)
847 857
848 // log connection 858 // log connection
849 my_log_conn(MY_RECV, connp, &sa, &udpbuff.msg, ssize, &ts, 0); 859 my_log_conn(MY_RECV, connp, &sa, &udpbuff.msg, ssize, &ts, 0);
850
851 // process echo+ packet
852 if ((cnf_echoplus)) 860 if ((cnf_echoplus))
853 { 861 {
854 udpbuff.msg.res_sn = udpbuff.msg.req_sn;
855 udpbuff.msg.recv_time = htonl(us_recv & 0xFFFFFFFFLL); 862 udpbuff.msg.recv_time = htonl(us_recv & 0xFFFFFFFFLL);
856 udpbuff.msg.failures = 0;
857 }; 863 };
858 864
859 // randomly drop packets 865 // randomly drop packets
@@ -861,10 +867,12 @@ int my_loop(int s, size_t * connp)
861 { 867 {
862 if ( (rand() % 100) < cnf_drop_perct) 868 if ( (rand() % 100) < cnf_drop_perct)
863 { 869 {
870 state.failures++;
864 my_log_conn(MY_DROP, connp, &sa, &udpbuff.msg, ssize, &ts, 0); 871 my_log_conn(MY_DROP, connp, &sa, &udpbuff.msg, ssize, &ts, 0);
865 return(0); 872 return(0);
866 }; 873 };
867 }; 874 };
875 state.res_sn++;
868 876
869 // insert random delay 877 // insert random delay
870 delay = 0; 878 delay = 0;
@@ -883,7 +891,9 @@ int my_loop(int s, size_t * connp)
883 // send response 891 // send response
884 if ((cnf_echoplus)) 892 if ((cnf_echoplus))
885 { 893 {
894 udpbuff.msg.res_sn = htonl(state.res_sn);
886 udpbuff.msg.reply_time = htonl(us_reply & 0xFFFFFFFFLL); 895 udpbuff.msg.reply_time = htonl(us_reply & 0xFFFFFFFFLL);
896 udpbuff.msg.failures = htonl(state.failures);
887 }; 897 };
888 sendto(s, udpbuff.bytes, (size_t)ssize, 0, &sa.sa, sinlen); 898 sendto(s, udpbuff.bytes, (size_t)ssize, 0, &sa.sa, sinlen);
889 899