Subject: Re: ipf + dhcp (not new) idea
To: None <muc-lists-netbsd-help@moderators.muc.de>
From: Michael Core <520079546242-0001@t-online.de>
List: netbsd-help
Date: 03/04/2002 20:47:56
Mipam wrote:

> Bothered by the fact that i had to use dhcp and having variable
> ip addresses when wishing to run ipf, this script helps:
> (in ipf.conf.in there is my_ip in the place of the ip of the interface) 
> 
> #!/bin/sh
> sed s/my_ip/`ifconfig fxp0 |awk '$1 == "inet" {print $2}'`/ ipf.conf.in\
> ipf.conf; ipf -Fa -f ipf.conf -E

(I added the backslash and ; for linebreak and copypaste reasons)

Since I'm not familar with awk, I used something much more complicated
with dnslookup and a dynamic DNS service. Looks I did not _kill_ the fly,
I _nuked_ it! ;-)

But I think the copying is not necessary. I'd prefer:

sed s/my_ip/`ifconfig fxp0 |\
awk '$1 == "inet" {print $2}'`/g ipf.conf.in |\
ipf -Fa -E -f -

I also added the g-flag to sed because there _might_ be a rule with my_ip
two times in a line.

BTW, does anyone know how I can get my IP in C(++) without establishing a
connection first? For some reason (or none) I have no hostname set, so
gethostname is no option. Further, it should be possible without
privileges. Any ideas?

HTH