[26574] in Perl-Users-Digest

home help back first fref pref prev next nref lref last post

Perl-Users Digest, Issue: 8710 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sun Nov 27 00:06:08 2005

Date: Sat, 26 Nov 2005 21:05:04 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Sat, 26 Nov 2005     Volume: 10 Number: 8710

Today's topics:
        [UDP] Overide "source" addr/port ? <stan@blznospam.hmrprintnospam.com>
    Re: [UDP] Overide "source" addr/port ? <No_4@dsl.pipex.com>
    Re: Hash's Regex Transformation with Map <xx087@freenet.carleton.ca>
        Logging Errors (Instead of Just Dying) <hal@thresholddigital.com>
    Re: Logging Errors (Instead of Just Dying) xhoster@gmail.com
    Re: Logging Errors (Instead of Just Dying) <mark.clementsREMOVETHIS@wanadoo.fr>
    Re: Logging Errors (Instead of Just Dying) <tadmc@augustmail.com>
    Re: Matching spaces at start of line (Anno Siegel)
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

----------------------------------------------------------------------

Date: Sat, 26 Nov 2005 17:18:16 -0800
From: "Stan R." <stan@blznospam.hmrprintnospam.com>
Subject: [UDP] Overide "source" addr/port ?
Message-Id: <1133054471_33325@spool6-east.superfeed.net>

Hello. I'm trying to write a UDP relay, which is easy enough, except for 
one little thing.

Ok heres what's going on:

I have 3 incoming logging feeds that send to UDP port 7150 on my system, 
to a special logging app. The login apps works by recieving the feeds, 
and depending on the remote (peer) addr the looging app show the log in 
seperate tabs within the app.

Here is the problem, and what I want todo

I can make the logging app listen on my LAN ip (192.168.1.2) and have my 
relay listen on my WAN ip, so it recieves the feed,

What I want to do is use my relay program to send to both my system 
(192.168.1.2) and my laptop (192.168.1.5).

The problem is, even though my relay works, the source address of the 
packet's it sends is 192.168.1.2, BUT the logging app is expecting one 
of the IP's from the remote UDP feeds.

Right now I'm using IO::Socket::INET, and obviously I can't set 
LocalAddr param to an IP not on my system. So I need some way to rewrite 
or overide the source address of a udp packet before it's sent.

I know this is possible because it's how any good NAT works, like on a 
router (so servers behind the router see the original source ip that 
that the router saw when it got the packet, otherwise said servers woudl 
see the router's LAN ip instead.)

Is this possible? (I'm assuming it will require something much "lower 
level" than IO::Socket::INET.)

Thanks very much.




------------------------------

Date: Sun, 27 Nov 2005 02:31:42 +0000
From: Big and Blue <No_4@dsl.pipex.com>
Subject: Re: [UDP] Overide "source" addr/port ?
Message-Id: <ocCdneyztNANhxTeRVnyug@pipex.net>

Stan R. wrote:
>
> The problem is, even though my relay works, the source address of the 
> packet's it sends is 192.168.1.2, BUT the logging app is expecting one 
> of the IP's from the remote UDP feeds.
> 
> Right now I'm using IO::Socket::INET, and obviously I can't set 
> LocalAddr param to an IP not on my system. So I need some way to rewrite 
> or overide the source address of a udp packet before it's sent.

    That needs can only be done at the network level (ie: in the OS).

> I know this is possible because it's how any good NAT works

    And that is done in the OS kernel.

> Is this possible? (I'm assuming it will require something much "lower 
> level" than IO::Socket::INET.)

    It will require somethng in the kernel.  If you're running Linux you 
*might* be able to arrange it using IPtables (although what you would do to 
distinguish which packets have to have their source address changed may be 
fun to work out), but that is far removed fom Perl.


-- 
              Just because I've written it doesn't mean that
                   either you or I have to believe it.


------------------------------

Date: 26 Nov 2005 19:13:32 GMT
From: Glenn Jackman <xx087@freenet.carleton.ca>
Subject: Re: Hash's Regex Transformation with Map
Message-Id: <slrndohcut.in6.xx087@smeagol.ncf.ca>

At 2005-11-26 08:30AM, robic0 <> wrote:
>  On 26 Nov 2005 12:47:57 GMT, Glenn Jackman <xx087@freenet.carleton.ca>
>  wrote:
> >    %nh = map { ($k = $_) =~ s/\[[ATCG]+\]/S/g; $k=> $h->{$_} } (keys %{$h});
>                         ^^
>  Yeah but get the can't use global in "my ($k = $_)" since $_ is
>  global and declared elsewhere (if strict).

You want "(my $k = $_)" then.  

-- 
Glenn Jackman
Ulterior Designer


------------------------------

Date: Sat, 26 Nov 2005 16:35:40 -0500
From: Hal Vaughan <hal@thresholddigital.com>
Subject: Logging Errors (Instead of Just Dying)
Message-Id: <o5udnQZUqou2SBXeRVn-sA@comcast.com>

I have several Perl daemons running on a particular system.  For the most
part, they are behaving well, but I notice that two need to be restarted a
few times a week.  I have a lot of logging statements saying what the
program is doing at different points.  What I'd like to do is log the
actual errors before the program dies (and is then restarted by it's
monitor).  In the routine, I want to be able to print the line number and
type of error (as given in the normal error messages) to my log file.

Is there any way, inside a Perl module, to do something like "If there are
any errors, don't die, call this function, THEN die"?  (Or just "call this
function" and I can always make the function itself terminate the program.)

I know the FAQ mentions using eval, but they reference Larry Wall's
"&realcode", which, when I Google it, comes up with references to the same
FAQ, where it is not explained.  I'm trying to understand using eval, but I
don't see how I could put an entire module in an eval block -- I would
expect that to only evaluate it when the module is loaded.  The few
examples of this (that I can find) are, at least to me, hard to follow, so
clearer examples would help a LOT.  (I'm wondering if, since it's in the
FAQ, nobody's bothered to cover this in depth or with more examples.)

For example, if most of what the program does is in the module, how would I
use eval around the subroutine calls from the main program?  Can I get away
with having one call to the mainloop (which is in a subroutine by itself)
in it and then using eval only around that one call to the main loop?

Any help in clarifying this is appreciated!

Hal


------------------------------

Date: 26 Nov 2005 22:36:41 GMT
From: xhoster@gmail.com
Subject: Re: Logging Errors (Instead of Just Dying)
Message-Id: <20051126173641.161$fS@newsreader.com>

Hal Vaughan <hal@thresholddigital.com> wrote:
> I have several Perl daemons running on a particular system.  For the most
> part, they are behaving well, but I notice that two need to be restarted
> a few times a week.  I have a lot of logging statements saying what the
> program is doing at different points.  What I'd like to do is log the
> actual errors before the program dies (and is then restarted by it's
> monitor).  In the routine, I want to be able to print the line number and
> type of error (as given in the normal error messages) to my log file.

Why not just direct STDERR to our log file?

> Is there any way, inside a Perl module, to do something like "If there
> are any errors, don't die, call this function, THEN die"?  (Or just "call
> this function" and I can always make the function itself terminate the
> program.)

see $SIG{__DIE__} in perldoc perlvar and perldoc -f die.

>
> I know the FAQ mentions using eval, but they reference Larry Wall's
> "&realcode", which,

How old is this FAQ?  How old is the version of Perl you are using?

> when I Google it, comes up with references to the
> same FAQ, where it is not explained.

&realcode is a stand-in for whatever your real code is.  Since Larry
doesn't know what your code is that you want plugged into the example, he
has to use a stand-in.  (&realcode is an old, mostly deprecated, way of
executing a subroutine named "realcode".)

Xho

-- 
-------------------- http://NewsReader.Com/ --------------------
Usenet Newsgroup Service                        $9.95/Month 30GB


------------------------------

Date: Sat, 26 Nov 2005 23:38:41 +0100
From: Mark Clements <mark.clementsREMOVETHIS@wanadoo.fr>
Subject: Re: Logging Errors (Instead of Just Dying)
Message-Id: <4388e3ec$0$19678$8fcfb975@news.wanadoo.fr>

Hal Vaughan wrote:
> I have several Perl daemons running on a particular system.  For the most
> part, they are behaving well, but I notice that two need to be restarted a
> few times a week.  I have a lot of logging statements saying what the
> program is doing at different points.  What I'd like to do is log the
> actual errors before the program dies (and is then restarted by it's
> monitor).  In the routine, I want to be able to print the line number and
> type of error (as given in the normal error messages) to my log file.
> 
> Is there any way, inside a Perl module, to do something like "If there are
> any errors, don't die, call this function, THEN die"?  (Or just "call this
> function" and I can always make the function itself terminate the program.)

You could define an END block and put some logging in there (see perldoc 
perlmod), and/or reinvoke your program via exec. You may have difficulty 
accessing error messages etc at this stage though.

<snip>

  > For example, if most of what the program does is in the module, how 
would I
> use eval around the subroutine calls from the main program?  Can I get away
> with having one call to the mainloop (which is in a subroutine by itself)
> in it and then using eval only around that one call to the main loop?

not entirely sure what you mean, but you could try:

eval {
	my $serviceLoop = ServiceLoop->new();
	$serviceLoop->run();
};

if($@){
	print "error in serviceloop => $@";
}else{
	print "exited serviceloop cleanly";
}

I also suggest checking out Log::Log4perl (or similar). Note this can be 
set up to display the location at which a message is output.

Mark


------------------------------

Date: Sat, 26 Nov 2005 16:58:21 -0600
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: Logging Errors (Instead of Just Dying)
Message-Id: <slrndohq4d.bb5.tadmc@magna.augustmail.com>

Hal Vaughan <hal@thresholddigital.com> wrote:

> What I'd like to do is log the
> actual errors before the program dies (and is then restarted by it's
> monitor).  In the routine, I want to be able to print the line number and
> type of error (as given in the normal error messages) to my log file.
> 
> Is there any way, inside a Perl module, to do something like "If there are
> any errors, don't die, call this function, THEN die"?  (Or just "call this
> function" and I can always make the function itself terminate the program.)


> For example, if most of what the program does is in the module, how would I
> use eval around the subroutine calls from the main program? 

   eval { subroutine_call( $arg1, $arg2) };
   exit_gracefully($@) if $@; # call exit_gracefully() if error was trapped


-- 
    Tad McClellan                          SGML consulting
    tadmc@augustmail.com                   Perl programming
    Fort Worth, Texas


------------------------------

Date: 26 Nov 2005 23:37:47 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Matching spaces at start of line
Message-Id: <dmarkb$8vr$1@mamenchi.zrz.TU-Berlin.DE>

John W. Krahn <krahnj@telus.net> wrote in comp.lang.perl.misc:
> Anno Siegel wrote:

[...]

> >            $valid_header =
> >                s{^(Date|From|Subject|Newsgroups|Comments):}
> >                 {\u\L$1:}i;
> >            $saw_newsgroup ||= $valid_header && $1 eq 'Newsgroups';
> 
> If the original header is not exactly 'Newsgroups', for example 'newsgroups'
> or 'NewsGroups', then that expression will fail.  Perhaps:
> 
>            $saw_newsgroup ||= $valid_header && lc( $1 ) eq 'newsgroups';
> 
> >        }
> >        print if $valid_header;
> >     }
> >     die "didn't get newsgroup from headers\n" unless $saw_newsgroup;

You are right, I noticed that bug myself after posting.  I thought of the
same fix too.

It is remarkable (and comforting) how carefully code is read that is
posted here.

Anno
-- 
If you want to post a followup via groups.google.com, don't use
the broken "Reply" link at the bottom of the article.  Click on 
"show options" at the top of the article, then click on the 
"Reply" at the bottom of the article headers.


------------------------------

Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 6 Apr 01)
Message-Id: <null>


Administrivia:

#The Perl-Users Digest is a retransmission of the USENET newsgroup
#comp.lang.perl.misc.  For subscription or unsubscription requests, send
#the single line:
#
#	subscribe perl-users
#or:
#	unsubscribe perl-users
#
#to almanac@ruby.oce.orst.edu.  

NOTE: due to the current flood of worm email banging on ruby, the smtp
server on ruby has been shut off until further notice. 

To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.

#To request back copies (available for a week or so), send your request
#to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
#where x is the volume number and y is the issue number.

#For other requests pertaining to the digest, send mail to
#perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
#sending perl questions to the -request address, I don't have time to
#answer them even if I did know the answer.


------------------------------
End of Perl-Users Digest V10 Issue 8710
***************************************


home help back first fref pref prev next nref lref last post