$dgs = new IO::Socket::INET(LocalPort => $lisport, Proto => 'udp') or die "Socket: $!\n";

I have a perl script that I want to run on tomato firmware router using the current shell scripting that it supports

How would I do the above in shell? In perl you have to use IO:Socket.

Is your next question going to be
"How do I do x in shell"
where x is some perl statement involving the USE of $dgs ?

There must be a reason for opening the port, which means there's going to be more things to do with that variable once you've initialised it.

Fixing it one line at a time won't solve your problem.

$dgs = new IO::Socket::INET(LocalPort => $lisport, Proto => 'udp') or die "Socket: $!\n";

I have a perl script that I want to run on tomato firmware router using the current shell scripting that it supports

How would I do the above in shell? In perl you have to use IO:Socket.

Generally speaking, one would first catalog all available CLI programs on the router and see if one of them approximates the perl functionality. Specifically in this instance, netcat might do the trick.

This the perl code I wish do convert to shell (ash so it works on Tomato),

#!/usr/bin/perl -w
 
use IO::Socket;

$ataip = '192.168.1.158';       
$ataport = 5060;              
$server = 'voipserver';       

$lport = 5070;                  # port to listen on
$dgs = new IO::Socket::INET(LocalPort => $lport, Proto => 'udp') or die "Socket: $!\n";
while (1) {
    $rcv = $dgs->recv($ibuf, 2000, 0);
    next unless $rcv && length($rcv) >= 8; # ignore errors
    $raddr = inet_ntoa((sockaddr_in($rcv))[1]); # get source addr
    if ($raddr eq $ataip) {      # packet from ATA
        $ibuf =~ s/(nonce=\"\w+_\w+)_[\w\-]+/$1/; # send original nonce to server
        $dpaddr = sockaddr_in(5070, inet_aton($server));
        $dgs->send($ibuf, 0, $dpaddr); # send to server
    }
    elsif ($raddr eq $server) { # packet from server
        if (($nonce) = $ibuf =~ /nonce=\"(\w+)/) { # need to fix nonce
            ($callid) = $ibuf =~ /Call-ID: ([\w\-]+)/ or die;
            $enonce = '_';      # compute extended nonce
            $enonce .= substr($callid, hex(substr($nonce, $_, 1)), 1) for (0..7);
            $ibuf =~ s/(nonce=\"\w+)/$1$enonce/; # pass new nonce to ATA
        }
        $dpaddr = sockaddr_in($ataport, inet_aton($ataip));
        $dgs->send($ibuf, 0, $dpaddr); # send to ATA
    }
}

No, this script cannot be converted to an ash script.

I take the reference in your first post is for this?
http://www.polarcloud.com/tomato

First, do you have a complete bash, or is that a cut-down version as well?

The answer (maybe) to the first step of opening a connection is perhaps here:
http://www.linuxquestions.org/questions/programming-9/using-sockets-in-a-bash-script-380706/

For more clues, more links
http://www.gnulamp.com/bashprogramming.html
http://tldp.org/LDP/Bash-Beginners-Guide/html/index.html
http://tldp.org/LDP/abs/html/index.html

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.