diff --git a/udpCallback.c b/udpCallback.c index f7d9180..1eb9242 100644 --- a/udpCallback.c +++ b/udpCallback.c @@ -48,6 +48,7 @@ static int udpSocket; struct sockaddr_in sockaddr; static int start_loop = 1; char *dvalue = NULL; +char *pvalue = NULL; int flood = 0; int oneByOne = 0; long int countToFlood = 0; @@ -238,11 +239,13 @@ static void callback_handler(u_char *user __attribute__((unused)), /* Set destination */ if (!dvalue) sockaddr.sin_addr.s_addr = ip_hdr.ip_dst.s_addr; + if (!pvalue) { #ifdef HAVE_STRUCT_UDPHDR_UH_DPORT - sockaddr.sin_port = udp_hdr.uh_dport; + sockaddr.sin_port = udp_hdr.uh_dport; #else - sockaddr.sin_port = udp_hdr.dest; + sockaddr.sin_port = udp_hdr.dest; #endif + } if (asterixTime) { diff --git a/udpCallback.h b/udpCallback.h index 12a9fd4..4f9d8cf 100644 --- a/udpCallback.h +++ b/udpCallback.h @@ -18,6 +18,7 @@ extern struct sockaddr_in sockaddr; extern int rewriteDestination; extern char *dvalue; +extern char *pvalue; extern int flood; extern int oneByOne; extern int asterixTime; diff --git a/udpReplay.1 b/udpReplay.1 index b85669b..8de560f 100644 --- a/udpReplay.1 +++ b/udpReplay.1 @@ -26,6 +26,9 @@ Adjust the Asterix Time Of Day to reflect the time the message is sent .BR -d\ host | --dest\ host Send the datagram to the specified host. It this option is not present, data are sent to the original host as recorded in the pcap file .TP +.BR -p\ port | --port\ port +Send the datagram to the specified port. It this option is not present, data are sent to the original port as recorded in the pcap file +.TP .BR --mttl\ ttlValue Set the time to live for multicast packets to the value specified as argument. Otherwise is set to 1 .TP diff --git a/udpReplay.c b/udpReplay.c index 4491107..4fbef45 100644 --- a/udpReplay.c +++ b/udpReplay.c @@ -41,13 +41,14 @@ int main(int argc, char* argv[]) {"step", no_argument, 0, '1'}, {"flood", no_argument, 0, 'f'}, {"dest", required_argument, 0, 'd'}, + {"port", required_argument, 0, 'p'}, {"astx", no_argument, 0, 4}, {"mttl", required_argument, 0, 1}, {0, 0, 0, 0} }; int option_index; - while ((c = getopt_long(argc, argv, "1fd:", long_options, &option_index)) != -1) + while ((c = getopt_long(argc, argv, "1fd:p:", long_options, &option_index)) != -1) switch (c) { case 1: setMulticastTTL = 1; @@ -65,6 +66,9 @@ int main(int argc, char* argv[]) case 'd': dvalue = optarg; break; + case 'p': + pvalue = optarg; + break; default: break; }; @@ -94,6 +98,18 @@ int main(int argc, char* argv[]) return -1; } } + if (pvalue) { + int port = atoi(pvalue); + if (port <= 0) { + printf("-p %s option is an invalid number or zero\n", pvalue); + return -1; + } + if (port > 65535) { + printf("-p %s option is greater then 65535\n", pvalue); + return -1; + } + sockaddr.sin_port = htons(port); + } pcap = pcap_open_offline(pcapName, errbuf);