is this perl doable in shell?

Reply

Join Date: Jun 2009
Posts: 2
Reputation: scotddn1 is an unknown quantity at this point 
Solved Threads: 0
scotddn1 scotddn1 is offline Offline
Newbie Poster

is this perl doable in shell?

 
0
  #1
Jun 15th, 2009
Shell Scripting Syntax (Toggle Plain Text)
  1. $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.
Last edited by scotddn1; Jun 15th, 2009 at 10:31 pm.
Reply With Quote Quick reply to this message  
Join Date: Dec 2005
Posts: 5,850
Reputation: Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute 
Solved Threads: 749
Team Colleague
Salem's Avatar
Salem Salem is offline Offline
Void main'ers are DOOMed

Re: is this perl doable in shell?

 
0
  #2
Jun 16th, 2009
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.
Reply With Quote Quick reply to this message  
Join Date: Aug 2007
Posts: 165
Reputation: Fest3er is an unknown quantity at this point 
Solved Threads: 18
Fest3er Fest3er is offline Offline
Junior Poster

Re: is this perl doable in shell?

 
0
  #3
Jun 17th, 2009
Originally Posted by scotddn1 View Post
Shell Scripting Syntax (Toggle Plain Text)
  1. $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 IOocket.
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.
Reply With Quote Quick reply to this message  
Join Date: Jun 2009
Posts: 2
Reputation: scotddn1 is an unknown quantity at this point 
Solved Threads: 0
scotddn1 scotddn1 is offline Offline
Newbie Poster

Re: is this perl doable in shell?

 
0
  #4
Jul 6th, 2009
This the perl code I wish do convert to shell (ash so it works on Tomato),
Shell Scripting Syntax (Toggle Plain Text)
  1. #!/usr/bin/perl -w
  2.  
  3. use IO::Socket;
  4.  
  5. $ataip = '192.168.1.158';
  6. $ataport = 5060;
  7. $server = 'voipserver';
  8.  
  9. $lport = 5070; # port to listen on
  10. $dgs = new IO::Socket::INET(LocalPort => $lport, Proto => 'udp') or die "Socket: $!\n";
  11. while (1) {
  12. $rcv = $dgs->recv($ibuf, 2000, 0);
  13. next unless $rcv && length($rcv) >= 8; # ignore errors
  14. $raddr = inet_ntoa((sockaddr_in($rcv))[1]); # get source addr
  15. if ($raddr eq $ataip) { # packet from ATA
  16. $ibuf =~ s/(nonce=\"\w+_\w+)_[\w\-]+/$1/; # send original nonce to server
  17. $dpaddr = sockaddr_in(5070, inet_aton($server));
  18. $dgs->send($ibuf, 0, $dpaddr); # send to server
  19. }
  20. elsif ($raddr eq $server) { # packet from server
  21. if (($nonce) = $ibuf =~ /nonce=\"(\w+)/) { # need to fix nonce
  22. ($callid) = $ibuf =~ /Call-ID: ([\w\-]+)/ or die;
  23. $enonce = '_'; # compute extended nonce
  24. $enonce .= substr($callid, hex(substr($nonce, $_, 1)), 1) for (0..7);
  25. $ibuf =~ s/(nonce=\"\w+)/$1$enonce/; # pass new nonce to ATA
  26. }
  27. $dpaddr = sockaddr_in($ataport, inet_aton($ataip));
  28. $dgs->send($ibuf, 0, $dpaddr); # send to ATA
  29. }
  30. }
  31.  
Reply With Quote Quick reply to this message  
Join Date: Oct 2008
Posts: 95
Reputation: fpmurphy is an unknown quantity at this point 
Solved Threads: 5
fpmurphy fpmurphy is offline Offline
Junior Poster in Training

Re: is this perl doable in shell?

 
0
  #5
Jul 7th, 2009
No, this script cannot be converted to an ash script.
Reply With Quote Quick reply to this message  
Join Date: Dec 2005
Posts: 5,850
Reputation: Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute 
Solved Threads: 749
Team Colleague
Salem's Avatar
Salem Salem is offline Offline
Void main'ers are DOOMed

Re: is this perl doable in shell?

 
0
  #6
Jul 7th, 2009
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/questi...script-380706/

For more clues, more links
http://www.gnulamp.com/bashprogramming.html
http://tldp.org/LDP/Bash-Beginners-G...tml/index.html
http://tldp.org/LDP/abs/html/index.html
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC