├── .travis.yml ├── AUTHORS ├── COPYING ├── ChangeLog ├── Makefile.am ├── NEWS ├── README ├── configure.ac ├── examples ├── Makefile.am ├── bsd │ ├── Makefile.am │ ├── vip-down.sh │ └── vip-up.sh └── linux │ ├── Makefile.am │ ├── vip-down.sh │ └── vip-up.sh ├── m4 ├── Makefile.am ├── codeset.m4 ├── gettext.m4 ├── glibc2.m4 ├── glibc21.m4 ├── iconv.m4 ├── intdiv0.m4 ├── intl.m4 ├── intldir.m4 ├── intlmacosx.m4 ├── intmax.m4 ├── inttypes-pri.m4 ├── inttypes_h.m4 ├── lcmessage.m4 ├── lib-ld.m4 ├── lib-link.m4 ├── lib-prefix.m4 ├── lock.m4 ├── longlong.m4 ├── nls.m4 ├── po.m4 ├── printf-posix.m4 ├── progtest.m4 ├── size_max.m4 ├── stdint_h.m4 ├── uintmax_t.m4 ├── visibility.m4 ├── wchar_t.m4 ├── wint_t.m4 └── xsize.m4 ├── po ├── ChangeLog ├── LINGUAS ├── Makefile.in.in ├── Makevars.template ├── POTFILES.in └── ucarp.pot └── src ├── Makefile.am ├── bsd-getopt_long.c ├── bsd-getopt_long.h ├── carp.c ├── carp_p.h ├── crypto-sha1.c ├── crypto-sha1.h ├── crypto.h ├── daemonize.c ├── daemonize.h ├── fakesnprintf.c ├── fakesnprintf.h ├── fillmac.c ├── fillmac.h ├── garp.c ├── garp.h ├── gettext.h ├── globals.h ├── ip_carp.h ├── log.c ├── log.h ├── mysnprintf.c ├── mysnprintf.h ├── spawn.c ├── spawn.h ├── syslognames.h ├── ucarp.c ├── ucarp.h └── ucarp_p.h /.travis.yml: -------------------------------------------------------------------------------- 1 | language: c 2 | 3 | compiler: 4 | - clang 5 | - gcc 6 | 7 | before_script: 8 | - sudo apt-get install libpcap-dev 9 | - ./autogen.sh 10 | - ./configure --disable-dependency-tracking 11 | 12 | script: make check 13 | -------------------------------------------------------------------------------- /AUTHORS: -------------------------------------------------------------------------------- 1 | * Frank DENIS 2 | * Eric Evans - maintainer of Debian packages. 3 | * David H - maintainer of Fink packages. 4 | * Richard Bellamy - helped a lot with 5 | Solaris portability. 6 | * Russell Mosemann - neutral mode and bug fixes. 7 | * Dean Gaudet - EINTR handling, log exec errors, 8 | --passfile. 9 | * Steve Kehlet and Marcus Goller - fixed the bogus code that issued poisonous 10 | gratuitous ARP, and improved the behavior when multiple nodes are started 11 | with the same interval and skew. Steve helped a lot on many things. 12 | * Tim Niemeyer - Ensure remastering works when the 13 | preferred master has its network connection flap. 14 | * Serve Sireskin - --ignoreifstate option. 15 | -------------------------------------------------------------------------------- /COPYING: -------------------------------------------------------------------------------- 1 | 2 | UCARP is covered by the following license : 3 | 4 | /* 5 | * Copyright (c) 2004-2015 Frank Denis with the help of 6 | * all contributors. 7 | * 8 | * Permission to use, copy, modify, and/or distribute this software for any 9 | * purpose with or without fee is hereby granted, provided that the above 10 | * copyright notice and this permission notice appear in all copies. 11 | * 12 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 13 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 14 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 15 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 16 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 17 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 18 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 19 | */ 20 | 21 | 22 | ------------------------------------------ 23 | 24 | 25 | Some code has been imported from the Pure-FTPd project. 26 | 27 | 28 | ------------------------------------------ 29 | 30 | 31 | 32 | The bsd-getopt_long.c and bsd-getopt_long.h source code is based upon the 33 | OpenBSD and NetBSD projects and it is covered by the BSD license. 34 | The carp.c and ip_carp.h files are derived from OpenBSD source code. 35 | The original license is enclosed at the beginning of the related files. 36 | -------------------------------------------------------------------------------- /ChangeLog: -------------------------------------------------------------------------------- 1 | 2 | * Version 1.5.2: 3 | - Uses arc4random() if available. 4 | - Avoids adverts that might be twice as what they should be. 5 | By Steve Kehlet. 6 | 7 | * Version 1.5.1: 8 | - New option (--nomcast / -M) to use broadcast advertisements instead of 9 | multicast ones. By Steve Kehlet. 10 | - autotools update. 11 | 12 | * Version 1.5: 13 | - Have ucarp register for the VRRP multicast group, by Petr Kohts. 14 | - Selection of master improved, by Greg Walton. 15 | - New option, -S (--ignoreifstate) to ignore unplugged network cable 16 | detection, for NICs that don't support that feature, by Serge Sireskin. 17 | - -o is now working as an alternative to --passfile, thanks to Eric Evans. 18 | - Have a degraded master send a last advertisement because if its network 19 | link gets cut and uncut, it doesn't know that the slave has taken the master 20 | role. Contributed by Tim Niemeyer. 21 | 22 | * Version 1.4: 23 | - --xparam shortcut is -m, not -x. Thanks fo Fabrice Dulaunoy. 24 | - Use multicast destination address for advertisements instead of 25 | broadcasts. Required for some switches. Fabrice Dulaunoy. 26 | - gettext upgrade. 27 | - Host with the lower IP address wit hnow be elected master when multiples 28 | nodes are started with the same parameters, in order to avoid flip-flop. 29 | By Steve Kehlet. 30 | - Improved gratuitous ARP payload for better interoperability, by Steve 31 | Kehlet. 32 | - Removed bogus gratuitous ARP code. Initial report by Marcus Goller. 33 | - Documentation updates, by Steve Kehlet. 34 | 35 | * Version 1.3: 36 | -n option wasn't properly parsed while --neutral was. Reported by Stefan 37 | Behte. 38 | gratuitous ARP packets should now be properly sent. Thanks to Marcus 39 | Rueckert for indirectly pointing out that the code was wrong. 40 | New -m option, and the virtual IP address is now passed to up/down scripts 41 | as well. By Fabrice Dulaunoy and Dirk Jagdmann who provided different 42 | implementations of the same idea. 43 | A bogus return statement has been removed, thanks to Alessio Cervellin. 44 | All interfaces should now be discovered on Solaris. 45 | EINTR is handled, thanks to Dean Gaudet. 46 | Log exec errors, Dean Gaudet. 47 | --passfile option, Dean Gaudet. 48 | Ignore POLLNVAL that looks bogus on some systems, at least OSX, reported 49 | by John Sterling. 50 | Send a delayed ARP request when switching to MASTER to deal with some L3 51 | switches (adapted from an OpenBSD diff by mpf at openbsd.org). 52 | Completly remove transition path INIT -> MASTER (adapted from an OpenBSD 53 | diff by mpf at openbsd.org). 54 | 55 | 56 | * Version 1.2: 57 | fakesnprintf/bsd-getopt_long updates from pure-ftpd 1.0.21. 58 | Avoid processing our own multicasts. Thanks to Gregory McGarry. 59 | --neutral mode, by Russell Mosemann. 60 | Avoid low prioritized hosts quickly switching to MASTER at bootup if 61 | preemption is enabled. 62 | 63 | * Version 1.1: 64 | 'exec' was removed from sample scripts since it confused some people 65 | who tried to add commands afterwards :) 66 | Workarounds have been added for unaligned pointers. It should fix 67 | crashes on Sparc hardware. 68 | logfile() properly sends errors to stderr and notices to stdout. 69 | The OpenBSD getopt_long() replacement has been fixed. 70 | inet_aton() has been replaced by inet_pton(); 71 | self-sent packets are now filtered out. 72 | The read timeout for pcap_open_live() has been shortened. 73 | Captured ethernet frames sometimes have extra bytes after the IP 74 | packet. This case is now properly handled. 75 | The interface is no more switched in promiscous mode. 76 | MAC addresses are fetched on Solaris and other Solaris portability 77 | improvements have been made, thanks to Richard Bellamy. 78 | Even in non-preemptive mode, we start to poll for a dead master as 79 | soon as we leave the INIT state. 80 | Syslog facilities can now be changed through the -f / --syslog switch. 81 | 82 | * Version 1.0: 83 | Finally the first 1.x release :) 84 | Thanks to everyone for testing every previous snapshot. 85 | -------------------------------------------------------------------------------- /Makefile.am: -------------------------------------------------------------------------------- 1 | SUBDIRS = \ 2 | m4 \ 3 | po \ 4 | src \ 5 | examples 6 | 7 | ACLOCAL_AMFLAGS = -I m4 8 | 9 | EXTRA_DIST = config.rpath 10 | -------------------------------------------------------------------------------- /NEWS: -------------------------------------------------------------------------------- 1 | * Version 1.5.2: 2 | - Avoid adverts that might be twice what they should be on some Linux 3 | systems (Steve Kehlet). 4 | 5 | * Version 1.5.1: 6 | - A new option has been added to try using broadcast advertisements instead 7 | of multicast ones. 8 | 9 | * Version 1.5: 10 | - Breakage introducted with version 1.4 should finally be fixed, thanks to 11 | Petr Kohts, Greg Walton and Steve Kehlet. 12 | - A new option has been added to ignore unplugged network cable detection, 13 | useful when nodes are connected with a crossover cable, not with a switch. 14 | 15 | * Version 1.4: 16 | - This version should finally fix every issue people had with gratuitous 17 | ARP announcements. 18 | - Nodes configured with the same intervals shouln't flip-flop any more. 19 | 20 | * Version 1.3: 21 | - Gratuitous ARP packets should now properly be sent, regardless of the 22 | architecture. 23 | - New option: -m (-xparam=...) in order to add arbitrary arguments to 24 | up/down scripts. 25 | - New option: -o (--passfile=...) in order to read the secret key from a 26 | file. 27 | - A delayed ARP request is sent after the first one when switching to 28 | MASTER, in order to deal with some layer-3 switches. 29 | - Bug fixes. 30 | 31 | * Version 1.2: 32 | - Neutral mode (--neutral). 33 | - NetBSD compatibility. 34 | - Minor bug fixes. 35 | 36 | * Version 1.1: 37 | - The non-preemptive mode should work flawlessly. 38 | - Syslog facilities can now be changed. 39 | - Self-sent packets are now filtered out. 40 | - Portability has been improved. 41 | 42 | * Version 1.0: 43 | - I18n support has been added. 44 | - Syslog support has been implemented. 45 | - Code cleanups and documentation updates. 46 | - A mailing-list is now available. 47 | - Daemonization (--daemonize / -B) has been added. 48 | 49 | 50 | -------------------------------------------------------------------------------- /README: -------------------------------------------------------------------------------- 1 | 2 | .:. UCARP .:. 3 | Documentation for version 1.5.2 4 | 5 | 6 | ------------------------ BLURB ------------------------ 7 | 8 | 9 | UCARP allows a couple of hosts to share common virtual IP addresses in order 10 | to provide automatic failover. It is a portable userland implementation of the 11 | secure and patent-free Common Address Redundancy Protocol (CARP, OpenBSD's 12 | alternative to the patents-bloated VRRP). 13 | 14 | Strong points of the CARP protocol are: very low overhead, cryptographically 15 | signed messages, interoperability between different operating systems and no 16 | need for any dedicated extra network link between redundant hosts. 17 | 18 | 19 | ------------------------ COMPILATION ------------------------ 20 | 21 | 22 | libpcap (http://www.tcpdump.org/) must be installed on your system, with 23 | development files (headers). 24 | 25 | Then, follow the boring traditional procedure: 26 | 27 | ./configure 28 | make install-strip 29 | 30 | For details, have a look at the INSTALL file. 31 | 32 | The software has been successfully tested on Linux 2.4, Linux 2.6, MacOS X, 33 | OpenBSD, MirBSD and NetBSD. 34 | 35 | 36 | ------------------------ REQUIREMENTS ------------------------ 37 | 38 | 39 | A couple of virtual hosts must be given: 40 | 41 | - A shared virtual IP, which will be dynamically answered by one alive host. 42 | Services that need high availability need to be assigned to that virtual IP. 43 | 44 | - A real IP address for each host. 45 | 46 | - A shared identifier for the virtual IP address, which is a number between 1 47 | and 255. 48 | 49 | - For each host : an advertisement interval, comprised of a base and skew value, 50 | which is the frequency the host will tell the other one that it's still alive. 51 | By default, base is 1 and skew is 0, which basically means one advertisement a 52 | second. The protocol is very light, a tiny packet every second won't have any 53 | noticeable impact on your network. 54 | 55 | - A shared password (that will never go plaintext to the network). 56 | 57 | - A script to bring the virtual address up when a host becomes the master. 58 | 59 | - Another script to bring the virtual address down when a host is no more the 60 | master. 61 | 62 | 63 | ------------------------ USAGE ------------------------ 64 | 65 | 66 | The server will usually be installed as : /usr/local/sbin/ucarp 67 | Everything is driven through command-line options. 68 | In order to see the list of available options, try : /usr/local/sbin/ucarp -h 69 | 70 | Better than a long technical discussion, here's a real-life setup example. 71 | 72 | Your company has an internal mail relay whose IP address is 10.1.1.252. Every 73 | user has configured his mail client with that host or IP address and the 74 | service must always be up and running without having to reconfigure every 75 | user's mail client in case of a failure. 76 | 77 | Instead of assigning 10.1.1.252 to a particular mail server, you decide 78 | to use ucarp to allow two hosts to share this IP address. Of course, 79 | only one server can answer for this address at a time, while the other 80 | sits idle. However the other server will automatically become active in 81 | case the first one fails. Thus you're providing a simple but powerful 82 | IP failover solution. 83 | 84 | So you set up two mail servers hosts with an identical configuration. 85 | Their real IP addresses are 10.1.1.1 and 10.1.1.2. 86 | 87 | First, we will create a script that brings the virtual IP address up. Let's 88 | save that file as /etc/vip-up.sh : 89 | 90 | #! /bin/sh 91 | /sbin/ip addr add 10.1.1.252/24 dev eth0 92 | 93 | Now another script to bring it down, /etc/vip-down.sh : 94 | 95 | #! /bin/sh 96 | /sbin/ip addr del 10.1.1.252/24 dev eth0 97 | 98 | Of course, anything can go in these scripts. For instance, you may want to add 99 | routes, to add something to log files or to send mail. And last, but not 100 | least, you can use a script that will connect to your switches and flush their 101 | ARP cache. Some users reported that transitions were way faster when also 102 | switching MAC addresses. 103 | 104 | The called scripts are passed arguments, in this order: 105 | 106 | 107 | 108 | For instance, as the is passed as the first argument to the called scripts, 109 | feel free to replace "eth0" with "$1" and 10.1.1.252 by "$2" in the previous 110 | examples. 111 | 112 | Don't forget to make those files executable : 113 | 114 | chmod +x /etc/vip-up.sh /etc/vip-down.sh 115 | 116 | Right. What we need now is an identifier for the virtual IP. Let's take "42". 117 | And we also need a password. Let's take "love". 118 | 119 | Now, on the first host (whoose real IP is 10.1.1.1), run : 120 | 121 | /usr/local/sbin/ucarp -v 42 -p love -a 10.1.1.252 -s 10.1.1.1 & 122 | 123 | On the second host, whose real IP is 10.1.1.2, run : 124 | 125 | /usr/local/sbin/ucarp -v 42 -p love -a 10.1.1.252 -s 10.1.1.2 & 126 | 127 | You should see that one of those hosts quickly becomes the master, and the 128 | other one the backup. Related scripts are spawned on change. 129 | 130 | Now unplug the master. After a few seconds, the other host becomes the new 131 | master. 132 | 133 | 134 | ------------------------ MULTICAST IP SELECTION ------------------------- 135 | 136 | The '--vhid' virtual IP identifier field only is only eight bits, providing up 137 | to 255 different virtual IPs on the same multicast group IP. For larger 138 | deployments, and more flexibility in allocation, ucarp can optionally use a 139 | different multicast IP. By default, ucarp will send/listen on 224.0.0.18, which 140 | is the assigned IP for VRRP. If you want to use a different address, use the 141 | '--mcast' option. Consult the available multicast addresses before deciding 142 | which to use. 143 | 144 | http://www.iana.org/assignments/multicast-addresses/multicast-addresses.xml 145 | http://tools.ietf.org/html/rfc5771 146 | http://tools.ietf.org/html/rfc2365 147 | 148 | Addresses within 239.192.0.0/14 should be most appropriate. 149 | 150 | If ucarp isn't working on a different IP, check that your networking gear is 151 | set up to handle it. tcpdump on each host can be handy for diagnosis: 152 | 153 | tcpdump -n 'net 224.0.0.0/4' 154 | 155 | 156 | ------------------------ MASTER ELECTION PROCESS ------------------------ 157 | 158 | 159 | When ucarp first runs, it starts as a backup and listens to the network 160 | to determine if it should become the master. If at any time more than 161 | three times the node's advertising interval (defined as the advertising 162 | base (seconds) plus a fudge factor, the advertising skew) passes without 163 | hearing a peer's CARP advertisement, the node will transition itself to 164 | being a master. 165 | 166 | Transitioning from backup to master means: 167 | 1. running the specified up script to assign the vip to the local system 168 | 2. sending a gratuitous arp to the network to claim the vip 169 | 3. continuously sending CARP advertisements to the network every interval. 170 | 171 | Transitioning from master to backup means: 172 | 1. running the specified down script to remove the vip from the local system 173 | 174 | To understand how ucarp works, it's important to note that the 175 | advertisement interval is not only used as the time in between which 176 | each CARP advertisement is sent by the master, but also as a priority 177 | mechanism where shorter (i.e. more frequent) is better. The interval 178 | base and skew values are stored in the CARP advertisement and are used 179 | by other nodes to make certain decisions. 180 | 181 | By default, once a node becomes the master, it will continue on 182 | indefinitely as the master. If you like/want/need this behavior, or don't 183 | have a preferred master, then choose the same interval on all hosts. 184 | If for whatever reason you were to choose different intervals on the 185 | hosts, then over time the one with the shortest interval would tend to 186 | become the master as machines are rebooted, after failures, etc. 187 | 188 | Also of note is a conflict resolution algorithm that in case a master 189 | hears another, equal (in terms of its advertised interval) master, the 190 | one with the lower IP address will remain master and the other will 191 | immediately demote itself. This is simply to eliminate flapping and 192 | quickly determine who should remain master. This situation should not 193 | happen very often but it can. 194 | 195 | If you want a "preferred" master to always be the master (even if another 196 | host is already the master), add the preempt switch (--preempt or -P) and 197 | assign a shorter interval via the advertisement base (--advbase or -b) and 198 | skew (--advskew or -k). This will cause the preferred node to ignore a 199 | master who is advertising a longer interval and promote itself to master. 200 | The old master will quickly hear the preferred node advertising a shorter 201 | interval and immediately demote itself. 202 | 203 | In summary, a backup will become master if: 204 | - no one else advertises for 3 times its own advertisement interval 205 | - you specified --preempt and it hears a master with a longer interval 206 | 207 | and a master will become backup if: 208 | - another master advertises a shorter interval 209 | - another master advertises the same interval, and has a lower IP address 210 | 211 | 212 | ------------------------ OTHER NOTES ------------------------ 213 | 214 | 215 | Specify the --neutral (-n) switch for ucarp to not run the downscript 216 | at startup. 217 | 218 | --shutdown (-z) will run the downscript at exit, unless ucarp is already in 219 | the backup state. 220 | 221 | The "dead ratio" (--deadratio=...) knob basically changes how long a backup 222 | server will wait for an unresponsive master before considering it as dead, and 223 | becoming the new master. In the original protocol, the ratio is 3. This is 224 | also the default when this command-line switch is missing. 225 | 226 | Notices are sent both to stderr/stdout and to the syslog daemon (with the 227 | "daemon" facility) by default. stderr/stdout are bypassed if the daemon is 228 | started in background (--daemonize). Facilities can be changed with the 229 | --syslog switch. Use --syslog=none to disable syslog logging, for instance if 230 | prefer using something like multilog. 231 | 232 | You can send the ucarp process a SIGUSR1 to have it log a status line to syslog, 233 | like: 234 | Jan 7 17:38:22 localhost ucarp[6103]: [INFO] BACKUP on eth0 id 198 235 | 236 | You can send the ucarp process a SIGUSR2 to have it demote itself from 237 | master to backup, pause 3 seconds, then proceed as usual to listen for 238 | other masters and promote itself if necessary. This could be useful if 239 | you wish another node to take over master. 240 | 241 | --ignoreifstate (-S) option tells ucarp to ignore unplugged network cable. It 242 | is useful when you connect ucarp nodes with a crossover patch cord (not via a 243 | hub or a switch). Without this option the node in MASTER state will switch to 244 | BACKUP state when the other node is powered down, because network interface 245 | shows that cable is unplugged (NO-CARRIER). Some network interface drivers 246 | don't support NO-CARRIER feature, and this option is not needed for these 247 | network cards. The card that definitely supports this feature is Realtek 8139. 248 | 249 | 250 | ------------------------ TRANSLATIONS ------------------------ 251 | 252 | 253 | UCARP can speak your native language through gettext / libintl. 254 | If you want to translate the software, have a look at the po/ directory. 255 | Copy the ucarp.pot file to .po and use software like Kbabel 256 | or Emacs to update the file. 257 | Better use use your local charset than UTF-8. 258 | -------------------------------------------------------------------------------- /configure.ac: -------------------------------------------------------------------------------- 1 | AC_PREREQ(2.59) 2 | AC_INIT([ucarp],[1.5.2]) 3 | AC_CONFIG_SRCDIR([src/ucarp.c]) 4 | AC_CONFIG_HEADERS([config.h]) 5 | AM_INIT_AUTOMAKE([1.9 dist-bzip2]) 6 | AC_CONFIG_LIBOBJ_DIR(src) 7 | 8 | AC_SUBST(VERSION) 9 | 10 | ISODATE=`date +%Y-%m-%d` 11 | AC_SUBST(ISODATE) 12 | 13 | # Checks for programs. 14 | AC_PROG_CC 15 | AC_PROG_CC_C_O 16 | AC_PROG_CPP 17 | AC_USE_SYSTEM_EXTENSIONS 18 | AC_PROG_INSTALL 19 | AC_PROG_LN_S 20 | AC_PROG_MAKE_SET 21 | AC_PROG_RANLIB 22 | AC_PROG_LIBTOOL 23 | 24 | AC_ISC_POSIX 25 | 26 | AM_GNU_GETTEXT([external]) 27 | 28 | # Checks for header files. 29 | AC_HEADER_STDC 30 | AC_HEADER_TIME 31 | AC_HEADER_SYS_WAIT 32 | AC_CHECK_HEADERS([memory.h strings.h unistd.h netinet/in_systm.h]) 33 | AC_CHECK_HEADERS([netinet/in.h stdlib.h string.h sys/socket.h sys/time.h]) 34 | AC_CHECK_HEADERS([ifaddrs.h net/if_dl.h net/if_types.h]) 35 | AC_CHECK_HEADERS([sys/sockio.h net/if_arp.h], [], [], 36 | [[ 37 | #include 38 | #ifdef HAS_SYS_SOCKET_H 39 | #include 40 | #endif 41 | #ifdef HAS_NETINET_IN_H 42 | #include 43 | #endif 44 | ]]) 45 | AC_CHECK_HEADERS([fcntl.h sys/fcntl.h ioctl.h sys/ioctl.h]) 46 | 47 | dnl Check for endianness 48 | AC_C_BIGENDIAN 49 | 50 | dnl Check for types 51 | AC_TYPE_SIGNAL 52 | AC_TYPE_PID_T 53 | AC_TYPE_SIZE_T 54 | AC_TYPE_SSIZE_T 55 | AC_CHECK_TYPE(dev_t, , [AC_DEFINE(dev_t, unsigned int, [dev_t type])], 56 | [ 57 | #ifdef HAVE_UNISTD_H 58 | # include 59 | #endif 60 | #include 61 | #include 62 | ]) 63 | 64 | dnl Check for sizes 65 | AC_CHECK_SIZEOF(short) 66 | AC_CHECK_SIZEOF(int) 67 | AC_CHECK_SIZEOF(long) 68 | AC_CHECK_SIZEOF(long long) 69 | 70 | dnl Socket things 71 | 72 | AC_CHECK_FUNC(connect, , [AC_CHECK_LIB(socket, connect)]) 73 | AC_CHECK_FUNC(gethostbyname, , [AC_CHECK_LIB(resolv, gethostbyname)]) 74 | AC_CHECK_FUNC(gethostbyname, , [AC_CHECK_LIB(nsl, gethostbyname)]) 75 | 76 | if test "x$ac_cv_lib_nsl_gethostbyname" != "xyes" && test "x$ac_cv_func_gethostbyname" != "xyes" ; then 77 | AC_CHECK_FUNC(gethostbyname, , [AC_CHECK_LIB(socket, gethostbyname)]) 78 | fi 79 | 80 | if test "$ac_cv_lib_nsl_gethostbyname" = "$ac_cv_func_gethostbyname" ; then 81 | AC_MSG_CHECKING([if we can include libnsl + libsocket]) 82 | LIBS="-lnsl -lsocket $LIBS" 83 | AC_LINK_IFELSE([AC_LANG_PROGRAM([[]], [[(void) gethostbyname]])],[my_ac_link_result=yes], 84 | [my_ac_link_result=no]) 85 | if test "$my_ac_link_result" = "no" ; then 86 | AC_MSG_RESULT([failure]) 87 | AC_MSG_ERROR([unable to use gethostbyname()]) 88 | else 89 | AC_MSG_RESULT([success]) 90 | fi 91 | fi 92 | 93 | # Checks for libraries. 94 | AC_CHECK_LIB([pcap], [pcap_lookupdev]) 95 | 96 | dnl Types - continued 97 | 98 | AC_CHECK_TYPE(socklen_t, , [AC_DEFINE(socklen_t, int, [socklen_t type])], 99 | [ 100 | #ifdef HAVE_UNISTD_H 101 | # include 102 | #endif 103 | #include 104 | #include 105 | ]) 106 | 107 | AC_CHECK_TYPE(ssize_t, , [AC_DEFINE(ssize_t, long int, [ssize_t type])], 108 | [ 109 | #include 110 | #ifdef STDC_HEADERS 111 | # include 112 | # include 113 | #else 114 | # if HAVE_STDLIB_H 115 | # include 116 | # endif 117 | #endif 118 | #ifdef HAVE_UNISTD_H 119 | # include 120 | #endif 121 | #include 122 | ]) 123 | 124 | AC_CHECK_TYPE(sig_atomic_t, , [AC_DEFINE(sig_atomic_t, signed char, 125 | [sig_atomic_t type])], 126 | [ 127 | #ifdef HAVE_UNISTD_H 128 | # include 129 | #endif 130 | #include 131 | #include 132 | ]) 133 | 134 | AC_CHECK_TYPE(nfds_t, , [AC_DEFINE(nfds_t, unsigned long, [nfds_t type])], 135 | [ 136 | #ifdef HAVE_UNISTD_H 137 | # include 138 | #endif 139 | #include 140 | #include 141 | ]) 142 | 143 | dnl Check for typedefs, structures, and compiler characteristics. 144 | AC_PROG_GCC_TRADITIONAL 145 | AC_C_CONST 146 | AC_C_INLINE 147 | 148 | dnl Options 149 | 150 | AC_ARG_WITH(debug, 151 | [AS_HELP_STRING(--with-debug,For maintainers only - please do not use)], 152 | [ if test "x$withval" = "xyes" ; then 153 | CFLAGS="$CFLAGS -DDEBUG=1 -g -Wall -W -Wcast-align -Wbad-function-cast -Wstrict-prototypes -Wwrite-strings -Wreturn-type " 154 | fi ]) 155 | 156 | dnl Checks for library functions. 157 | AC_FUNC_ALLOCA 158 | AC_FUNC_MEMCMP 159 | AC_FUNC_STRFTIME 160 | AC_FUNC_STAT 161 | AC_FUNC_VPRINTF 162 | AC_FUNC_FORK 163 | AC_FUNC_WAIT3 164 | 165 | AC_CHECK_FUNCS(initgroups setrlimit waitpid setproctitle getopt_long) 166 | AC_CHECK_FUNCS(seteuid setreuid setresuid setegid setregid setresgid) 167 | AC_CHECK_FUNCS(strtoull strtoq) 168 | AC_CHECK_FUNCS(memset munmap strdup fileno) 169 | AC_CHECK_FUNCS(getaddrinfo getnameinfo inet_ntop inet_pton) 170 | AC_CHECK_FUNCS(snprintf vsnprintf vfprintf gethostname) 171 | AC_CHECK_FUNCS(setlocale) 172 | AC_CHECK_FUNCS(random srandomdev arc4random) 173 | AC_CHECK_FUNCS(getifaddrs) 174 | 175 | if test "x$sysconfdir" = 'xNONE' || test "x$sysconfdir" = 'x'; then 176 | CONFDIR='/etc' 177 | else 178 | if test "x$sysconfdir" = 'x${prefix}/etc'; then 179 | if test "x$prefix" = 'xNONE' || test "x$prefix" = 'x/usr'; then 180 | CONFDIR='/etc' 181 | else 182 | CONFDIR="$sysconfdir" 183 | fi 184 | else 185 | CONFDIR="$sysconfdir" 186 | fi 187 | fi 188 | 189 | if test -r /dev/arandom; then 190 | AC_MSG_NOTICE([You have /dev/arandom - Great]) 191 | AC_DEFINE(HAVE_DEV_ARANDOM,,[Define if you have /dev/arandom]) 192 | fi 193 | if test -r /dev/urandom; then 194 | AC_MSG_NOTICE([You have /dev/urandom - Great]) 195 | AC_DEFINE(HAVE_DEV_URANDOM,,[Define if you have /dev/urandom]) 196 | fi 197 | if test -r /dev/random; then 198 | AC_MSG_NOTICE([You have /dev/random - Great]) 199 | AC_DEFINE(HAVE_DEV_RANDOM,,[Define if you have /dev/random]) 200 | fi 201 | 202 | AC_MSG_CHECKING(whether snprintf is C99 conformant) 203 | AC_RUN_IFELSE([AC_LANG_SOURCE([[ 204 | #include 205 | #ifdef STDC_HEADERS 206 | # include 207 | # include 208 | #else 209 | # if HAVE_STDLIB_H 210 | # include 211 | # endif 212 | #endif 213 | #ifdef HAVE_UNISTD_H 214 | # include 215 | #endif 216 | 217 | int main(void) 218 | { 219 | char buf[4]; 220 | 221 | (void) fprintf(fopen("conftestval", "w"), "%d\n", 222 | (int) snprintf(buf, sizeof buf, "12345678")); 223 | return 0; 224 | } 225 | ]])],[CONF_SNPRINTF_TYPE=`cat conftestval` 226 | ],[],[]) 227 | AC_MSG_RESULT(done) 228 | if test "x$CONF_SNPRINTF_TYPE" = "x" ; then 229 | AC_MSG_WARN(your operating system doesn't implement snprintf) 230 | else 231 | AC_DEFINE_UNQUOTED(CONF_SNPRINTF_TYPE, $CONF_SNPRINTF_TYPE, 232 | [return value of an overflowed snprintf]) 233 | fi 234 | 235 | AC_MSG_CHECKING(whether you already have a standard SHA1 implementation) 236 | AC_RUN_IFELSE([AC_LANG_SOURCE([[ 237 | #include 238 | #include 239 | #include 240 | #include 241 | 242 | int main(void) 243 | { 244 | SHA1_CTX ctx; 245 | char b[41]; 246 | 247 | SHA1Init(&ctx); 248 | SHA1Update(&ctx, (const unsigned char *) "test", 4U); 249 | SHA1End(&ctx, b); 250 | b[40] = 0; 251 | 252 | return strcasecmp(b, "a94a8fe5ccb19ba61c4c0873d391e987982fbbd3"); 253 | } 254 | ]])],[ 255 | AC_MSG_RESULT(yes) 256 | AC_DEFINE(USE_SYSTEM_CRYPT_SHA1,,[Define if you already have standard 257 | SHA1 functions]) 258 | ],[AC_MSG_RESULT(no) 259 | ],[]) 260 | 261 | AC_MSG_CHECKING([whether syslog names are available]) 262 | AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[ 263 | #define SYSLOG_NAMES 1 264 | #include 265 | #include 266 | ]], [[ 267 | (void) facilitynames 268 | ]])],[ 269 | AC_MSG_RESULT(yes) 270 | AC_DEFINE(HAVE_SYSLOG_NAMES,,[define if syslog names are available]) 271 | ],[ 272 | AC_MSG_RESULT(no) 273 | ]) 274 | 275 | sysconfdir="$CONFDIR" 276 | AC_SUBST(sysconfdir) 277 | 278 | CPPFLAGS="$CPPFLAGS -DCONFDIR=\\\"$sysconfdir\\\"" 279 | 280 | dnl Output 281 | 282 | AC_CONFIG_FILES(Makefile src/Makefile examples/Makefile 283 | examples/linux/Makefile examples/bsd/Makefile 284 | po/Makefile.in m4/Makefile ) 285 | 286 | AC_OUTPUT 287 | -------------------------------------------------------------------------------- /examples/Makefile.am: -------------------------------------------------------------------------------- 1 | SUBDIRS = \ 2 | linux \ 3 | bsd 4 | 5 | 6 | -------------------------------------------------------------------------------- /examples/bsd/Makefile.am: -------------------------------------------------------------------------------- 1 | EXTRA_DIST = \ 2 | vip-up.sh \ 3 | vip-down.sh 4 | -------------------------------------------------------------------------------- /examples/bsd/vip-down.sh: -------------------------------------------------------------------------------- 1 | #! /bin/sh 2 | exec 2> /dev/null 3 | 4 | /sbin/ifconfig "$1" -alias "$2" 5 | -------------------------------------------------------------------------------- /examples/bsd/vip-up.sh: -------------------------------------------------------------------------------- 1 | #! /bin/sh 2 | exec 2> /dev/null 3 | 4 | /sbin/ifconfig "$1" alias "$2" netmask 255.255.255.255 5 | -------------------------------------------------------------------------------- /examples/linux/Makefile.am: -------------------------------------------------------------------------------- 1 | EXTRA_DIST = \ 2 | vip-up.sh \ 3 | vip-down.sh 4 | -------------------------------------------------------------------------------- /examples/linux/vip-down.sh: -------------------------------------------------------------------------------- 1 | #! /bin/sh 2 | exec 2> /dev/null 3 | 4 | /sbin/ip addr del "$2"/24 dev "$1" 5 | 6 | # or alternatively: 7 | # /sbin/ifconfig "$1":254 down 8 | -------------------------------------------------------------------------------- /examples/linux/vip-up.sh: -------------------------------------------------------------------------------- 1 | #! /bin/sh 2 | exec 2> /dev/null 3 | 4 | /sbin/ip addr add "$2"/24 dev "$1" 5 | 6 | # or alternatively: 7 | # /sbin/ifconfig "$1":254 "$2" netmask 255.255.255.0 8 | -------------------------------------------------------------------------------- /m4/Makefile.am: -------------------------------------------------------------------------------- 1 | EXTRA_DIST = \ 2 | gettext.m4 \ 3 | iconv.m4 \ 4 | lib-ld.m4 \ 5 | lib-link.m4 \ 6 | lib-prefix.m4 \ 7 | nls.m4 \ 8 | po.m4 \ 9 | progtest.m4 10 | -------------------------------------------------------------------------------- /m4/codeset.m4: -------------------------------------------------------------------------------- 1 | # codeset.m4 serial 2 (gettext-0.16) 2 | dnl Copyright (C) 2000-2002, 2006 Free Software Foundation, Inc. 3 | dnl This file is free software; the Free Software Foundation 4 | dnl gives unlimited permission to copy and/or distribute it, 5 | dnl with or without modifications, as long as this notice is preserved. 6 | 7 | dnl From Bruno Haible. 8 | 9 | AC_DEFUN([AM_LANGINFO_CODESET], 10 | [ 11 | AC_CACHE_CHECK([for nl_langinfo and CODESET], am_cv_langinfo_codeset, 12 | [AC_TRY_LINK([#include ], 13 | [char* cs = nl_langinfo(CODESET); return !cs;], 14 | am_cv_langinfo_codeset=yes, 15 | am_cv_langinfo_codeset=no) 16 | ]) 17 | if test $am_cv_langinfo_codeset = yes; then 18 | AC_DEFINE(HAVE_LANGINFO_CODESET, 1, 19 | [Define if you have and nl_langinfo(CODESET).]) 20 | fi 21 | ]) 22 | -------------------------------------------------------------------------------- /m4/gettext.m4: -------------------------------------------------------------------------------- 1 | # gettext.m4 serial 60 (gettext-0.17) 2 | dnl Copyright (C) 1995-2007 Free Software Foundation, Inc. 3 | dnl This file is free software; the Free Software Foundation 4 | dnl gives unlimited permission to copy and/or distribute it, 5 | dnl with or without modifications, as long as this notice is preserved. 6 | dnl 7 | dnl This file can can be used in projects which are not available under 8 | dnl the GNU General Public License or the GNU Library General Public 9 | dnl License but which still want to provide support for the GNU gettext 10 | dnl functionality. 11 | dnl Please note that the actual code of the GNU gettext library is covered 12 | dnl by the GNU Library General Public License, and the rest of the GNU 13 | dnl gettext package package is covered by the GNU General Public License. 14 | dnl They are *not* in the public domain. 15 | 16 | dnl Authors: 17 | dnl Ulrich Drepper , 1995-2000. 18 | dnl Bruno Haible , 2000-2006. 19 | 20 | dnl Macro to add for using GNU gettext. 21 | 22 | dnl Usage: AM_GNU_GETTEXT([INTLSYMBOL], [NEEDSYMBOL], [INTLDIR]). 23 | dnl INTLSYMBOL can be one of 'external', 'no-libtool', 'use-libtool'. The 24 | dnl default (if it is not specified or empty) is 'no-libtool'. 25 | dnl INTLSYMBOL should be 'external' for packages with no intl directory, 26 | dnl and 'no-libtool' or 'use-libtool' for packages with an intl directory. 27 | dnl If INTLSYMBOL is 'use-libtool', then a libtool library 28 | dnl $(top_builddir)/intl/libintl.la will be created (shared and/or static, 29 | dnl depending on --{enable,disable}-{shared,static} and on the presence of 30 | dnl AM-DISABLE-SHARED). If INTLSYMBOL is 'no-libtool', a static library 31 | dnl $(top_builddir)/intl/libintl.a will be created. 32 | dnl If NEEDSYMBOL is specified and is 'need-ngettext', then GNU gettext 33 | dnl implementations (in libc or libintl) without the ngettext() function 34 | dnl will be ignored. If NEEDSYMBOL is specified and is 35 | dnl 'need-formatstring-macros', then GNU gettext implementations that don't 36 | dnl support the ISO C 99 formatstring macros will be ignored. 37 | dnl INTLDIR is used to find the intl libraries. If empty, 38 | dnl the value `$(top_builddir)/intl/' is used. 39 | dnl 40 | dnl The result of the configuration is one of three cases: 41 | dnl 1) GNU gettext, as included in the intl subdirectory, will be compiled 42 | dnl and used. 43 | dnl Catalog format: GNU --> install in $(datadir) 44 | dnl Catalog extension: .mo after installation, .gmo in source tree 45 | dnl 2) GNU gettext has been found in the system's C library. 46 | dnl Catalog format: GNU --> install in $(datadir) 47 | dnl Catalog extension: .mo after installation, .gmo in source tree 48 | dnl 3) No internationalization, always use English msgid. 49 | dnl Catalog format: none 50 | dnl Catalog extension: none 51 | dnl If INTLSYMBOL is 'external', only cases 2 and 3 can occur. 52 | dnl The use of .gmo is historical (it was needed to avoid overwriting the 53 | dnl GNU format catalogs when building on a platform with an X/Open gettext), 54 | dnl but we keep it in order not to force irrelevant filename changes on the 55 | dnl maintainers. 56 | dnl 57 | AC_DEFUN([AM_GNU_GETTEXT], 58 | [ 59 | dnl Argument checking. 60 | ifelse([$1], [], , [ifelse([$1], [external], , [ifelse([$1], [no-libtool], , [ifelse([$1], [use-libtool], , 61 | [errprint([ERROR: invalid first argument to AM_GNU_GETTEXT 62 | ])])])])]) 63 | ifelse([$2], [], , [ifelse([$2], [need-ngettext], , [ifelse([$2], [need-formatstring-macros], , 64 | [errprint([ERROR: invalid second argument to AM_GNU_GETTEXT 65 | ])])])]) 66 | define([gt_included_intl], 67 | ifelse([$1], [external], 68 | ifdef([AM_GNU_GETTEXT_][INTL_SUBDIR], [yes], [no]), 69 | [yes])) 70 | define([gt_libtool_suffix_prefix], ifelse([$1], [use-libtool], [l], [])) 71 | gt_NEEDS_INIT 72 | AM_GNU_GETTEXT_NEED([$2]) 73 | 74 | AC_REQUIRE([AM_PO_SUBDIRS])dnl 75 | ifelse(gt_included_intl, yes, [ 76 | AC_REQUIRE([AM_INTL_SUBDIR])dnl 77 | ]) 78 | 79 | dnl Prerequisites of AC_LIB_LINKFLAGS_BODY. 80 | AC_REQUIRE([AC_LIB_PREPARE_PREFIX]) 81 | AC_REQUIRE([AC_LIB_RPATH]) 82 | 83 | dnl Sometimes libintl requires libiconv, so first search for libiconv. 84 | dnl Ideally we would do this search only after the 85 | dnl if test "$USE_NLS" = "yes"; then 86 | dnl if { eval "gt_val=\$$gt_func_gnugettext_libc"; test "$gt_val" != "yes"; }; then 87 | dnl tests. But if configure.in invokes AM_ICONV after AM_GNU_GETTEXT 88 | dnl the configure script would need to contain the same shell code 89 | dnl again, outside any 'if'. There are two solutions: 90 | dnl - Invoke AM_ICONV_LINKFLAGS_BODY here, outside any 'if'. 91 | dnl - Control the expansions in more detail using AC_PROVIDE_IFELSE. 92 | dnl Since AC_PROVIDE_IFELSE is only in autoconf >= 2.52 and not 93 | dnl documented, we avoid it. 94 | ifelse(gt_included_intl, yes, , [ 95 | AC_REQUIRE([AM_ICONV_LINKFLAGS_BODY]) 96 | ]) 97 | 98 | dnl Sometimes, on MacOS X, libintl requires linking with CoreFoundation. 99 | gt_INTL_MACOSX 100 | 101 | dnl Set USE_NLS. 102 | AC_REQUIRE([AM_NLS]) 103 | 104 | ifelse(gt_included_intl, yes, [ 105 | BUILD_INCLUDED_LIBINTL=no 106 | USE_INCLUDED_LIBINTL=no 107 | ]) 108 | LIBINTL= 109 | LTLIBINTL= 110 | POSUB= 111 | 112 | dnl Add a version number to the cache macros. 113 | case " $gt_needs " in 114 | *" need-formatstring-macros "*) gt_api_version=3 ;; 115 | *" need-ngettext "*) gt_api_version=2 ;; 116 | *) gt_api_version=1 ;; 117 | esac 118 | gt_func_gnugettext_libc="gt_cv_func_gnugettext${gt_api_version}_libc" 119 | gt_func_gnugettext_libintl="gt_cv_func_gnugettext${gt_api_version}_libintl" 120 | 121 | dnl If we use NLS figure out what method 122 | if test "$USE_NLS" = "yes"; then 123 | gt_use_preinstalled_gnugettext=no 124 | ifelse(gt_included_intl, yes, [ 125 | AC_MSG_CHECKING([whether included gettext is requested]) 126 | AC_ARG_WITH(included-gettext, 127 | [ --with-included-gettext use the GNU gettext library included here], 128 | nls_cv_force_use_gnu_gettext=$withval, 129 | nls_cv_force_use_gnu_gettext=no) 130 | AC_MSG_RESULT($nls_cv_force_use_gnu_gettext) 131 | 132 | nls_cv_use_gnu_gettext="$nls_cv_force_use_gnu_gettext" 133 | if test "$nls_cv_force_use_gnu_gettext" != "yes"; then 134 | ]) 135 | dnl User does not insist on using GNU NLS library. Figure out what 136 | dnl to use. If GNU gettext is available we use this. Else we have 137 | dnl to fall back to GNU NLS library. 138 | 139 | if test $gt_api_version -ge 3; then 140 | gt_revision_test_code=' 141 | #ifndef __GNU_GETTEXT_SUPPORTED_REVISION 142 | #define __GNU_GETTEXT_SUPPORTED_REVISION(major) ((major) == 0 ? 0 : -1) 143 | #endif 144 | changequote(,)dnl 145 | typedef int array [2 * (__GNU_GETTEXT_SUPPORTED_REVISION(0) >= 1) - 1]; 146 | changequote([,])dnl 147 | ' 148 | else 149 | gt_revision_test_code= 150 | fi 151 | if test $gt_api_version -ge 2; then 152 | gt_expression_test_code=' + * ngettext ("", "", 0)' 153 | else 154 | gt_expression_test_code= 155 | fi 156 | 157 | AC_CACHE_CHECK([for GNU gettext in libc], [$gt_func_gnugettext_libc], 158 | [AC_TRY_LINK([#include 159 | $gt_revision_test_code 160 | extern int _nl_msg_cat_cntr; 161 | extern int *_nl_domain_bindings;], 162 | [bindtextdomain ("", ""); 163 | return * gettext ("")$gt_expression_test_code + _nl_msg_cat_cntr + *_nl_domain_bindings], 164 | [eval "$gt_func_gnugettext_libc=yes"], 165 | [eval "$gt_func_gnugettext_libc=no"])]) 166 | 167 | if { eval "gt_val=\$$gt_func_gnugettext_libc"; test "$gt_val" != "yes"; }; then 168 | dnl Sometimes libintl requires libiconv, so first search for libiconv. 169 | ifelse(gt_included_intl, yes, , [ 170 | AM_ICONV_LINK 171 | ]) 172 | dnl Search for libintl and define LIBINTL, LTLIBINTL and INCINTL 173 | dnl accordingly. Don't use AC_LIB_LINKFLAGS_BODY([intl],[iconv]) 174 | dnl because that would add "-liconv" to LIBINTL and LTLIBINTL 175 | dnl even if libiconv doesn't exist. 176 | AC_LIB_LINKFLAGS_BODY([intl]) 177 | AC_CACHE_CHECK([for GNU gettext in libintl], 178 | [$gt_func_gnugettext_libintl], 179 | [gt_save_CPPFLAGS="$CPPFLAGS" 180 | CPPFLAGS="$CPPFLAGS $INCINTL" 181 | gt_save_LIBS="$LIBS" 182 | LIBS="$LIBS $LIBINTL" 183 | dnl Now see whether libintl exists and does not depend on libiconv. 184 | AC_TRY_LINK([#include 185 | $gt_revision_test_code 186 | extern int _nl_msg_cat_cntr; 187 | extern 188 | #ifdef __cplusplus 189 | "C" 190 | #endif 191 | const char *_nl_expand_alias (const char *);], 192 | [bindtextdomain ("", ""); 193 | return * gettext ("")$gt_expression_test_code + _nl_msg_cat_cntr + *_nl_expand_alias ("")], 194 | [eval "$gt_func_gnugettext_libintl=yes"], 195 | [eval "$gt_func_gnugettext_libintl=no"]) 196 | dnl Now see whether libintl exists and depends on libiconv. 197 | if { eval "gt_val=\$$gt_func_gnugettext_libintl"; test "$gt_val" != yes; } && test -n "$LIBICONV"; then 198 | LIBS="$LIBS $LIBICONV" 199 | AC_TRY_LINK([#include 200 | $gt_revision_test_code 201 | extern int _nl_msg_cat_cntr; 202 | extern 203 | #ifdef __cplusplus 204 | "C" 205 | #endif 206 | const char *_nl_expand_alias (const char *);], 207 | [bindtextdomain ("", ""); 208 | return * gettext ("")$gt_expression_test_code + _nl_msg_cat_cntr + *_nl_expand_alias ("")], 209 | [LIBINTL="$LIBINTL $LIBICONV" 210 | LTLIBINTL="$LTLIBINTL $LTLIBICONV" 211 | eval "$gt_func_gnugettext_libintl=yes" 212 | ]) 213 | fi 214 | CPPFLAGS="$gt_save_CPPFLAGS" 215 | LIBS="$gt_save_LIBS"]) 216 | fi 217 | 218 | dnl If an already present or preinstalled GNU gettext() is found, 219 | dnl use it. But if this macro is used in GNU gettext, and GNU 220 | dnl gettext is already preinstalled in libintl, we update this 221 | dnl libintl. (Cf. the install rule in intl/Makefile.in.) 222 | if { eval "gt_val=\$$gt_func_gnugettext_libc"; test "$gt_val" = "yes"; } \ 223 | || { { eval "gt_val=\$$gt_func_gnugettext_libintl"; test "$gt_val" = "yes"; } \ 224 | && test "$PACKAGE" != gettext-runtime \ 225 | && test "$PACKAGE" != gettext-tools; }; then 226 | gt_use_preinstalled_gnugettext=yes 227 | else 228 | dnl Reset the values set by searching for libintl. 229 | LIBINTL= 230 | LTLIBINTL= 231 | INCINTL= 232 | fi 233 | 234 | ifelse(gt_included_intl, yes, [ 235 | if test "$gt_use_preinstalled_gnugettext" != "yes"; then 236 | dnl GNU gettext is not found in the C library. 237 | dnl Fall back on included GNU gettext library. 238 | nls_cv_use_gnu_gettext=yes 239 | fi 240 | fi 241 | 242 | if test "$nls_cv_use_gnu_gettext" = "yes"; then 243 | dnl Mark actions used to generate GNU NLS library. 244 | BUILD_INCLUDED_LIBINTL=yes 245 | USE_INCLUDED_LIBINTL=yes 246 | LIBINTL="ifelse([$3],[],\${top_builddir}/intl,[$3])/libintl.[]gt_libtool_suffix_prefix[]a $LIBICONV $LIBTHREAD" 247 | LTLIBINTL="ifelse([$3],[],\${top_builddir}/intl,[$3])/libintl.[]gt_libtool_suffix_prefix[]a $LTLIBICONV $LTLIBTHREAD" 248 | LIBS=`echo " $LIBS " | sed -e 's/ -lintl / /' -e 's/^ //' -e 's/ $//'` 249 | fi 250 | 251 | CATOBJEXT= 252 | if test "$gt_use_preinstalled_gnugettext" = "yes" \ 253 | || test "$nls_cv_use_gnu_gettext" = "yes"; then 254 | dnl Mark actions to use GNU gettext tools. 255 | CATOBJEXT=.gmo 256 | fi 257 | ]) 258 | 259 | if test -n "$INTL_MACOSX_LIBS"; then 260 | if test "$gt_use_preinstalled_gnugettext" = "yes" \ 261 | || test "$nls_cv_use_gnu_gettext" = "yes"; then 262 | dnl Some extra flags are needed during linking. 263 | LIBINTL="$LIBINTL $INTL_MACOSX_LIBS" 264 | LTLIBINTL="$LTLIBINTL $INTL_MACOSX_LIBS" 265 | fi 266 | fi 267 | 268 | if test "$gt_use_preinstalled_gnugettext" = "yes" \ 269 | || test "$nls_cv_use_gnu_gettext" = "yes"; then 270 | AC_DEFINE(ENABLE_NLS, 1, 271 | [Define to 1 if translation of program messages to the user's native language 272 | is requested.]) 273 | else 274 | USE_NLS=no 275 | fi 276 | fi 277 | 278 | AC_MSG_CHECKING([whether to use NLS]) 279 | AC_MSG_RESULT([$USE_NLS]) 280 | if test "$USE_NLS" = "yes"; then 281 | AC_MSG_CHECKING([where the gettext function comes from]) 282 | if test "$gt_use_preinstalled_gnugettext" = "yes"; then 283 | if { eval "gt_val=\$$gt_func_gnugettext_libintl"; test "$gt_val" = "yes"; }; then 284 | gt_source="external libintl" 285 | else 286 | gt_source="libc" 287 | fi 288 | else 289 | gt_source="included intl directory" 290 | fi 291 | AC_MSG_RESULT([$gt_source]) 292 | fi 293 | 294 | if test "$USE_NLS" = "yes"; then 295 | 296 | if test "$gt_use_preinstalled_gnugettext" = "yes"; then 297 | if { eval "gt_val=\$$gt_func_gnugettext_libintl"; test "$gt_val" = "yes"; }; then 298 | AC_MSG_CHECKING([how to link with libintl]) 299 | AC_MSG_RESULT([$LIBINTL]) 300 | AC_LIB_APPENDTOVAR([CPPFLAGS], [$INCINTL]) 301 | fi 302 | 303 | dnl For backward compatibility. Some packages may be using this. 304 | AC_DEFINE(HAVE_GETTEXT, 1, 305 | [Define if the GNU gettext() function is already present or preinstalled.]) 306 | AC_DEFINE(HAVE_DCGETTEXT, 1, 307 | [Define if the GNU dcgettext() function is already present or preinstalled.]) 308 | fi 309 | 310 | dnl We need to process the po/ directory. 311 | POSUB=po 312 | fi 313 | 314 | ifelse(gt_included_intl, yes, [ 315 | dnl If this is used in GNU gettext we have to set BUILD_INCLUDED_LIBINTL 316 | dnl to 'yes' because some of the testsuite requires it. 317 | if test "$PACKAGE" = gettext-runtime || test "$PACKAGE" = gettext-tools; then 318 | BUILD_INCLUDED_LIBINTL=yes 319 | fi 320 | 321 | dnl Make all variables we use known to autoconf. 322 | AC_SUBST(BUILD_INCLUDED_LIBINTL) 323 | AC_SUBST(USE_INCLUDED_LIBINTL) 324 | AC_SUBST(CATOBJEXT) 325 | 326 | dnl For backward compatibility. Some configure.ins may be using this. 327 | nls_cv_header_intl= 328 | nls_cv_header_libgt= 329 | 330 | dnl For backward compatibility. Some Makefiles may be using this. 331 | DATADIRNAME=share 332 | AC_SUBST(DATADIRNAME) 333 | 334 | dnl For backward compatibility. Some Makefiles may be using this. 335 | INSTOBJEXT=.mo 336 | AC_SUBST(INSTOBJEXT) 337 | 338 | dnl For backward compatibility. Some Makefiles may be using this. 339 | GENCAT=gencat 340 | AC_SUBST(GENCAT) 341 | 342 | dnl For backward compatibility. Some Makefiles may be using this. 343 | INTLOBJS= 344 | if test "$USE_INCLUDED_LIBINTL" = yes; then 345 | INTLOBJS="\$(GETTOBJS)" 346 | fi 347 | AC_SUBST(INTLOBJS) 348 | 349 | dnl Enable libtool support if the surrounding package wishes it. 350 | INTL_LIBTOOL_SUFFIX_PREFIX=gt_libtool_suffix_prefix 351 | AC_SUBST(INTL_LIBTOOL_SUFFIX_PREFIX) 352 | ]) 353 | 354 | dnl For backward compatibility. Some Makefiles may be using this. 355 | INTLLIBS="$LIBINTL" 356 | AC_SUBST(INTLLIBS) 357 | 358 | dnl Make all documented variables known to autoconf. 359 | AC_SUBST(LIBINTL) 360 | AC_SUBST(LTLIBINTL) 361 | AC_SUBST(POSUB) 362 | ]) 363 | 364 | 365 | dnl gt_NEEDS_INIT ensures that the gt_needs variable is initialized. 366 | m4_define([gt_NEEDS_INIT], 367 | [ 368 | m4_divert_text([DEFAULTS], [gt_needs=]) 369 | m4_define([gt_NEEDS_INIT], []) 370 | ]) 371 | 372 | 373 | dnl Usage: AM_GNU_GETTEXT_NEED([NEEDSYMBOL]) 374 | AC_DEFUN([AM_GNU_GETTEXT_NEED], 375 | [ 376 | m4_divert_text([INIT_PREPARE], [gt_needs="$gt_needs $1"]) 377 | ]) 378 | 379 | 380 | dnl Usage: AM_GNU_GETTEXT_VERSION([gettext-version]) 381 | AC_DEFUN([AM_GNU_GETTEXT_VERSION], []) 382 | -------------------------------------------------------------------------------- /m4/glibc2.m4: -------------------------------------------------------------------------------- 1 | # glibc2.m4 serial 1 2 | dnl Copyright (C) 2000-2002, 2004 Free Software Foundation, Inc. 3 | dnl This file is free software; the Free Software Foundation 4 | dnl gives unlimited permission to copy and/or distribute it, 5 | dnl with or without modifications, as long as this notice is preserved. 6 | 7 | # Test for the GNU C Library, version 2.0 or newer. 8 | # From Bruno Haible. 9 | 10 | AC_DEFUN([gt_GLIBC2], 11 | [ 12 | AC_CACHE_CHECK(whether we are using the GNU C Library 2 or newer, 13 | ac_cv_gnu_library_2, 14 | [AC_EGREP_CPP([Lucky GNU user], 15 | [ 16 | #include 17 | #ifdef __GNU_LIBRARY__ 18 | #if (__GLIBC__ >= 2) 19 | Lucky GNU user 20 | #endif 21 | #endif 22 | ], 23 | ac_cv_gnu_library_2=yes, 24 | ac_cv_gnu_library_2=no) 25 | ] 26 | ) 27 | AC_SUBST(GLIBC2) 28 | GLIBC2="$ac_cv_gnu_library_2" 29 | ] 30 | ) 31 | -------------------------------------------------------------------------------- /m4/glibc21.m4: -------------------------------------------------------------------------------- 1 | # glibc21.m4 serial 3 2 | dnl Copyright (C) 2000-2002, 2004 Free Software Foundation, Inc. 3 | dnl This file is free software; the Free Software Foundation 4 | dnl gives unlimited permission to copy and/or distribute it, 5 | dnl with or without modifications, as long as this notice is preserved. 6 | 7 | # Test for the GNU C Library, version 2.1 or newer. 8 | # From Bruno Haible. 9 | 10 | AC_DEFUN([gl_GLIBC21], 11 | [ 12 | AC_CACHE_CHECK(whether we are using the GNU C Library 2.1 or newer, 13 | ac_cv_gnu_library_2_1, 14 | [AC_EGREP_CPP([Lucky GNU user], 15 | [ 16 | #include 17 | #ifdef __GNU_LIBRARY__ 18 | #if (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 1) || (__GLIBC__ > 2) 19 | Lucky GNU user 20 | #endif 21 | #endif 22 | ], 23 | ac_cv_gnu_library_2_1=yes, 24 | ac_cv_gnu_library_2_1=no) 25 | ] 26 | ) 27 | AC_SUBST(GLIBC21) 28 | GLIBC21="$ac_cv_gnu_library_2_1" 29 | ] 30 | ) 31 | -------------------------------------------------------------------------------- /m4/iconv.m4: -------------------------------------------------------------------------------- 1 | # iconv.m4 serial AM6 (gettext-0.17) 2 | dnl Copyright (C) 2000-2002, 2007 Free Software Foundation, Inc. 3 | dnl This file is free software; the Free Software Foundation 4 | dnl gives unlimited permission to copy and/or distribute it, 5 | dnl with or without modifications, as long as this notice is preserved. 6 | 7 | dnl From Bruno Haible. 8 | 9 | AC_DEFUN([AM_ICONV_LINKFLAGS_BODY], 10 | [ 11 | dnl Prerequisites of AC_LIB_LINKFLAGS_BODY. 12 | AC_REQUIRE([AC_LIB_PREPARE_PREFIX]) 13 | AC_REQUIRE([AC_LIB_RPATH]) 14 | 15 | dnl Search for libiconv and define LIBICONV, LTLIBICONV and INCICONV 16 | dnl accordingly. 17 | AC_LIB_LINKFLAGS_BODY([iconv]) 18 | ]) 19 | 20 | AC_DEFUN([AM_ICONV_LINK], 21 | [ 22 | dnl Some systems have iconv in libc, some have it in libiconv (OSF/1 and 23 | dnl those with the standalone portable GNU libiconv installed). 24 | AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles 25 | 26 | dnl Search for libiconv and define LIBICONV, LTLIBICONV and INCICONV 27 | dnl accordingly. 28 | AC_REQUIRE([AM_ICONV_LINKFLAGS_BODY]) 29 | 30 | dnl Add $INCICONV to CPPFLAGS before performing the following checks, 31 | dnl because if the user has installed libiconv and not disabled its use 32 | dnl via --without-libiconv-prefix, he wants to use it. The first 33 | dnl AC_TRY_LINK will then fail, the second AC_TRY_LINK will succeed. 34 | am_save_CPPFLAGS="$CPPFLAGS" 35 | AC_LIB_APPENDTOVAR([CPPFLAGS], [$INCICONV]) 36 | 37 | AC_CACHE_CHECK([for iconv], am_cv_func_iconv, [ 38 | am_cv_func_iconv="no, consider installing GNU libiconv" 39 | am_cv_lib_iconv=no 40 | AC_TRY_LINK([#include 41 | #include ], 42 | [iconv_t cd = iconv_open("",""); 43 | iconv(cd,NULL,NULL,NULL,NULL); 44 | iconv_close(cd);], 45 | am_cv_func_iconv=yes) 46 | if test "$am_cv_func_iconv" != yes; then 47 | am_save_LIBS="$LIBS" 48 | LIBS="$LIBS $LIBICONV" 49 | AC_TRY_LINK([#include 50 | #include ], 51 | [iconv_t cd = iconv_open("",""); 52 | iconv(cd,NULL,NULL,NULL,NULL); 53 | iconv_close(cd);], 54 | am_cv_lib_iconv=yes 55 | am_cv_func_iconv=yes) 56 | LIBS="$am_save_LIBS" 57 | fi 58 | ]) 59 | if test "$am_cv_func_iconv" = yes; then 60 | AC_CACHE_CHECK([for working iconv], am_cv_func_iconv_works, [ 61 | dnl This tests against bugs in AIX 5.1 and HP-UX 11.11. 62 | am_save_LIBS="$LIBS" 63 | if test $am_cv_lib_iconv = yes; then 64 | LIBS="$LIBS $LIBICONV" 65 | fi 66 | AC_TRY_RUN([ 67 | #include 68 | #include 69 | int main () 70 | { 71 | /* Test against AIX 5.1 bug: Failures are not distinguishable from successful 72 | returns. */ 73 | { 74 | iconv_t cd_utf8_to_88591 = iconv_open ("ISO8859-1", "UTF-8"); 75 | if (cd_utf8_to_88591 != (iconv_t)(-1)) 76 | { 77 | static const char input[] = "\342\202\254"; /* EURO SIGN */ 78 | char buf[10]; 79 | const char *inptr = input; 80 | size_t inbytesleft = strlen (input); 81 | char *outptr = buf; 82 | size_t outbytesleft = sizeof (buf); 83 | size_t res = iconv (cd_utf8_to_88591, 84 | (char **) &inptr, &inbytesleft, 85 | &outptr, &outbytesleft); 86 | if (res == 0) 87 | return 1; 88 | } 89 | } 90 | #if 0 /* This bug could be worked around by the caller. */ 91 | /* Test against HP-UX 11.11 bug: Positive return value instead of 0. */ 92 | { 93 | iconv_t cd_88591_to_utf8 = iconv_open ("utf8", "iso88591"); 94 | if (cd_88591_to_utf8 != (iconv_t)(-1)) 95 | { 96 | static const char input[] = "\304rger mit b\366sen B\374bchen ohne Augenma\337"; 97 | char buf[50]; 98 | const char *inptr = input; 99 | size_t inbytesleft = strlen (input); 100 | char *outptr = buf; 101 | size_t outbytesleft = sizeof (buf); 102 | size_t res = iconv (cd_88591_to_utf8, 103 | (char **) &inptr, &inbytesleft, 104 | &outptr, &outbytesleft); 105 | if ((int)res > 0) 106 | return 1; 107 | } 108 | } 109 | #endif 110 | /* Test against HP-UX 11.11 bug: No converter from EUC-JP to UTF-8 is 111 | provided. */ 112 | if (/* Try standardized names. */ 113 | iconv_open ("UTF-8", "EUC-JP") == (iconv_t)(-1) 114 | /* Try IRIX, OSF/1 names. */ 115 | && iconv_open ("UTF-8", "eucJP") == (iconv_t)(-1) 116 | /* Try AIX names. */ 117 | && iconv_open ("UTF-8", "IBM-eucJP") == (iconv_t)(-1) 118 | /* Try HP-UX names. */ 119 | && iconv_open ("utf8", "eucJP") == (iconv_t)(-1)) 120 | return 1; 121 | return 0; 122 | }], [am_cv_func_iconv_works=yes], [am_cv_func_iconv_works=no], 123 | [case "$host_os" in 124 | aix* | hpux*) am_cv_func_iconv_works="guessing no" ;; 125 | *) am_cv_func_iconv_works="guessing yes" ;; 126 | esac]) 127 | LIBS="$am_save_LIBS" 128 | ]) 129 | case "$am_cv_func_iconv_works" in 130 | *no) am_func_iconv=no am_cv_lib_iconv=no ;; 131 | *) am_func_iconv=yes ;; 132 | esac 133 | else 134 | am_func_iconv=no am_cv_lib_iconv=no 135 | fi 136 | if test "$am_func_iconv" = yes; then 137 | AC_DEFINE(HAVE_ICONV, 1, 138 | [Define if you have the iconv() function and it works.]) 139 | fi 140 | if test "$am_cv_lib_iconv" = yes; then 141 | AC_MSG_CHECKING([how to link with libiconv]) 142 | AC_MSG_RESULT([$LIBICONV]) 143 | else 144 | dnl If $LIBICONV didn't lead to a usable library, we don't need $INCICONV 145 | dnl either. 146 | CPPFLAGS="$am_save_CPPFLAGS" 147 | LIBICONV= 148 | LTLIBICONV= 149 | fi 150 | AC_SUBST(LIBICONV) 151 | AC_SUBST(LTLIBICONV) 152 | ]) 153 | 154 | AC_DEFUN([AM_ICONV], 155 | [ 156 | AM_ICONV_LINK 157 | if test "$am_cv_func_iconv" = yes; then 158 | AC_MSG_CHECKING([for iconv declaration]) 159 | AC_CACHE_VAL(am_cv_proto_iconv, [ 160 | AC_TRY_COMPILE([ 161 | #include 162 | #include 163 | extern 164 | #ifdef __cplusplus 165 | "C" 166 | #endif 167 | #if defined(__STDC__) || defined(__cplusplus) 168 | size_t iconv (iconv_t cd, char * *inbuf, size_t *inbytesleft, char * *outbuf, size_t *outbytesleft); 169 | #else 170 | size_t iconv(); 171 | #endif 172 | ], [], am_cv_proto_iconv_arg1="", am_cv_proto_iconv_arg1="const") 173 | am_cv_proto_iconv="extern size_t iconv (iconv_t cd, $am_cv_proto_iconv_arg1 char * *inbuf, size_t *inbytesleft, char * *outbuf, size_t *outbytesleft);"]) 174 | am_cv_proto_iconv=`echo "[$]am_cv_proto_iconv" | tr -s ' ' | sed -e 's/( /(/'` 175 | AC_MSG_RESULT([$]{ac_t:- 176 | }[$]am_cv_proto_iconv) 177 | AC_DEFINE_UNQUOTED(ICONV_CONST, $am_cv_proto_iconv_arg1, 178 | [Define as const if the declaration of iconv() needs const.]) 179 | fi 180 | ]) 181 | -------------------------------------------------------------------------------- /m4/intdiv0.m4: -------------------------------------------------------------------------------- 1 | # intdiv0.m4 serial 2 (gettext-0.17) 2 | dnl Copyright (C) 2002, 2007 Free Software Foundation, Inc. 3 | dnl This file is free software; the Free Software Foundation 4 | dnl gives unlimited permission to copy and/or distribute it, 5 | dnl with or without modifications, as long as this notice is preserved. 6 | 7 | dnl From Bruno Haible. 8 | 9 | AC_DEFUN([gt_INTDIV0], 10 | [ 11 | AC_REQUIRE([AC_PROG_CC])dnl 12 | AC_REQUIRE([AC_CANONICAL_HOST])dnl 13 | 14 | AC_CACHE_CHECK([whether integer division by zero raises SIGFPE], 15 | gt_cv_int_divbyzero_sigfpe, 16 | [ 17 | gt_cv_int_divbyzero_sigfpe= 18 | changequote(,)dnl 19 | case "$host_os" in 20 | macos* | darwin[6-9]* | darwin[1-9][0-9]*) 21 | # On MacOS X 10.2 or newer, just assume the same as when cross- 22 | # compiling. If we were to perform the real test, 1 Crash Report 23 | # dialog window would pop up. 24 | case "$host_cpu" in 25 | i[34567]86 | x86_64) 26 | gt_cv_int_divbyzero_sigfpe="guessing yes" ;; 27 | esac 28 | ;; 29 | esac 30 | changequote([,])dnl 31 | if test -z "$gt_cv_int_divbyzero_sigfpe"; then 32 | AC_TRY_RUN([ 33 | #include 34 | #include 35 | 36 | static void 37 | sigfpe_handler (int sig) 38 | { 39 | /* Exit with code 0 if SIGFPE, with code 1 if any other signal. */ 40 | exit (sig != SIGFPE); 41 | } 42 | 43 | int x = 1; 44 | int y = 0; 45 | int z; 46 | int nan; 47 | 48 | int main () 49 | { 50 | signal (SIGFPE, sigfpe_handler); 51 | /* IRIX and AIX (when "xlc -qcheck" is used) yield signal SIGTRAP. */ 52 | #if (defined (__sgi) || defined (_AIX)) && defined (SIGTRAP) 53 | signal (SIGTRAP, sigfpe_handler); 54 | #endif 55 | /* Linux/SPARC yields signal SIGILL. */ 56 | #if defined (__sparc__) && defined (__linux__) 57 | signal (SIGILL, sigfpe_handler); 58 | #endif 59 | 60 | z = x / y; 61 | nan = y / y; 62 | exit (1); 63 | } 64 | ], gt_cv_int_divbyzero_sigfpe=yes, gt_cv_int_divbyzero_sigfpe=no, 65 | [ 66 | # Guess based on the CPU. 67 | changequote(,)dnl 68 | case "$host_cpu" in 69 | alpha* | i[34567]86 | x86_64 | m68k | s390*) 70 | gt_cv_int_divbyzero_sigfpe="guessing yes";; 71 | *) 72 | gt_cv_int_divbyzero_sigfpe="guessing no";; 73 | esac 74 | changequote([,])dnl 75 | ]) 76 | fi 77 | ]) 78 | case "$gt_cv_int_divbyzero_sigfpe" in 79 | *yes) value=1;; 80 | *) value=0;; 81 | esac 82 | AC_DEFINE_UNQUOTED(INTDIV0_RAISES_SIGFPE, $value, 83 | [Define if integer division by zero raises signal SIGFPE.]) 84 | ]) 85 | -------------------------------------------------------------------------------- /m4/intl.m4: -------------------------------------------------------------------------------- 1 | # intl.m4 serial 8 (gettext-0.17) 2 | dnl Copyright (C) 1995-2007 Free Software Foundation, Inc. 3 | dnl This file is free software; the Free Software Foundation 4 | dnl gives unlimited permission to copy and/or distribute it, 5 | dnl with or without modifications, as long as this notice is preserved. 6 | dnl 7 | dnl This file can can be used in projects which are not available under 8 | dnl the GNU General Public License or the GNU Library General Public 9 | dnl License but which still want to provide support for the GNU gettext 10 | dnl functionality. 11 | dnl Please note that the actual code of the GNU gettext library is covered 12 | dnl by the GNU Library General Public License, and the rest of the GNU 13 | dnl gettext package package is covered by the GNU General Public License. 14 | dnl They are *not* in the public domain. 15 | 16 | dnl Authors: 17 | dnl Ulrich Drepper , 1995-2000. 18 | dnl Bruno Haible , 2000-2006. 19 | 20 | AC_PREREQ(2.52) 21 | 22 | dnl Checks for all prerequisites of the intl subdirectory, 23 | dnl except for INTL_LIBTOOL_SUFFIX_PREFIX (and possibly LIBTOOL), INTLOBJS, 24 | dnl USE_INCLUDED_LIBINTL, BUILD_INCLUDED_LIBINTL. 25 | AC_DEFUN([AM_INTL_SUBDIR], 26 | [ 27 | AC_REQUIRE([AC_PROG_INSTALL])dnl 28 | AC_REQUIRE([AM_PROG_MKDIR_P])dnl defined by automake 29 | AC_REQUIRE([AC_PROG_CC])dnl 30 | AC_REQUIRE([AC_CANONICAL_HOST])dnl 31 | AC_REQUIRE([gt_GLIBC2])dnl 32 | AC_REQUIRE([AC_PROG_RANLIB])dnl 33 | AC_REQUIRE([gl_VISIBILITY])dnl 34 | AC_REQUIRE([gt_INTL_SUBDIR_CORE])dnl 35 | AC_REQUIRE([AC_TYPE_LONG_LONG_INT])dnl 36 | AC_REQUIRE([gt_TYPE_WCHAR_T])dnl 37 | AC_REQUIRE([gt_TYPE_WINT_T])dnl 38 | AC_REQUIRE([gl_AC_HEADER_INTTYPES_H]) 39 | AC_REQUIRE([gt_TYPE_INTMAX_T]) 40 | AC_REQUIRE([gt_PRINTF_POSIX]) 41 | AC_REQUIRE([gl_GLIBC21])dnl 42 | AC_REQUIRE([gl_XSIZE])dnl 43 | AC_REQUIRE([gt_INTL_MACOSX])dnl 44 | 45 | AC_CHECK_TYPE([ptrdiff_t], , 46 | [AC_DEFINE([ptrdiff_t], [long], 47 | [Define as the type of the result of subtracting two pointers, if the system doesn't define it.]) 48 | ]) 49 | AC_CHECK_HEADERS([stddef.h stdlib.h string.h]) 50 | AC_CHECK_FUNCS([asprintf fwprintf putenv setenv setlocale snprintf wcslen]) 51 | 52 | dnl Use the _snprintf function only if it is declared (because on NetBSD it 53 | dnl is defined as a weak alias of snprintf; we prefer to use the latter). 54 | gt_CHECK_DECL(_snprintf, [#include ]) 55 | gt_CHECK_DECL(_snwprintf, [#include ]) 56 | 57 | dnl Use the *_unlocked functions only if they are declared. 58 | dnl (because some of them were defined without being declared in Solaris 59 | dnl 2.5.1 but were removed in Solaris 2.6, whereas we want binaries built 60 | dnl on Solaris 2.5.1 to run on Solaris 2.6). 61 | dnl Don't use AC_CHECK_DECLS because it isn't supported in autoconf-2.13. 62 | gt_CHECK_DECL(getc_unlocked, [#include ]) 63 | 64 | case $gt_cv_func_printf_posix in 65 | *yes) HAVE_POSIX_PRINTF=1 ;; 66 | *) HAVE_POSIX_PRINTF=0 ;; 67 | esac 68 | AC_SUBST([HAVE_POSIX_PRINTF]) 69 | if test "$ac_cv_func_asprintf" = yes; then 70 | HAVE_ASPRINTF=1 71 | else 72 | HAVE_ASPRINTF=0 73 | fi 74 | AC_SUBST([HAVE_ASPRINTF]) 75 | if test "$ac_cv_func_snprintf" = yes; then 76 | HAVE_SNPRINTF=1 77 | else 78 | HAVE_SNPRINTF=0 79 | fi 80 | AC_SUBST([HAVE_SNPRINTF]) 81 | if test "$ac_cv_func_wprintf" = yes; then 82 | HAVE_WPRINTF=1 83 | else 84 | HAVE_WPRINTF=0 85 | fi 86 | AC_SUBST([HAVE_WPRINTF]) 87 | 88 | AM_LANGINFO_CODESET 89 | gt_LC_MESSAGES 90 | 91 | dnl Compilation on mingw and Cygwin needs special Makefile rules, because 92 | dnl 1. when we install a shared library, we must arrange to export 93 | dnl auxiliary pointer variables for every exported variable, 94 | dnl 2. when we install a shared library and a static library simultaneously, 95 | dnl the include file specifies __declspec(dllimport) and therefore we 96 | dnl must arrange to define the auxiliary pointer variables for the 97 | dnl exported variables _also_ in the static library. 98 | if test "$enable_shared" = yes; then 99 | case "$host_os" in 100 | mingw* | cygwin*) is_woe32dll=yes ;; 101 | *) is_woe32dll=no ;; 102 | esac 103 | else 104 | is_woe32dll=no 105 | fi 106 | WOE32DLL=$is_woe32dll 107 | AC_SUBST([WOE32DLL]) 108 | 109 | dnl On mingw and Cygwin, we can activate special Makefile rules which add 110 | dnl version information to the shared libraries and executables. 111 | case "$host_os" in 112 | mingw* | cygwin*) is_woe32=yes ;; 113 | *) is_woe32=no ;; 114 | esac 115 | WOE32=$is_woe32 116 | AC_SUBST([WOE32]) 117 | if test $WOE32 = yes; then 118 | dnl Check for a program that compiles Windows resource files. 119 | AC_CHECK_TOOL([WINDRES], [windres]) 120 | fi 121 | 122 | dnl Determine whether when creating a library, "-lc" should be passed to 123 | dnl libtool or not. On many platforms, it is required for the libtool option 124 | dnl -no-undefined to work. On HP-UX, however, the -lc - stored by libtool 125 | dnl in the *.la files - makes it impossible to create multithreaded programs, 126 | dnl because libtool also reorders the -lc to come before the -pthread, and 127 | dnl this disables pthread_create() . 128 | case "$host_os" in 129 | hpux*) LTLIBC="" ;; 130 | *) LTLIBC="-lc" ;; 131 | esac 132 | AC_SUBST([LTLIBC]) 133 | 134 | dnl Rename some macros and functions used for locking. 135 | AH_BOTTOM([ 136 | #define __libc_lock_t gl_lock_t 137 | #define __libc_lock_define gl_lock_define 138 | #define __libc_lock_define_initialized gl_lock_define_initialized 139 | #define __libc_lock_init gl_lock_init 140 | #define __libc_lock_lock gl_lock_lock 141 | #define __libc_lock_unlock gl_lock_unlock 142 | #define __libc_lock_recursive_t gl_recursive_lock_t 143 | #define __libc_lock_define_recursive gl_recursive_lock_define 144 | #define __libc_lock_define_initialized_recursive gl_recursive_lock_define_initialized 145 | #define __libc_lock_init_recursive gl_recursive_lock_init 146 | #define __libc_lock_lock_recursive gl_recursive_lock_lock 147 | #define __libc_lock_unlock_recursive gl_recursive_lock_unlock 148 | #define glthread_in_use libintl_thread_in_use 149 | #define glthread_lock_init libintl_lock_init 150 | #define glthread_lock_lock libintl_lock_lock 151 | #define glthread_lock_unlock libintl_lock_unlock 152 | #define glthread_lock_destroy libintl_lock_destroy 153 | #define glthread_rwlock_init libintl_rwlock_init 154 | #define glthread_rwlock_rdlock libintl_rwlock_rdlock 155 | #define glthread_rwlock_wrlock libintl_rwlock_wrlock 156 | #define glthread_rwlock_unlock libintl_rwlock_unlock 157 | #define glthread_rwlock_destroy libintl_rwlock_destroy 158 | #define glthread_recursive_lock_init libintl_recursive_lock_init 159 | #define glthread_recursive_lock_lock libintl_recursive_lock_lock 160 | #define glthread_recursive_lock_unlock libintl_recursive_lock_unlock 161 | #define glthread_recursive_lock_destroy libintl_recursive_lock_destroy 162 | #define glthread_once libintl_once 163 | #define glthread_once_call libintl_once_call 164 | #define glthread_once_singlethreaded libintl_once_singlethreaded 165 | ]) 166 | ]) 167 | 168 | 169 | dnl Checks for the core files of the intl subdirectory: 170 | dnl dcigettext.c 171 | dnl eval-plural.h 172 | dnl explodename.c 173 | dnl finddomain.c 174 | dnl gettextP.h 175 | dnl gmo.h 176 | dnl hash-string.h hash-string.c 177 | dnl l10nflist.c 178 | dnl libgnuintl.h.in (except the *printf stuff) 179 | dnl loadinfo.h 180 | dnl loadmsgcat.c 181 | dnl localealias.c 182 | dnl log.c 183 | dnl plural-exp.h plural-exp.c 184 | dnl plural.y 185 | dnl Used by libglocale. 186 | AC_DEFUN([gt_INTL_SUBDIR_CORE], 187 | [ 188 | AC_REQUIRE([AC_C_INLINE])dnl 189 | AC_REQUIRE([AC_TYPE_SIZE_T])dnl 190 | AC_REQUIRE([gl_AC_HEADER_STDINT_H]) 191 | AC_REQUIRE([AC_FUNC_ALLOCA])dnl 192 | AC_REQUIRE([AC_FUNC_MMAP])dnl 193 | AC_REQUIRE([gt_INTDIV0])dnl 194 | AC_REQUIRE([gl_AC_TYPE_UINTMAX_T])dnl 195 | AC_REQUIRE([gt_INTTYPES_PRI])dnl 196 | AC_REQUIRE([gl_LOCK])dnl 197 | 198 | AC_TRY_LINK( 199 | [int foo (int a) { a = __builtin_expect (a, 10); return a == 10 ? 0 : 1; }], 200 | [], 201 | [AC_DEFINE([HAVE_BUILTIN_EXPECT], 1, 202 | [Define to 1 if the compiler understands __builtin_expect.])]) 203 | 204 | AC_CHECK_HEADERS([argz.h inttypes.h limits.h unistd.h sys/param.h]) 205 | AC_CHECK_FUNCS([getcwd getegid geteuid getgid getuid mempcpy munmap \ 206 | stpcpy strcasecmp strdup strtoul tsearch argz_count argz_stringify \ 207 | argz_next __fsetlocking]) 208 | 209 | dnl Use the *_unlocked functions only if they are declared. 210 | dnl (because some of them were defined without being declared in Solaris 211 | dnl 2.5.1 but were removed in Solaris 2.6, whereas we want binaries built 212 | dnl on Solaris 2.5.1 to run on Solaris 2.6). 213 | dnl Don't use AC_CHECK_DECLS because it isn't supported in autoconf-2.13. 214 | gt_CHECK_DECL(feof_unlocked, [#include ]) 215 | gt_CHECK_DECL(fgets_unlocked, [#include ]) 216 | 217 | AM_ICONV 218 | 219 | dnl glibc >= 2.4 has a NL_LOCALE_NAME macro when _GNU_SOURCE is defined, 220 | dnl and a _NL_LOCALE_NAME macro always. 221 | AC_CACHE_CHECK([for NL_LOCALE_NAME macro], gt_cv_nl_locale_name, 222 | [AC_TRY_LINK([#include 223 | #include ], 224 | [char* cs = nl_langinfo(_NL_LOCALE_NAME(LC_MESSAGES)); 225 | return !cs; 226 | ], 227 | gt_cv_nl_locale_name=yes, 228 | gt_cv_nl_locale_name=no) 229 | ]) 230 | if test $gt_cv_nl_locale_name = yes; then 231 | AC_DEFINE(HAVE_NL_LOCALE_NAME, 1, 232 | [Define if you have and it defines the NL_LOCALE_NAME macro if _GNU_SOURCE is defined.]) 233 | fi 234 | 235 | dnl intl/plural.c is generated from intl/plural.y. It requires bison, 236 | dnl because plural.y uses bison specific features. It requires at least 237 | dnl bison-1.26 because earlier versions generate a plural.c that doesn't 238 | dnl compile. 239 | dnl bison is only needed for the maintainer (who touches plural.y). But in 240 | dnl order to avoid separate Makefiles or --enable-maintainer-mode, we put 241 | dnl the rule in general Makefile. Now, some people carelessly touch the 242 | dnl files or have a broken "make" program, hence the plural.c rule will 243 | dnl sometimes fire. To avoid an error, defines BISON to ":" if it is not 244 | dnl present or too old. 245 | AC_CHECK_PROGS([INTLBISON], [bison]) 246 | if test -z "$INTLBISON"; then 247 | ac_verc_fail=yes 248 | else 249 | dnl Found it, now check the version. 250 | AC_MSG_CHECKING([version of bison]) 251 | changequote(<<,>>)dnl 252 | ac_prog_version=`$INTLBISON --version 2>&1 | sed -n 's/^.*GNU Bison.* \([0-9]*\.[0-9.]*\).*$/\1/p'` 253 | case $ac_prog_version in 254 | '') ac_prog_version="v. ?.??, bad"; ac_verc_fail=yes;; 255 | 1.2[6-9]* | 1.[3-9][0-9]* | [2-9].*) 256 | changequote([,])dnl 257 | ac_prog_version="$ac_prog_version, ok"; ac_verc_fail=no;; 258 | *) ac_prog_version="$ac_prog_version, bad"; ac_verc_fail=yes;; 259 | esac 260 | AC_MSG_RESULT([$ac_prog_version]) 261 | fi 262 | if test $ac_verc_fail = yes; then 263 | INTLBISON=: 264 | fi 265 | ]) 266 | 267 | 268 | dnl gt_CHECK_DECL(FUNC, INCLUDES) 269 | dnl Check whether a function is declared. 270 | AC_DEFUN([gt_CHECK_DECL], 271 | [ 272 | AC_CACHE_CHECK([whether $1 is declared], ac_cv_have_decl_$1, 273 | [AC_TRY_COMPILE([$2], [ 274 | #ifndef $1 275 | char *p = (char *) $1; 276 | #endif 277 | ], ac_cv_have_decl_$1=yes, ac_cv_have_decl_$1=no)]) 278 | if test $ac_cv_have_decl_$1 = yes; then 279 | gt_value=1 280 | else 281 | gt_value=0 282 | fi 283 | AC_DEFINE_UNQUOTED([HAVE_DECL_]translit($1, [a-z], [A-Z]), [$gt_value], 284 | [Define to 1 if you have the declaration of `$1', and to 0 if you don't.]) 285 | ]) 286 | -------------------------------------------------------------------------------- /m4/intldir.m4: -------------------------------------------------------------------------------- 1 | # intldir.m4 serial 1 (gettext-0.16) 2 | dnl Copyright (C) 2006 Free Software Foundation, Inc. 3 | dnl This file is free software; the Free Software Foundation 4 | dnl gives unlimited permission to copy and/or distribute it, 5 | dnl with or without modifications, as long as this notice is preserved. 6 | dnl 7 | dnl This file can can be used in projects which are not available under 8 | dnl the GNU General Public License or the GNU Library General Public 9 | dnl License but which still want to provide support for the GNU gettext 10 | dnl functionality. 11 | dnl Please note that the actual code of the GNU gettext library is covered 12 | dnl by the GNU Library General Public License, and the rest of the GNU 13 | dnl gettext package package is covered by the GNU General Public License. 14 | dnl They are *not* in the public domain. 15 | 16 | AC_PREREQ(2.52) 17 | 18 | dnl Tells the AM_GNU_GETTEXT macro to consider an intl/ directory. 19 | AC_DEFUN([AM_GNU_GETTEXT_INTL_SUBDIR], []) 20 | -------------------------------------------------------------------------------- /m4/intlmacosx.m4: -------------------------------------------------------------------------------- 1 | # intlmacosx.m4 serial 1 (gettext-0.17) 2 | dnl Copyright (C) 2004-2007 Free Software Foundation, Inc. 3 | dnl This file is free software; the Free Software Foundation 4 | dnl gives unlimited permission to copy and/or distribute it, 5 | dnl with or without modifications, as long as this notice is preserved. 6 | dnl 7 | dnl This file can can be used in projects which are not available under 8 | dnl the GNU General Public License or the GNU Library General Public 9 | dnl License but which still want to provide support for the GNU gettext 10 | dnl functionality. 11 | dnl Please note that the actual code of the GNU gettext library is covered 12 | dnl by the GNU Library General Public License, and the rest of the GNU 13 | dnl gettext package package is covered by the GNU General Public License. 14 | dnl They are *not* in the public domain. 15 | 16 | dnl Checks for special options needed on MacOS X. 17 | dnl Defines INTL_MACOSX_LIBS. 18 | AC_DEFUN([gt_INTL_MACOSX], 19 | [ 20 | dnl Check for API introduced in MacOS X 10.2. 21 | AC_CACHE_CHECK([for CFPreferencesCopyAppValue], 22 | gt_cv_func_CFPreferencesCopyAppValue, 23 | [gt_save_LIBS="$LIBS" 24 | LIBS="$LIBS -Wl,-framework -Wl,CoreFoundation" 25 | AC_TRY_LINK([#include ], 26 | [CFPreferencesCopyAppValue(NULL, NULL)], 27 | [gt_cv_func_CFPreferencesCopyAppValue=yes], 28 | [gt_cv_func_CFPreferencesCopyAppValue=no]) 29 | LIBS="$gt_save_LIBS"]) 30 | if test $gt_cv_func_CFPreferencesCopyAppValue = yes; then 31 | AC_DEFINE([HAVE_CFPREFERENCESCOPYAPPVALUE], 1, 32 | [Define to 1 if you have the MacOS X function CFPreferencesCopyAppValue in the CoreFoundation framework.]) 33 | fi 34 | dnl Check for API introduced in MacOS X 10.3. 35 | AC_CACHE_CHECK([for CFLocaleCopyCurrent], gt_cv_func_CFLocaleCopyCurrent, 36 | [gt_save_LIBS="$LIBS" 37 | LIBS="$LIBS -Wl,-framework -Wl,CoreFoundation" 38 | AC_TRY_LINK([#include ], [CFLocaleCopyCurrent();], 39 | [gt_cv_func_CFLocaleCopyCurrent=yes], 40 | [gt_cv_func_CFLocaleCopyCurrent=no]) 41 | LIBS="$gt_save_LIBS"]) 42 | if test $gt_cv_func_CFLocaleCopyCurrent = yes; then 43 | AC_DEFINE([HAVE_CFLOCALECOPYCURRENT], 1, 44 | [Define to 1 if you have the MacOS X function CFLocaleCopyCurrent in the CoreFoundation framework.]) 45 | fi 46 | INTL_MACOSX_LIBS= 47 | if test $gt_cv_func_CFPreferencesCopyAppValue = yes || test $gt_cv_func_CFLocaleCopyCurrent = yes; then 48 | INTL_MACOSX_LIBS="-Wl,-framework -Wl,CoreFoundation" 49 | fi 50 | AC_SUBST([INTL_MACOSX_LIBS]) 51 | ]) 52 | -------------------------------------------------------------------------------- /m4/intmax.m4: -------------------------------------------------------------------------------- 1 | # intmax.m4 serial 3 (gettext-0.16) 2 | dnl Copyright (C) 2002-2005 Free Software Foundation, Inc. 3 | dnl This file is free software; the Free Software Foundation 4 | dnl gives unlimited permission to copy and/or distribute it, 5 | dnl with or without modifications, as long as this notice is preserved. 6 | 7 | dnl From Bruno Haible. 8 | dnl Test whether the system has the 'intmax_t' type, but don't attempt to 9 | dnl find a replacement if it is lacking. 10 | 11 | AC_DEFUN([gt_TYPE_INTMAX_T], 12 | [ 13 | AC_REQUIRE([gl_AC_HEADER_INTTYPES_H]) 14 | AC_REQUIRE([gl_AC_HEADER_STDINT_H]) 15 | AC_CACHE_CHECK(for intmax_t, gt_cv_c_intmax_t, 16 | [AC_TRY_COMPILE([ 17 | #include 18 | #include 19 | #if HAVE_STDINT_H_WITH_UINTMAX 20 | #include 21 | #endif 22 | #if HAVE_INTTYPES_H_WITH_UINTMAX 23 | #include 24 | #endif 25 | ], [intmax_t x = -1; 26 | return !x;], 27 | gt_cv_c_intmax_t=yes, 28 | gt_cv_c_intmax_t=no)]) 29 | if test $gt_cv_c_intmax_t = yes; then 30 | AC_DEFINE(HAVE_INTMAX_T, 1, 31 | [Define if you have the 'intmax_t' type in or .]) 32 | fi 33 | ]) 34 | -------------------------------------------------------------------------------- /m4/inttypes-pri.m4: -------------------------------------------------------------------------------- 1 | # inttypes-pri.m4 serial 4 (gettext-0.16) 2 | dnl Copyright (C) 1997-2002, 2006 Free Software Foundation, Inc. 3 | dnl This file is free software; the Free Software Foundation 4 | dnl gives unlimited permission to copy and/or distribute it, 5 | dnl with or without modifications, as long as this notice is preserved. 6 | 7 | dnl From Bruno Haible. 8 | 9 | AC_PREREQ(2.52) 10 | 11 | # Define PRI_MACROS_BROKEN if exists and defines the PRI* 12 | # macros to non-string values. This is the case on AIX 4.3.3. 13 | 14 | AC_DEFUN([gt_INTTYPES_PRI], 15 | [ 16 | AC_CHECK_HEADERS([inttypes.h]) 17 | if test $ac_cv_header_inttypes_h = yes; then 18 | AC_CACHE_CHECK([whether the inttypes.h PRIxNN macros are broken], 19 | gt_cv_inttypes_pri_broken, 20 | [ 21 | AC_TRY_COMPILE([#include 22 | #ifdef PRId32 23 | char *p = PRId32; 24 | #endif 25 | ], [], gt_cv_inttypes_pri_broken=no, gt_cv_inttypes_pri_broken=yes) 26 | ]) 27 | fi 28 | if test "$gt_cv_inttypes_pri_broken" = yes; then 29 | AC_DEFINE_UNQUOTED(PRI_MACROS_BROKEN, 1, 30 | [Define if exists and defines unusable PRI* macros.]) 31 | PRI_MACROS_BROKEN=1 32 | else 33 | PRI_MACROS_BROKEN=0 34 | fi 35 | AC_SUBST([PRI_MACROS_BROKEN]) 36 | ]) 37 | -------------------------------------------------------------------------------- /m4/inttypes_h.m4: -------------------------------------------------------------------------------- 1 | # inttypes_h.m4 serial 7 2 | dnl Copyright (C) 1997-2004, 2006 Free Software Foundation, Inc. 3 | dnl This file is free software; the Free Software Foundation 4 | dnl gives unlimited permission to copy and/or distribute it, 5 | dnl with or without modifications, as long as this notice is preserved. 6 | 7 | dnl From Paul Eggert. 8 | 9 | # Define HAVE_INTTYPES_H_WITH_UINTMAX if exists, 10 | # doesn't clash with , and declares uintmax_t. 11 | 12 | AC_DEFUN([gl_AC_HEADER_INTTYPES_H], 13 | [ 14 | AC_CACHE_CHECK([for inttypes.h], gl_cv_header_inttypes_h, 15 | [AC_TRY_COMPILE( 16 | [#include 17 | #include ], 18 | [uintmax_t i = (uintmax_t) -1; return !i;], 19 | gl_cv_header_inttypes_h=yes, 20 | gl_cv_header_inttypes_h=no)]) 21 | if test $gl_cv_header_inttypes_h = yes; then 22 | AC_DEFINE_UNQUOTED(HAVE_INTTYPES_H_WITH_UINTMAX, 1, 23 | [Define if exists, doesn't clash with , 24 | and declares uintmax_t. ]) 25 | fi 26 | ]) 27 | -------------------------------------------------------------------------------- /m4/lcmessage.m4: -------------------------------------------------------------------------------- 1 | # lcmessage.m4 serial 4 (gettext-0.14.2) 2 | dnl Copyright (C) 1995-2002, 2004-2005 Free Software Foundation, Inc. 3 | dnl This file is free software; the Free Software Foundation 4 | dnl gives unlimited permission to copy and/or distribute it, 5 | dnl with or without modifications, as long as this notice is preserved. 6 | dnl 7 | dnl This file can can be used in projects which are not available under 8 | dnl the GNU General Public License or the GNU Library General Public 9 | dnl License but which still want to provide support for the GNU gettext 10 | dnl functionality. 11 | dnl Please note that the actual code of the GNU gettext library is covered 12 | dnl by the GNU Library General Public License, and the rest of the GNU 13 | dnl gettext package package is covered by the GNU General Public License. 14 | dnl They are *not* in the public domain. 15 | 16 | dnl Authors: 17 | dnl Ulrich Drepper , 1995. 18 | 19 | # Check whether LC_MESSAGES is available in . 20 | 21 | AC_DEFUN([gt_LC_MESSAGES], 22 | [ 23 | AC_CACHE_CHECK([for LC_MESSAGES], gt_cv_val_LC_MESSAGES, 24 | [AC_TRY_LINK([#include ], [return LC_MESSAGES], 25 | gt_cv_val_LC_MESSAGES=yes, gt_cv_val_LC_MESSAGES=no)]) 26 | if test $gt_cv_val_LC_MESSAGES = yes; then 27 | AC_DEFINE(HAVE_LC_MESSAGES, 1, 28 | [Define if your file defines LC_MESSAGES.]) 29 | fi 30 | ]) 31 | -------------------------------------------------------------------------------- /m4/lib-ld.m4: -------------------------------------------------------------------------------- 1 | # lib-ld.m4 serial 3 (gettext-0.13) 2 | dnl Copyright (C) 1996-2003 Free Software Foundation, Inc. 3 | dnl This file is free software; the Free Software Foundation 4 | dnl gives unlimited permission to copy and/or distribute it, 5 | dnl with or without modifications, as long as this notice is preserved. 6 | 7 | dnl Subroutines of libtool.m4, 8 | dnl with replacements s/AC_/AC_LIB/ and s/lt_cv/acl_cv/ to avoid collision 9 | dnl with libtool.m4. 10 | 11 | dnl From libtool-1.4. Sets the variable with_gnu_ld to yes or no. 12 | AC_DEFUN([AC_LIB_PROG_LD_GNU], 13 | [AC_CACHE_CHECK([if the linker ($LD) is GNU ld], acl_cv_prog_gnu_ld, 14 | [# I'd rather use --version here, but apparently some GNU ld's only accept -v. 15 | case `$LD -v 2>&1 conf$$.sh 35 | echo "exit 0" >>conf$$.sh 36 | chmod +x conf$$.sh 37 | if (PATH="/nonexistent;."; conf$$.sh) >/dev/null 2>&1; then 38 | PATH_SEPARATOR=';' 39 | else 40 | PATH_SEPARATOR=: 41 | fi 42 | rm -f conf$$.sh 43 | fi 44 | ac_prog=ld 45 | if test "$GCC" = yes; then 46 | # Check if gcc -print-prog-name=ld gives a path. 47 | AC_MSG_CHECKING([for ld used by GCC]) 48 | case $host in 49 | *-*-mingw*) 50 | # gcc leaves a trailing carriage return which upsets mingw 51 | ac_prog=`($CC -print-prog-name=ld) 2>&5 | tr -d '\015'` ;; 52 | *) 53 | ac_prog=`($CC -print-prog-name=ld) 2>&5` ;; 54 | esac 55 | case $ac_prog in 56 | # Accept absolute paths. 57 | [[\\/]* | [A-Za-z]:[\\/]*)] 58 | [re_direlt='/[^/][^/]*/\.\./'] 59 | # Canonicalize the path of ld 60 | ac_prog=`echo $ac_prog| sed 's%\\\\%/%g'` 61 | while echo $ac_prog | grep "$re_direlt" > /dev/null 2>&1; do 62 | ac_prog=`echo $ac_prog| sed "s%$re_direlt%/%"` 63 | done 64 | test -z "$LD" && LD="$ac_prog" 65 | ;; 66 | "") 67 | # If it fails, then pretend we aren't using GCC. 68 | ac_prog=ld 69 | ;; 70 | *) 71 | # If it is relative, then search for the first ld in PATH. 72 | with_gnu_ld=unknown 73 | ;; 74 | esac 75 | elif test "$with_gnu_ld" = yes; then 76 | AC_MSG_CHECKING([for GNU ld]) 77 | else 78 | AC_MSG_CHECKING([for non-GNU ld]) 79 | fi 80 | AC_CACHE_VAL(acl_cv_path_LD, 81 | [if test -z "$LD"; then 82 | IFS="${IFS= }"; ac_save_ifs="$IFS"; IFS="${IFS}${PATH_SEPARATOR-:}" 83 | for ac_dir in $PATH; do 84 | test -z "$ac_dir" && ac_dir=. 85 | if test -f "$ac_dir/$ac_prog" || test -f "$ac_dir/$ac_prog$ac_exeext"; then 86 | acl_cv_path_LD="$ac_dir/$ac_prog" 87 | # Check to see if the program is GNU ld. I'd rather use --version, 88 | # but apparently some GNU ld's only accept -v. 89 | # Break only if it was the GNU/non-GNU ld that we prefer. 90 | case `"$acl_cv_path_LD" -v 2>&1 < /dev/null` in 91 | *GNU* | *'with BFD'*) 92 | test "$with_gnu_ld" != no && break ;; 93 | *) 94 | test "$with_gnu_ld" != yes && break ;; 95 | esac 96 | fi 97 | done 98 | IFS="$ac_save_ifs" 99 | else 100 | acl_cv_path_LD="$LD" # Let the user override the test with a path. 101 | fi]) 102 | LD="$acl_cv_path_LD" 103 | if test -n "$LD"; then 104 | AC_MSG_RESULT($LD) 105 | else 106 | AC_MSG_RESULT(no) 107 | fi 108 | test -z "$LD" && AC_MSG_ERROR([no acceptable ld found in \$PATH]) 109 | AC_LIB_PROG_LD_GNU 110 | ]) 111 | -------------------------------------------------------------------------------- /m4/lib-prefix.m4: -------------------------------------------------------------------------------- 1 | # lib-prefix.m4 serial 5 (gettext-0.15) 2 | dnl Copyright (C) 2001-2005 Free Software Foundation, Inc. 3 | dnl This file is free software; the Free Software Foundation 4 | dnl gives unlimited permission to copy and/or distribute it, 5 | dnl with or without modifications, as long as this notice is preserved. 6 | 7 | dnl From Bruno Haible. 8 | 9 | dnl AC_LIB_ARG_WITH is synonymous to AC_ARG_WITH in autoconf-2.13, and 10 | dnl similar to AC_ARG_WITH in autoconf 2.52...2.57 except that is doesn't 11 | dnl require excessive bracketing. 12 | ifdef([AC_HELP_STRING], 13 | [AC_DEFUN([AC_LIB_ARG_WITH], [AC_ARG_WITH([$1],[[$2]],[$3],[$4])])], 14 | [AC_DEFUN([AC_][LIB_ARG_WITH], [AC_ARG_WITH([$1],[$2],[$3],[$4])])]) 15 | 16 | dnl AC_LIB_PREFIX adds to the CPPFLAGS and LDFLAGS the flags that are needed 17 | dnl to access previously installed libraries. The basic assumption is that 18 | dnl a user will want packages to use other packages he previously installed 19 | dnl with the same --prefix option. 20 | dnl This macro is not needed if only AC_LIB_LINKFLAGS is used to locate 21 | dnl libraries, but is otherwise very convenient. 22 | AC_DEFUN([AC_LIB_PREFIX], 23 | [ 24 | AC_BEFORE([$0], [AC_LIB_LINKFLAGS]) 25 | AC_REQUIRE([AC_PROG_CC]) 26 | AC_REQUIRE([AC_CANONICAL_HOST]) 27 | AC_REQUIRE([AC_LIB_PREPARE_MULTILIB]) 28 | AC_REQUIRE([AC_LIB_PREPARE_PREFIX]) 29 | dnl By default, look in $includedir and $libdir. 30 | use_additional=yes 31 | AC_LIB_WITH_FINAL_PREFIX([ 32 | eval additional_includedir=\"$includedir\" 33 | eval additional_libdir=\"$libdir\" 34 | ]) 35 | AC_LIB_ARG_WITH([lib-prefix], 36 | [ --with-lib-prefix[=DIR] search for libraries in DIR/include and DIR/lib 37 | --without-lib-prefix don't search for libraries in includedir and libdir], 38 | [ 39 | if test "X$withval" = "Xno"; then 40 | use_additional=no 41 | else 42 | if test "X$withval" = "X"; then 43 | AC_LIB_WITH_FINAL_PREFIX([ 44 | eval additional_includedir=\"$includedir\" 45 | eval additional_libdir=\"$libdir\" 46 | ]) 47 | else 48 | additional_includedir="$withval/include" 49 | additional_libdir="$withval/$acl_libdirstem" 50 | fi 51 | fi 52 | ]) 53 | if test $use_additional = yes; then 54 | dnl Potentially add $additional_includedir to $CPPFLAGS. 55 | dnl But don't add it 56 | dnl 1. if it's the standard /usr/include, 57 | dnl 2. if it's already present in $CPPFLAGS, 58 | dnl 3. if it's /usr/local/include and we are using GCC on Linux, 59 | dnl 4. if it doesn't exist as a directory. 60 | if test "X$additional_includedir" != "X/usr/include"; then 61 | haveit= 62 | for x in $CPPFLAGS; do 63 | AC_LIB_WITH_FINAL_PREFIX([eval x=\"$x\"]) 64 | if test "X$x" = "X-I$additional_includedir"; then 65 | haveit=yes 66 | break 67 | fi 68 | done 69 | if test -z "$haveit"; then 70 | if test "X$additional_includedir" = "X/usr/local/include"; then 71 | if test -n "$GCC"; then 72 | case $host_os in 73 | linux* | gnu* | k*bsd*-gnu) haveit=yes;; 74 | esac 75 | fi 76 | fi 77 | if test -z "$haveit"; then 78 | if test -d "$additional_includedir"; then 79 | dnl Really add $additional_includedir to $CPPFLAGS. 80 | CPPFLAGS="${CPPFLAGS}${CPPFLAGS:+ }-I$additional_includedir" 81 | fi 82 | fi 83 | fi 84 | fi 85 | dnl Potentially add $additional_libdir to $LDFLAGS. 86 | dnl But don't add it 87 | dnl 1. if it's the standard /usr/lib, 88 | dnl 2. if it's already present in $LDFLAGS, 89 | dnl 3. if it's /usr/local/lib and we are using GCC on Linux, 90 | dnl 4. if it doesn't exist as a directory. 91 | if test "X$additional_libdir" != "X/usr/$acl_libdirstem"; then 92 | haveit= 93 | for x in $LDFLAGS; do 94 | AC_LIB_WITH_FINAL_PREFIX([eval x=\"$x\"]) 95 | if test "X$x" = "X-L$additional_libdir"; then 96 | haveit=yes 97 | break 98 | fi 99 | done 100 | if test -z "$haveit"; then 101 | if test "X$additional_libdir" = "X/usr/local/$acl_libdirstem"; then 102 | if test -n "$GCC"; then 103 | case $host_os in 104 | linux*) haveit=yes;; 105 | esac 106 | fi 107 | fi 108 | if test -z "$haveit"; then 109 | if test -d "$additional_libdir"; then 110 | dnl Really add $additional_libdir to $LDFLAGS. 111 | LDFLAGS="${LDFLAGS}${LDFLAGS:+ }-L$additional_libdir" 112 | fi 113 | fi 114 | fi 115 | fi 116 | fi 117 | ]) 118 | 119 | dnl AC_LIB_PREPARE_PREFIX creates variables acl_final_prefix, 120 | dnl acl_final_exec_prefix, containing the values to which $prefix and 121 | dnl $exec_prefix will expand at the end of the configure script. 122 | AC_DEFUN([AC_LIB_PREPARE_PREFIX], 123 | [ 124 | dnl Unfortunately, prefix and exec_prefix get only finally determined 125 | dnl at the end of configure. 126 | if test "X$prefix" = "XNONE"; then 127 | acl_final_prefix="$ac_default_prefix" 128 | else 129 | acl_final_prefix="$prefix" 130 | fi 131 | if test "X$exec_prefix" = "XNONE"; then 132 | acl_final_exec_prefix='${prefix}' 133 | else 134 | acl_final_exec_prefix="$exec_prefix" 135 | fi 136 | acl_save_prefix="$prefix" 137 | prefix="$acl_final_prefix" 138 | eval acl_final_exec_prefix=\"$acl_final_exec_prefix\" 139 | prefix="$acl_save_prefix" 140 | ]) 141 | 142 | dnl AC_LIB_WITH_FINAL_PREFIX([statement]) evaluates statement, with the 143 | dnl variables prefix and exec_prefix bound to the values they will have 144 | dnl at the end of the configure script. 145 | AC_DEFUN([AC_LIB_WITH_FINAL_PREFIX], 146 | [ 147 | acl_save_prefix="$prefix" 148 | prefix="$acl_final_prefix" 149 | acl_save_exec_prefix="$exec_prefix" 150 | exec_prefix="$acl_final_exec_prefix" 151 | $1 152 | exec_prefix="$acl_save_exec_prefix" 153 | prefix="$acl_save_prefix" 154 | ]) 155 | 156 | dnl AC_LIB_PREPARE_MULTILIB creates a variable acl_libdirstem, containing 157 | dnl the basename of the libdir, either "lib" or "lib64". 158 | AC_DEFUN([AC_LIB_PREPARE_MULTILIB], 159 | [ 160 | dnl There is no formal standard regarding lib and lib64. The current 161 | dnl practice is that on a system supporting 32-bit and 64-bit instruction 162 | dnl sets or ABIs, 64-bit libraries go under $prefix/lib64 and 32-bit 163 | dnl libraries go under $prefix/lib. We determine the compiler's default 164 | dnl mode by looking at the compiler's library search path. If at least 165 | dnl of its elements ends in /lib64 or points to a directory whose absolute 166 | dnl pathname ends in /lib64, we assume a 64-bit ABI. Otherwise we use the 167 | dnl default, namely "lib". 168 | acl_libdirstem=lib 169 | searchpath=`(LC_ALL=C $CC -print-search-dirs) 2>/dev/null | sed -n -e 's,^libraries: ,,p' | sed -e 's,^=,,'` 170 | if test -n "$searchpath"; then 171 | acl_save_IFS="${IFS= }"; IFS=":" 172 | for searchdir in $searchpath; do 173 | if test -d "$searchdir"; then 174 | case "$searchdir" in 175 | */lib64/ | */lib64 ) acl_libdirstem=lib64 ;; 176 | *) searchdir=`cd "$searchdir" && pwd` 177 | case "$searchdir" in 178 | */lib64 ) acl_libdirstem=lib64 ;; 179 | esac ;; 180 | esac 181 | fi 182 | done 183 | IFS="$acl_save_IFS" 184 | fi 185 | ]) 186 | -------------------------------------------------------------------------------- /m4/lock.m4: -------------------------------------------------------------------------------- 1 | # lock.m4 serial 7 (gettext-0.17) 2 | dnl Copyright (C) 2005-2007 Free Software Foundation, Inc. 3 | dnl This file is free software; the Free Software Foundation 4 | dnl gives unlimited permission to copy and/or distribute it, 5 | dnl with or without modifications, as long as this notice is preserved. 6 | 7 | dnl From Bruno Haible. 8 | 9 | dnl Tests for a multithreading library to be used. 10 | dnl Defines at most one of the macros USE_POSIX_THREADS, USE_SOLARIS_THREADS, 11 | dnl USE_PTH_THREADS, USE_WIN32_THREADS 12 | dnl Sets the variables LIBTHREAD and LTLIBTHREAD to the linker options for use 13 | dnl in a Makefile (LIBTHREAD for use without libtool, LTLIBTHREAD for use with 14 | dnl libtool). 15 | dnl Sets the variables LIBMULTITHREAD and LTLIBMULTITHREAD similarly, for 16 | dnl programs that really need multithread functionality. The difference 17 | dnl between LIBTHREAD and LIBMULTITHREAD is that on platforms supporting weak 18 | dnl symbols, typically LIBTHREAD="" whereas LIBMULTITHREAD="-lpthread". 19 | dnl Adds to CPPFLAGS the flag -D_REENTRANT or -D_THREAD_SAFE if needed for 20 | dnl multithread-safe programs. 21 | 22 | AC_DEFUN([gl_LOCK_EARLY], 23 | [ 24 | AC_REQUIRE([gl_LOCK_EARLY_BODY]) 25 | ]) 26 | 27 | dnl The guts of gl_LOCK_EARLY. Needs to be expanded only once. 28 | 29 | AC_DEFUN([gl_LOCK_EARLY_BODY], 30 | [ 31 | dnl Ordering constraints: This macro modifies CPPFLAGS in a way that 32 | dnl influences the result of the autoconf tests that test for *_unlocked 33 | dnl declarations, on AIX 5 at least. Therefore it must come early. 34 | AC_BEFORE([$0], [gl_FUNC_GLIBC_UNLOCKED_IO])dnl 35 | AC_BEFORE([$0], [gl_ARGP])dnl 36 | 37 | AC_REQUIRE([AC_CANONICAL_HOST]) 38 | dnl _GNU_SOURCE is needed for pthread_rwlock_t on glibc systems. 39 | dnl AC_USE_SYSTEM_EXTENSIONS was introduced in autoconf 2.60 and obsoletes 40 | dnl AC_GNU_SOURCE. 41 | m4_ifdef([AC_USE_SYSTEM_EXTENSIONS], 42 | [AC_REQUIRE([AC_USE_SYSTEM_EXTENSIONS])], 43 | [AC_REQUIRE([AC_GNU_SOURCE])]) 44 | dnl Check for multithreading. 45 | AC_ARG_ENABLE(threads, 46 | AC_HELP_STRING([--enable-threads={posix|solaris|pth|win32}], [specify multithreading API]) 47 | AC_HELP_STRING([--disable-threads], [build without multithread safety]), 48 | [gl_use_threads=$enableval], 49 | [case "$host_os" in 50 | dnl Disable multithreading by default on OSF/1, because it interferes 51 | dnl with fork()/exec(): When msgexec is linked with -lpthread, its child 52 | dnl process gets an endless segmentation fault inside execvp(). 53 | osf*) gl_use_threads=no ;; 54 | *) gl_use_threads=yes ;; 55 | esac 56 | ]) 57 | if test "$gl_use_threads" = yes || test "$gl_use_threads" = posix; then 58 | # For using : 59 | case "$host_os" in 60 | osf*) 61 | # On OSF/1, the compiler needs the flag -D_REENTRANT so that it 62 | # groks . cc also understands the flag -pthread, but 63 | # we don't use it because 1. gcc-2.95 doesn't understand -pthread, 64 | # 2. putting a flag into CPPFLAGS that has an effect on the linker 65 | # causes the AC_TRY_LINK test below to succeed unexpectedly, 66 | # leading to wrong values of LIBTHREAD and LTLIBTHREAD. 67 | CPPFLAGS="$CPPFLAGS -D_REENTRANT" 68 | ;; 69 | esac 70 | # Some systems optimize for single-threaded programs by default, and 71 | # need special flags to disable these optimizations. For example, the 72 | # definition of 'errno' in . 73 | case "$host_os" in 74 | aix* | freebsd*) CPPFLAGS="$CPPFLAGS -D_THREAD_SAFE" ;; 75 | solaris*) CPPFLAGS="$CPPFLAGS -D_REENTRANT" ;; 76 | esac 77 | fi 78 | ]) 79 | 80 | dnl The guts of gl_LOCK. Needs to be expanded only once. 81 | 82 | AC_DEFUN([gl_LOCK_BODY], 83 | [ 84 | AC_REQUIRE([gl_LOCK_EARLY_BODY]) 85 | gl_threads_api=none 86 | LIBTHREAD= 87 | LTLIBTHREAD= 88 | LIBMULTITHREAD= 89 | LTLIBMULTITHREAD= 90 | if test "$gl_use_threads" != no; then 91 | dnl Check whether the compiler and linker support weak declarations. 92 | AC_MSG_CHECKING([whether imported symbols can be declared weak]) 93 | gl_have_weak=no 94 | AC_TRY_LINK([extern void xyzzy (); 95 | #pragma weak xyzzy], [xyzzy();], [gl_have_weak=yes]) 96 | AC_MSG_RESULT([$gl_have_weak]) 97 | if test "$gl_use_threads" = yes || test "$gl_use_threads" = posix; then 98 | # On OSF/1, the compiler needs the flag -pthread or -D_REENTRANT so that 99 | # it groks . It's added above, in gl_LOCK_EARLY_BODY. 100 | AC_CHECK_HEADER(pthread.h, gl_have_pthread_h=yes, gl_have_pthread_h=no) 101 | if test "$gl_have_pthread_h" = yes; then 102 | # Other possible tests: 103 | # -lpthreads (FSU threads, PCthreads) 104 | # -lgthreads 105 | gl_have_pthread= 106 | # Test whether both pthread_mutex_lock and pthread_mutexattr_init exist 107 | # in libc. IRIX 6.5 has the first one in both libc and libpthread, but 108 | # the second one only in libpthread, and lock.c needs it. 109 | AC_TRY_LINK([#include ], 110 | [pthread_mutex_lock((pthread_mutex_t*)0); 111 | pthread_mutexattr_init((pthread_mutexattr_t*)0);], 112 | [gl_have_pthread=yes]) 113 | # Test for libpthread by looking for pthread_kill. (Not pthread_self, 114 | # since it is defined as a macro on OSF/1.) 115 | if test -n "$gl_have_pthread"; then 116 | # The program links fine without libpthread. But it may actually 117 | # need to link with libpthread in order to create multiple threads. 118 | AC_CHECK_LIB(pthread, pthread_kill, 119 | [LIBMULTITHREAD=-lpthread LTLIBMULTITHREAD=-lpthread 120 | # On Solaris and HP-UX, most pthread functions exist also in libc. 121 | # Therefore pthread_in_use() needs to actually try to create a 122 | # thread: pthread_create from libc will fail, whereas 123 | # pthread_create will actually create a thread. 124 | case "$host_os" in 125 | solaris* | hpux*) 126 | AC_DEFINE([PTHREAD_IN_USE_DETECTION_HARD], 1, 127 | [Define if the pthread_in_use() detection is hard.]) 128 | esac 129 | ]) 130 | else 131 | # Some library is needed. Try libpthread and libc_r. 132 | AC_CHECK_LIB(pthread, pthread_kill, 133 | [gl_have_pthread=yes 134 | LIBTHREAD=-lpthread LTLIBTHREAD=-lpthread 135 | LIBMULTITHREAD=-lpthread LTLIBMULTITHREAD=-lpthread]) 136 | if test -z "$gl_have_pthread"; then 137 | # For FreeBSD 4. 138 | AC_CHECK_LIB(c_r, pthread_kill, 139 | [gl_have_pthread=yes 140 | LIBTHREAD=-lc_r LTLIBTHREAD=-lc_r 141 | LIBMULTITHREAD=-lc_r LTLIBMULTITHREAD=-lc_r]) 142 | fi 143 | fi 144 | if test -n "$gl_have_pthread"; then 145 | gl_threads_api=posix 146 | AC_DEFINE([USE_POSIX_THREADS], 1, 147 | [Define if the POSIX multithreading library can be used.]) 148 | if test -n "$LIBMULTITHREAD" || test -n "$LTLIBMULTITHREAD"; then 149 | if test $gl_have_weak = yes; then 150 | AC_DEFINE([USE_POSIX_THREADS_WEAK], 1, 151 | [Define if references to the POSIX multithreading library should be made weak.]) 152 | LIBTHREAD= 153 | LTLIBTHREAD= 154 | fi 155 | fi 156 | # OSF/1 4.0 and MacOS X 10.1 lack the pthread_rwlock_t type and the 157 | # pthread_rwlock_* functions. 158 | AC_CHECK_TYPE([pthread_rwlock_t], 159 | [AC_DEFINE([HAVE_PTHREAD_RWLOCK], 1, 160 | [Define if the POSIX multithreading library has read/write locks.])], 161 | [], 162 | [#include ]) 163 | # glibc defines PTHREAD_MUTEX_RECURSIVE as enum, not as a macro. 164 | AC_TRY_COMPILE([#include ], 165 | [#if __FreeBSD__ == 4 166 | error "No, in FreeBSD 4.0 recursive mutexes actually don't work." 167 | #else 168 | int x = (int)PTHREAD_MUTEX_RECURSIVE; 169 | return !x; 170 | #endif], 171 | [AC_DEFINE([HAVE_PTHREAD_MUTEX_RECURSIVE], 1, 172 | [Define if the defines PTHREAD_MUTEX_RECURSIVE.])]) 173 | fi 174 | fi 175 | fi 176 | if test -z "$gl_have_pthread"; then 177 | if test "$gl_use_threads" = yes || test "$gl_use_threads" = solaris; then 178 | gl_have_solaristhread= 179 | gl_save_LIBS="$LIBS" 180 | LIBS="$LIBS -lthread" 181 | AC_TRY_LINK([#include 182 | #include ], 183 | [thr_self();], 184 | [gl_have_solaristhread=yes]) 185 | LIBS="$gl_save_LIBS" 186 | if test -n "$gl_have_solaristhread"; then 187 | gl_threads_api=solaris 188 | LIBTHREAD=-lthread 189 | LTLIBTHREAD=-lthread 190 | LIBMULTITHREAD="$LIBTHREAD" 191 | LTLIBMULTITHREAD="$LTLIBTHREAD" 192 | AC_DEFINE([USE_SOLARIS_THREADS], 1, 193 | [Define if the old Solaris multithreading library can be used.]) 194 | if test $gl_have_weak = yes; then 195 | AC_DEFINE([USE_SOLARIS_THREADS_WEAK], 1, 196 | [Define if references to the old Solaris multithreading library should be made weak.]) 197 | LIBTHREAD= 198 | LTLIBTHREAD= 199 | fi 200 | fi 201 | fi 202 | fi 203 | if test "$gl_use_threads" = pth; then 204 | gl_save_CPPFLAGS="$CPPFLAGS" 205 | AC_LIB_LINKFLAGS(pth) 206 | gl_have_pth= 207 | gl_save_LIBS="$LIBS" 208 | LIBS="$LIBS -lpth" 209 | AC_TRY_LINK([#include ], [pth_self();], gl_have_pth=yes) 210 | LIBS="$gl_save_LIBS" 211 | if test -n "$gl_have_pth"; then 212 | gl_threads_api=pth 213 | LIBTHREAD="$LIBPTH" 214 | LTLIBTHREAD="$LTLIBPTH" 215 | LIBMULTITHREAD="$LIBTHREAD" 216 | LTLIBMULTITHREAD="$LTLIBTHREAD" 217 | AC_DEFINE([USE_PTH_THREADS], 1, 218 | [Define if the GNU Pth multithreading library can be used.]) 219 | if test -n "$LIBMULTITHREAD" || test -n "$LTLIBMULTITHREAD"; then 220 | if test $gl_have_weak = yes; then 221 | AC_DEFINE([USE_PTH_THREADS_WEAK], 1, 222 | [Define if references to the GNU Pth multithreading library should be made weak.]) 223 | LIBTHREAD= 224 | LTLIBTHREAD= 225 | fi 226 | fi 227 | else 228 | CPPFLAGS="$gl_save_CPPFLAGS" 229 | fi 230 | fi 231 | if test -z "$gl_have_pthread"; then 232 | if test "$gl_use_threads" = yes || test "$gl_use_threads" = win32; then 233 | if { case "$host_os" in 234 | mingw*) true;; 235 | *) false;; 236 | esac 237 | }; then 238 | gl_threads_api=win32 239 | AC_DEFINE([USE_WIN32_THREADS], 1, 240 | [Define if the Win32 multithreading API can be used.]) 241 | fi 242 | fi 243 | fi 244 | fi 245 | AC_MSG_CHECKING([for multithread API to use]) 246 | AC_MSG_RESULT([$gl_threads_api]) 247 | AC_SUBST(LIBTHREAD) 248 | AC_SUBST(LTLIBTHREAD) 249 | AC_SUBST(LIBMULTITHREAD) 250 | AC_SUBST(LTLIBMULTITHREAD) 251 | ]) 252 | 253 | AC_DEFUN([gl_LOCK], 254 | [ 255 | AC_REQUIRE([gl_LOCK_EARLY]) 256 | AC_REQUIRE([gl_LOCK_BODY]) 257 | gl_PREREQ_LOCK 258 | ]) 259 | 260 | # Prerequisites of lib/lock.c. 261 | AC_DEFUN([gl_PREREQ_LOCK], [ 262 | AC_REQUIRE([AC_C_INLINE]) 263 | ]) 264 | 265 | dnl Survey of platforms: 266 | dnl 267 | dnl Platform Available Compiler Supports test-lock 268 | dnl flavours option weak result 269 | dnl --------------- --------- --------- -------- --------- 270 | dnl Linux 2.4/glibc posix -lpthread Y OK 271 | dnl 272 | dnl GNU Hurd/glibc posix 273 | dnl 274 | dnl FreeBSD 5.3 posix -lc_r Y 275 | dnl posix -lkse ? Y 276 | dnl posix -lpthread ? Y 277 | dnl posix -lthr Y 278 | dnl 279 | dnl FreeBSD 5.2 posix -lc_r Y 280 | dnl posix -lkse Y 281 | dnl posix -lthr Y 282 | dnl 283 | dnl FreeBSD 4.0,4.10 posix -lc_r Y OK 284 | dnl 285 | dnl NetBSD 1.6 -- 286 | dnl 287 | dnl OpenBSD 3.4 posix -lpthread Y OK 288 | dnl 289 | dnl MacOS X 10.[123] posix -lpthread Y OK 290 | dnl 291 | dnl Solaris 7,8,9 posix -lpthread Y Sol 7,8: 0.0; Sol 9: OK 292 | dnl solaris -lthread Y Sol 7,8: 0.0; Sol 9: OK 293 | dnl 294 | dnl HP-UX 11 posix -lpthread N (cc) OK 295 | dnl Y (gcc) 296 | dnl 297 | dnl IRIX 6.5 posix -lpthread Y 0.5 298 | dnl 299 | dnl AIX 4.3,5.1 posix -lpthread N AIX 4: 0.5; AIX 5: OK 300 | dnl 301 | dnl OSF/1 4.0,5.1 posix -pthread (cc) N OK 302 | dnl -lpthread (gcc) Y 303 | dnl 304 | dnl Cygwin posix -lpthread Y OK 305 | dnl 306 | dnl Any of the above pth -lpth 0.0 307 | dnl 308 | dnl Mingw win32 N OK 309 | dnl 310 | dnl BeOS 5 -- 311 | dnl 312 | dnl The test-lock result shows what happens if in test-lock.c EXPLICIT_YIELD is 313 | dnl turned off: 314 | dnl OK if all three tests terminate OK, 315 | dnl 0.5 if the first test terminates OK but the second one loops endlessly, 316 | dnl 0.0 if the first test already loops endlessly. 317 | -------------------------------------------------------------------------------- /m4/longlong.m4: -------------------------------------------------------------------------------- 1 | # longlong.m4 serial 13 2 | dnl Copyright (C) 1999-2007 Free Software Foundation, Inc. 3 | dnl This file is free software; the Free Software Foundation 4 | dnl gives unlimited permission to copy and/or distribute it, 5 | dnl with or without modifications, as long as this notice is preserved. 6 | 7 | dnl From Paul Eggert. 8 | 9 | # Define HAVE_LONG_LONG_INT if 'long long int' works. 10 | # This fixes a bug in Autoconf 2.61, but can be removed once we 11 | # assume 2.62 everywhere. 12 | 13 | # Note: If the type 'long long int' exists but is only 32 bits large 14 | # (as on some very old compilers), HAVE_LONG_LONG_INT will not be 15 | # defined. In this case you can treat 'long long int' like 'long int'. 16 | 17 | AC_DEFUN([AC_TYPE_LONG_LONG_INT], 18 | [ 19 | AC_CACHE_CHECK([for long long int], [ac_cv_type_long_long_int], 20 | [AC_LINK_IFELSE( 21 | [_AC_TYPE_LONG_LONG_SNIPPET], 22 | [dnl This catches a bug in Tandem NonStop Kernel (OSS) cc -O circa 2004. 23 | dnl If cross compiling, assume the bug isn't important, since 24 | dnl nobody cross compiles for this platform as far as we know. 25 | AC_RUN_IFELSE( 26 | [AC_LANG_PROGRAM( 27 | [[@%:@include 28 | @%:@ifndef LLONG_MAX 29 | @%:@ define HALF \ 30 | (1LL << (sizeof (long long int) * CHAR_BIT - 2)) 31 | @%:@ define LLONG_MAX (HALF - 1 + HALF) 32 | @%:@endif]], 33 | [[long long int n = 1; 34 | int i; 35 | for (i = 0; ; i++) 36 | { 37 | long long int m = n << i; 38 | if (m >> i != n) 39 | return 1; 40 | if (LLONG_MAX / 2 < m) 41 | break; 42 | } 43 | return 0;]])], 44 | [ac_cv_type_long_long_int=yes], 45 | [ac_cv_type_long_long_int=no], 46 | [ac_cv_type_long_long_int=yes])], 47 | [ac_cv_type_long_long_int=no])]) 48 | if test $ac_cv_type_long_long_int = yes; then 49 | AC_DEFINE([HAVE_LONG_LONG_INT], 1, 50 | [Define to 1 if the system has the type `long long int'.]) 51 | fi 52 | ]) 53 | 54 | # Define HAVE_UNSIGNED_LONG_LONG_INT if 'unsigned long long int' works. 55 | # This fixes a bug in Autoconf 2.61, but can be removed once we 56 | # assume 2.62 everywhere. 57 | 58 | # Note: If the type 'unsigned long long int' exists but is only 32 bits 59 | # large (as on some very old compilers), AC_TYPE_UNSIGNED_LONG_LONG_INT 60 | # will not be defined. In this case you can treat 'unsigned long long int' 61 | # like 'unsigned long int'. 62 | 63 | AC_DEFUN([AC_TYPE_UNSIGNED_LONG_LONG_INT], 64 | [ 65 | AC_CACHE_CHECK([for unsigned long long int], 66 | [ac_cv_type_unsigned_long_long_int], 67 | [AC_LINK_IFELSE( 68 | [_AC_TYPE_LONG_LONG_SNIPPET], 69 | [ac_cv_type_unsigned_long_long_int=yes], 70 | [ac_cv_type_unsigned_long_long_int=no])]) 71 | if test $ac_cv_type_unsigned_long_long_int = yes; then 72 | AC_DEFINE([HAVE_UNSIGNED_LONG_LONG_INT], 1, 73 | [Define to 1 if the system has the type `unsigned long long int'.]) 74 | fi 75 | ]) 76 | 77 | # Expands to a C program that can be used to test for simultaneous support 78 | # of 'long long' and 'unsigned long long'. We don't want to say that 79 | # 'long long' is available if 'unsigned long long' is not, or vice versa, 80 | # because too many programs rely on the symmetry between signed and unsigned 81 | # integer types (excluding 'bool'). 82 | AC_DEFUN([_AC_TYPE_LONG_LONG_SNIPPET], 83 | [ 84 | AC_LANG_PROGRAM( 85 | [[/* Test preprocessor. */ 86 | #if ! (-9223372036854775807LL < 0 && 0 < 9223372036854775807ll) 87 | error in preprocessor; 88 | #endif 89 | #if ! (18446744073709551615ULL <= -1ull) 90 | error in preprocessor; 91 | #endif 92 | /* Test literals. */ 93 | long long int ll = 9223372036854775807ll; 94 | long long int nll = -9223372036854775807LL; 95 | unsigned long long int ull = 18446744073709551615ULL; 96 | /* Test constant expressions. */ 97 | typedef int a[((-9223372036854775807LL < 0 && 0 < 9223372036854775807ll) 98 | ? 1 : -1)]; 99 | typedef int b[(18446744073709551615ULL <= (unsigned long long int) -1 100 | ? 1 : -1)]; 101 | int i = 63;]], 102 | [[/* Test availability of runtime routines for shift and division. */ 103 | long long int llmax = 9223372036854775807ll; 104 | unsigned long long int ullmax = 18446744073709551615ull; 105 | return ((ll << 63) | (ll >> 63) | (ll < i) | (ll > i) 106 | | (llmax / ll) | (llmax % ll) 107 | | (ull << 63) | (ull >> 63) | (ull << i) | (ull >> i) 108 | | (ullmax / ull) | (ullmax % ull));]]) 109 | ]) 110 | -------------------------------------------------------------------------------- /m4/nls.m4: -------------------------------------------------------------------------------- 1 | # nls.m4 serial 3 (gettext-0.15) 2 | dnl Copyright (C) 1995-2003, 2005-2006 Free Software Foundation, Inc. 3 | dnl This file is free software; the Free Software Foundation 4 | dnl gives unlimited permission to copy and/or distribute it, 5 | dnl with or without modifications, as long as this notice is preserved. 6 | dnl 7 | dnl This file can can be used in projects which are not available under 8 | dnl the GNU General Public License or the GNU Library General Public 9 | dnl License but which still want to provide support for the GNU gettext 10 | dnl functionality. 11 | dnl Please note that the actual code of the GNU gettext library is covered 12 | dnl by the GNU Library General Public License, and the rest of the GNU 13 | dnl gettext package package is covered by the GNU General Public License. 14 | dnl They are *not* in the public domain. 15 | 16 | dnl Authors: 17 | dnl Ulrich Drepper , 1995-2000. 18 | dnl Bruno Haible , 2000-2003. 19 | 20 | AC_PREREQ(2.50) 21 | 22 | AC_DEFUN([AM_NLS], 23 | [ 24 | AC_MSG_CHECKING([whether NLS is requested]) 25 | dnl Default is enabled NLS 26 | AC_ARG_ENABLE(nls, 27 | [ --disable-nls do not use Native Language Support], 28 | USE_NLS=$enableval, USE_NLS=yes) 29 | AC_MSG_RESULT($USE_NLS) 30 | AC_SUBST(USE_NLS) 31 | ]) 32 | -------------------------------------------------------------------------------- /m4/printf-posix.m4: -------------------------------------------------------------------------------- 1 | # printf-posix.m4 serial 3 (gettext-0.17) 2 | dnl Copyright (C) 2003, 2007 Free Software Foundation, Inc. 3 | dnl This file is free software; the Free Software Foundation 4 | dnl gives unlimited permission to copy and/or distribute it, 5 | dnl with or without modifications, as long as this notice is preserved. 6 | 7 | dnl From Bruno Haible. 8 | dnl Test whether the printf() function supports POSIX/XSI format strings with 9 | dnl positions. 10 | 11 | AC_DEFUN([gt_PRINTF_POSIX], 12 | [ 13 | AC_REQUIRE([AC_PROG_CC]) 14 | AC_CACHE_CHECK([whether printf() supports POSIX/XSI format strings], 15 | gt_cv_func_printf_posix, 16 | [ 17 | AC_TRY_RUN([ 18 | #include 19 | #include 20 | /* The string "%2$d %1$d", with dollar characters protected from the shell's 21 | dollar expansion (possibly an autoconf bug). */ 22 | static char format[] = { '%', '2', '$', 'd', ' ', '%', '1', '$', 'd', '\0' }; 23 | static char buf[100]; 24 | int main () 25 | { 26 | sprintf (buf, format, 33, 55); 27 | return (strcmp (buf, "55 33") != 0); 28 | }], gt_cv_func_printf_posix=yes, gt_cv_func_printf_posix=no, 29 | [ 30 | AC_EGREP_CPP(notposix, [ 31 | #if defined __NetBSD__ || defined __BEOS__ || defined _MSC_VER || defined __MINGW32__ || defined __CYGWIN__ 32 | notposix 33 | #endif 34 | ], gt_cv_func_printf_posix="guessing no", 35 | gt_cv_func_printf_posix="guessing yes") 36 | ]) 37 | ]) 38 | case $gt_cv_func_printf_posix in 39 | *yes) 40 | AC_DEFINE(HAVE_POSIX_PRINTF, 1, 41 | [Define if your printf() function supports format strings with positions.]) 42 | ;; 43 | esac 44 | ]) 45 | -------------------------------------------------------------------------------- /m4/progtest.m4: -------------------------------------------------------------------------------- 1 | # progtest.m4 serial 4 (gettext-0.14.2) 2 | dnl Copyright (C) 1996-2003, 2005 Free Software Foundation, Inc. 3 | dnl This file is free software; the Free Software Foundation 4 | dnl gives unlimited permission to copy and/or distribute it, 5 | dnl with or without modifications, as long as this notice is preserved. 6 | dnl 7 | dnl This file can can be used in projects which are not available under 8 | dnl the GNU General Public License or the GNU Library General Public 9 | dnl License but which still want to provide support for the GNU gettext 10 | dnl functionality. 11 | dnl Please note that the actual code of the GNU gettext library is covered 12 | dnl by the GNU Library General Public License, and the rest of the GNU 13 | dnl gettext package package is covered by the GNU General Public License. 14 | dnl They are *not* in the public domain. 15 | 16 | dnl Authors: 17 | dnl Ulrich Drepper , 1996. 18 | 19 | AC_PREREQ(2.50) 20 | 21 | # Search path for a program which passes the given test. 22 | 23 | dnl AM_PATH_PROG_WITH_TEST(VARIABLE, PROG-TO-CHECK-FOR, 24 | dnl TEST-PERFORMED-ON-FOUND_PROGRAM [, VALUE-IF-NOT-FOUND [, PATH]]) 25 | AC_DEFUN([AM_PATH_PROG_WITH_TEST], 26 | [ 27 | # Prepare PATH_SEPARATOR. 28 | # The user is always right. 29 | if test "${PATH_SEPARATOR+set}" != set; then 30 | echo "#! /bin/sh" >conf$$.sh 31 | echo "exit 0" >>conf$$.sh 32 | chmod +x conf$$.sh 33 | if (PATH="/nonexistent;."; conf$$.sh) >/dev/null 2>&1; then 34 | PATH_SEPARATOR=';' 35 | else 36 | PATH_SEPARATOR=: 37 | fi 38 | rm -f conf$$.sh 39 | fi 40 | 41 | # Find out how to test for executable files. Don't use a zero-byte file, 42 | # as systems may use methods other than mode bits to determine executability. 43 | cat >conf$$.file <<_ASEOF 44 | #! /bin/sh 45 | exit 0 46 | _ASEOF 47 | chmod +x conf$$.file 48 | if test -x conf$$.file >/dev/null 2>&1; then 49 | ac_executable_p="test -x" 50 | else 51 | ac_executable_p="test -f" 52 | fi 53 | rm -f conf$$.file 54 | 55 | # Extract the first word of "$2", so it can be a program name with args. 56 | set dummy $2; ac_word=[$]2 57 | AC_MSG_CHECKING([for $ac_word]) 58 | AC_CACHE_VAL(ac_cv_path_$1, 59 | [case "[$]$1" in 60 | [[\\/]]* | ?:[[\\/]]*) 61 | ac_cv_path_$1="[$]$1" # Let the user override the test with a path. 62 | ;; 63 | *) 64 | ac_save_IFS="$IFS"; IFS=$PATH_SEPARATOR 65 | for ac_dir in ifelse([$5], , $PATH, [$5]); do 66 | IFS="$ac_save_IFS" 67 | test -z "$ac_dir" && ac_dir=. 68 | for ac_exec_ext in '' $ac_executable_extensions; do 69 | if $ac_executable_p "$ac_dir/$ac_word$ac_exec_ext"; then 70 | echo "$as_me: trying $ac_dir/$ac_word..." >&AS_MESSAGE_LOG_FD 71 | if [$3]; then 72 | ac_cv_path_$1="$ac_dir/$ac_word$ac_exec_ext" 73 | break 2 74 | fi 75 | fi 76 | done 77 | done 78 | IFS="$ac_save_IFS" 79 | dnl If no 4th arg is given, leave the cache variable unset, 80 | dnl so AC_PATH_PROGS will keep looking. 81 | ifelse([$4], , , [ test -z "[$]ac_cv_path_$1" && ac_cv_path_$1="$4" 82 | ])dnl 83 | ;; 84 | esac])dnl 85 | $1="$ac_cv_path_$1" 86 | if test ifelse([$4], , [-n "[$]$1"], ["[$]$1" != "$4"]); then 87 | AC_MSG_RESULT([$]$1) 88 | else 89 | AC_MSG_RESULT(no) 90 | fi 91 | AC_SUBST($1)dnl 92 | ]) 93 | -------------------------------------------------------------------------------- /m4/size_max.m4: -------------------------------------------------------------------------------- 1 | # size_max.m4 serial 6 2 | dnl Copyright (C) 2003, 2005-2006 Free Software Foundation, Inc. 3 | dnl This file is free software; the Free Software Foundation 4 | dnl gives unlimited permission to copy and/or distribute it, 5 | dnl with or without modifications, as long as this notice is preserved. 6 | 7 | dnl From Bruno Haible. 8 | 9 | AC_DEFUN([gl_SIZE_MAX], 10 | [ 11 | AC_CHECK_HEADERS(stdint.h) 12 | dnl First test whether the system already has SIZE_MAX. 13 | AC_MSG_CHECKING([for SIZE_MAX]) 14 | AC_CACHE_VAL([gl_cv_size_max], [ 15 | gl_cv_size_max= 16 | AC_EGREP_CPP([Found it], [ 17 | #include 18 | #if HAVE_STDINT_H 19 | #include 20 | #endif 21 | #ifdef SIZE_MAX 22 | Found it 23 | #endif 24 | ], gl_cv_size_max=yes) 25 | if test -z "$gl_cv_size_max"; then 26 | dnl Define it ourselves. Here we assume that the type 'size_t' is not wider 27 | dnl than the type 'unsigned long'. Try hard to find a definition that can 28 | dnl be used in a preprocessor #if, i.e. doesn't contain a cast. 29 | AC_COMPUTE_INT([size_t_bits_minus_1], [sizeof (size_t) * CHAR_BIT - 1], 30 | [#include 31 | #include ], size_t_bits_minus_1=) 32 | AC_COMPUTE_INT([fits_in_uint], [sizeof (size_t) <= sizeof (unsigned int)], 33 | [#include ], fits_in_uint=) 34 | if test -n "$size_t_bits_minus_1" && test -n "$fits_in_uint"; then 35 | if test $fits_in_uint = 1; then 36 | dnl Even though SIZE_MAX fits in an unsigned int, it must be of type 37 | dnl 'unsigned long' if the type 'size_t' is the same as 'unsigned long'. 38 | AC_TRY_COMPILE([#include 39 | extern size_t foo; 40 | extern unsigned long foo; 41 | ], [], fits_in_uint=0) 42 | fi 43 | dnl We cannot use 'expr' to simplify this expression, because 'expr' 44 | dnl works only with 'long' integers in the host environment, while we 45 | dnl might be cross-compiling from a 32-bit platform to a 64-bit platform. 46 | if test $fits_in_uint = 1; then 47 | gl_cv_size_max="(((1U << $size_t_bits_minus_1) - 1) * 2 + 1)" 48 | else 49 | gl_cv_size_max="(((1UL << $size_t_bits_minus_1) - 1) * 2 + 1)" 50 | fi 51 | else 52 | dnl Shouldn't happen, but who knows... 53 | gl_cv_size_max='((size_t)~(size_t)0)' 54 | fi 55 | fi 56 | ]) 57 | AC_MSG_RESULT([$gl_cv_size_max]) 58 | if test "$gl_cv_size_max" != yes; then 59 | AC_DEFINE_UNQUOTED([SIZE_MAX], [$gl_cv_size_max], 60 | [Define as the maximum value of type 'size_t', if the system doesn't define it.]) 61 | fi 62 | ]) 63 | 64 | dnl Autoconf >= 2.61 has AC_COMPUTE_INT built-in. 65 | dnl Remove this when we can assume autoconf >= 2.61. 66 | m4_ifdef([AC_COMPUTE_INT], [], [ 67 | AC_DEFUN([AC_COMPUTE_INT], [_AC_COMPUTE_INT([$2],[$1],[$3],[$4])]) 68 | ]) 69 | -------------------------------------------------------------------------------- /m4/stdint_h.m4: -------------------------------------------------------------------------------- 1 | # stdint_h.m4 serial 6 2 | dnl Copyright (C) 1997-2004, 2006 Free Software Foundation, Inc. 3 | dnl This file is free software; the Free Software Foundation 4 | dnl gives unlimited permission to copy and/or distribute it, 5 | dnl with or without modifications, as long as this notice is preserved. 6 | 7 | dnl From Paul Eggert. 8 | 9 | # Define HAVE_STDINT_H_WITH_UINTMAX if exists, 10 | # doesn't clash with , and declares uintmax_t. 11 | 12 | AC_DEFUN([gl_AC_HEADER_STDINT_H], 13 | [ 14 | AC_CACHE_CHECK([for stdint.h], gl_cv_header_stdint_h, 15 | [AC_TRY_COMPILE( 16 | [#include 17 | #include ], 18 | [uintmax_t i = (uintmax_t) -1; return !i;], 19 | gl_cv_header_stdint_h=yes, 20 | gl_cv_header_stdint_h=no)]) 21 | if test $gl_cv_header_stdint_h = yes; then 22 | AC_DEFINE_UNQUOTED(HAVE_STDINT_H_WITH_UINTMAX, 1, 23 | [Define if exists, doesn't clash with , 24 | and declares uintmax_t. ]) 25 | fi 26 | ]) 27 | -------------------------------------------------------------------------------- /m4/uintmax_t.m4: -------------------------------------------------------------------------------- 1 | # uintmax_t.m4 serial 10 2 | dnl Copyright (C) 1997-2004, 2007 Free Software Foundation, Inc. 3 | dnl This file is free software; the Free Software Foundation 4 | dnl gives unlimited permission to copy and/or distribute it, 5 | dnl with or without modifications, as long as this notice is preserved. 6 | 7 | dnl From Paul Eggert. 8 | 9 | AC_PREREQ(2.13) 10 | 11 | # Define uintmax_t to 'unsigned long' or 'unsigned long long' 12 | # if it is not already defined in or . 13 | 14 | AC_DEFUN([gl_AC_TYPE_UINTMAX_T], 15 | [ 16 | AC_REQUIRE([gl_AC_HEADER_INTTYPES_H]) 17 | AC_REQUIRE([gl_AC_HEADER_STDINT_H]) 18 | if test $gl_cv_header_inttypes_h = no && test $gl_cv_header_stdint_h = no; then 19 | AC_REQUIRE([AC_TYPE_UNSIGNED_LONG_LONG_INT]) 20 | test $ac_cv_type_unsigned_long_long_int = yes \ 21 | && ac_type='unsigned long long' \ 22 | || ac_type='unsigned long' 23 | AC_DEFINE_UNQUOTED(uintmax_t, $ac_type, 24 | [Define to unsigned long or unsigned long long 25 | if and don't define.]) 26 | else 27 | AC_DEFINE(HAVE_UINTMAX_T, 1, 28 | [Define if you have the 'uintmax_t' type in or .]) 29 | fi 30 | ]) 31 | -------------------------------------------------------------------------------- /m4/visibility.m4: -------------------------------------------------------------------------------- 1 | # visibility.m4 serial 1 (gettext-0.15) 2 | dnl Copyright (C) 2005 Free Software Foundation, Inc. 3 | dnl This file is free software; the Free Software Foundation 4 | dnl gives unlimited permission to copy and/or distribute it, 5 | dnl with or without modifications, as long as this notice is preserved. 6 | 7 | dnl From Bruno Haible. 8 | 9 | dnl Tests whether the compiler supports the command-line option 10 | dnl -fvisibility=hidden and the function and variable attributes 11 | dnl __attribute__((__visibility__("hidden"))) and 12 | dnl __attribute__((__visibility__("default"))). 13 | dnl Does *not* test for __visibility__("protected") - which has tricky 14 | dnl semantics (see the 'vismain' test in glibc) and does not exist e.g. on 15 | dnl MacOS X. 16 | dnl Does *not* test for __visibility__("internal") - which has processor 17 | dnl dependent semantics. 18 | dnl Does *not* test for #pragma GCC visibility push(hidden) - which is 19 | dnl "really only recommended for legacy code". 20 | dnl Set the variable CFLAG_VISIBILITY. 21 | dnl Defines and sets the variable HAVE_VISIBILITY. 22 | 23 | AC_DEFUN([gl_VISIBILITY], 24 | [ 25 | AC_REQUIRE([AC_PROG_CC]) 26 | CFLAG_VISIBILITY= 27 | HAVE_VISIBILITY=0 28 | if test -n "$GCC"; then 29 | AC_MSG_CHECKING([for simple visibility declarations]) 30 | AC_CACHE_VAL(gl_cv_cc_visibility, [ 31 | gl_save_CFLAGS="$CFLAGS" 32 | CFLAGS="$CFLAGS -fvisibility=hidden" 33 | AC_TRY_COMPILE( 34 | [extern __attribute__((__visibility__("hidden"))) int hiddenvar; 35 | extern __attribute__((__visibility__("default"))) int exportedvar; 36 | extern __attribute__((__visibility__("hidden"))) int hiddenfunc (void); 37 | extern __attribute__((__visibility__("default"))) int exportedfunc (void);], 38 | [], 39 | gl_cv_cc_visibility=yes, 40 | gl_cv_cc_visibility=no) 41 | CFLAGS="$gl_save_CFLAGS"]) 42 | AC_MSG_RESULT([$gl_cv_cc_visibility]) 43 | if test $gl_cv_cc_visibility = yes; then 44 | CFLAG_VISIBILITY="-fvisibility=hidden" 45 | HAVE_VISIBILITY=1 46 | fi 47 | fi 48 | AC_SUBST([CFLAG_VISIBILITY]) 49 | AC_SUBST([HAVE_VISIBILITY]) 50 | AC_DEFINE_UNQUOTED([HAVE_VISIBILITY], [$HAVE_VISIBILITY], 51 | [Define to 1 or 0, depending whether the compiler supports simple visibility declarations.]) 52 | ]) 53 | -------------------------------------------------------------------------------- /m4/wchar_t.m4: -------------------------------------------------------------------------------- 1 | # wchar_t.m4 serial 1 (gettext-0.12) 2 | dnl Copyright (C) 2002-2003 Free Software Foundation, Inc. 3 | dnl This file is free software; the Free Software Foundation 4 | dnl gives unlimited permission to copy and/or distribute it, 5 | dnl with or without modifications, as long as this notice is preserved. 6 | 7 | dnl From Bruno Haible. 8 | dnl Test whether has the 'wchar_t' type. 9 | dnl Prerequisite: AC_PROG_CC 10 | 11 | AC_DEFUN([gt_TYPE_WCHAR_T], 12 | [ 13 | AC_CACHE_CHECK([for wchar_t], gt_cv_c_wchar_t, 14 | [AC_TRY_COMPILE([#include 15 | wchar_t foo = (wchar_t)'\0';], , 16 | gt_cv_c_wchar_t=yes, gt_cv_c_wchar_t=no)]) 17 | if test $gt_cv_c_wchar_t = yes; then 18 | AC_DEFINE(HAVE_WCHAR_T, 1, [Define if you have the 'wchar_t' type.]) 19 | fi 20 | ]) 21 | -------------------------------------------------------------------------------- /m4/wint_t.m4: -------------------------------------------------------------------------------- 1 | # wint_t.m4 serial 2 (gettext-0.17) 2 | dnl Copyright (C) 2003, 2007 Free Software Foundation, Inc. 3 | dnl This file is free software; the Free Software Foundation 4 | dnl gives unlimited permission to copy and/or distribute it, 5 | dnl with or without modifications, as long as this notice is preserved. 6 | 7 | dnl From Bruno Haible. 8 | dnl Test whether has the 'wint_t' type. 9 | dnl Prerequisite: AC_PROG_CC 10 | 11 | AC_DEFUN([gt_TYPE_WINT_T], 12 | [ 13 | AC_CACHE_CHECK([for wint_t], gt_cv_c_wint_t, 14 | [AC_TRY_COMPILE([ 15 | /* Tru64 with Desktop Toolkit C has a bug: must be included before 16 | . 17 | BSD/OS 4.0.1 has a bug: , and must be included 18 | before . */ 19 | #include 20 | #include 21 | #include 22 | #include 23 | wint_t foo = (wchar_t)'\0';], , 24 | gt_cv_c_wint_t=yes, gt_cv_c_wint_t=no)]) 25 | if test $gt_cv_c_wint_t = yes; then 26 | AC_DEFINE(HAVE_WINT_T, 1, [Define if you have the 'wint_t' type.]) 27 | fi 28 | ]) 29 | -------------------------------------------------------------------------------- /m4/xsize.m4: -------------------------------------------------------------------------------- 1 | # xsize.m4 serial 3 2 | dnl Copyright (C) 2003-2004 Free Software Foundation, Inc. 3 | dnl This file is free software; the Free Software Foundation 4 | dnl gives unlimited permission to copy and/or distribute it, 5 | dnl with or without modifications, as long as this notice is preserved. 6 | 7 | AC_DEFUN([gl_XSIZE], 8 | [ 9 | dnl Prerequisites of lib/xsize.h. 10 | AC_REQUIRE([gl_SIZE_MAX]) 11 | AC_REQUIRE([AC_C_INLINE]) 12 | AC_CHECK_HEADERS(stdint.h) 13 | ]) 14 | -------------------------------------------------------------------------------- /po/ChangeLog: -------------------------------------------------------------------------------- 1 | 2009-05-27 gettextize 2 | 3 | * Makefile.in.in: Upgrade to gettext-0.17. 4 | 5 | 2008-01-19 gettextize 6 | 7 | * Makefile.in.in: Upgrade to gettext-0.16.1. 8 | 9 | 2006-02-25 gettextize 10 | 11 | * Makefile.in.in: New file, from gettext-0.14.5. 12 | * Rules-quot: Upgrade to gettext-0.14.5. 13 | 14 | -------------------------------------------------------------------------------- /po/LINGUAS: -------------------------------------------------------------------------------- 1 | en@quot 2 | en@boldquot 3 | 4 | -------------------------------------------------------------------------------- /po/Makevars.template: -------------------------------------------------------------------------------- 1 | # Makefile variables for PO directory in any package using GNU gettext. 2 | 3 | # Usually the message domain is the same as the package name. 4 | DOMAIN = $(PACKAGE) 5 | 6 | # These two variables depend on the location of this directory. 7 | subdir = po 8 | top_builddir = .. 9 | 10 | # These options get passed to xgettext. 11 | XGETTEXT_OPTIONS = --keyword=_ --keyword=N_ 12 | 13 | # This is the copyright holder that gets inserted into the header of the 14 | # $(DOMAIN).pot file. Set this to the copyright holder of the surrounding 15 | # package. (Note that the msgstr strings, extracted from the package's 16 | # sources, belong to the copyright holder of the package.) Translators are 17 | # expected to transfer the copyright for their translations to this person 18 | # or entity, or to disclaim their copyright. The empty string stands for 19 | # the public domain; in this case the translators are expected to disclaim 20 | # their copyright. 21 | COPYRIGHT_HOLDER = Free Software Foundation, Inc. 22 | 23 | # This is the email address or URL to which the translators shall report 24 | # bugs in the untranslated strings: 25 | # - Strings which are not entire sentences, see the maintainer guidelines 26 | # in the GNU gettext documentation, section 'Preparing Strings'. 27 | # - Strings which use unclear terms or require additional context to be 28 | # understood. 29 | # - Strings which make invalid assumptions about notation of date, time or 30 | # money. 31 | # - Pluralisation problems. 32 | # - Incorrect English spelling. 33 | # - Incorrect formatting. 34 | # It can be your email address, or a mailing list address where translators 35 | # can write to without being subscribed, or the URL of a web page through 36 | # which the translators can contact you. 37 | MSGID_BUGS_ADDRESS = 38 | 39 | # This is the list of locale categories, beyond LC_MESSAGES, for which the 40 | # message catalogs shall be used. It is usually empty. 41 | EXTRA_LOCALE_CATEGORIES = 42 | -------------------------------------------------------------------------------- /po/POTFILES.in: -------------------------------------------------------------------------------- 1 | src/bsd-getopt_long.c 2 | src/bsd-getopt_long.h 3 | src/carp.c 4 | src/carp_p.h 5 | src/crypto.h 6 | src/crypto-sha1.c 7 | src/crypto-sha1.h 8 | src/daemonize.c 9 | src/daemonize.h 10 | src/fakesnprintf.c 11 | src/fakesnprintf.h 12 | src/fillmac.c 13 | src/fillmac.h 14 | src/garp.c 15 | src/garp.h 16 | src/globals.h 17 | src/ip_carp.h 18 | src/mysnprintf.c 19 | src/mysnprintf.h 20 | src/spawn.c 21 | src/spawn.h 22 | src/ucarp.c 23 | src/ucarp.h 24 | src/ucarp_p.h 25 | -------------------------------------------------------------------------------- /po/ucarp.pot: -------------------------------------------------------------------------------- 1 | # SOME DESCRIPTIVE TITLE. 2 | # Copyright (C) YEAR UCARP team 3 | # This file is distributed under the same license as the PACKAGE package. 4 | # FIRST AUTHOR , YEAR. 5 | # 6 | #, fuzzy 7 | msgid "" 8 | msgstr "" 9 | "Project-Id-Version: ucarp 1.5.2\n" 10 | "Report-Msgid-Bugs-To: nobody@example.org\n" 11 | "POT-Creation-Date: 2010-01-31 23:04+0100\n" 12 | "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" 13 | "Last-Translator: FULL NAME \n" 14 | "Language-Team: LANGUAGE \n" 15 | "MIME-Version: 1.0\n" 16 | "Content-Type: text/plain; charset=CHARSET\n" 17 | "Content-Transfer-Encoding: 8bit\n" 18 | 19 | #: src/carp.c:58 20 | msgid "Switching to state: INIT" 21 | msgstr "" 22 | 23 | #: src/carp.c:61 24 | msgid "Switching to state: BACKUP" 25 | msgstr "" 26 | 27 | #: src/carp.c:67 28 | msgid "Switching to state: MASTER" 29 | msgstr "" 30 | 31 | #: src/carp.c:72 32 | #, c-format 33 | msgid "Unknown state: [%d]" 34 | msgstr "" 35 | 36 | #: src/carp.c:222 37 | msgid "Out of memory to create packet" 38 | msgstr "" 39 | 40 | #: src/carp.c:287 41 | #, c-format 42 | msgid "write() has failed: %s" 43 | msgstr "" 44 | 45 | #: src/carp.c:293 46 | #, c-format 47 | msgid "write() error #%d/%d" 48 | msgstr "" 49 | 50 | #: src/carp.c:314 51 | msgid "* advertisement injected *" 52 | msgstr "" 53 | 54 | #: src/carp.c:346 src/carp.c:772 55 | #, c-format 56 | msgid "initializing now to gettimeofday() failed: %s" 57 | msgstr "" 58 | 59 | #: src/carp.c:397 60 | msgid "master_down event in INIT state" 61 | msgstr "" 62 | 63 | #: src/carp.c:502 64 | #, c-format 65 | msgid "Bad TTL: [%u]" 66 | msgstr "" 67 | 68 | #: src/carp.c:507 69 | #, c-format 70 | msgid "Bad version: [%u]" 71 | msgstr "" 72 | 73 | #: src/carp.c:513 74 | #, c-format 75 | msgid "Ignoring vhid: [%u]" 76 | msgstr "" 77 | 78 | #: src/carp.c:519 79 | msgid "Bad IP checksum" 80 | msgstr "" 81 | 82 | #: src/carp.c:542 83 | #, c-format 84 | msgid "" 85 | "Bad digest - md2=[%02x%02x%02x%02x...] md=[%02x%02x%02x%02x...] - Check " 86 | "vhid, password and virtual IP address" 87 | msgstr "" 88 | 89 | #: src/carp.c:598 90 | msgid "Preferred master advertised: going back to BACKUP state" 91 | msgstr "" 92 | 93 | #: src/carp.c:613 94 | msgid "" 95 | "Non-preferred master advertising: reasserting control of VIP with another " 96 | "gratuitous arp" 97 | msgstr "" 98 | 99 | #: src/carp.c:624 100 | msgid "Putting MASTER down - preemption" 101 | msgstr "" 102 | 103 | #: src/carp.c:637 104 | msgid "Putting MASTER DOWN (going to time out)" 105 | msgstr "" 106 | 107 | #: src/carp.c:724 108 | msgid "Password too long" 109 | msgstr "" 110 | 111 | #: src/carp.c:737 112 | #, c-format 113 | msgid "Unable to find MAC address of [%s]" 114 | msgstr "" 115 | 116 | #: src/carp.c:741 117 | #, c-format 118 | msgid "Local advertised ethernet address is [%02x:%02x:%02x:%02x:%02x:%02x]" 119 | msgstr "" 120 | 121 | #: src/carp.c:748 122 | #, c-format 123 | msgid "Unable to open interface [%s]: %s" 124 | msgstr "" 125 | 126 | #: src/carp.c:754 127 | #, c-format 128 | msgid "Unable to compile pcap rule: %s [%s]" 129 | msgstr "" 130 | 131 | #: src/carp.c:778 132 | #, c-format 133 | msgid "Error opening socket for interface [%s]: %s" 134 | msgstr "" 135 | 136 | #: src/carp.c:796 src/fillmac.c:51 137 | msgid "Interface name too long" 138 | msgstr "" 139 | 140 | #: src/carp.c:854 src/carp.c:875 141 | #, c-format 142 | msgid "gettimeofday() failed: %s" 143 | msgstr "" 144 | 145 | #: src/carp.c:867 146 | #, c-format 147 | msgid "exiting: poll() error: %s" 148 | msgstr "" 149 | 150 | #: src/carp.c:870 151 | #, c-format 152 | msgid "exiting: pfds[0].revents = %d" 153 | msgstr "" 154 | 155 | #: src/daemonize.c:53 156 | #, c-format 157 | msgid "Unable to get in background: [fork: %s]" 158 | msgstr "" 159 | 160 | #: src/daemonize.c:61 161 | #, c-format 162 | msgid "Unable to detach from the current session: %s" 163 | msgstr "" 164 | 165 | #: src/daemonize.c:74 166 | msgid "Unable to detach: /dev/null can't be duplicated" 167 | msgstr "" 168 | 169 | #: src/fillmac.c:42 170 | #, c-format 171 | msgid "Unable to open raw device: [%s]" 172 | msgstr "" 173 | 174 | #: src/fillmac.c:57 175 | #, c-format 176 | msgid "Unable to get hardware info about an interface: %s" 177 | msgstr "" 178 | 179 | #: src/fillmac.c:67 180 | #, c-format 181 | msgid "Unknown hardware type [%u]" 182 | msgstr "" 183 | 184 | #: src/fillmac.c:80 185 | #, c-format 186 | msgid "Unable to get interface address: %s" 187 | msgstr "" 188 | 189 | #: src/fillmac.c:92 190 | #, c-format 191 | msgid "Invalid media / hardware address for [%s]" 192 | msgstr "" 193 | 194 | #: src/fillmac.c:116 195 | msgid "ioctl SIOCGLIFNUM error" 196 | msgstr "" 197 | 198 | #: src/fillmac.c:120 199 | msgid "No interface found" 200 | msgstr "" 201 | 202 | #: src/fillmac.c:128 203 | msgid "ioctl SIOCGLIFCONF error" 204 | msgstr "" 205 | 206 | #: src/fillmac.c:135 207 | #, c-format 208 | msgid "Interface [%s] not found" 209 | msgstr "" 210 | 211 | #: src/fillmac.c:148 212 | #, c-format 213 | msgid "Unable to get hardware info about [%s]" 214 | msgstr "" 215 | 216 | #: src/garp.c:50 217 | msgid "out of memory to send gratuitous ARP" 218 | msgstr "" 219 | 220 | #: src/garp.c:60 221 | #, c-format 222 | msgid "write() in garp: %s" 223 | msgstr "" 224 | 225 | #: src/spawn.c:24 226 | #, c-format 227 | msgid "Unable to exec %s %s %s%s%s: %s" 228 | msgstr "" 229 | 230 | #: src/spawn.c:30 231 | #, c-format 232 | msgid "Spawning [%s %s %s%s%s]" 233 | msgstr "" 234 | 235 | #: src/spawn.c:50 236 | #, c-format 237 | msgid "Unable to spawn the script: %s" 238 | msgstr "" 239 | 240 | #: src/ucarp.c:26 241 | msgid "" 242 | "--interface= (-i ): bind interface \n" 243 | "--srcip= (-s ): source (real) IP address of that host\n" 244 | "--vhid= (-v ): virtual IP identifier (1-255)\n" 245 | "--pass= (-p ): password\n" 246 | "--passfile= (-o ): read password from file\n" 247 | "--preempt (-P): becomes a master as soon as possible\n" 248 | "--neutral (-n): don't run downscript at start if backup\n" 249 | "--addr= (-a ): virtual shared IP address\n" 250 | "--help (-h): summary of command-line options\n" 251 | "--advbase= (-b ): advertisement frequency\n" 252 | "--advskew= (-k ): advertisement skew (0-255)\n" 253 | "--upscript= (-u ): run to become a master\n" 254 | "--downscript= (-d ): run to become a backup\n" 255 | "--deadratio= (-r ): ratio to consider a host as dead\n" 256 | "--shutdown (-z): call shutdown script at exit\n" 257 | "--daemonize (-B): run in background\n" 258 | "--ignoreifstate (-S): ignore interface state (down, no carrier)\n" 259 | "--nomcast (-M): use broadcast (instead of multicast) advertisements\n" 260 | "--facility= (-f): set syslog facility (default=daemon)\n" 261 | "--xparam= (-x): extra parameter to send to up/down scripts\n" 262 | "\n" 263 | "Sample usage:\n" 264 | "\n" 265 | "Manage the 10.1.1.252 shared virtual address on interface eth0, with\n" 266 | "1 as a virtual address idenfitier, mypassword as a password, and\n" 267 | "10.1.1.1 as a real permanent address for this host.\n" 268 | "Call /etc/vip-up.sh when the host becomes a master, and\n" 269 | "/etc/vip-down.sh when the virtual IP address has to be disabled.\n" 270 | "\n" 271 | "ucarp --interface=eth0 --srcip=10.1.1.1 --vhid=1 --pass=mypassword \\\n" 272 | " --addr=10.1.1.252 \\\n" 273 | " --upscript=/etc/vip-up.sh --downscript=/etc/vip-down.sh\n" 274 | "\n" 275 | "\n" 276 | "Please report bugs to " 277 | msgstr "" 278 | 279 | #: src/ucarp.c:81 280 | msgid "Out of memory" 281 | msgstr "" 282 | 283 | #: src/ucarp.c:115 src/ucarp.c:168 284 | #, c-format 285 | msgid "Invalid address: [%s]" 286 | msgstr "" 287 | 288 | #: src/ucarp.c:137 289 | #, c-format 290 | msgid "unable to open passfile %s for reading: %s" 291 | msgstr "" 292 | 293 | #: src/ucarp.c:142 294 | #, c-format 295 | msgid "error reading passfile %s: %s" 296 | msgstr "" 297 | 298 | #: src/ucarp.c:144 299 | msgid "unexpected end of file" 300 | msgstr "" 301 | 302 | #: src/ucarp.c:226 303 | #, c-format 304 | msgid "Unknown syslog facility: [%s]" 305 | msgstr "" 306 | 307 | #: src/ucarp.c:254 308 | msgid "You must supply a network interface" 309 | msgstr "" 310 | 311 | #: src/ucarp.c:257 312 | #, c-format 313 | msgid "Using [%s] as a network interface" 314 | msgstr "" 315 | 316 | #: src/ucarp.c:260 317 | msgid "You must supply a valid virtual host id" 318 | msgstr "" 319 | 320 | #: src/ucarp.c:264 321 | msgid "You must supply a password" 322 | msgstr "" 323 | 324 | #: src/ucarp.c:268 325 | msgid "You must supply an advertisement time base" 326 | msgstr "" 327 | 328 | #: src/ucarp.c:272 329 | msgid "You must supply a persistent source address" 330 | msgstr "" 331 | 332 | #: src/ucarp.c:276 333 | msgid "You must supply a virtual host address" 334 | msgstr "" 335 | 336 | #: src/ucarp.c:280 337 | msgid "Warning: no script called when going up" 338 | msgstr "" 339 | 340 | #: src/ucarp.c:283 341 | msgid "Warning: no script called when going down" 342 | msgstr "" 343 | 344 | #: src/ucarp.c:286 345 | msgid "Dead ratio can't be zero" 346 | msgstr "" 347 | -------------------------------------------------------------------------------- /src/Makefile.am: -------------------------------------------------------------------------------- 1 | localedir = $(datadir)/locale 2 | 3 | INCLUDES = -DLOCALEDIR=\"$(localedir)\" 4 | 5 | sbin_PROGRAMS = \ 6 | ucarp 7 | 8 | ucarp_SOURCES = \ 9 | gettext.h \ 10 | ucarp.c \ 11 | ucarp.h \ 12 | carp.c \ 13 | carp_p.h \ 14 | ucarp_p.h \ 15 | ip_carp.h \ 16 | crypto-sha1.c \ 17 | crypto.h \ 18 | crypto-sha1.h \ 19 | globals.h \ 20 | fillmac.c \ 21 | fillmac.h \ 22 | bsd-getopt_long.h \ 23 | bsd-getopt_long.c \ 24 | garp.c \ 25 | garp.h \ 26 | spawn.c \ 27 | spawn.h \ 28 | fakesnprintf.c \ 29 | fakesnprintf.h \ 30 | mysnprintf.c \ 31 | mysnprintf.h \ 32 | log.c \ 33 | log.h \ 34 | daemonize.c \ 35 | daemonize.h \ 36 | syslognames.h 37 | 38 | ucarp_LDADD = \ 39 | $(LTLIBINTL) 40 | 41 | -------------------------------------------------------------------------------- /src/bsd-getopt_long.h: -------------------------------------------------------------------------------- 1 | 2 | /* $OpenBSD: getopt_long.c,v 1.13 2003/06/03 01:52:40 millert Exp $ */ 3 | /* $NetBSD: getopt_long.c,v 1.15 2002/01/31 22:43:40 tv Exp $ */ 4 | 5 | /* 6 | * Copyright (c) 2002 Todd C. Miller 7 | * 8 | * Permission to use, copy, modify, and distribute this software for any 9 | * purpose with or without fee is hereby granted, provided that the above 10 | * copyright notice and this permission notice appear in all copies. 11 | * 12 | * THE SOFTWARE IS PROVIDED "AS IS" AND TODD C. MILLER DISCLAIMS ALL 13 | * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES 14 | * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL TODD C. MILLER BE LIABLE 15 | * FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 16 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION 17 | * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN 18 | * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 19 | */ 20 | /*- 21 | * Copyright (c) 2000 The NetBSD Foundation, Inc. 22 | * All rights reserved. 23 | * 24 | * This code is derived from software contributed to The NetBSD Foundation 25 | * by Dieter Baron and Thomas Klausner. 26 | * 27 | * Redistribution and use in source and binary forms, with or without 28 | * modification, are permitted provided that the following conditions 29 | * are met: 30 | * 1. Redistributions of source code must retain the above copyright 31 | * notice, this list of conditions and the following disclaimer. 32 | * 2. Redistributions in binary form must reproduce the above copyright 33 | * notice, this list of conditions and the following disclaimer in the 34 | * documentation and/or other materials provided with the distribution. 35 | * 3. All advertising materials mentioning features or use of this software 36 | * must display the following acknowledgement: 37 | * This product includes software developed by the NetBSD 38 | * Foundation, Inc. and its contributors. 39 | * 4. Neither the name of The NetBSD Foundation nor the names of its 40 | * contributors may be used to endorse or promote products derived 41 | * from this software without specific prior written permission. 42 | * 43 | * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 44 | * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 45 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 46 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 47 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 48 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 49 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 50 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 51 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 52 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 53 | * POSSIBILITY OF SUCH DAMAGE. 54 | */ 55 | 56 | #ifndef __BSD_GETOPT_LONG_H__ 57 | #define __BSD_GETOPT_LONG_H__ 58 | 59 | #ifndef HAVE_GETOPT_LONG 60 | 61 | /* 62 | * GNU-like getopt_long() and 4.4BSD getsubopt()/optreset extensions 63 | */ 64 | # ifndef no_argument 65 | # define no_argument 0 66 | # endif 67 | # ifndef required_argument 68 | # define required_argument 1 69 | # endif 70 | # ifndef optional_argument 71 | # define optional_argument 2 72 | # endif 73 | 74 | struct pure_option { 75 | /* name of long option */ 76 | const char *name; 77 | /* 78 | * one of no_argument, required_argument, and optional_argument: 79 | * whether option takes an argument 80 | */ 81 | int has_arg; 82 | /* if not NULL, set *flag to val when option found */ 83 | int *flag; 84 | /* if flag not NULL, value to set *flag to; else return value */ 85 | int val; 86 | }; 87 | 88 | int pure_getopt_long(int nargc, char * const *nargv, const char *options, 89 | const struct pure_option *long_options, int *idx); 90 | 91 | int pure_getopt_long_only(int nargc, char * const *nargv, 92 | const char *options, 93 | const struct pure_option *long_options, 94 | int *idx); 95 | 96 | int pure_getopt(int nargc, char * const *nargv, const char *options); 97 | 98 | extern const char *pure_optarg; /* getopt(3) external variables */ 99 | extern int pure_opterr; 100 | extern int pure_optind; 101 | extern int pure_optopt; 102 | extern int pure_optreset; 103 | 104 | /* prefix+macros just to avoid clashes with existing getopt() implementations */ 105 | 106 | # ifndef IN_GETOPT_LONG_C 107 | # undef option 108 | # define option pure_option 109 | # undef getopt_long 110 | # define getopt_long(A, B, C, D, E) pure_getopt_long(A, B, C, D, E) 111 | # undef getopt_long_only 112 | # define getopt_long_only(A, B, C, D, E) pure_getopt_long_only(A, B, C, D, E) 113 | # undef getopt 114 | # define getopt(A, B, C) pure_getopt(A, B, C) 115 | # undef optarg 116 | # define optarg pure_optarg 117 | # undef opterr 118 | # define opterr pure_opterr 119 | # undef optind 120 | # define optind pure_optind 121 | # undef optopt 122 | # define optopt pure_optopt 123 | # undef optreset 124 | # define optreset pure_optreset 125 | # endif 126 | 127 | #endif 128 | 129 | #endif 130 | -------------------------------------------------------------------------------- /src/carp_p.h: -------------------------------------------------------------------------------- 1 | #ifndef __CARP_P_H__ 2 | #define __CARP_P_H__ 1 3 | 4 | static struct carp_softc sc; 5 | static struct timeval now; 6 | static pcap_t *dev_desc; 7 | static int dev_desc_fd = -1; 8 | static int carp_suppress_preempt; 9 | 10 | static void carp_send_ad_all(struct carp_softc *sc); 11 | 12 | #endif 13 | -------------------------------------------------------------------------------- /src/crypto-sha1.c: -------------------------------------------------------------------------------- 1 | /* 2 | * SHA-1 in C 3 | * By Steve Reid 4 | * 100% Public Domain 5 | * 6 | * Test Vectors (from FIPS PUB 180-1) 7 | * "abc" 8 | * A9993E36 4706816A BA3E2571 7850C26C 9CD0D89D 9 | * "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq" 10 | * 84983E44 1C3BD26E BAAE4AA1 F95129E5 E54670F1 11 | * A million repetitions of "a" 12 | * 34AA973C D4C4DAA4 F61EEB2B DBAD2731 6534016F 13 | */ 14 | 15 | #include 16 | 17 | #ifndef USE_SYSTEM_CRYPT_SHA1 18 | 19 | #include "ucarp.h" 20 | #include "crypto.h" 21 | #include "crypto-sha1.h" 22 | 23 | #ifdef WITH_DMALLOC 24 | # include 25 | #endif 26 | 27 | /* #define SHA1HANDSOFF * Copies data before messing with it. */ 28 | 29 | #define SHA1HANDSOFF 30 | 31 | #define rol(value, bits) (((value) << (bits)) | ((value) >> (32 - (bits)))) 32 | 33 | /* blk0() and blk() perform the initial expand. */ 34 | /* I got the idea of expanding during the round function from SSLeay */ 35 | #ifndef WORDS_BIGENDIAN 36 | # define blk0(i) (block->l[i] = (rol(block->l[i],24)&0xFF00FF00) \ 37 | |(rol(block->l[i],8)&0x00FF00FF)) 38 | #else 39 | # define blk0(i) block->l[i] 40 | #endif 41 | #define blk(i) (block->l[i&15] = rol(block->l[(i+13)&15]^block->l[(i+8)&15] \ 42 | ^block->l[(i+2)&15]^block->l[i&15],1)) 43 | 44 | /* (R0+R1), R2, R3, R4 are the different operations used in SHA1 */ 45 | #define R0(v,w,x,y,z,i) z+=((w&(x^y))^y)+blk0(i)+0x5A827999+rol(v,5);w=rol(w,30); 46 | #define R1(v,w,x,y,z,i) z+=((w&(x^y))^y)+blk(i)+0x5A827999+rol(v,5);w=rol(w,30); 47 | #define R2(v,w,x,y,z,i) z+=(w^x^y)+blk(i)+0x6ED9EBA1+rol(v,5);w=rol(w,30); 48 | #define R3(v,w,x,y,z,i) z+=(((w|x)&y)|(w&x))+blk(i)+0x8F1BBCDC+rol(v,5);w=rol(w,30); 49 | #define R4(v,w,x,y,z,i) z+=(w^x^y)+blk(i)+0xCA62C1D6+rol(v,5);w=rol(w,30); 50 | 51 | 52 | /* Hash a single 512-bit block. This is the core of the algorithm. */ 53 | 54 | static void SHA1Transform(crypto_uint4 state[5], 55 | const unsigned char buffer[64]) 56 | { 57 | crypto_uint4 a, b, c, d, e; 58 | typedef union { 59 | unsigned char c[64]; 60 | unsigned int l[16]; 61 | } CHAR64LONG16; 62 | CHAR64LONG16 *block; 63 | #ifdef SHA1HANDSOFF 64 | static CHAR64LONG16 workspace; 65 | 66 | block = &workspace; 67 | memcpy(block, buffer, 64); 68 | #else 69 | block = (CHAR64LONG16 *) buffer; 70 | #endif 71 | /* Copy context->state[] to working vars */ 72 | a = state[0]; 73 | b = state[1]; 74 | c = state[2]; 75 | d = state[3]; 76 | e = state[4]; 77 | /* 4 rounds of 20 operations each. Loop unrolled. */ 78 | R0(a, b, c, d, e, 0); 79 | R0(e, a, b, c, d, 1); 80 | R0(d, e, a, b, c, 2); 81 | R0(c, d, e, a, b, 3); 82 | R0(b, c, d, e, a, 4); 83 | R0(a, b, c, d, e, 5); 84 | R0(e, a, b, c, d, 6); 85 | R0(d, e, a, b, c, 7); 86 | R0(c, d, e, a, b, 8); 87 | R0(b, c, d, e, a, 9); 88 | R0(a, b, c, d, e, 10); 89 | R0(e, a, b, c, d, 11); 90 | R0(d, e, a, b, c, 12); 91 | R0(c, d, e, a, b, 13); 92 | R0(b, c, d, e, a, 14); 93 | R0(a, b, c, d, e, 15); 94 | R1(e, a, b, c, d, 16); 95 | R1(d, e, a, b, c, 17); 96 | R1(c, d, e, a, b, 18); 97 | R1(b, c, d, e, a, 19); 98 | R2(a, b, c, d, e, 20); 99 | R2(e, a, b, c, d, 21); 100 | R2(d, e, a, b, c, 22); 101 | R2(c, d, e, a, b, 23); 102 | R2(b, c, d, e, a, 24); 103 | R2(a, b, c, d, e, 25); 104 | R2(e, a, b, c, d, 26); 105 | R2(d, e, a, b, c, 27); 106 | R2(c, d, e, a, b, 28); 107 | R2(b, c, d, e, a, 29); 108 | R2(a, b, c, d, e, 30); 109 | R2(e, a, b, c, d, 31); 110 | R2(d, e, a, b, c, 32); 111 | R2(c, d, e, a, b, 33); 112 | R2(b, c, d, e, a, 34); 113 | R2(a, b, c, d, e, 35); 114 | R2(e, a, b, c, d, 36); 115 | R2(d, e, a, b, c, 37); 116 | R2(c, d, e, a, b, 38); 117 | R2(b, c, d, e, a, 39); 118 | R3(a, b, c, d, e, 40); 119 | R3(e, a, b, c, d, 41); 120 | R3(d, e, a, b, c, 42); 121 | R3(c, d, e, a, b, 43); 122 | R3(b, c, d, e, a, 44); 123 | R3(a, b, c, d, e, 45); 124 | R3(e, a, b, c, d, 46); 125 | R3(d, e, a, b, c, 47); 126 | R3(c, d, e, a, b, 48); 127 | R3(b, c, d, e, a, 49); 128 | R3(a, b, c, d, e, 50); 129 | R3(e, a, b, c, d, 51); 130 | R3(d, e, a, b, c, 52); 131 | R3(c, d, e, a, b, 53); 132 | R3(b, c, d, e, a, 54); 133 | R3(a, b, c, d, e, 55); 134 | R3(e, a, b, c, d, 56); 135 | R3(d, e, a, b, c, 57); 136 | R3(c, d, e, a, b, 58); 137 | R3(b, c, d, e, a, 59); 138 | R4(a, b, c, d, e, 60); 139 | R4(e, a, b, c, d, 61); 140 | R4(d, e, a, b, c, 62); 141 | R4(c, d, e, a, b, 63); 142 | R4(b, c, d, e, a, 64); 143 | R4(a, b, c, d, e, 65); 144 | R4(e, a, b, c, d, 66); 145 | R4(d, e, a, b, c, 67); 146 | R4(c, d, e, a, b, 68); 147 | R4(b, c, d, e, a, 69); 148 | R4(a, b, c, d, e, 70); 149 | R4(e, a, b, c, d, 71); 150 | R4(d, e, a, b, c, 72); 151 | R4(c, d, e, a, b, 73); 152 | R4(b, c, d, e, a, 74); 153 | R4(a, b, c, d, e, 75); 154 | R4(e, a, b, c, d, 76); 155 | R4(d, e, a, b, c, 77); 156 | R4(c, d, e, a, b, 78); 157 | R4(b, c, d, e, a, 79); 158 | /* Add the working vars back into context.state[] */ 159 | state[0] += a; 160 | state[1] += b; 161 | state[2] += c; 162 | state[3] += d; 163 | state[4] += e; 164 | /* Wipe variables */ 165 | a = b = c = d = e = 0; 166 | } 167 | 168 | 169 | /* SHA1Init - Initialize new context */ 170 | 171 | void SHA1Init(SHA1_CTX * context) 172 | { 173 | /* SHA1 initialization constants */ 174 | context->state[0] = 0x67452301; 175 | context->state[1] = 0xEFCDAB89; 176 | context->state[2] = 0x98BADCFE; 177 | context->state[3] = 0x10325476; 178 | context->state[4] = 0xC3D2E1F0; 179 | context->count[0] = context->count[1] = 0; 180 | } 181 | 182 | 183 | /* Run your data through this. */ 184 | 185 | void SHA1Update(SHA1_CTX * context, const unsigned char *data, 186 | unsigned int len) 187 | { 188 | unsigned int i; 189 | unsigned int j; 190 | 191 | j = context->count[0]; 192 | if ((context->count[0] += len << 3) < j) 193 | context->count[1] += (len >> 29) + 1; 194 | j = (j >> 3) & 63; 195 | if ((j + len) > 63) { 196 | memcpy(&context->buffer[j], data, (i = 64 - j)); 197 | SHA1Transform(context->state, context->buffer); 198 | for (; i + 63 < len; i += 64) { 199 | SHA1Transform(context->state, &data[i]); 200 | } 201 | j = 0; 202 | } else 203 | i = 0; 204 | memcpy(&context->buffer[j], &data[i], len - i); 205 | } 206 | 207 | 208 | /* Add padding and return the message digest. */ 209 | 210 | void SHA1Final(unsigned char digest[20], SHA1_CTX * context) 211 | { 212 | unsigned int i; 213 | unsigned char finalcount[8]; 214 | 215 | for (i = 0; i < 8; i++) { 216 | finalcount[i] = (unsigned char) ((context->count[(i >= 4 ? 0 : 1)] 217 | >> ((3 - (i & 3)) * 8)) & 255); /* Endian independent */ 218 | } 219 | SHA1Update(context, (const unsigned char *) "\200", 1); 220 | while ((context->count[0] & 504) != 448) { 221 | SHA1Update(context, (const unsigned char *) "\0", 1); 222 | } 223 | SHA1Update(context, finalcount, 8); /* Should cause a SHA1Transform() */ 224 | 225 | if (digest != NULL) { 226 | for (i = 0; i < 20; i++) { 227 | digest[i] = (unsigned char) 228 | ((context->state[i >> 2] >> ((3 - (i & 3)) * 8)) & 255); 229 | } 230 | } 231 | #if 0 232 | /* Wipe variables */ 233 | i = 0; 234 | memset(context->buffer, 0, 64); 235 | memset(context->state, 0, 20); 236 | memset(context->count, 0, 8); 237 | memset(&finalcount, 0, 8); 238 | # ifdef SHA1HANDSOFF /* make SHA1Transform overwrite it's own static vars */ 239 | SHA1Transform(context->state, context->buffer); 240 | # endif 241 | #endif 242 | } 243 | 244 | #else 245 | extern char *interface; 246 | #endif 247 | -------------------------------------------------------------------------------- /src/crypto-sha1.h: -------------------------------------------------------------------------------- 1 | /* 2 | * SHA-1 in C 3 | * By Steve Reid 4 | * 100% Public Domain 5 | */ 6 | 7 | #ifndef __SHA1_H__ 8 | #define __SHA1_H__ 1 9 | 10 | #include "crypto.h" 11 | 12 | typedef struct { 13 | crypto_uint4 state[5]; 14 | crypto_uint4 count[2]; 15 | unsigned char buffer[64]; 16 | } SHA1_CTX; 17 | 18 | void SHA1Init(SHA1_CTX * context); 19 | void SHA1Update(SHA1_CTX * context, const unsigned char * data, 20 | unsigned int len); 21 | void SHA1Final(unsigned char digest[20], SHA1_CTX * context); 22 | 23 | #endif 24 | -------------------------------------------------------------------------------- /src/crypto.h: -------------------------------------------------------------------------------- 1 | #ifndef __CRYPTO_H__ 2 | #define __CRYPTO_H__ 1 3 | 4 | #if SIZEOF_SHORT == 4 5 | typedef short crypto_int4; 6 | typedef unsigned short crypto_uint4; 7 | #elif SIZEOF_INT == 4 8 | typedef int crypto_int4; 9 | typedef unsigned int crypto_uint4; 10 | #elif SIZEOF_LONG == 4 11 | typedef long crypto_int4; 12 | typedef unsigned long crypto_uint4; 13 | #elif SIZEOF_SHORT > 4 14 | typedef short crypto_int4; 15 | typedef unsigned short crypto_uint4; 16 | #elif SIZEOF_INT > 4 17 | typedef int crypto_int4; 18 | typedef unsigned int crypto_uint4; 19 | #elif SIZEOF_LONG > 4 20 | typedef long crypto_int4; 21 | typedef unsigned long crypto_uint4; 22 | #else 23 | # error Please report your architecture and OS type to j at ucarp dot org 24 | #endif 25 | 26 | char *crypto_hash_sha1(const char *string, const int hex); 27 | char *crypto_hash_ssha1(const char *string, const char *stored); 28 | char *crypto_hash_md5(const char *string, const int hex); 29 | char *crypto_hash_smd5(const char *string, const char *stored); 30 | 31 | #endif 32 | -------------------------------------------------------------------------------- /src/daemonize.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include "daemonize.h" 3 | #include "ucarp.h" 4 | #include "log.h" 5 | 6 | #ifdef WITH_DMALLOC 7 | # include 8 | #endif 9 | 10 | static unsigned int open_max(void) 11 | { 12 | long z; 13 | 14 | if ((z = (long) sysconf(_SC_OPEN_MAX)) < 0L) { 15 | logfile(LOG_ERR, "_SC_OPEN_MAX"); 16 | _exit(EXIT_FAILURE); 17 | } 18 | return (unsigned int) z; 19 | } 20 | 21 | static int closedesc_all(const int closestdin) 22 | { 23 | int fodder; 24 | 25 | if (closestdin != 0) { 26 | (void) close(0); 27 | if ((fodder = open("/dev/null", O_RDONLY)) == -1) { 28 | return -1; 29 | } 30 | (void) dup2(fodder, 0); 31 | if (fodder > 0) { 32 | (void) close(fodder); 33 | } 34 | } 35 | if ((fodder = open("/dev/null", O_WRONLY)) == -1) { 36 | return -1; 37 | } 38 | (void) dup2(fodder, 1); 39 | (void) dup2(1, 2); 40 | if (fodder > 2) { 41 | (void) close(fodder); 42 | } 43 | return 0; 44 | } 45 | 46 | void dodaemonize(void) 47 | { 48 | pid_t child; 49 | unsigned int i; 50 | 51 | /* Contributed by Jason Lunz - also based on APUI code, see open_max() */ 52 | if (daemonize != 0) { 53 | if ((child = fork()) == (pid_t) -1) { 54 | logfile(LOG_ERR, _("Unable to get in background: [fork: %s]"), 55 | strerror(errno)); 56 | return; 57 | } else if (child != (pid_t) 0) { 58 | _exit(EXIT_SUCCESS); /* parent exits */ 59 | } 60 | if (setsid() == (pid_t) -1) { 61 | logfile(LOG_WARNING, 62 | _("Unable to detach from the current session: %s"), 63 | strerror(errno)); /* continue anyway */ 64 | } 65 | 66 | /* Fork again so we're not a session leader */ 67 | if ((child = fork()) == (pid_t) -1) { 68 | logfile(LOG_ERR, _("Unable to background: [fork: %s] #2"), 69 | strerror(errno)); 70 | return; 71 | } else if ( child != (pid_t) 0) { 72 | _exit(EXIT_SUCCESS); /* parent exits */ 73 | } 74 | 75 | chdir("/"); 76 | i = open_max(); 77 | do { 78 | if (isatty((int) i)) { 79 | (void) close((int) i); 80 | } 81 | i--; 82 | } while (i > 2U); 83 | if (closedesc_all(1) != 0) { 84 | logfile(LOG_ERR, 85 | _("Unable to detach: /dev/null can't be duplicated")); 86 | _exit(EXIT_FAILURE); 87 | } 88 | } 89 | } 90 | 91 | -------------------------------------------------------------------------------- /src/daemonize.h: -------------------------------------------------------------------------------- 1 | #ifndef __DAEMONIZE_H__ 2 | #define __DAEMONIZE_H__ 1 3 | 4 | void dodaemonize(void); 5 | 6 | #endif 7 | -------------------------------------------------------------------------------- /src/fakesnprintf.c: -------------------------------------------------------------------------------- 1 | /* 2 | * snprintf() / vsnprintf() re-implementation by Frank Denis 3 | * 4 | * These functions understand : 5 | * - characters ("%c") . 6 | * - space padding ("%3d", "%-3s") . 7 | * - zero padding ("%04d") . 8 | * - explicit '+' ("%+d", "%+3.2f") . 9 | * - length restrictions ("%.30s", "%-42.30s", "%.4d") . 10 | * - int, long, long long types ("%lld", "%-3ld", "%i") . 11 | * - unsigned int, long, long long types ("%llu", "%-3lu", "%u") . 12 | * - hex and octal unsigned types ("%llX", "%04x", "%-3o") . 13 | * - double and long double types ("%f", "%Lf") . 14 | * - floating point frac restrictions ("%.2f") . 15 | * - combinations of everything ("%-8.5llo") . 16 | * 17 | * Nothing more. Return value is if an overflow occured, or the 18 | * copied size if no overflow occured (mostly compatible with C99 19 | * snprintf() behavior, except that it doesn't return any value larger 20 | * than ). 21 | * 22 | * These functions are portable, they are twice faster than their BSD and GNU 23 | * implementations, and they don't tamper with errno. But they only know 24 | * a limited subset of what a full-implementation is supposed to do. 25 | * 26 | * It's enough for UCARP, though. 27 | */ 28 | 29 | #include 30 | 31 | #include "ucarp.h" 32 | 33 | #ifdef WITH_DMALLOC 34 | # include 35 | #endif 36 | 37 | #if !defined(HAVE_SNPRINTF) || !defined(HAVE_VSNPRINTF) 38 | 39 | /* 40 | * add a string to the buffer 41 | * \param zero if this is non-zero, we pad with zeroes, else we pad 42 | * with a blank. 43 | * \param maxlen sets the maximum size of the string to be added 44 | */ 45 | 46 | static void fakesnprintf_addstr(char **str, size_t *size, const char *pnt, 47 | size_t maxlen, size_t padlen, 48 | unsigned char zero, unsigned char minuspad) 49 | { 50 | size_t maxlenc; 51 | 52 | /* prepare to cut off string if longer than maxlen */ 53 | maxlenc = strlen(pnt); 54 | if (maxlen > 0U && maxlen < maxlenc) { 55 | maxlenc = maxlen; 56 | } 57 | if (padlen > 0U && minuspad == 0U && padlen > maxlenc) { 58 | size_t maxlenp = padlen - maxlenc; 59 | 60 | if (maxlenp > *size) { 61 | maxlenp = *size; 62 | } 63 | if (maxlenp > 0U) { 64 | memset(*str, zero != 0 ? '0' : ' ', maxlenp); 65 | (*size) -= maxlenp; 66 | (*str) += maxlenp; 67 | } 68 | } 69 | if (maxlenc > *size) { 70 | maxlenc = *size; 71 | } 72 | if (maxlenc > 0U) { 73 | memcpy(*str, pnt, maxlenc); 74 | (*size) -= maxlenc; 75 | (*str) += maxlenc; 76 | } 77 | if (padlen > 0U && minuspad > 0U && padlen > maxlenc) { 78 | size_t maxlenp = padlen - maxlenc; 79 | 80 | if (maxlenp > *size) { 81 | maxlenp = *size; 82 | } 83 | if (maxlenp > 0U) { 84 | memset(*str, ' ', maxlenp); 85 | (*size) -= maxlenp; 86 | (*str) += maxlenp; 87 | } 88 | } 89 | } 90 | 91 | int fakesnprintf_vsnprintf(char * const str_, const size_t size_, 92 | const char *format, va_list va) 93 | { 94 | char *str; 95 | size_t size; 96 | size_t maxlen; 97 | size_t padlen; 98 | unsigned char longs; 99 | unsigned char zero; 100 | unsigned char minuspad; 101 | unsigned char hasmaxlen; 102 | unsigned char plussign; 103 | 104 | str = str_; 105 | size = size_; 106 | str_[size_ - 1U] = 1; 107 | while (size > 0U && *format != 0) { 108 | if (*format != '%') { 109 | *str++ = *format++; 110 | size--; 111 | continue; 112 | } 113 | longs = 0U; 114 | zero = 0U; 115 | minuspad = 0U; 116 | maxlen = 0U; 117 | padlen = 0U; 118 | hasmaxlen = 0U; 119 | plussign = 0U; 120 | 121 | for (;;) { 122 | breakpoint_nextspecial_inc: 123 | format++; 124 | breakpoint_nextspecial_noinc: 125 | switch (*format) { 126 | case 0: 127 | goto breakpoint_end; 128 | case '%': 129 | *str++ = '%'; 130 | size--; 131 | goto breakpoint_next; 132 | case 'c': { 133 | int val; 134 | 135 | val = va_arg(va, int); 136 | *str++ = (char) val; 137 | size--; 138 | goto breakpoint_next; 139 | } 140 | case 'l': case 'L': 141 | longs++; 142 | goto breakpoint_nextspecial_inc; 143 | case '0': 144 | zero++; 145 | goto breakpoint_nextspecial_inc; 146 | case '.': 147 | format++; 148 | hasmaxlen = 1U; 149 | while ((unsigned char) *format >= '0' && 150 | (unsigned char) *format <= '9') { 151 | maxlen *= 10U; 152 | maxlen += (*format - '0'); 153 | format++; 154 | } 155 | goto breakpoint_nextspecial_noinc; 156 | case '1': case '2': case '3': case '4': case '5': 157 | case '6': case '7': case '8': case '9': 158 | do { 159 | padlen *= 10U; 160 | padlen += *format - '0'; 161 | format++; 162 | } while ((unsigned char) *format >= '0' && 163 | (unsigned char) *format <= '9'); 164 | goto breakpoint_nextspecial_noinc; 165 | case '-': 166 | minuspad++; 167 | format++; 168 | goto breakpoint_nextspecial_noinc; 169 | case '+': 170 | plussign++; 171 | format++; 172 | goto breakpoint_nextspecial_noinc; 173 | case 's': { 174 | const char *pnt; 175 | 176 | pnt = va_arg(va, const char *); 177 | if (pnt == NULL) { 178 | pnt = ""; 179 | } 180 | fakesnprintf_addstr(&str, &size, pnt, maxlen, padlen, 181 | zero, minuspad); 182 | goto breakpoint_next; 183 | } 184 | case 'u': case 'o': case 'x': case 'X': { 185 | unsigned long long val; 186 | char vals[256]; 187 | char *valspnt = vals + sizeof vals; 188 | const char *basics; 189 | unsigned int base; 190 | 191 | switch (longs) { 192 | case 2: 193 | val = va_arg(va, unsigned long long); 194 | break; 195 | case 1: 196 | val = (unsigned long long) va_arg(va, unsigned long); 197 | break; 198 | default: 199 | val = (unsigned long long) va_arg(va, unsigned int); 200 | } 201 | basics = "0123456789abcdef"; 202 | switch (*format) { 203 | case 'o': 204 | base = 8U; 205 | break; 206 | case 'X': 207 | basics = "0123456789ABCDEF"; 208 | case 'x': 209 | base = 16U; 210 | break; 211 | default: 212 | base = 10U; 213 | } 214 | *--valspnt = 0; 215 | do { 216 | *--valspnt = basics[val % base]; 217 | val /= base; 218 | } while (valspnt != &vals[0] && val > 0ULL); 219 | fakesnprintf_addstr(&str, &size, valspnt, maxlen, padlen, 220 | zero, minuspad); 221 | goto breakpoint_next; 222 | } 223 | case 'd': case 'i': { 224 | long long val; 225 | unsigned char minussign = 0U; 226 | char vals[256]; 227 | char *valspnt = vals + sizeof vals; 228 | 229 | switch (longs) { 230 | case 2: 231 | val = va_arg(va, long long); 232 | break; 233 | case 1: 234 | val = (long long) va_arg(va, long); 235 | break; 236 | default: 237 | val = (long long) va_arg(va, int); 238 | } 239 | if (val < 0LL) { 240 | minussign++; 241 | val = -val; 242 | } 243 | *--valspnt = 0; 244 | do { 245 | *--valspnt = "0123456789"[val % 10LL]; 246 | val /= 10LL; 247 | } while (valspnt != &vals[1] && val > 0LL); 248 | if (minussign != 0) { 249 | *--valspnt = '-'; 250 | } else if (plussign != 0) { 251 | *--valspnt = '+'; 252 | } 253 | fakesnprintf_addstr(&str, &size, valspnt, maxlen, padlen, 254 | zero, minuspad); 255 | goto breakpoint_next; 256 | } 257 | case 'e': case 'E': case 'f': case 'F': case 'g': case 'G': { 258 | unsigned int nfrac = 6U; 259 | long double val; 260 | unsigned long long vali; 261 | unsigned char minussign = 0U; 262 | char vals[512]; 263 | char *valspnt = vals + sizeof vals / 2U; 264 | char *valsleft; 265 | 266 | if (longs != 0) { 267 | val = va_arg(va, long double); 268 | } else { 269 | val = va_arg(va, double); 270 | } 271 | if (val < 0.0L) { 272 | minussign++; 273 | val = -val; 274 | } 275 | vali = (unsigned long long) val; 276 | do { 277 | *--valspnt = '0' + vali % 10ULL; 278 | vali /= 10ULL; 279 | } while (valspnt != &vals[1] && vali > 0ULL); 280 | if (minussign != 0) { 281 | *--valspnt = '-'; 282 | } else if (plussign != 0) { 283 | *--valspnt = '+'; 284 | } 285 | valsleft = valspnt; 286 | valspnt = vals + sizeof vals / 2U; 287 | if (maxlen > (sizeof vals / 2U) - 3U) { 288 | nfrac = (sizeof vals / 2U) - 3U; 289 | } else if (hasmaxlen != 0U) { 290 | nfrac = maxlen; 291 | } 292 | if (nfrac > 0U) { 293 | *valspnt++ = '.'; 294 | } 295 | while (nfrac > 0U) { 296 | nfrac--; 297 | val *= 10.0L; 298 | *valspnt++ = '0' + (((unsigned long long) val) % 10U); 299 | } 300 | *valspnt = 0; 301 | fakesnprintf_addstr(&str, &size, valsleft, sizeof vals, 302 | padlen, zero, minuspad); 303 | goto breakpoint_next; 304 | } 305 | } 306 | } 307 | breakpoint_next: 308 | format++; 309 | } 310 | breakpoint_end: 311 | if (str_[size_ - 1U] != 1) { 312 | str_[size_ - 1U] = 0; 313 | return (int) size_; 314 | } 315 | *str = 0; 316 | 317 | return (int) (size_ - size); 318 | } 319 | 320 | int fakesnprintf_snprintf(char * const str, const size_t size, 321 | const char * const format, ...) 322 | { 323 | int ret; 324 | va_list va; 325 | 326 | va_start(va, format); 327 | ret = fakesnprintf_vsnprintf(str, size, format, va); 328 | va_end(va); 329 | 330 | return ret; 331 | } 332 | 333 | #endif /* !HAVE_SNPRINTF */ 334 | -------------------------------------------------------------------------------- /src/fakesnprintf.h: -------------------------------------------------------------------------------- 1 | #ifndef __FAKESNPRINTF_H__ 2 | #define __FAKESNPRINTF_H__ 1 3 | 4 | #if !defined(HAVE_SNPRINTF) || !defined(HAVE_VSNPRINTF) 5 | 6 | int fakesnprintf_vsnprintf(char * const str_, const size_t size_, 7 | const char *format, va_list va); 8 | 9 | int fakesnprintf_snprintf(char * const str, const size_t size, 10 | const char * const format, ...); 11 | 12 | # define snprintf fakesnprintf_snprintf 13 | # define vsnprintf fakesnprintf_vsnprintf 14 | 15 | # ifdef CONF_SNPRINTF_TYPE 16 | # undef CONF_SNPRINTF_TYPE 17 | # endif 18 | # define CONF_SNPRINTF_TYPE 4 19 | 20 | #endif 21 | 22 | #endif /* FAKESNPRINTF_H */ 23 | -------------------------------------------------------------------------------- /src/fillmac.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include "ucarp.h" 3 | #include "fillmac.h" 4 | #include 5 | #ifdef HAVE_IFADDRS_H 6 | # include 7 | #endif 8 | #ifdef HAVE_NET_IF_DL_H 9 | # include 10 | #endif 11 | #ifdef HAVE_NET_IF_TYPES_H 12 | # include 13 | #endif 14 | #ifdef HAVE_SYS_SOCKIO_H 15 | # include 16 | #endif 17 | #ifndef HAVE_NET_IF_ARP_H 18 | # include 19 | #endif 20 | #include "log.h" 21 | 22 | #ifdef WITH_DMALLOC 23 | # include 24 | #endif 25 | 26 | #ifdef PF_PACKET 27 | # define HWINFO_DOMAIN PF_PACKET 28 | #else 29 | # define HWINFO_DOMAIN PF_INET 30 | #endif 31 | #ifdef SOCK_PACKET 32 | # define HWINFO_TYPE SOCK_PACKET 33 | #else 34 | # define HWINFO_TYPE SOCK_DGRAM 35 | #endif 36 | 37 | int fill_mac_address(void) 38 | { 39 | int s; 40 | 41 | if ((s = socket(HWINFO_DOMAIN, HWINFO_TYPE, 0)) == -1) { 42 | logfile(LOG_ERR, _("Unable to open raw device: [%s]"), 43 | strerror(errno)); 44 | return -1; 45 | } 46 | #ifdef SIOCGIFHWADDR 47 | { 48 | struct ifreq ifr; 49 | 50 | if (strlen(interface) >= sizeof ifr.ifr_name) { 51 | logfile(LOG_ERR, _("Interface name too long")); 52 | return -1; 53 | } 54 | strncpy(ifr.ifr_name, interface, sizeof ifr.ifr_name); 55 | if (ioctl(s, SIOCGIFHWADDR, &ifr) != 0) { 56 | logfile(LOG_ERR, 57 | _("Unable to get hardware info about an interface: %s"), 58 | strerror(errno)); 59 | (void) close(s); 60 | return -1; 61 | } 62 | switch (ifr.ifr_hwaddr.sa_family) { 63 | case ARPHRD_ETHER: 64 | case ARPHRD_IEEE802: 65 | break; 66 | default: 67 | logfile(LOG_ERR, _("Unknown hardware type [%u]"), 68 | (unsigned int) ifr.ifr_hwaddr.sa_family); 69 | } 70 | memcpy(hwaddr, &ifr.ifr_hwaddr.sa_data, sizeof hwaddr); 71 | } 72 | #elif defined(HAVE_GETIFADDRS) 73 | { 74 | struct ifaddrs *ifas; 75 | struct ifaddrs *ifa; 76 | struct sockaddr_dl *sadl; 77 | struct ether_addr *ea; 78 | 79 | if (getifaddrs(&ifas) != 0) { 80 | logfile(LOG_ERR, _("Unable to get interface address: %s"), 81 | strerror(errno)); 82 | return -1; 83 | } 84 | ifa = ifas; 85 | while (ifa != NULL) { 86 | if (strcmp(ifa->ifa_name, interface) == 0 && 87 | ifa->ifa_addr->sa_family == AF_LINK) { 88 | sadl = (struct sockaddr_dl *) (void *) ifa->ifa_addr; 89 | if (sadl == NULL || sadl->sdl_type != IFT_ETHER || 90 | sadl->sdl_alen <= 0) { 91 | logfile(LOG_ERR, 92 | _("Invalid media / hardware address for [%s]"), 93 | interface); 94 | return -1; 95 | } 96 | ea = (struct ether_addr *) LLADDR(sadl); 97 | memcpy(hwaddr, ea, sizeof hwaddr); 98 | 99 | return 0; 100 | } 101 | ifa = ifa->ifa_next; 102 | } 103 | return -1; 104 | } 105 | #elif defined(SIOCGLIFNUM) 106 | { 107 | struct lifconf lifc; 108 | struct lifnum lifn; 109 | struct lifreq *lifr; 110 | caddr_t *lifrspace; 111 | struct arpreq arpreq; 112 | 113 | lifn.lifn_flags = 0; 114 | lifn.lifn_family = AF_INET; 115 | if (ioctl(s, SIOCGLIFNUM, &lifn) < 0) { 116 | logfile(LOG_ERR, _("ioctl SIOCGLIFNUM error")); 117 | return -1; 118 | } 119 | if (lifn.lifn_count <= 0) { 120 | logfile(LOG_ERR, _("No interface found")); 121 | return -1; 122 | } 123 | lifc.lifc_family = lifn.lifn_family; 124 | lifc.lifc_len = lifn.lifn_count * sizeof *lifr; 125 | lifrspace = ALLOCA(lifc.lifc_len); 126 | lifc.lifc_buf = (caddr_t) lifrspace; 127 | if (ioctl(s, SIOCGLIFCONF, &lifc) < 0) { 128 | logfile(LOG_ERR, _("ioctl SIOCGLIFCONF error")); 129 | ALLOCA_FREE(lifrspace); 130 | return -1; 131 | } 132 | lifr = lifc.lifc_req; 133 | for(;;) { 134 | if (lifn.lifn_count <= 0) { 135 | logfile(LOG_ERR, _("Interface [%s] not found"), interface); 136 | ALLOCA_FREE(lifrspace); 137 | return -1; 138 | } 139 | lifn.lifn_count--; 140 | if (strcmp(lifr->lifr_name, interface) == 0) { 141 | break; 142 | } 143 | lifr++; 144 | } 145 | memcpy(&arpreq.arp_pa, &lifr->lifr_addr, sizeof arpreq.arp_pa); 146 | ALLOCA_FREE(lifrspace); 147 | if (ioctl(s, SIOCGARP, &arpreq) != 0) { 148 | logfile(LOG_ERR, _("Unable to get hardware info about [%s]"), 149 | interface); 150 | return -1; 151 | } 152 | memcpy(hwaddr, &arpreq.arp_ha.sa_data, sizeof hwaddr); 153 | } 154 | #endif 155 | 156 | (void) close(s); 157 | 158 | return 0; 159 | } 160 | -------------------------------------------------------------------------------- /src/fillmac.h: -------------------------------------------------------------------------------- 1 | #ifndef __FILLMAC_H__ 2 | #define __FILLMAC_H__ 1 3 | 4 | int fill_mac_address(void); 5 | 6 | #endif 7 | -------------------------------------------------------------------------------- /src/garp.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include "ucarp.h" 3 | #include "garp.h" 4 | #include "log.h" 5 | 6 | #ifdef WITH_DMALLOC 7 | # include 8 | #endif 9 | 10 | int gratuitous_arp(const int dev_desc_fd) 11 | { 12 | struct ether_header eh; 13 | static unsigned char arp[28] = { 14 | 0x00, 0x01, /* MAC address type */ 15 | 0x08, 0x00, /* Protocol address type */ 16 | 0x06, 0x04, /* MAC address size, protocol address size */ 17 | 0x00, 0x01, /* OP (1=request, 2=reply) */ 18 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* Sender MAC */ 19 | 0x00, 0x00, 0x00, 0x00, /* Sender IP */ 20 | 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* Target MAC */ 21 | 0xff, 0xff, 0xff, 0xff /* Target IP */ 22 | }; 23 | unsigned char *pkt; 24 | int rc; 25 | 26 | if (ETHER_ADDR_LEN > 6) { 27 | abort(); 28 | } 29 | 30 | /* 31 | * - Gratuitous ARPs should use requests for the highest interoperability. 32 | * - Target MAC and IP should match sender 33 | * http://www1.ietf.org/mail-archive/web/dhcwg/current/msg03797.html 34 | * http://en.wikipedia.org/wiki/Address_Resolution_Protocol 35 | * http://ettercap.sourceforge.net/forum/viewtopic.php?t=2392 36 | * http://wiki.ethereal.com/Gratuitous_ARP 37 | */ 38 | arp[7] = 0x01; /* request op */ 39 | memcpy(&arp[8], hwaddr, sizeof hwaddr); /* Sender MAC */ 40 | memcpy(&arp[14], &vaddr.s_addr, (size_t) 4U); /* Sender IP */ 41 | memcpy(&arp[18], hwaddr, sizeof hwaddr); /* Target MAC */ 42 | memcpy(&arp[24], &vaddr.s_addr, (size_t) 4U); /* Target IP */ 43 | 44 | memset(&eh, 0, sizeof eh); 45 | memcpy(&eh.ether_shost, hwaddr, sizeof hwaddr); 46 | memset(&eh.ether_dhost, 0xff, ETHER_ADDR_LEN); 47 | eh.ether_type = htons(ETHERTYPE_ARP); 48 | 49 | if ((pkt = ALLOCA(sizeof eh + sizeof arp)) == NULL) { 50 | logfile(LOG_ERR, _("out of memory to send gratuitous ARP")); 51 | return -1; 52 | } 53 | memcpy(pkt, &eh, sizeof eh); 54 | memcpy(pkt + sizeof eh, arp, sizeof arp); 55 | 56 | do { 57 | rc = write(dev_desc_fd, pkt, sizeof eh + sizeof arp); 58 | } while (rc < 0 && errno == EINTR); 59 | if (rc < 0) { 60 | logfile(LOG_ERR, _("write() in garp: %s"), strerror(errno)); 61 | ALLOCA_FREE(pkt); 62 | return -1; 63 | } 64 | ALLOCA_FREE(pkt); 65 | 66 | return 0; 67 | } 68 | -------------------------------------------------------------------------------- /src/garp.h: -------------------------------------------------------------------------------- 1 | #ifndef __GARP_H__ 2 | #define __GARP_H__ 1 3 | 4 | int gratuitous_arp(const int dev_desc_fd); 5 | 6 | #endif 7 | -------------------------------------------------------------------------------- /src/gettext.h: -------------------------------------------------------------------------------- 1 | /* Convenience header for conditional use of GNU . 2 | Copyright (C) 1995-1998, 2000-2002, 2004 Free Software Foundation, Inc. 3 | 4 | This program is free software; you can redistribute it and/or modify it 5 | under the terms of the GNU Library General Public License as published 6 | by the Free Software Foundation; either version 2, or (at your option) 7 | any later version. 8 | 9 | This program is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | Library General Public License for more details. 13 | 14 | You should have received a copy of the GNU Library General Public 15 | License along with this program; if not, write to the Free Software 16 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 17 | USA. */ 18 | 19 | #ifndef _LIBGETTEXT_H 20 | #define _LIBGETTEXT_H 1 21 | 22 | /* NLS can be disabled through the configure --disable-nls option. */ 23 | #if ENABLE_NLS 24 | 25 | /* Get declarations of GNU message catalog functions. */ 26 | # include 27 | 28 | #else 29 | 30 | /* Solaris /usr/include/locale.h includes /usr/include/libintl.h, which 31 | chokes if dcgettext is defined as a macro. So include it now, to make 32 | later inclusions of a NOP. We don't include 33 | as well because people using "gettext.h" will not include , 34 | and also including would fail on SunOS 4, whereas 35 | is OK. */ 36 | #if defined(__sun) 37 | # include 38 | #endif 39 | 40 | /* Many header files from the libstdc++ coming with g++ 3.3 or newer include 41 | , which chokes if dcgettext is defined as a macro. So include 42 | it now, to make later inclusions of a NOP. */ 43 | #if defined(__cplusplus) && defined(__GNUG__) && (__GNUC__ >= 3) 44 | # include 45 | # if (__GLIBC__ >= 2) || _GLIBCXX_HAVE_LIBINTL_H 46 | # include 47 | # endif 48 | #endif 49 | 50 | /* Disabled NLS. 51 | The casts to 'const char *' serve the purpose of producing warnings 52 | for invalid uses of the value returned from these functions. 53 | On pre-ANSI systems without 'const', the config.h file is supposed to 54 | contain "#define const". */ 55 | # define gettext(Msgid) ((const char *) (Msgid)) 56 | # define dgettext(Domainname, Msgid) ((const char *) (Msgid)) 57 | # define dcgettext(Domainname, Msgid, Category) ((const char *) (Msgid)) 58 | # define ngettext(Msgid1, Msgid2, N) \ 59 | ((N) == 1 ? (const char *) (Msgid1) : (const char *) (Msgid2)) 60 | # define dngettext(Domainname, Msgid1, Msgid2, N) \ 61 | ((N) == 1 ? (const char *) (Msgid1) : (const char *) (Msgid2)) 62 | # define dcngettext(Domainname, Msgid1, Msgid2, N, Category) \ 63 | ((N) == 1 ? (const char *) (Msgid1) : (const char *) (Msgid2)) 64 | # define textdomain(Domainname) ((const char *) (Domainname)) 65 | # define bindtextdomain(Domainname, Dirname) ((const char *) (Dirname)) 66 | # define bind_textdomain_codeset(Domainname, Codeset) ((const char *) (Codeset)) 67 | 68 | #endif 69 | 70 | /* A pseudo function call that serves as a marker for the automated 71 | extraction of messages, but does not call gettext(). The run-time 72 | translation is done at a different place in the code. 73 | The argument, String, should be a literal string. Concatenated strings 74 | and other string expressions won't work. 75 | The macro's expansion is not parenthesized, so that it is suitable as 76 | initializer for static 'char[]' or 'const char[]' variables. */ 77 | #define gettext_noop(String) String 78 | 79 | #endif /* _LIBGETTEXT_H */ 80 | -------------------------------------------------------------------------------- /src/globals.h: -------------------------------------------------------------------------------- 1 | #ifndef __GLOBALS_H__ 2 | #define __GLOBALS_H__ 1 3 | 4 | #ifdef DEFINE_GLOBALS 5 | # define GLOBAL0(A) A 6 | # define GLOBAL(A, B) A = B 7 | #else 8 | # define GLOBAL0(A) extern A 9 | # define GLOBAL(A, B) extern A 10 | #endif 11 | 12 | GLOBAL0(char *interface); 13 | GLOBAL0(struct in_addr srcip); 14 | GLOBAL0(struct in_addr mcastip); 15 | GLOBAL0(unsigned char vhid); 16 | GLOBAL0(char *pass); 17 | GLOBAL0(struct in_addr vaddr); 18 | GLOBAL(unsigned char advbase, DEFAULT_ADVBASE); 19 | GLOBAL(unsigned int dead_ratio, DEFAULT_DEAD_RATIO); 20 | GLOBAL0(unsigned char advskew); 21 | GLOBAL0(char *upscript); 22 | GLOBAL0(char *downscript); 23 | GLOBAL0(signed char debug); 24 | GLOBAL0(signed char preempt); 25 | GLOBAL0(signed char neutral); 26 | GLOBAL0(signed char shutdown_at_exit); 27 | GLOBAL0(unsigned char hwaddr[6]); 28 | GLOBAL0(signed char no_syslog); 29 | GLOBAL0(signed char daemonize); 30 | GLOBAL0(signed char ignoreifstate); 31 | GLOBAL0(signed char no_mcast); 32 | GLOBAL(int syslog_facility, DEFAULT_FACILITY); 33 | GLOBAL0(char *vaddr_arg); 34 | GLOBAL0(char *xparam); 35 | GLOBAL0(sig_atomic_t received_signal); 36 | #endif 37 | -------------------------------------------------------------------------------- /src/ip_carp.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2002 Michael Shalayeff. All rights reserved. 3 | * Copyright (c) 2003 Ryan McBride. All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 8 | * 1. Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * 14 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 15 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 16 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 17 | * IN NO EVENT SHALL THE AUTHOR OR HIS RELATIVES BE LIABLE FOR ANY DIRECT, 18 | * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 19 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 20 | * SERVICES; LOSS OF MIND, USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 22 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 23 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 24 | * THE POSSIBILITY OF SUCH DAMAGE. 25 | */ 26 | 27 | /* 28 | * The CARP header layout is as follows: 29 | * 30 | * 0 1 2 3 31 | * 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 32 | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 33 | * |Version| Type | VirtualHostID | AdvSkew | Auth Len | 34 | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 35 | * | Reserved | AdvBase | Checksum | 36 | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 37 | * | Counter (1) | 38 | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 39 | * | Counter (2) | 40 | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 41 | * | SHA-1 HMAC (1) | 42 | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 43 | * | SHA-1 HMAC (2) | 44 | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 45 | * | SHA-1 HMAC (3) | 46 | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 47 | * | SHA-1 HMAC (4) | 48 | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 49 | * | SHA-1 HMAC (5) | 50 | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 51 | * 52 | */ 53 | 54 | #ifndef __IP_CARP_H__ 55 | #define __IP_CARP_H__ 1 56 | 57 | struct carp_header { 58 | #ifdef WORDS_BIGENDIAN 59 | u_int8_t carp_version:4, 60 | carp_type:4; 61 | #else 62 | u_int8_t carp_type:4, 63 | carp_version:4; 64 | #endif 65 | u_int8_t carp_vhid; /* virtual host id */ 66 | u_int8_t carp_advskew; /* advertisement skew */ 67 | u_int8_t carp_authlen; /* size of counter+md, 32bit chunks */ 68 | u_int8_t carp_pad1; /* reserved */ 69 | u_int8_t carp_advbase; /* advertisement interval */ 70 | u_int16_t carp_cksum; 71 | u_int32_t carp_counter[2]; 72 | unsigned char carp_md[20]; /* SHA1 HMAC */ 73 | } __packed; 74 | 75 | #define CARP_DFLTTL 255 76 | 77 | /* carp_version */ 78 | #define CARP_VERSION 2 79 | 80 | /* carp_type */ 81 | #define CARP_ADVERTISEMENT 0x01 82 | 83 | #define CARP_KEY_LEN 20 /* a sha1 hash of a passphrase */ 84 | 85 | /* carp_advbase */ 86 | #define CARP_DFLTINTV 1 87 | 88 | #define CARP_BULK_UPDATE_MIN_DELAY 240 89 | 90 | /* 91 | * Statistics. 92 | */ 93 | struct carpstats { 94 | u_int64_t carps_ipackets; /* total input packets, IPv4 */ 95 | u_int64_t carps_ipackets6; /* total input packets, IPv6 */ 96 | u_int64_t carps_badif; /* wrong interface */ 97 | u_int64_t carps_badttl; /* TTL is not CARP_DFLTTL */ 98 | u_int64_t carps_hdrops; /* packets shorter than header */ 99 | u_int64_t carps_badsum; /* bad checksum */ 100 | u_int64_t carps_badver; /* bad (incl unsupp) version */ 101 | u_int64_t carps_badlen; /* data length does not match */ 102 | u_int64_t carps_badauth; /* bad authentication */ 103 | u_int64_t carps_badvhid; /* bad VHID */ 104 | u_int64_t carps_badaddrs; /* bad address list */ 105 | 106 | u_int64_t carps_opackets; /* total output packets, IPv4 */ 107 | u_int64_t carps_opackets6; /* total output packets, IPv6 */ 108 | u_int64_t carps_onomem; /* no memory for an mbuf */ 109 | u_int64_t carps_ostates; /* total state updates sent */ 110 | 111 | u_int64_t carps_preempt; /* if enabled, preemptions */ 112 | }; 113 | 114 | /* 115 | * Configuration structure for SIOCSVH SIOCGVH 116 | */ 117 | struct carpreq { 118 | int carpr_state; 119 | #define CARP_STATES "INIT", "BACKUP", "MASTER" 120 | #define CARP_MAXSTATE 2 121 | int carpr_vhid; 122 | int carpr_advskew; 123 | int carpr_advbase; 124 | unsigned char carpr_key[CARP_KEY_LEN]; 125 | }; 126 | #define SIOCSVH _IOWR('i', 245, struct ifreq) 127 | #define SIOCGVH _IOWR('i', 246, struct ifreq) 128 | 129 | /* 130 | * Names for CARP sysctl objects 131 | */ 132 | #define CARPCTL_ALLOW 1 /* accept incoming CARP packets */ 133 | #define CARPCTL_PREEMPT 2 /* high-pri backup preemption mode */ 134 | #define CARPCTL_LOG 3 /* log bad packets */ 135 | #define CARPCTL_ARPBALANCE 4 /* balance arp responses */ 136 | #define CARPCTL_MAXID 5 137 | 138 | #define CARPCTL_NAMES { \ 139 | { 0, 0 }, \ 140 | { "allow", CTLTYPE_INT }, \ 141 | { "preempt", CTLTYPE_INT }, \ 142 | { "log", CTLTYPE_INT }, \ 143 | { "arpbalance", CTLTYPE_INT }, \ 144 | } 145 | 146 | #endif 147 | -------------------------------------------------------------------------------- /src/log.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include "log.h" 4 | #include "ucarp.h" 5 | 6 | #ifdef WITH_DMALLOC 7 | # include 8 | #endif 9 | 10 | void logfile(const int crit, const char *format, ...) 11 | { 12 | const char *urgency; 13 | va_list va; 14 | char line[MAX_SYSLOG_LINE]; 15 | 16 | if (crit == LOG_DEBUG && ! debug) 17 | return; 18 | 19 | va_start(va, format); 20 | vsnprintf(line, sizeof line, format, va); 21 | switch (crit) { 22 | case LOG_INFO: 23 | urgency = "[INFO] "; 24 | break; 25 | case LOG_WARNING: 26 | urgency = "[WARNING] "; 27 | break; 28 | case LOG_ERR: 29 | urgency = "[ERROR] "; 30 | break; 31 | case LOG_NOTICE: 32 | urgency = "[NOTICE] "; 33 | break; 34 | case LOG_DEBUG: 35 | urgency = "[DEBUG] "; 36 | break; 37 | default: 38 | urgency = ""; 39 | } 40 | if (no_syslog == 0) { 41 | #ifdef SAVE_DESCRIPTORS 42 | openlog("ucarp", LOG_PID, syslog_facility); 43 | #endif 44 | syslog(crit, "%s%s", urgency, line); 45 | #ifdef SAVE_DESCRIPTORS 46 | closelog(); 47 | #endif 48 | } 49 | if (daemonize == 0) { 50 | char timestr[200]; 51 | struct timeval tv; 52 | struct tm *tmp; 53 | 54 | if (gettimeofday(&tv, NULL)) { 55 | perror("gettimeofday"); 56 | return; 57 | } 58 | if (!(tmp = localtime(&tv.tv_sec))) { 59 | perror("localtime"); 60 | return; 61 | } 62 | 63 | if (strftime(timestr, sizeof(timestr), "%Y-%m-%dT%H:%M:%S", tmp) == 0) { 64 | fprintf(stderr, "strftime returned 0"); 65 | return; 66 | } 67 | 68 | switch (crit) { 69 | case LOG_WARNING: 70 | case LOG_ERR: 71 | fprintf(stderr, "%s.%06ld: %s%s\n", timestr, tv.tv_usec, urgency, line); 72 | break; 73 | default: 74 | printf("%s.%06ld: %s%s\n", timestr, tv.tv_usec, urgency, line); 75 | } 76 | } 77 | va_end(va); 78 | } 79 | -------------------------------------------------------------------------------- /src/log.h: -------------------------------------------------------------------------------- 1 | #ifndef __LOG_H__ 2 | #define __LOG_H__ 1 3 | 4 | void logfile(const int crit, const char *format, ...); 5 | 6 | #endif 7 | -------------------------------------------------------------------------------- /src/mysnprintf.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include 4 | #ifdef STDC_HEADERS 5 | # include 6 | # include 7 | # include 8 | #else 9 | # ifdef HAVE_STDLIB_H 10 | # include 11 | # endif 12 | #endif 13 | #ifdef HAVE_INTTYPES_H 14 | # include 15 | #endif 16 | #ifdef HAVE_UNISTD_H 17 | # include 18 | #endif 19 | #include 20 | #include "mysnprintf.h" 21 | 22 | #ifdef WITH_DMALLOC 23 | # include 24 | #endif 25 | 26 | #ifdef SNPRINTF_IS_BOGUS 27 | int workaround_snprintf(char *str, size_t size, const char *format, ...) 28 | { 29 | int v; 30 | int r = 0; 31 | 32 | va_list va; 33 | va_start(va, format); 34 | v = vsnprintf(str, size, format, va); 35 | if (v < 0 || (ssize_t) v >= (ssize_t) size) { 36 | r--; 37 | } 38 | va_end(va); 39 | 40 | return r; 41 | } 42 | #endif 43 | -------------------------------------------------------------------------------- /src/mysnprintf.h: -------------------------------------------------------------------------------- 1 | #ifndef __MYSNPRINTF_H__ 2 | #define __MYSNPRINTF_H__ 1 3 | 4 | int workaround_snprintf(char *str, size_t size, const char *format, ...); 5 | 6 | #ifndef HAVE_SNPRINTF 7 | # include "fakesnprintf.h" 8 | #endif 9 | #ifdef CONF_SNPRINTF_TYPE 10 | # if CONF_SNPRINTF_TYPE == 8 11 | # define SNPRINTF_C99 1 12 | # elif CONF_SNPRINTF_TYPE <= 0 13 | # define SNPRINTF_OLD 1 14 | # define SNPRINTF_IS_BOGUS 1 15 | # else 16 | # define SNPRINTF_IS_BOGUS 1 17 | # endif 18 | #else 19 | # warning Unknown snprintf() type 20 | # define SNPRINTF_IS_BOGUS 1 21 | #endif 22 | 23 | #if CONF_SNPRINTF_TYPE < 0 24 | # define SNCHECK(CALL, SIZE) ((CALL) < 0) 25 | #elif defined(SNPRINTF_IS_BOGUS) || !defined(SNPRINTF_C99) || \ 26 | CONF_SNPRINTF_TYPE == 4 || CONF_SNPRINTF_TYPE == 8 27 | # define SNCHECK(CALL, SIZE) ((CALL) >= ((int) (SIZE))) 28 | #else 29 | # define SNCHECK(CALL, SIZE) (workaround_ ## CALL) 30 | #endif 31 | 32 | #endif 33 | -------------------------------------------------------------------------------- /src/spawn.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include "ucarp.h" 3 | #include "spawn.h" 4 | #ifdef HAVE_SYS_WAIT_H 5 | # include 6 | #endif 7 | #include "log.h" 8 | 9 | #ifdef WITH_DMALLOC 10 | # include 11 | #endif 12 | 13 | int spawn_handler(const int dev_desc_fd, const char * const script) 14 | { 15 | pid_t pid; 16 | 17 | if (script == NULL || *script == 0) { 18 | return 0; 19 | } 20 | pid = fork(); 21 | if (pid == (pid_t) 0) { 22 | (void) close(dev_desc_fd); 23 | execl(script, script, interface, vaddr_arg, xparam, (char *) NULL); 24 | logfile(LOG_ERR, _("Unable to exec %s %s %s%s%s: %s"), 25 | script, interface, vaddr_arg, 26 | (xparam ? " " : ""), (xparam ? xparam : ""), 27 | strerror(errno)); 28 | _exit(EXIT_FAILURE); 29 | } else if (pid != (pid_t) -1) { 30 | logfile(LOG_WARNING, _("Spawning [%s %s %s%s%s]"), 31 | script, interface, vaddr_arg, 32 | (xparam ? " " : ""), (xparam ? xparam : "")); 33 | #ifdef HAVE_WAITPID 34 | { 35 | while (waitpid(pid, NULL, 0) == (pid_t) -1 && errno == EINTR); 36 | } 37 | #else 38 | { 39 | pid_t foundpid; 40 | 41 | do { 42 | foundpid = wait3(NULL, 0, NULL); 43 | if (foundpid == (pid_t) -1 && errno == EINTR) { 44 | continue; 45 | } 46 | } while (foundpid != (pid_t) -1 && foundpid != pid); 47 | } 48 | #endif 49 | } else { 50 | logfile(LOG_ERR, _("Unable to spawn the script: %s"), 51 | strerror(errno)); 52 | return -1; 53 | } 54 | return 0; 55 | } 56 | -------------------------------------------------------------------------------- /src/spawn.h: -------------------------------------------------------------------------------- 1 | #ifndef __SPAWN_H__ 2 | #define __SPAWN_H__ 1 3 | 4 | int spawn_handler(const int dev_desc_fd, const char * const script); 5 | 6 | #endif 7 | -------------------------------------------------------------------------------- /src/syslognames.h: -------------------------------------------------------------------------------- 1 | #ifndef __SYSLOGNAMES_H__ 2 | #define __SYSLOGNAMES_H__ 1 3 | 4 | #ifdef SYSLOG_NAMES 5 | 6 | struct { 7 | const char *c_name; 8 | int c_val; 9 | } facilitynames[] = 10 | { 11 | # ifdef LOG_AUTH 12 | { "auth", LOG_AUTH }, 13 | # endif 14 | # ifdef LOG_AUTHPRIV 15 | { "authpriv", LOG_AUTHPRIV }, 16 | # endif 17 | # ifdef LOG_CRON 18 | { "cron", LOG_CRON }, 19 | # endif 20 | # ifdef LOG_DAEMON 21 | { "daemon", LOG_DAEMON }, 22 | # endif 23 | # ifdef LOG_FTP 24 | { "ftp", LOG_FTP }, 25 | # endif 26 | # ifdef LOG_KERN 27 | { "kern", LOG_KERN }, 28 | # endif 29 | # ifdef LOG_LPR 30 | { "lpr", LOG_LPR }, 31 | # endif 32 | # ifdef LOG_MAIL 33 | { "mail", LOG_MAIL }, 34 | # endif 35 | # ifdef INTERNAL_MARK 36 | { "mark", INTERNAL_MARK }, /* INTERNAL */ 37 | # endif 38 | # ifdef LOG_NEWS 39 | { "news", LOG_NEWS }, 40 | # endif 41 | # ifdef LOG_AUTH 42 | { "security", LOG_AUTH }, /* DEPRECATED */ 43 | # endif 44 | # ifdef LOG_SYSLOG 45 | { "syslog", LOG_SYSLOG }, 46 | # endif 47 | # ifdef LOG_USER 48 | { "user", LOG_USER }, 49 | # endif 50 | # ifdef LOG_UUCP 51 | { "uucp", LOG_UUCP }, 52 | # endif 53 | # ifdef LOG_LOCAL0 54 | { "local0", LOG_LOCAL0 }, 55 | # endif 56 | # ifdef LOG_LOCAL1 57 | { "local1", LOG_LOCAL1 }, 58 | # endif 59 | # ifdef LOG_LOCAL2 60 | { "local2", LOG_LOCAL2 }, 61 | # endif 62 | # ifdef LOG_LOCAL3 63 | { "local3", LOG_LOCAL3 }, 64 | # endif 65 | # ifdef LOG_LOCAL4 66 | { "local4", LOG_LOCAL4 }, 67 | # endif 68 | # ifdef LOG_LOCAL5 69 | { "local5", LOG_LOCAL5 }, 70 | # endif 71 | # ifdef LOG_LOCAL6 72 | { "local6", LOG_LOCAL6 }, 73 | # endif 74 | # ifdef LOG_LOCAL7 75 | { "local7", LOG_LOCAL7 }, 76 | # endif 77 | # ifdef LOG_LOCAL8 78 | { "local8", LOG_LOCAL8 }, 79 | # endif 80 | # ifdef LOG_LOCAL9 81 | { "local9", LOG_LOCAL9 }, 82 | # endif 83 | { NULL, -1 } 84 | }; 85 | 86 | #else 87 | 88 | extern struct { 89 | const char *c_name; 90 | int c_val; 91 | } facilitynames[]; 92 | 93 | #endif 94 | 95 | #endif 96 | -------------------------------------------------------------------------------- /src/ucarp.c: -------------------------------------------------------------------------------- 1 | 2 | #define DEFINE_GLOBALS 1 3 | 4 | #include 5 | #include "ucarp.h" 6 | #ifndef HAVE_GETOPT_LONG 7 | # include "bsd-getopt_long.h" 8 | #else 9 | # include 10 | #endif 11 | #ifdef HAVE_SETLOCALE 12 | # include 13 | #endif 14 | #include "log.h" 15 | #include "daemonize.h" 16 | #include "ucarp_p.h" 17 | 18 | #ifdef WITH_DMALLOC 19 | # include 20 | #endif 21 | 22 | static void usage(void) 23 | { 24 | puts("\n" PACKAGE_STRING " - " __DATE__ "\n"); 25 | fputs(_( 26 | "--interface= (-i ): bind interface \n" 27 | "--srcip= (-s ): source (real) IP address of that host\n" 28 | "--mcast= (-m ): multicast group IP address (default 224.0.0.18)\n" 29 | "--vhid= (-v ): virtual IP identifier (1-255)\n" 30 | "--pass= (-p ): password\n" 31 | "--passfile= (-o ): read password from file\n" 32 | "--preempt (-P): becomes a master as soon as possible\n" 33 | "--neutral (-n): don't run downscript at start if backup\n" 34 | "--addr= (-a ): virtual shared IP address\n" 35 | "--help (-h): summary of command-line options\n" 36 | "--advbase= (-b ): advertisement frequency\n" 37 | "--advskew= (-k ): advertisement skew (0-255)\n" 38 | "--upscript= (-u ): run to become a master\n" 39 | "--downscript= (-d ): run to become a backup\n" 40 | "--deadratio= (-r ): ratio to consider a host as dead\n" 41 | "--debug (-D): enable debug output\n" 42 | "--shutdown (-z): call shutdown script at exit\n" 43 | "--daemonize (-B): run in background\n" 44 | "--ignoreifstate (-S): ignore interface state (down, no carrier)\n" 45 | "--nomcast (-M): use broadcast (instead of multicast) advertisements\n" 46 | "--facility= (-f): set syslog facility (default=daemon)\n" 47 | "--xparam= (-x): extra parameter to send to up/down scripts\n" 48 | "\n" 49 | "Sample usage:\n" 50 | "\n" 51 | "Manage the 10.1.1.252 shared virtual address on interface eth0, with\n" 52 | "1 as a virtual address idenfitier, mypassword as a password, and\n" 53 | "10.1.1.1 as a real permanent address for this host.\n" 54 | "Call /etc/vip-up.sh when the host becomes a master, and\n" 55 | "/etc/vip-down.sh when the virtual IP address has to be disabled.\n" 56 | "\n" 57 | "ucarp --interface=eth0 --srcip=10.1.1.1 --vhid=1 --pass=mypassword \\\n" 58 | " --addr=10.1.1.252 \\\n" 59 | " --upscript=/etc/vip-up.sh --downscript=/etc/vip-down.sh\n" 60 | "\n\n" 61 | "Please report bugs to "), stdout); 62 | puts(PACKAGE_BUGREPORT ".\n"); 63 | 64 | exit(EXIT_SUCCESS); 65 | } 66 | 67 | static void init_rand(void) 68 | { 69 | struct timeval tv; 70 | 71 | gettimeofday(&tv, NULL); 72 | #ifdef HAVE_SRANDOMDEV 73 | srandomdev(); 74 | #elif defined(HAVE_RANDOM) 75 | srandom((unsigned int) (tv.tv_sec ^ tv.tv_usec ^ (getpid() << 16))); 76 | #else 77 | srand((unsigned int) (tv.tv_sec ^ tv.tv_usec ^ (getpid() << 16))); 78 | #endif 79 | } 80 | 81 | static void die_mem(void) 82 | { 83 | logfile(LOG_ERR, _("Out of memory")); 84 | 85 | exit(EXIT_FAILURE); 86 | } 87 | 88 | int main(int argc, char *argv[]) 89 | { 90 | int option_index = 0; 91 | int fodder; 92 | 93 | #ifdef HAVE_SETLOCALE 94 | setlocale(LC_ALL, ""); 95 | #endif 96 | bindtextdomain(PACKAGE, LOCALEDIR); 97 | textdomain(PACKAGE); 98 | 99 | if (argc <= 1) { 100 | usage(); 101 | } 102 | inet_pton(AF_INET, DEFAULT_MCASTIP, &mcastip); 103 | while ((fodder = getopt_long(argc, argv, GETOPT_OPTIONS, long_options, 104 | &option_index)) != -1) { 105 | switch (fodder) { 106 | case 'h': { 107 | usage(); 108 | } 109 | case 'i': { 110 | free(interface); 111 | if ((interface = strdup(optarg)) == NULL) { 112 | die_mem(); 113 | } 114 | break; 115 | } 116 | case 's': { 117 | if (inet_pton(AF_INET, optarg, &srcip) == 0) { 118 | logfile(LOG_ERR, _("Invalid address: [%s]"), optarg); 119 | return 1; 120 | } 121 | break; 122 | } 123 | case 'm': { 124 | if (inet_pton(AF_INET, optarg, &mcastip) == 0) { 125 | logfile(LOG_ERR, _("Invalid address: [%s]"), optarg); 126 | return 1; 127 | } 128 | break; 129 | } 130 | case 'v': { 131 | if (strtoul(optarg, NULL, 0) > 255 || strtol(optarg, NULL, 0) < 1) { 132 | logfile(LOG_ERR, _("vhid must be between 1 and 255.")); 133 | return 1; 134 | } 135 | vhid = (unsigned char) strtoul(optarg, NULL, 0); 136 | break; 137 | } 138 | case 'p': { 139 | free(pass); 140 | if ((pass = strdup(optarg)) == NULL) { 141 | die_mem(); 142 | } 143 | break; 144 | } 145 | case 'o': { 146 | char buf[512U]; 147 | char *p; 148 | FILE *pw; 149 | if ((pw = fopen(optarg, "r")) == NULL) { 150 | logfile(LOG_ERR, 151 | _("unable to open passfile %s for reading: %s"), 152 | optarg, strerror(errno)); 153 | return 1; 154 | } 155 | if (fgets(buf, sizeof buf, pw) == NULL) { 156 | logfile(LOG_ERR, _("error reading passfile %s: %s"), optarg, 157 | ferror(pw) ? 158 | strerror(errno) : _("unexpected end of file")); 159 | fclose(pw); 160 | return 1; 161 | } 162 | fclose(pw); 163 | p = strchr(buf, '\n'); 164 | if (p != NULL) { 165 | *p = 0; 166 | } 167 | if ((pass = strdup(buf)) == NULL) { 168 | die_mem(); 169 | } 170 | break; 171 | } 172 | case 'P': { 173 | preempt = 1; 174 | break; 175 | } 176 | case 'n': { 177 | neutral = 1; 178 | break; 179 | } 180 | case 'a': { 181 | free(vaddr_arg); 182 | if (inet_pton(AF_INET, optarg, &vaddr) == 0) { 183 | logfile(LOG_ERR, _("Invalid address: [%s]"), optarg); 184 | return 1; 185 | } 186 | vaddr_arg = strdup(optarg); 187 | break; 188 | } 189 | case 'b': { 190 | advbase = (unsigned char) strtoul(optarg, NULL, 0); 191 | break; 192 | } 193 | case 'k': { 194 | advskew = (unsigned char) strtoul(optarg, NULL, 0); 195 | break; 196 | } 197 | case 'd': { 198 | free(downscript); 199 | if ((downscript = strdup(optarg)) == NULL) { 200 | die_mem(); 201 | } 202 | break; 203 | } 204 | case 'D': { 205 | debug = 1; 206 | break; 207 | } 208 | case 'u': { 209 | free(upscript); 210 | if ((upscript = strdup(optarg)) == NULL) { 211 | die_mem(); 212 | } 213 | break; 214 | } 215 | case 'r': { 216 | dead_ratio = (unsigned int) strtoul(optarg, NULL, 0); 217 | break; 218 | } 219 | case 'z': { 220 | shutdown_at_exit = 1; 221 | break; 222 | } 223 | case 'B': { 224 | daemonize = 1; 225 | break; 226 | } 227 | case 'S': { 228 | ignoreifstate = 1; 229 | break; 230 | } 231 | case 'f': { 232 | int n = 0; 233 | 234 | if (strcasecmp(optarg, "none") == 0) { 235 | no_syslog = 1; 236 | break; 237 | } 238 | while (facilitynames[n].c_name && 239 | strcasecmp(facilitynames[n].c_name, optarg) != 0) { 240 | n++; 241 | } 242 | if (facilitynames[n].c_name) { 243 | syslog_facility = facilitynames[n].c_val; 244 | } else { 245 | logfile(LOG_ERR, _("Unknown syslog facility: [%s]"), optarg); 246 | } 247 | break; 248 | } 249 | case 'x': { 250 | free(xparam); 251 | if ((xparam = strdup(optarg)) == NULL) { 252 | die_mem(); 253 | } 254 | break; 255 | } 256 | case 'M': { 257 | no_mcast = 1; 258 | break; 259 | } 260 | default: { 261 | usage(); 262 | } 263 | } 264 | } 265 | #ifndef SAVE_DESCRIPTORS 266 | if (no_syslog == 0) { 267 | openlog("ucarp", LOG_PID, syslog_facility); 268 | } 269 | #endif 270 | if (interface == NULL || *interface == 0) { 271 | interface = pcap_lookupdev(NULL); 272 | if (interface == NULL || *interface == 0) { 273 | logfile(LOG_ERR, _("You must supply a network interface")); 274 | return 1; 275 | } 276 | logfile(LOG_INFO, _("Using [%s] as a network interface"), interface); 277 | } 278 | if (vhid == 0) { 279 | logfile(LOG_ERR, _("You must supply a valid virtual host id")); 280 | return 1; 281 | } 282 | if (pass == NULL || *pass == 0) { 283 | logfile(LOG_ERR, _("You must supply a password")); 284 | return 1; 285 | } 286 | if (advbase == 0 && advskew == 0) { 287 | logfile(LOG_ERR, _("You must supply an advertisement time base")); 288 | return 1; 289 | } 290 | if (srcip.s_addr == 0) { 291 | logfile(LOG_ERR, _("You must supply a persistent source address")); 292 | return 1; 293 | } 294 | if (vaddr.s_addr == 0) { 295 | logfile(LOG_ERR, _("You must supply a virtual host address")); 296 | return 1; 297 | } 298 | if (upscript == NULL) { 299 | logfile(LOG_WARNING, _("Warning: no script called when going up")); 300 | } 301 | if (downscript == NULL) { 302 | logfile(LOG_WARNING, _("Warning: no script called when going down")); 303 | } 304 | if (dead_ratio <= 0U) { 305 | logfile(LOG_ERR, _("Dead ratio can't be zero")); 306 | return 1; 307 | } 308 | dodaemonize(); 309 | init_rand(); 310 | if (docarp() != 0) { 311 | return 2; 312 | } 313 | 314 | #ifndef SAVE_DESCRIPTORS 315 | if (no_syslog == 0) { 316 | closelog(); 317 | } 318 | #endif 319 | 320 | return 0; 321 | } 322 | -------------------------------------------------------------------------------- /src/ucarp.h: -------------------------------------------------------------------------------- 1 | #ifndef __UCARP_H__ 2 | #define __UCARP_H__ 1 3 | 4 | #include 5 | #ifdef STDC_HEADERS 6 | # include 7 | # include 8 | # include 9 | #else 10 | # ifdef HAVE_STDLIB_H 11 | # include 12 | # endif 13 | #endif 14 | #if HAVE_STRING_H 15 | # if !STDC_HEADERS && HAVE_MEMORY_H 16 | # include 17 | # endif 18 | # include 19 | #else 20 | # if HAVE_STRINGS_H 21 | # include 22 | # endif 23 | #endif 24 | #ifdef HAVE_UNISTD_H 25 | # include 26 | #endif 27 | #include 28 | #include 29 | #if TIME_WITH_SYS_TIME 30 | # include 31 | # include 32 | #else 33 | # if HAVE_SYS_TIME_H 34 | # include 35 | # else 36 | # include 37 | # endif 38 | #endif 39 | #include 40 | #include 41 | #ifdef HAVE_FCNTL_H 42 | # include 43 | #elif defined(HAVE_SYS_FCNTL_H) 44 | # include 45 | #endif 46 | #ifdef HAVE_IOCTL_H 47 | # include 48 | #elif defined(HAVE_SYS_IOCTL_H) 49 | # include 50 | #endif 51 | #include 52 | #ifdef HAVE_NETINET_IN_H 53 | # include 54 | #endif 55 | #include 56 | #ifdef HAVE_NETINET_IN_SYSTM_H 57 | # include 58 | #endif 59 | #include 60 | #include 61 | #include 62 | #include 63 | #include 64 | 65 | #ifdef __sun__ 66 | # define u_int8_t uint8_t 67 | # define u_int16_t uint16_t 68 | # define u_int32_t uint32_t 69 | # define u_int64_t uint64_t 70 | # define ether_shost ether_shost.ether_addr_octet 71 | # define ether_dhost ether_dhost.ether_addr_octet 72 | #endif 73 | 74 | #include "gettext.h" 75 | #define _(txt) gettext(txt) 76 | #define N_(txt) txt 77 | 78 | #include "mysnprintf.h" 79 | #include "crypto.h" 80 | #ifndef USE_SYSTEM_CRYPT_SHA1 81 | # include "crypto-sha1.h" 82 | #else 83 | # include 84 | #endif 85 | #include "ip_carp.h" 86 | 87 | #ifndef errno 88 | extern int errno; 89 | #endif 90 | 91 | #ifdef HAVE_ALLOCA 92 | # ifdef HAVE_ALLOCA_H 93 | # include 94 | # endif 95 | # define ALLOCA(X) alloca(X) 96 | # define ALLOCA_FREE(X) do { } while (0) 97 | #else 98 | # define ALLOCA(X) malloc(X) 99 | # define ALLOCA_FREE(X) free(X) 100 | #endif 101 | 102 | #ifdef DEFINE_GLOBALS 103 | # define SYSLOG_NAMES 1 /* for -f */ 104 | #endif 105 | #include 106 | #ifndef HAVE_SYSLOG_NAMES 107 | # include "syslognames.h" 108 | #endif 109 | #ifndef MAX_SYSLOG_LINE 110 | # define MAX_SYSLOG_LINE 4096U 111 | #endif 112 | 113 | #ifndef __GNUC__ 114 | # define __packed__ 115 | #endif 116 | 117 | #define ETHERNET_MTU 1500 118 | #ifndef ETHER_ADDR_LEN 119 | # define ETHER_ADDR_LEN 6 120 | #endif 121 | #ifndef IPPROTO_CARP 122 | # define IPPROTO_CARP 112 123 | #endif 124 | #ifndef timercmp 125 | # define timercmp(tvp, uvp, cmp) \ 126 | (((tvp)->tv_sec == (uvp)->tv_sec) ? \ 127 | ((tvp)->tv_usec cmp (uvp)->tv_usec) : \ 128 | ((tvp)->tv_sec cmp (uvp)->tv_sec)) 129 | #endif 130 | 131 | #ifndef HAVE_SETEUID 132 | # ifdef HAVE_SETREUID 133 | # define seteuid(X) setreuid(-1, (X)) 134 | # elif defined(HAVE_SETRESUID) 135 | # define seteuid(X) setresuid(-1, (X), -1) 136 | # else 137 | # define seteuid(X) (-1) 138 | # endif 139 | #endif 140 | #ifndef HAVE_SETEGID 141 | # ifdef HAVE_SETREGID 142 | # define setegid(X) setregid(-1, (X)) 143 | # elif defined(HAVE_SETRESGID) 144 | # define setegid(X) setresgid(-1, (X), -1) 145 | # else 146 | # define setegid(X) (-1) 147 | # endif 148 | #endif 149 | 150 | #ifndef HAVE_STRTOULL 151 | # ifdef HAVE_STRTOQ 152 | # define strtoull(X, Y, Z) strtoq(X, Y, Z) 153 | # else 154 | # define strtoull(X, Y, Z) strtoul(X, Y, Z) 155 | # endif 156 | #endif 157 | 158 | #ifndef ULONG_LONG_MAX 159 | # define ULONG_LONG_MAX (1ULL << 63) 160 | #endif 161 | 162 | #ifdef WITH_DMALLOC 163 | # define _exit(X) exit(X) 164 | #endif 165 | 166 | #define CAPTURE_TIMEOUT 1000 167 | 168 | #ifndef MAX 169 | #define MAX(a, b) ((a) < (b) ? (b) : (a)) 170 | #endif 171 | 172 | struct carp_softc { 173 | int if_flags; /* current flags to treat UP/DOWN */ 174 | struct ifnet *sc_ifp; 175 | struct in_ifaddr *sc_ia; /* primary iface address */ 176 | #ifdef INET6 177 | struct in6_ifaddr *sc_ia6; /* primary iface address v6 */ 178 | struct ip6_moptions sc_im6o; 179 | #endif /* INET6 */ 180 | 181 | enum { INIT = 0, BACKUP, MASTER } sc_state; 182 | 183 | int sc_flags_backup; 184 | int sc_suppress; 185 | 186 | int sc_sendad_errors; 187 | #define CARP_SENDAD_MAX_ERRORS 3 188 | int sc_sendad_success; 189 | #define CARP_SENDAD_MIN_SUCCESS 3 190 | 191 | int sc_vhid; 192 | int sc_advskew; 193 | int sc_naddrs; 194 | int sc_naddrs6; 195 | int sc_advbase; /* seconds */ 196 | int sc_init_counter; 197 | u_int64_t sc_counter; 198 | int sc_delayed_arp; 199 | 200 | /* authentication */ 201 | #define CARP_HMAC_PAD 64 202 | unsigned char sc_key[CARP_KEY_LEN]; 203 | unsigned char sc_pad[CARP_HMAC_PAD]; 204 | SHA1_CTX sc_sha1; 205 | 206 | struct timeval sc_ad_tmo; /* advertisement timeout */ 207 | struct timeval sc_md_tmo; /* master down timeout */ 208 | struct timeval sc_md6_tmo; /* master down timeout */ 209 | }; 210 | 211 | #define CARP_AUTHLEN 7 212 | #define DEFAULT_ADVBASE 1U 213 | #define DEFAULT_DEAD_RATIO 3U 214 | #define DEFAULT_MCASTIP "224.0.0.18" 215 | #define SECONDS_TO_WAIT_AFTER_INTERFACE_IS_DOWN 10U 216 | 217 | #define DEFAULT_FACILITY LOG_DAEMON 218 | 219 | int docarp(void); 220 | 221 | #include "globals.h" 222 | 223 | #endif 224 | -------------------------------------------------------------------------------- /src/ucarp_p.h: -------------------------------------------------------------------------------- 1 | #ifndef __CARP_P_H__ 2 | #define __CARP_P_H__ 1 3 | 4 | static const char *GETOPT_OPTIONS = "i:s:v:p:Pa:hb:k:x:nu:d:Dr:zf:Bo:SM"; 5 | 6 | static struct option long_options[] = { 7 | { "interface", 1, NULL, 'i' }, 8 | { "srcip", 1, NULL, 's' }, 9 | { "mcastip", 1, NULL, 'm' }, 10 | { "vhid", 1, NULL, 'v' }, 11 | { "pass", 1, NULL, 'p' }, 12 | { "preempt", 0, NULL, 'P' }, 13 | { "neutral", 0, NULL, 'n' }, 14 | { "addr", 1, NULL, 'a' }, 15 | { "help", 0, NULL, 'h' }, 16 | { "advbase", 1, NULL, 'b' }, 17 | { "advskew", 1, NULL, 'k' }, 18 | { "upscript", 1, NULL, 'u' }, 19 | { "downscript", 1, NULL, 'd' }, 20 | { "deadratio", 1, NULL, 'r' }, 21 | { "debug", 0, NULL, 'D' }, 22 | { "shutdown", 0, NULL, 'z' }, 23 | { "facility", 1, NULL, 'f' }, 24 | { "daemonize", 0, NULL, 'B' }, 25 | { "ignoreifstate", 0, NULL, 'S' }, 26 | { "nomcast", 0, NULL, 'M' }, 27 | { "passfile", 1, NULL, 'o' }, 28 | { "xparam", 1, NULL, 'x' }, 29 | { NULL, 0, NULL, 0 } 30 | }; 31 | 32 | #endif 33 | --------------------------------------------------------------------------------