Skip to content

Instantly share code, notes, and snippets.

@jesboat
Created June 3, 2014 05:44
Show Gist options
  • Save jesboat/96bb14a12b2e24dbd997 to your computer and use it in GitHub Desktop.
Save jesboat/96bb14a12b2e24dbd997 to your computer and use it in GitHub Desktop.
#!/usr/bin/perl
use strict;
use warnings;
use Errno;
use IO::Socket::INET;
my $sock = IO::Socket::INET->new(
LocalPort => 6666,
ReuseAddr => 1,
ReusePort => 1,
Proto => "udp",
)
or die "socket: $!\n";
$| = 1;
my $quit;
$SIG{TERM} = sub { $quit = 1 };
while (not $quit) {
my $buf = "";
my $peer = recv($sock, $buf, 1024 * 1024, 0);
if (not $peer) {
die "recv: $!\n" unless $!{EINTR} or $!{EAGAIN};
}
print $buf;
}
@jesboat
Copy link
Author

jesboat commented Jun 3, 2014

Because BSD netcat sucks and socat keeps segfaulting.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment