openbsd-ports/net/fping/patches/patch-fping_c

102 lines
2.7 KiB
Plaintext

$OpenBSD: patch-fping_c,v 1.4 2003/01/28 05:03:32 fgsch Exp $
--- fping.c.orig Wed Jan 8 17:29:43 1997
+++ fping.c Tue Jan 28 01:55:42 2003
@@ -186,7 +186,11 @@ extern "C" {
#include <string.h>
+#if (defined(__unix__) || defined(unix)) && !defined(USG)
+#include <sys/param.h>
+#else
#include <sys/types.h>
+#endif
#include <sys/time.h>
#include <sys/socket.h>
@@ -217,10 +221,19 @@ extern "C" {
/* externals */
+#if !(defined(BSD) && (BSD >= 199103))
+extern char *sys_errlist[];
+#endif
+
+#ifndef __OpenBSD__
extern char *optarg;
extern int optind,opterr;
-extern char *sys_errlist[];
extern int h_errno;
+#endif
+
+#ifdef HAVE_PROGNAME
+extern char *__progname;
+#endif
#ifdef __cplusplus
}
@@ -473,9 +486,14 @@ int main(int argc, char **argv)
s = socket(AF_INET, SOCK_RAW, proto->p_proto);
if (s<0) errno_crash_and_burn("can't create raw socket");
- /*seteuid(getuid());*/
+ seteuid(getuid());
+ setuid(getuid());
- prog = argv[0];
+#ifdef HAVE_PROGNAME
+ prog = __progname;
+#else
+ prog = (prog = strrchr(argv[0], '/')) ? prog + 1 : argv[0];
+#endif
ident = getpid() & 0xFFFF;
verbose_flag = 1;
@@ -662,8 +680,12 @@ int main(int argc, char **argv)
++argv;
} else if (filename) {
FILE *ping_file;
- char line[132];
- char host[132],*p;
+#ifdef MAXHOSTNAMELEN
+ char line[MAXHOSTNAMELEN], host[MAXHOSTNAMELEN];
+#else
+ char line[256], char host[256];
+#endif
+ char *p;
if (strcmp(filename,"-")==0) {
ping_file=fdopen(0,"r");
} else {
@@ -1099,6 +1121,8 @@ int wait_for_reply()
result=recvfrom_wto(s,buffer,4096,
(struct sockaddr *)&response_addr,select_time);
+ /* get time of receipt as close to the real time as possible */
+ gettimeofday(&current_time,&tz);
if (result<0) { return 0; } /* timeout */
#ifdef DEBUG
@@ -1107,7 +1131,7 @@ int wait_for_reply()
return 0;
#endif
ip = (struct ip *) buffer;
-#if defined(__alpha__) && __STDC__
+#if defined(__FreeBSD__) && defined(__alpha__) && __STDC__
/* The alpha headers are decidedly broken.
* Using an ANSI compiler, it provides ip_vhl instead of ip_hl and
* ip_v. So, to get ip_hl, we mask off the bottom four bits.
@@ -1144,13 +1168,12 @@ int wait_for_reply()
h=table[n];
/* received ping is cool, so process it */
- gettimeofday(&current_time,&tz);
h->waiting = 0;
h->timeout = timeout;
h->num_recv++; h->num_recv_i++;
pdp = (PING_DATA *)icp->icmp_data;
- sent_time = pdp->ping_ts;
+ memcpy(&sent_time, &(pdp->ping_ts), sizeof(struct timeval));
this_count = pdp->ping_count;
#ifdef DEBUG
if (trace_flag)