1
2
3
4
5
6
11:03:15.885446 IP 10.40.3.5.2000 > 10.40.3.255.2000: UDP, length 1020
11:03:15.932432 IP 10.40.3.5.2000 > 10.40.3.255.2000: UDP, length 598
11:03:15.975834 IP 10.40.3.5.2000 > 10.40.3.255.2000: UDP, length 1025
11:03:16.025577 IP 10.40.3.5.2000 > 10.40.3.255.2000: UDP, length 1024
11:03:16.072304 IP 10.40.3.5.2000 > 10.40.3.255.2000: UDP, length 178
11:03:16.105481 IP 10.40.3.5.2000 > 10.40.3.255.2000: UDP, length 960
1
2
eth0 Link encap:Ethernet Hardware Adresse 00:19:99:xx:xx:xx
inet Adresse:10.40.3.250 Bcast:10.40.3.255 Maske:255.255.255.0
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
#!/usr/bin/perl use strict; use warnings; use IO::Socket; my($sock, $nachricht, $maxlen, $portno); my $maxlen=1024; $sock = IO::Socket::INET -> new ( PeerAddr => '10.40.3.255', PeerPort => 2000, # LocalAddr => '10.40.3.250', Broadcast => 1, Proto => 'udp') or die "socket-problem: $@"; while ($sock->recv($nachricht, $MAXLEN)) { print "Message: %0x\n", $nachricht; } close($sock);
QuoteSome systems may have even weirder byte orders such as
0x56 0x78 0x12 0x34
0x34 0x12 0x78 0x56
You can see your system's preference with
print join(" ", map { sprintf "%#02x", $_ }
unpack("C*",pack("L",0x12345678))), "\n";
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
#!/usr/bin/perl -w # udpqotd - UDP message server use strict; use IO::Socket; my($sock, $oldmsg, $newmsg, $hisaddr, $hishost, $MAXLEN, $PORTNO); $MAXLEN = 1024; $PORTNO = 2000; $sock = IO::Socket::INET->new(LocalPort => $PORTNO, Proto => 'udp') or die "socket: $@"; print "Awaiting UDP messages on port $PORTNO\n"; $oldmsg = "This is the starting message."; while ($sock->recv($newmsg, $MAXLEN)) { my($port, $ipaddr) = sockaddr_in($sock->peername); $hishost = gethostbyaddr($ipaddr, AF_INET); print "Client $hishost said ``$newmsg''\n"; $sock->send($oldmsg); $oldmsg = "[$hishost] $newmsg"; } die "recv: $!"