in reply to RFC: Net::SNTP::Server v1
way too complicated# Convert the decimal to hexadecimal and pad the result with a lea +ding # zero if needed. my $hex = sprintf("%x", $dec); $hex = length( $hex ) == 1 ? "0".$hex : $hex;
conversion tablemy $hex = sprintf '%02x', $dec;
0 -> 00 1 -> 01 15 -> 0f 20 -> 14 255 -> ff 256 -> 100 # garbage in, garbage out2) nesting subs does not work:
is equivalent tosub basicSNTPSetup { ... sub keyDifference { .. }; };
3) dead code / sub-ref / conditionalsub basicSNTPSetup { ... }; sub keyDifference { .. };
This functions does not seem to be referenced anywhere in your code. Additionally: Why do you code it as a sub reference instead of an actual function?my $verify_port = sub { my $port = shift; if ( defined $port && $port =~ /^[0-9]+$/ ) { if ( $port >= MIN_UDP_PORT || $port <= MAX_UDP_PORT ) { return FALSE; } } return TRUE; };
inside verify_port you are using the wrong conditionalsub verify_port { ... };
This will happily allow 10000000000 as a valid port. At the very least you should replace || with &&. I'm to lazy too look up operator precedence, but you may also need to replace && with 'and' or put the conditions into parenthesis.if ( $port >= MIN_UDP_PORT || $port <= MAX_UDP_PORT ) {
either: if ( ($port >= MIN_UDP_PORT) && ($port <= MAX_UDP_PORT) ) { or: if ( $port >= MIN_UDP_PORT and $port <= MAX_UDP_PORT ) {
Resumee:
I would not want to touch this module with a ten-foot pole. I wasn't even looking very hard.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: RFC: Net::SNTP::Server v1
by thanos1983 (Parson) on Jul 17, 2015 at 23:17 UTC | |
by Monk::Thomas (Friar) on Jul 20, 2015 at 15:01 UTC |