Lines Matching +full:device +full:- +full:addr
1 #!/local/bin/perl --*-perl-*-
8 ;# Rainer Pruy Friedrich-Alexander Universitaet Erlangen-Nuernberg
48 die("usage: $0 [-p <port>] [-l <logfile>] [host] ...\n");
52 &Getopts if 0; # make -w happy
56 $opt_p = 0 # port to use locally - (0 does mean: will be chosen by kernel)
63 $DEBUGFILE="&STDERR" if $DEBUGFILE eq '-';
126 ;# a Request element looks like: pack("a4SC",addr,associd,op)
131 local($name,$addr);
137 ($name,$addr) =
142 $addr = pack("C4",$1,$2,$3,$4);
147 ($name,$addr) = (gethostbyname($_))[$[,$[+4];
150 warn "$0: unknown host \"$_\" - ignored\n";
155 $Host{$name} = $addr;
156 $Host{$_} = $addr;
157 push(@Requests,pack("a4SC",$addr,0,6)); # schedule a set trap request for $name
163 local($addr) = @_;
164 return $HostName{$addr} if defined($HostName{$addr});
165 local($name) = gethostbyaddr($addr,&AF_INET);
166 &debug(sprintf("hostname(%d.%d.%d.%d) = \"%s\"",unpack("C4",$addr),$name))
168 defined($name) && ($HostName{$addr} = $name) && (return $name);
169 &debug(sprintf("Failed to get name for %d.%d.%d.%d",unpack("C4",$addr)));
170 return sprintf("[%d.%d.%d.%d]",unpack("C4",$addr));
177 grep(&debug(" - ".$_),keys(%Host));
180 $addr="";
198 ($addr,$assoc,$op) = unpack("a4SC",($req = shift(@Requests)));
199 &debug(sprintf("Request: %s: %s(%d)",&hostname($addr), &ntp'cntrlop_name($op), $assoc)); #';))
201 pack("Sna4x8",&AF_INET,$ntp_port,$addr));
202 &set_timeout("retry-".unpack("H*",$req),time+$BASE_TIMEOUT,
216 $timeout = $TIMEOUTS{$TIMEOUTS[$[]} - time;
223 ;# no work yet - wait for some messages dropping in
255 $from = (unpack("Sna4",$from))[$[+2]; # keep host addr only
256 ;# could check for ntp_port - but who cares
257 &debug("-Packet from ",&hostname($from));
269 &clear_timeout("retry-".unpack("H*",pack("a4SC",$from,$associd,$op))) unless $op == 7;
280 &clear_timeout("retry-".unpack("H*",pack("a4SC",$from,$associd,$op)));
317 local($addr) = @_[$[];
318 $addr = pack("H*",$addr);
319 &debug(sprintf("Refreshing trap for %s", &hostname($addr)));
320 push(@Requests,pack("a4SC",$addr,0,6));
350 $msg .= sprintf("%40s trap#%-5d",
376 ($peer) = ($data =~ /peer=([0-9]+)/);
381 if (($device) = ($data =~ /device=\"([^\"]+)\"/))
383 ($cstatus) = ($data =~ /refclockstatus=0?x?([\da-fA-F]+)/);
385 $msg .= sprintf("- %-32s",&ntp'clock_status($Cstatus)); #');
387 $msg .= " \"$device\" \"$timecode\"";
399 $msg .= sprintf("%-18s %40s ", "[$srcadr]",
406 if (($device) = ($data =~ /device=\"([^\"]+)\"/))
408 ;#&debug("----\n$data\n====\n");
409 ($cstatus) = ($data =~ /refclockstatus=0?x?([\da-fA-F]+)/);
411 $msg .= sprintf("- %-32s",&ntp'clock_status($Cstatus)); #');
413 $msg .= " \"$device\" \"$timecode\"";
417 ;# no clockvars included - post a cv request
431 &set_timeout("refresh-".unpack("H*",$from),time+$REFRESH_TIME,
447 $msg .= sprintf("%-32s",&ntp'clock_status($status)); #');
448 ($device) = ($data =~ /device=\"([^\"]+)\"/);
450 $msg .= " \"$device\" \"$timecode\"";
456 &clear_timeout("refresh-".unpack("H*",$from));