-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathNSDP.pm
35 lines (28 loc) · 856 Bytes
/
NSDP.pm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
package NSDP;
use IO::Socket;
use constant TLV_MODEL => 0x0001;
use constant TLV_NAME => 0x0003;
use constant TLV_MAC => 0x0004;
use constant TLV_IP => 0x0006;
use constant TLV_MASK => 0x0007;
use constant TLV_GW => 0x0008;
use constant TLV_FWVER => 0x000d;
my $DEBUG = 0;
sub setDebug {
my $debug = shift;
$DEBUG = ($debug ne 0);
};
sub NSDP_send {
my $sock = shift;
my $DST_ADDR = shift;
my $selfmac = shift;
my $swmac = shift;
my $seq = shift;
my $msg = shift;
my $header = "\x01\x01\x00\x00\x00\x00\x00\x00".$selfmac.$swmac."\x00\x00".pack("N", $seq)."NSDP\x00\x00\x00\x00".$msg."\xff\xff\xff\xff";
my $dst = sockaddr_in(63322, $DST_ADDR);
$sock->send($msg, 0, $dst) or die "send: $!";
my @hexdata = unpack("C*", $msg);
printf ">> %s\n", join(' ', map(sprintf("0x%.2x", $_), @hexdata));
};
1;