ports/net/nsping/patches/patch-nsping_c

65 lines
1.7 KiB
Text

Index: nsping.c
--- nsping.c.orig
+++ nsping.c
@@ -12,6 +12,7 @@ int snprintf(char *, int, char *, ...);
#include "nsping.h"
#include <stdarg.h>
+#include <stdlib.h>
#include <assert.h>
/* store state on sent queries */
@@ -57,8 +58,7 @@ int main(int argc, char **argv) {
u_int32_t address = INADDR_ANY;
u_int32_t port = getpid() + 1024;
char *timearg = NULL;
- char c;
- int i;
+ int i, c;
for(i = 0; i < QUERY_BACKLOG; i++) {
Queries[i].id = -1;
@@ -67,7 +67,7 @@ int main(int argc, char **argv) {
#define OPTS "z:h:t:p:dP:a:c:T:rR"
- while((c = getopt(argc, argv, OPTS)) != EOF) {
+ while((c = getopt(argc, argv, OPTS)) != -1) {
switch(c) {
case 'c':
Max_Sends = atoi(optarg);
@@ -189,10 +189,14 @@ int main(int argc, char **argv) {
int guess_zone() {
char lhn[MAXDNAME];
+ struct hostent *hp;
char *cp;
if(gethostname(lhn, MAXDNAME) < 0)
return(0);
+ if((hp = gethostbyname(lhn)) == NULL)
+ return(0);
+ strlcpy(lhn, hp->h_name, sizeof(lhn));
cp = strchr(lhn, '.');
if(!cp || !(*(++cp)))
@@ -336,7 +340,7 @@ int dns_packet(u_char **qp, int id) {
if(!seed)
seed = getpid() ^ time(0);
- snprintf(hname, MAXDNAME, "%d.%s", random(), Zone);
+ snprintf(hname, MAXDNAME, "%ld.%s", random(), Zone);
name = hname;
}
@@ -679,9 +683,7 @@ char *xstrdup(char *v) {
/* -------------------------------------------------------------------------- */
void usage() {
- fprintf(stderr, "nsping [ -z <zone> | -h <hostname> ] -p <port> -t <timeout>\n"
- "\t\t-a <local address> -P <local port>\n"
- "\t\t-T <type> <-r | -R, recurse?>\n");
+ fprintf(stderr, "Usage: nsping [-dR] [-c count] [-z zone | -h hostname] [-t timeout] [-p dport] [-P sport] [-a saddr] [-T querytype]\n");
return;
}