I am trying to develop applications based upon UDP, but ran into a problem
doing UDP communications in the LAN on which I test my stuff, and I don't
have the vaguest idea where to start checking.

The perl Camel book has an example of communicating with UDP sockets.  A
slightly modified script is attached to this E-mail message.

When I try the script in the LAN as follows:
$ ./udpecho.pl 192.168.0.1 192.168.0.2 127.0.0.1 localhost 192.168.0.26 \ 
> 192.168.0.31

I get the following output:
error sending to 192.168.0.1: Invalid argument
error sending to 192.168.0.2: Invalid argument
error sending to 192.168.0.31: Invalid argument
Reply from host geosedit:  Host 3: 127.0.0.1
Reply from host geosedit:  Host 4: localhost
Reply from host geosedit:  Host 5: 192.168.0.26

Analysis:
192.168.0.1 - exists in the LAN
192.168.0.2 - does not exist
127.0.0.1 - my own host
localhost - my own host (of course!)
192.168.0.26 - my own host
192.168.0.31 - exists in the LAN

I don't understand why the UDP communication with 192.168.0.1 or 
192.168.0.31 does not work as it should be.  The UDP port 7 is enabled
(when it is blocked, I get a "Connection refused" error, rather than
"Invalid argument").

With TCP/IP (telnet, HTTP, etc.) I had absolutely no problems.


Environmental Details:
----------------------
1. The LAN is 100-Base TX Ethernet, with hub model DH-1600
   10/100Mbps Dual Speed Hub, manufactured by Planet Technology Corp.
2. The perl version being used is 5.005_03 built for i386-linux.
3. The Linux version being used by localhost is:
             Red Hat Linux release 6.2 (Zoot)
             Kernel 2.2.14-5.0 on an i586
4. The relevant line from /etc/inetd.conf is:
echo    dgram   udp     wait    root    internal

Any advice where should I look for the reasons for my UDP/IP problems?
                                            Thanks,
                                                 --- Omer


-- Attached file included as plaintext by Listar --
-- File: udpecho.pl

#!/usr/bin/perl -w
# udpecho.pl script - speak to an UDP echo port.
#
# Was written by Omer Zak in order to test communication by UDP/IP.

use strict;
use Socket;
use Sys::Hostname;

my ($count, $hisiaddr, $hispaddr,
    $host, $iaddr, $msg, $paddr, $port, $proto,
    $rin, $rout, $response);

$iaddr = gethostbyname(hostname());
$proto = getprotobyname('udp');
$port = getservbyname('echo', 'udp');
$paddr = sockaddr_in(0, $iaddr); # 0 means let kernel pick

socket(SOCKET, PF_INET, SOCK_DGRAM, $proto)   || die "socket: $!";
bind(SOCKET, $paddr)                          || die "bind: $!";

$| = 1;

$count = 0;
for $host (@ARGV) {
    $count++;
    $hisiaddr = inet_aton($host)    || die "unknown host";
    $msg = "Host $count: $host";
    $hispaddr = sockaddr_in($port, $hisiaddr);
    defined(send(SOCKET, $msg, 0, $hispaddr))    || print "error sending to $host: 
$!\n";
}

$rin = '';
vec($rin, fileno(SOCKET), 1) = 1;

# timeout after 10.0 seconds
while ($count && select($rout = $rin, undef, undef, 10.0)) {
    ($hispaddr = recv(SOCKET, $response, 65536, 0))        || print "reception error: 
$!\n";
    ($port, $hisiaddr) = sockaddr_in($hispaddr);
    $host = gethostbyaddr($hisiaddr, AF_INET);
    print "Reply from host $host:  $response\n";
    $count--;
}

# End of udpecho.pl

=================================================================
To unsubscribe, send mail to [EMAIL PROTECTED] with
the word "unsubscribe" in the message body, e.g., run the command
echo unsubscribe | mail [EMAIL PROTECTED]

Reply via email to