943,633 Members | Top Members by Rank

Ad:
Jun 15th, 2009
0

is this perl doable in shell?

Expand 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 IO:Socket.
Last edited by scotddn1; Jun 15th, 2009 at 10:31 pm.
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
scotddn1 is offline Offline
2 posts
since Jun 2009
Jun 16th, 2009
0

Re: is this perl doable in shell?

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.
Team Colleague
Reputation Points: 5862
Solved Threads: 950
Posting Sage
Salem is offline Offline
7,164 posts
since Dec 2005
Jun 17th, 2009
0

Re: is this perl doable in shell?

Click to Expand / Collapse  Quote originally posted by scotddn1 ...
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.
Reputation Points: 51
Solved Threads: 35
Posting Whiz in Training
Fest3er is offline Offline
238 posts
since Aug 2007
Jul 6th, 2009
0

Re: is this perl doable in shell?

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.  
Reputation Points: 10
Solved Threads: 0
Newbie Poster
scotddn1 is offline Offline
2 posts
since Jun 2009
Jul 7th, 2009
0

Re: is this perl doable in shell?

No, this script cannot be converted to an ash script.
Reputation Points: 22
Solved Threads: 11
Junior Poster
fpmurphy is offline Offline
144 posts
since Oct 2008
Jul 7th, 2009
0

Re: is this perl doable in shell?

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
Team Colleague
Reputation Points: 5862
Solved Threads: 950
Posting Sage
Salem is offline Offline
7,164 posts
since Dec 2005

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Shell Scripting Forum Timeline: *nix shell script symbols
Next Thread in Shell Scripting Forum Timeline: getopts





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC