Mailing-List: contact cygwin-help AT sourceware DOT cygnus DOT com; run by ezmlm List-Subscribe: List-Archive: List-Post: List-Help: , Sender: cygwin-owner AT sources DOT redhat DOT com Delivered-To: mailing list cygwin AT sources DOT redhat DOT com Message-ID: <3BAB563C.4050308@likai.net> Date: Fri, 21 Sep 2001 11:01:16 -0400 From: Li-Kai Liu User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:0.9.4) Gecko/20010913 X-Accept-Language: en-us MIME-Version: 1.0 To: cygwin AT cygwin DOT com Subject: Re: read the IP automatically??? References: <006901c142a9$ecae59c0$e4396ba4 AT ceegs DOT ohiostate DOT edu> Content-Type: multipart/mixed; boundary="------------030907090202080503000101" --------------030907090202080503000101 Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit if you just want to run the program on cygwin, then simple enough, you can just parse the output from ipconfig.exe but if you want to maintain a cross compatibility with linux, then i have a gift for you. it is a ipconfig to dhcpcd wrapper. it is written in perl and it emulates a subset of what linux dhcpcd has to offer. after you run dhcpcd, the file containing gateway and interface IP is generated at /etc/dhcpc/dhcpcd-ethn.info (whereas ethn is the linux style interface name, such as eth0, eth1, eth2, ...) this is a primitive hack, and it has proven to be workable. installation: just put the file in /sbin where linux usually put it. if you run into problems, first check if you have /etc/dhcpc directory set with a permission that dhcpcd can access. dhcpcd is a user mode program that does not bear special privilege. also, it does not perform error checking. so if there is an error with ipconfig, you will get an empty /etc/dhcpc/dhcpcd-ethn.info file. there will be more ways to break dhcpcd, so please bear with me. i haven't worked on it for a long time, and if it is needed, i *could* ... liulk hongxun lee wrote: >Hi, all >cygwin/xfree is installed on win2000. Is it possible to read the IP >automatically (and then exported to a variale for display configration) >whenevr xwindow is started? Thanks > > > >-- >Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple >Bug reporting: http://cygwin.com/bugs.html >Documentation: http://cygwin.com/docs.html >FAQ: http://cygwin.com/faq/ > > --------------030907090202080503000101 Content-Type: text/plain; name="dhcpcd" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="dhcpcd" #!/usr/bin/perl -w # emulated dhcpcd daemon for cygwin on win2k # we need access to the system ipconfig # this is a very crude hack. # first of all, the original win2k ipconfig must be visible in the file # system. supply the complete path here. $sys_ipconfig = "/mnt/hdc/winnt/system32/ipconfig.exe"; # list the mapping of linux ethN to win2k interface name using # associative hash. $eth = { "eth0" => "Local Area Connection" }; # default action $action = "RENEW"; foreach $opt (@ARGV) { if ($opt eq "-k") { $action = "RELEASE" } elsif ($opt eq "-h") { print <, version 0.2 this version of dhcpcd emulates a subset of linux dhcpcd functions. before usage, you must edit this program and change applicable setting at the beginning of the file, typically the path to ipconfig.exe and the mapping of linux style ethn name to win2k name. usage: dhcpcd [-r] [-k] ethn -r renew the interface ethn -k release the interface ethn note that, unlike the linux dhcp client daemon, this dhcpcd does not reside in memory, so -k does not kill any processes but only releases the IP address. when you get a new IP address, a dhcp style info file is generated at /etc/dhcpc/dhcpcd-ethn.info this file is an unreleased part of cygwin-magixpak project. EOQ } elsif ($opt =~ /eth[0-9]/) { $int = $opt; } } if (!$int) { $int = "eth0" }; die "dhcpcd: interface undefined: $int" unless ( $eth->{$int} ); if ($action eq "RELEASE") { open (DHCPOUT, "$sys_ipconfig /release \"$eth->{$int}\" |") or die "dhcpcd: cannot parse ipconfig output"; while () { if ( $_ =~ /success/ ) { unlink "/etc/dhcpc/dhcpcd-$int.info"; } } close DHCPOUT; } else { open (DHCPINFO, ">/etc/dhcpc/dhcpcd-$int.info") or die "dhcpcd: cannot create dhcp info"; open (DHCPOUT, "$sys_ipconfig /renew \"$eth->{$int}\" |") or die "dhcpcd: cannot parse ipconfig output"; while () { if ( $_ =~ /IP Address.+ : ([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)/ ) { print DHCPINFO "IPADDR=$1\n"; } elsif ( $_ =~ /Default Gateway.+ : ([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)/ ) { print DHCPINFO "GATEWAY=$1\n"; } } close DHCPOUT; close DHCPINFO; } --------------030907090202080503000101 Content-Type: text/plain; charset=us-ascii -- Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple Bug reporting: http://cygwin.com/bugs.html Documentation: http://cygwin.com/docs.html FAQ: http://cygwin.com/faq/ --------------030907090202080503000101--