This is the mail archive of the cygwin@cygwin.com mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: Re:Gcc & WinMain@16


libcmain probably is not using WinMain@16.
try -mno-cygwin.
----- Original Message -----
From: "Jorge Goncalvez" <goncal11@col.bsf.alcatel.fr>
To: <cygwin@sources.redhat.com>
Sent: Tuesday, July 24, 2001 1:54 AM
Subject: Re:Gcc & WinMain@16


> Hi, I checked the mailing list but I didn't find some informations except
the
> use of -lm.
> So i tried to port the dhcp version 2 of the ISC but I have some
compilation
> errors:
>  $ make
> Making all in common
> make[1]: Entering directory `/cygdrive/d/dhcp/code/dhcp/common'
> make[1]: Nothing to be done for `all'.
> make[1]: Leaving directory `/cygdrive/d/dhcp/code/dhcp/common'
> Making all in server
> make[1]: Entering directory `/cygdrive/d/dhcp/code/dhcp/server'
> make[1]: Nothing to be done for `all'.
> make[1]: Leaving directory `/cygdrive/d/dhcp/code/dhcp/server'
> Making all in relay
> make[1]: Entering directory `/cygdrive/d/dhcp/code/dhcp/relay'
> /bin/gcc  -o dhcrelay dhcrelay.o  ../common/libdhcp.a
> /usr/lib/libcygwin.a(libcmain.o)(.text+0x6a):libcmain.c: undefined
reference to
> `WinMain@16'
> collect2: ld returned 1 exit status
> make[1]: *** [dhcrelay] Error 1
> make[1]: Leaving directory `/cygdrive/d/dhcp/code/dhcp/relay'
> make: *** [all] Error 1
>
> Why? Thanks.
>


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


> # Makefile.conf
> #
> # Copyright (c) 1996, 1997, 1998, 1999 The Internet Software Consortium.
> # All rights reserved.
> #
> # Redistribution and use in source and binary forms, with or without
> # modification, are permitted provided that the following conditions
> # are met:
> #
> # 1. Redistributions of source code must retain the above copyright
> #    notice, this list of conditions and the following disclaimer.
> # 2. Redistributions in binary form must reproduce the above copyright
> #    notice, this list of conditions and the following disclaimer in the
> #    documentation and/or other materials provided with the distribution.
> # 3. Neither the name of The Internet Software Consortium nor the names of
its
> #    contributors may be used to endorse or promote products derived
> #    from this software without specific prior written permission.
> #
> # THIS SOFTWARE IS PROVIDED BY THE INTERNET SOFTWARE CONSORTIUM AND
> # CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
> # BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
FITNESS
> # FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL
> # THE INTERNET SOFTWARE CONSORTIUM OR CONTRIBUTORS BE LIABLE FOR ANY
DIRECT,
> # INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
> # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
> # SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
> # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
> # STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
> # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
> # OF THE POSSIBILITY OF SUCH DAMAGE.
> #
>
> ## Defaults...
> SCRIPT = none
> BINDIR = /usr/sbin
> CLIENTBINDIR=/sbin
> ADMMANEXT = .0
> FFMANEXT = .0
> ADMMANDIR = /usr/share/man/cat8
> FFMANDIR = /usr/share/man/cat5
> INSTALL  = /bin/install -c
> MANINSTALL = install -c -m 444
> CHMOD = chmod
> CATMANPAGES =
> MANCAT = cat
> ETC = /etc
> VARRUN = /var/run
> VARDB = /var/db
> SUBDIRS= common server relay tools dupli client
> UTILSLDFLAGS = -lutil
>
> INITDIR = /etc/rc.d/init.d
>
> CC = $(CROSS_COMPILE)gcc
> LD = $(CROSS_COMPILE)ld
> AR = $(CROSS_COMPILE)ar
> RANLIB = $(CROSS_COMPILE)ranlib
>
> ## Porting::
> #
> # For each supported operating system, there is a block of text below
> # beginning with #--os-name-- and ending with #--os-name--.   Between
> # these delimiters are assignments, commented out, which define the
> # Makefile variables required for that operating system.
> #
> # The configure shell script figures out what operating system it's
> # being run on and then runs Makefile.dist through a sed script which
> # removes the comment characters from the appropriate set of
> # assignments, and writes the output to Makefile.
>
> ## AIX 4.1.5.0
> ##--aix--
> #CF = cf/aix.h
> #CC=cc -Daix
> #INSTALL=/usr/ucb/install
> #MANINSTALL=/usr/ucb/install
> #ADMMANEXT = .8
> #FFMANEXT = .5
> #VARRUN = /etc
> #VARDB = /etc
> ##--aix--
>
> ## NEXTSTEP 3.x,4.x
> ##--nextstep--
> #LIBS =
> #CF = cf/nextstep.h
> #CC=cc
> #COPTS = -Wall
> #BINDIR=/usr/etc
> #ADMMANDIR = /usr/local/man/cat8
> #FFMANDIR = /usr/local/man/cat5
> #ADMMANEXT = .8
> #FFMANEXT = .5
> #VARRUN = /etc
> #VARDB = /etc
> ##--nextstep--
>
> ## SunOS 4.1
> ##--sunos4--
> #LIBS = -lresolv
> #CF = cf/sunos4.h
> #BINDIR=/usr/etc
> #CLIENTBINDIR=/etc
> #ADMMANEXT = .8
> #FFMANEXT = .5
> #VARRUN = /etc
> #VARDB = /etc
> ##--sunos4--
>
> ## Solaris 2.5 (with gcc)
> ##--sunos5-gcc--
> #INSTALL=/usr/ucb/install
> #MANINSTALL=/usr/ucb/install
> #LIBS = -lresolv -lsocket -lnsl -lgen
> #CC=gcc
> #COPTS = -Wall -Wno-unused -Wno-implicit -Wno-comment \
> # -Wno-uninitialized -Wno-char-subscripts -Werror
> #CF = cf/sunos5-5.h
> #ADMMANDIR = /usr/share/man/cat1m
> #ADMMANEXT = .1m
> #FFMANDIR = /usr/share/man/cat4
> #FFMANEXT = .4
> #VARRUN = /etc
> #VARDB = /etc
> #SCRIPT=solaris
> ##--sunos5-gcc--
>
> ## Solaris 2.5 (with Sun cc)
> ##--sunos5-cc--
> #INSTALL=/usr/ucb/install
> #MANINSTALL=/usr/ucb/install
> #LIBS = -lresolv -lsocket -lnsl
> ##CC=cc
> #CC = $(CROSS_COMPILE)gcc
> #SUNTOOLSPATH=/usr/ccs/bin/
> #LD = $(SUNTOOLSPATH)ld
> #AR = $(SUNTOOLSPATH)ar
> #RANLIB = $(SUNTOOLSPATH)ranlib
> #COPTS = -D__svr4__ -DUSE_DLPI_RAW
> #CF = cf/sunos5-5.h
> #ADMMANDIR = /usr/share/man/cat1m
> #ADMMANEXT = .1m
> #FFMANDIR = /usr/share/man/cat4
> #FFMANEXT = .4
> #VARRUN = /etc
> #VARDB = /etc
> #SCRIPT=solaris
> #SUBDIRS= common server relay tools
> #UTILSLDFLAGS = -lnsl
> ##--sunos5-cc--
>
> ## DEC Alpha/OSF1
> ##--alphaosf--
> #INSTALL=/usr/ucb/installbsd
> #MANINSTALL=/usr/ucb/installbsd
> #LIBS=
> #CF = cf/alphaosf.h
> #ADMMANEXT = .8
> #FFMANEXT = .5
> #VARDB = /etc
> ##--alphaosf--
>
> ## BSD/OS 2.1
> ##--bsdos--
> #LIBS= -lresolv
> #CC=gcc2
> #CF = cf/bsdos.h
> ##--bsdos--
>
> ## FreeBSD
> ##--freebsd--
> #CF = cf/freebsd.h
> #SCRIPT=freebsd
> ##--freebsd--
>
> ## Rhapsody
> ##--rhapsody--
> #CF = cf/rhapsody.h
> #COPTS  = -Wall -Wno-unused -Wno-implicit -Wno-comment \
> #   -Wno-uninitialized -Werror -pipe
> #SCRIPT=rhapsody
> ##--rhapsody--
>
> ## NetBSD
> ##--netbsd--
> #CF = cf/netbsd.h
> #COPTS  = -Wall -Wstrict-prototypes -Wno-unused -Wno-implicit -Wno-comment
\
> #   -Wno-uninitialized -Werror -pipe
> #SCRIPT=netbsd
> ##--netbsd--
>
> ## Ultrix
> ##--ultrix--
> #BINDIR = /usr/etc
> #CLIENTBINDIR=/etc
> #VARRUN = /etc
> #VARDB = /etc
> #CF = cf/ultrix.h
> #ADMMANDIR = /usr/man/man8
> #ADMMANEXT = .8
> #FFMANDIR = /usr/man/man5
> #FFMANEXT = .5
> ##--ultrix--
>
> ## Linux 1.x
> ##--linux-1--
> #COPTS = -DLINUX_MAJOR=1 -DLINUX_MINOR=0
> #CF = cf/linux.h
> #ADMMANDIR = /usr/man/man8
> #ADMMANEXT = .8
> #FFMANDIR = /usr/man/man5
> #FFMANEXT = .5
> #MANCAT = man
> #VARRUN = /var/run
> #VARDB = /var/state/dhcp # see rationale in includes/cf/linux.h
> #SCRIPT=linux
> ##--linux-1--
>
> ## Linux 2.0
> ##--linux-2.0--
> #COPTS = -DLINUX_MAJOR=2 -DLINUX_MINOR=0
> #CF = cf/linux.h
> #ADMMANDIR = /usr/man/man8
> #ADMMANEXT = .8
> #FFMANDIR = /usr/man/man5
> #FFMANEXT = .5
> #MANCAT = man
> #VARRUN = /var/run
> #VARDB = /var/state/dhcp # see rationale in includes/cf/linux.h
> #SCRIPT=linux
> ##--linux-2.0--
>
> ## Linux 2.1
> ##--linux-2.1--
> #COPTS = -DLINUX_MAJOR=2 -DLINUX_MINOR=1
> #CF = cf/linux.h
> #ADMMANDIR = /usr/man/man8
> #ADMMANEXT = .8
> #FFMANDIR = /usr/share/man/man5
> #FFMANEXT = .5
> #MANCAT = man
> #VARRUN = /var/run
> #VARDB = /var/state/dhcp # see rationale in includes/cf/linux.h
> #SCRIPT=linux
> ##--linux-2.1--
>
> ## Linux 2.2
> ##--linux-2.2--
> #COPTS = -DLINUX_MAJOR=2 -DLINUX_MINOR=2
> #CF = cf/linux.h
> #ADMMANDIR = /usr/man/man8
> #ADMMANEXT = .8
> #FFMANDIR = /usr/share/man/man5
> #FFMANEXT = .5
> #MANCAT = man
> #VARRUN = /var/run
> #VARDB = /var/state/dhcp # see rationale in includes/cf/linux.h
> #SCRIPT=linux
> #DHS3EXTFLAGS= -DDHS3_DUPLI -DDHS3_INCIDENT -DDHS3TIMEOUTARP
> #SUBDIRS= common server relay tools dupli
> ##--linux-2.2--
>
> ## SCO
> ##--sco--
> #CF = cf/sco.h
> #PREDEFINES=-DSCO -DBROKEN_ANSI
> #BINDIR = /usr/etc
> #CLIENTBINDIR=/etc
> #ADMMANDIR = /usr/man/cat.ADMN
> #ADMMANEXT = .ADMN.Z
> #FFMANDIR = /usr/man/cat.SFF
> #FFMANEXT = .SFF.Z
> #INSTALL = cp
> #MANFROM = <
> #MANINSTALL = compress
> #MANTO = >
> #VARRUN = /etc
> #VARDB = /etc
> #CATMANPAGES=
> ##--sco--
>
> ## QNX
> ##--qnx--
> #CF = cf/qnx.h
> #ADMMANDIR = /usr/man/man8
> #ADMMANEXT = .8
> #FFMANDIR = /usr/man/man5
> #FFMANEXT = .5
> #MANCAT = man
> #VARRUN = /etc
> #COPTS=-w3 -Dlint
> #LFLAGS=$(DEBUG) "-Wl,op symfile" -l socket
> #MANINSTALL = /bin/true
> #INSTALL = cp
> #BINDIR = /etc
> #CLIENTBINDIR = /etc
> ##--qnx--
>
> ## CygWin
> #--cygwin--
> CF =/includes/cf/cygwin32.h
> ADMMANDIR =c:/cygwin/usr/man/man8
> ADMMANEXT = .8
> FFMANDIR = /usr/man/man5
> FFMANEXT = .5
> VARRUN = /etc
> MANINSTALL = /bin/true
> INSTALL = cp
> BINDIR = /etc
> CLIENTBINDIR = /etc
> CC=/bin/gcc
> AR=/bin/ar
> AS=/usr/i686-pc-cygwin/bin/as
> LD=/bin/ld
> NM=/usr/i686-pc-cygwin/bin/nm
> RANLIB=/bin/ranlib
> STRIP=/usr/i686-pc-cygwin/bin/strip
> #--cygwin--
>
> ## IRIX 6.x
> ##--irix--
> #LIBS = -lbind
> #LFLAGS=$(DEBUG) -L/usr/local/lib -Wl,-woff,84 -Wl,-woff,85 -Wl,-woff,134
> #CC=gcc
> #COPTS = -I/usr/local/include
> #CF = cf/irix.h
> #BINDIR = /usr/local/etc
> #ADMMANDIR = /usr/local/man/man8
> #ADMMANEXT = .8
> #FFMANDIR = /usr/local/man/man5
> #FFMANEXT = .5
> #MANCAT = man
> #INSTALL = install
> #MANINSTALL = install
> #CHMOD = chmod
> #ETC = /etc
> #VARRUN = /etc
> #VARDB = /usr/local/etc/dhcp
> ##--irix--
> # Makefile.dist
> #
> # Copyright (c) 1996, 1997 The Internet Software Consortium.
> # All rights reserved.
> #
> # Redistribution and use in source and binary forms, with or without
> # modification, are permitted provided that the following conditions
> # are met:
> #
> # 1. Redistributions of source code must retain the above copyright
> #    notice, this list of conditions and the following disclaimer.
> # 2. Redistributions in binary form must reproduce the above copyright
> #    notice, this list of conditions and the following disclaimer in the
> #    documentation and/or other materials provided with the distribution.
> # 3. Neither the name of The Internet Software Consortium nor the names of
its
> #    contributors may be used to endorse or promote products derived
> #    from this software without specific prior written permission.
> #
> # THIS SOFTWARE IS PROVIDED BY THE INTERNET SOFTWARE CONSORTIUM AND
> # CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
> # BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
FITNESS
> # FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL
> # THE INTERNET SOFTWARE CONSORTIUM OR CONTRIBUTORS BE LIABLE FOR ANY
DIRECT,
> # INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
> # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
> # SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
> # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
> # STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
> # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
> # OF THE POSSIBILITY OF SUCH DAMAGE.
> #
>
> CATMANPAGES = dhcrelay.cat8
> SEDMANPAGES = dhcrelay.cat8
> SRCS   = dhcrelay.c
> OBJS   = dhcrelay.o
> PROG   = dhcrelay
> MAN    = dhcrelay.8
>
> #DEBUG  = -g # /* RA CDHva40265 */
> #CC = $(CROSS_COMPILE)gcc
> #LD = $(CROSS_COMPILE)ld
> INCLUDES = $(INCLUDES_PATH) -I.. -I../includes
> DHCPLIB = ../common/libdhcp.a
> CFLAGS = $(DEBUG) $(PREDEFINES) $(INCLUDES) $(COPTS) -DDHS3_SYS
>
> all: $(PROG) #$(CATMANPAGES) DHS3_SYS: no man pages
>
> install: all
> mkdir -p $(INSTALL_PATH)$(BINDIR); \
> cp $(PROG) $(INSTALL_PATH)$(BINDIR);
>
> # for dir in $(BINDIR) $(ADMMANDIR); do \
> #   foo=""; \
> #   for bar in `echo $(DESTDIR)$${dir} |tr / ' '`; do \
> #     foo=$${foo}/$$bar; \
> #     if [ ! -d $$foo ]; then \
> #       mkdir $$foo; \
> #       chmod 755 $$foo; \
> #     fi; \
> #   done; \
> # done
> # $(INSTALL) dhcrelay $(DESTDIR)$(BINDIR)
> # $(CHMOD) 755 $(DESTDIR)$(BINDIR)/dhcrelay
> # #$(MANINSTALL) $(MANFROM) dhcrelay.$(MANCAT)8 $(MANTO) \
> # $(DESTDIR)$(ADMMANDIR)/dhcrelay$(ADMMANEXT) DHS3_SYS: no man pages
>
> clean:
> -rm -f $(OBJS) dhclient.o
>
> realclean: clean
> -rm -f $(PROG) $(CATMANPAGES) $(SEDMANPAGES) *~ #*
>
> distclean: realclean
> -rm -f Makefile
>
> # These should only be done on 4.4 BSD-based systems, since the mandoc
> # macros aren't available on older unices.   Catted man pages are
> # provided in the distribution so that this doesn't become a problem.
>
> dhcrelay.cat8: dhcrelay.man8
> nroff -man dhcrelay.man8 >dhcrelay.cat8
>
> dhcrelay.man8: dhcrelay.8
> sed -e "s#ETCDIR#$(ETC)#" -e "s#DBDIR#$(VARDB)#" \
> -e "s#RUNDIR#$(VARRUN)#" < dhcrelay.8 >dhcrelay.man8
>
> dhcrelay: dhcrelay.o $(DHCPLIB)
> $(CC) $(LFLAGS) -o $(PROG) dhcrelay.o $(LIBS_PATH) $(DHCPLIB) $(LIBS)
>
> # Dependencies (semi-automatically-generated)
>
> dhcrelay.o: dhcrelay.c ../includes/dhcpd.h \
>  ../includes/cdefs.h ../includes/osdep.h ../includes/site.h \
>  ../includes/cf/netbsd.h ../includes/dhcp.h \
>  ../includes/tree.h ../includes/hash.h ../includes/inet.h \
>  ../includes/sysconf.h ../includes/version.h
>


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


> /* dhcrelay.c
>
>    DHCP/BOOTP Relay Agent. */
>
> /*
>  * Copyright (c) 1997, 1998, 1999 The Internet Software Consortium.
>  * All rights reserved.
>  *
>  * Redistribution and use in source and binary forms, with or without
>  * modification, are permitted provided that the following conditions
>  * are met:
>  *
>  * 1. Redistributions of source code must retain the above copyright
>  *    notice, this list of conditions and the following disclaimer.
>  * 2. Redistributions in binary form must reproduce the above copyright
>  *    notice, this list of conditions and the following disclaimer in the
>  *    documentation and/or other materials provided with the distribution.
>  * 3. Neither the name of The Internet Software Consortium nor the names
>  *    of its contributors may be used to endorse or promote products
derived
>  *    from this software without specific prior written permission.
>  *
>  * THIS SOFTWARE IS PROVIDED BY THE INTERNET SOFTWARE CONSORTIUM AND
>  * CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
>  * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
>  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
>  * DISCLAIMED.  IN NO EVENT SHALL THE INTERNET SOFTWARE CONSORTIUM OR
>  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
>  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
>  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
>  * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
>  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
>  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
>  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
>  * SUCH DAMAGE.
>  *
>  * This software has been written for the Internet Software Consortium
>  * by Ted Lemon <mellon@fugue.com> in cooperation with Vixie
>  * Enterprises.  To learn more about the Internet Software Consortium,
>  * see ``http://www.vix.com/isc''.  To learn more about Vixie
>  * Enterprises, see ``http://www.vix.com''.
>  */
> /*
>  *    @RA CDHva32968  N. Moutrousteguy 99/10/15
>  *               DHCP modifications.
>  *               @@
>  * @RA CDHva45762 Gilles Courcoux 2001/06/07
>  * DHCPD: support for Alize clients
>  * @@
>  */
> #ifndef lint
> static char ocopyright [] =
> "$Id: dhcrelay.c,v 1.9.2.32 1999/06/22 13:38:39 mellon Exp $ Copyright (c)
1997, 1998, 1999 The Internet Software Consortium.  All rights reserved.\n";
> #endif /* not lint */
>
> #include "dhcpd.h"
> #include "version.h"
>
> static void usage PROTO ((char *));
>
> TIME cur_time;
> TIME default_lease_time = 43200; /* 12 hours... */
> TIME max_lease_time = 86400; /* 24 hours... */
> struct tree_cache *global_options [256];
>
> int log_perror = 1;
>
> /* Needed to prevent linking against conflex.c. */
> int lexline;
> int lexchar;
> char *token_line;
> char *tlname;
>
> char *path_dhcrelay_pid = _PATH_DHCRELAY_PID;
>
> u_int16_t local_port;
> u_int16_t remote_port;
> int log_priority;
>
> struct server_list {
> struct server_list *next;
> struct sockaddr_in to;
> } *servers;
>
> static char copyright [] =
> "Copyright 1997, 1998, 1999 The Internet Software Consortium.";
> static char arr [] = "All rights reserved.";
> static char message [] = "Internet Software Consortium DHCP Relay Agent";
> static char contrib [] = "Please contribute if you find this software
useful.";
> static char url [] = "For info, please visit
http://www.isc.org/dhcp-contrib.html";;
>
> int main (argc, argv, envp)
> int argc;
> char **argv, **envp;
> {
> int i;
> struct servent *ent;
> struct server_list *sp = (struct server_list *)0;
> int no_daemon = 0;
> int quiet = 0;
> char *s;
>
> s = strrchr (argv [0], '/');
> if (!s)
> s = argv [0];
> else
> s++;
>
> /* Initially, log errors to stderr as well as to syslogd. */
> #ifdef SYSLOG_4_2
> openlog (s, LOG_NDELAY);
> log_priority = DHCPD_LOG_FACILITY;
> #else
> openlog (s, LOG_NDELAY, DHCPD_LOG_FACILITY);
> #endif
>
> #if !(defined (DEBUG) || defined (SYSLOG_4_2))
> setlogmask (LOG_UPTO (LOG_INFO));
> #endif
>
> for (i = 1; i < argc; i++) {
> if (!strcmp (argv [i], "-p")) {
> if (++i == argc)
> usage (s);
> local_port = htons (atoi (argv [i]));
> debug ("binding to user-specified port %d",
>        ntohs (local_port));
> } else if (!strcmp (argv [i], "-pf")) {
> if (++i == argc)
> usage (s);
> path_dhcrelay_pid = argv [i];
> } else if (!strcmp (argv [i], "-d")) {
> no_daemon = 1;
>   } else if (!strcmp (argv [i], "-i")) {
> struct interface_info *tmp =
> ((struct interface_info *)
> dmalloc (sizeof *tmp, "specified_interface"));
> if (!tmp)
> error ("Insufficient memory to %s %s",
>        "record interface", argv [i]);
> if (++i == argc) {
> usage (s);
> }
> memset (tmp, 0, sizeof *tmp);
> strcpy (tmp -> name, argv [i]);
> tmp -> next = interfaces;
> tmp -> flags = INTERFACE_REQUESTED;
> interfaces = tmp;
> } else if (!strcmp (argv [i], "-q")) {
> quiet = 1;
> quiet_interface_discovery = 1;
>   } else if (argv [i][0] == '-') {
>       usage (s);
>   } else {
> struct hostent *he;
> struct in_addr ia, *iap = (struct in_addr *)0;
> if (inet_aton (argv [i], &ia)) {
> iap = &ia;
> } else {
> he = gethostbyname (argv [i]);
> if (!he) {
> warn ("%s: host unknown", argv [i]);
> } else {
> iap = ((struct in_addr *)
>        he -> h_addr_list [0]);
> }
> }
> if (iap) {
> sp = (struct server_list *)malloc (sizeof *sp);
> if (!sp)
> error ("no memory for server.\n");
> sp -> next = servers;
> servers = sp;
> memcpy (&sp -> to.sin_addr,
> iap, sizeof *iap);
> }
>   }
> }
>
> if (!quiet) {
> note ("%s %s", message, DHCP_VERSION);
> note (copyright);
> note (arr);
> note ("");
> note (contrib);
> note (url);
> note ("");
> }
> /* RA CDHva32968 + */
> #ifdef DHS3_SYS
> /* close all file descriptor for netadmin usage of rshd... */
> /* we need to close the link to the rsh cmd */
> {
>     int status;
>     if(!no_daemon)
> {
>     /*
>      * Close any open files descriptors.
>      */
>     closelog();
>     for (i=0;i<31;i++)
> {
>     close(i); /* close all open devices */
> }
>     errno=0; /* probably got set to EBADF from a close */
>
>
>     /* Attach file descriptor 0, 1, 2 to /dev/null.
>      * Application expect them to be at least open.
>      */
>     if(status = open("/dev/null", O_RDWR) != 0)
> {
>     if( status < 0)
> {
>     error("error opening /dev/null: %m");
> }
>     else
> {
>     error("open /dev/null: expected fd 0, got %d", status);
> }
> }
>     if((status = dup(0)) != 1)
> {
>     if( status < 0)
> {
>     error("dup failed: %m");
> }
>     else
> {
>     error("dup(0): expected fd 1, got %d", status);
> }
> }
>     if((status = dup(0)) != 2)
> {
>     if( status < 0)
> {
>     error("dup failed: %m");
> }
>     else
> {
>     error("dup(0): expected fd 2, got %d", status);
> }
> }
>     /* re-open syslogd. */
> #ifdef SYSLOG_4_2
>     openlog (s, LOG_NDELAY);
>     log_priority = DHCPD_LOG_FACILITY;
> #else
>     openlog (s, LOG_NDELAY, DHCPD_LOG_FACILITY);
> #endif
>
> #if !(defined (DEBUG) || defined (SYSLOG_4_2))
>     setlogmask (LOG_UPTO (LOG_INFO));
> #endif
>
> }
> }
> #endif
> /* RA CDHva32968 - */
>
> /* Default to the DHCP/BOOTP port. */
> if (!local_port) {
>        ent = getservbyname ("dhcps", "udp");
>        if (!ent)
> local_port = htons (67);
> else
> local_port = ent -> s_port;
> endservent ();
> }
> remote_port = htons (ntohs (local_port) + 1);
>
> /* We need at least one server. */
> if (!sp) {
> usage (s);
> }
>
> /* Set up the server sockaddrs. */
> for (sp = servers; sp; sp = sp -> next) {
> sp -> to.sin_port = local_port;
> sp -> to.sin_family = AF_INET;
> #ifdef HAVE_SA_LEN
> sp -> to.sin_len = sizeof sp -> to;
> #endif
> }
>
> /* Get the current time... */
> GET_TIME (&cur_time);
>
> /* Discover all the network interfaces. */
> discover_interfaces (DISCOVER_RELAY);
>
> /* Set up the bootp packet handler... */
> bootp_packet_handler = relay;
>
> /* Become a daemon... */
> if (!no_daemon) {
> int pid;
> FILE *pf;
> int pfdesc;
>
> log_perror = 0;
>
> if ((pid = fork()) < 0)
> error ("can't fork daemon: %m");
> else if (pid)
> exit (0);
>
> pfdesc = open (path_dhcrelay_pid,
>        O_CREAT | O_TRUNC | O_WRONLY, 0644);
>
> if (pfdesc < 0) {
> warn ("Can't create %s: %m", path_dhcrelay_pid);
> } else {
> pf = fdopen (pfdesc, "w");
> if (!pf)
> warn ("Can't fdopen %s: %m",
>       path_dhcrelay_pid);
> else {
> fprintf (pf, "%ld\n", (long)getpid ());
> fclose (pf);
> }
> }
>
> close (0);
> close (1);
> close (2);
> pid = setsid ();
> }
>
> /* Start dispatching packets and timeouts... */
> dispatch ();
>
> /*NOTREACHED*/
> return 0;
> }
>
> void relay (ip, packet, length, from_port, from, hfrom)
> struct interface_info *ip;
> struct dhcp_packet *packet;
> int length;
> unsigned int from_port;
> struct iaddr from;
> struct hardware *hfrom;
> {
> struct server_list *sp;
> struct sockaddr_in to;
> struct interface_info *out;
> struct hardware hto;
>
> if (packet -> hlen > sizeof packet -> chaddr) {
> note ("Discarding packet with invalid hlen.");
> return;
> }
> #ifdef DHS3_SYS /* need to do it here if setarp is called */
>         to.sin_family = AF_INET;
> #ifdef HAVE_SA_LEN
>         to.sin_len = sizeof to;
> #endif
>
>         /* Set up the hardware destination address. */
>         hto.hlen = packet -> hlen;
>         if (hto.hlen > sizeof hto.haddr)
>             hto.hlen = sizeof hto.haddr;
>         memcpy (hto.haddr, packet -> chaddr, hto.hlen);
>         hto.htype = packet -> htype;
> #endif
> /* If it's a bootreply, forward it to the client. */
> if (packet -> op == BOOTREPLY) {
> #ifdef DHS3_SYS
>             if (!(packet -> flags & htons (BOOTP_BROADCAST))){
> if(can_unicast_without_arp ()) {
>     to.sin_addr = packet -> yiaddr;
>     to.sin_port = remote_port;
> }
>                 else if ((packet -> xid == htonl(A4400_ID))
> /* RA CDHva45762+ */
> || (packet -> xid == htonl(ALIZE_ID))) {
> /* RA CDHva45762- */
>     to.sin_addr = packet -> yiaddr;
>     to.sin_port = remote_port;
>     /*
>      * WARNING : this piece of code is only available on chorus OS
>      * this is the only part of the code which needs to have the root
>      * priviledge to work ........
>      * Force unicast for old A4400 clients.
>      */
>     if(setarp (&to.sin_addr, (char*)hto.haddr, hto.hlen, hto.htype)) {
> note("BOOTREPLY is forced in broadcast\n");
> to.sin_addr.s_addr = INADDR_BROADCAST;
>     }
> }
> else {
>     to.sin_addr.s_addr = htonl (INADDR_BROADCAST);
>     to.sin_port = remote_port;
> }
>             }
> #else
>     if (!(packet -> flags & htons (BOOTP_BROADCAST)) &&
> can_unicast_without_arp ()) {
> to.sin_addr = packet -> yiaddr;
> to.sin_port = remote_port;
> }
> #endif
> else {
> to.sin_addr.s_addr = htonl (INADDR_BROADCAST);
> to.sin_port = remote_port;
> }
> #ifndef DHS3_SYS /* alread ydone above */
> to.sin_family = AF_INET;
> #ifdef HAVE_SA_LEN
> to.sin_len = sizeof to;
> #endif
>
> /* Set up the hardware destination address. */
> hto.hlen = packet -> hlen;
> if (hto.hlen > sizeof hto.haddr)
> hto.hlen = sizeof hto.haddr;
> memcpy (hto.haddr, packet -> chaddr, hto.hlen);
> hto.htype = packet -> htype;
> #endif /* DHS3_SYS */
>
> /* Find the interface that corresponds to the giaddr
>    in the packet. */
> for (out = interfaces; out; out = out -> next) {
> if (!memcmp (&out -> primary_address,
>      &packet -> giaddr,
>      sizeof packet -> giaddr))
> break;
> }
> if (!out) {
> warn ("packet to bogus giaddr %s.\n",
>       inet_ntoa (packet -> giaddr));
> return;
> }
>
> if (!send_packet (out,
>   (struct packet *)0,
>   packet, length, out -> primary_address,
>   &to, &hto) < 0)
> debug ("forwarded BOOTREPLY for %s to %s",
>        print_hw_addr (packet -> htype, packet -> hlen,
>       packet -> chaddr),
>        inet_ntoa (to.sin_addr));
>
> return;
> }
>
> /* If giaddr is set on a BOOTREQUEST, ignore it - it's already
>    been gatewayed. */
> if (packet -> giaddr.s_addr) {
> note ("ignoring BOOTREQUEST with giaddr of %s\n",
>       inet_ntoa (packet -> giaddr));
> return;
> }
>
> /* Set the giaddr so the server can figure out what net it's
>    from and so that we can later forward the response to the
>    correct net. */
> packet -> giaddr = ip -> primary_address;
>
> /* Otherwise, it's a BOOTREQUEST, so forward it to all the
>    servers. */
> for (sp = servers; sp; sp = sp -> next) {
> if (!send_packet ((fallback_interface
>    ? fallback_interface : interfaces),
>   (struct packet *)0,
>   packet, length, ip -> primary_address,
>   &sp -> to, (struct hardware *)0) < 0) {
> debug ("forwarded BOOTREQUEST for %s to %s",
>        print_hw_addr (packet -> htype, packet -> hlen,
>       packet -> chaddr),
>        inet_ntoa (sp -> to.sin_addr));
> }
> }
>
> }
>
> static void usage (appname)
> char *appname;
> {
> note (message);
> note (copyright);
> note (arr);
> note ("");
> note (contrib);
> note (url);
> note ("");
>
> warn ("Usage: %s [-i] [-d] [-i if0] [...-i ifN] [-p <port>]", appname);
> error ("      [-pf pidfilename] [server1 [... serverN]]");
> }
>
> void cleanup ()
> {
> }
>
> int write_lease (lease)
> struct lease *lease;
> {
> return 1;
> }
>
> int commit_leases ()
> {
> return 1;
> }
>
> void bootp (packet)
> struct packet *packet;
> {
> }
>
> void dhcp (packet)
> struct packet *packet;
> {
> }
>
>


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


> --
> 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/


_________________________________________________________
Do You Yahoo!?
Get your free @yahoo.com address at http://mail.yahoo.com


--
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/


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]