-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathudpsendsendsend.pl
More file actions
executable file
·46 lines (39 loc) · 1.04 KB
/
Copy pathudpsendsendsend.pl
File metadata and controls
executable file
·46 lines (39 loc) · 1.04 KB
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
36
37
38
39
40
41
42
43
44
45
#!/usr/local/bin/perl
use Socket;
use POSIX;
sub udp_client_setup
{
local(*SH,$host,$port)=@_;
# $host is ignoreed
local($proto,$sin);
$proto = getprotobyname('udp') || die "getprotobyname:$!";
socket(SH,PF_INET,SOCK_DGRAM,$proto) || die "socket:$!";
if($host || $port){
local($iaddr)=inet_aton($host) || die "Error inet_aton:$!";
local($sin)=pack_sockaddr_in($port,$iaddr);
bind(SH,$sin) || die "bind():$!";
}
}
sub udp_get_sockaddr_in
{
local($host,$port)=@_;
local($iaddr,$sin);
$iaddr = inet_aton($host) || die "inet_aton:$!";
($port =~ /\d+/)
|| ($port = getservbyname($port,'udp')) || die "getportbyname:$!";
$sin = sockaddr_in($port,$iaddr) || die "sockaddr_in:$!";
return $sin;
}
if($0 eq __FILE__){
local($host,$port) = @_;
$size = ($ARGV[0] || 10000);shift;
$host = ($ARGV[0] || 'localhost');shift;
$port = ($ARGV[0] || 9999);shift;
&udp_client_setup(*SH);
$sin=&udp_get_sockaddr_in($host,$port);
$buf = "a" x $size;
while(1){
send(SH,$buf,0,$sin);
}
}
1;