]> Pileus Git - ~andy/fetchmail/blob - interface.c
Clean up the horrible HAVE_[V]SNPRINTF mess, use Trio on systems that lack
[~andy/fetchmail] / interface.c
1 /*
2  * interface.c -- implements fetchmail 'interface' and 'monitor' commands
3  *
4  * This module was implemented by George M. Sipe <gsipe@pobox.com>
5  * or <gsipe@acm.org> and is:
6  *
7  *      Copyright (c) 1996,1997 by George M. Sipe
8  *
9  *      FreeBSD specific portions written by and Copyright (c) 1999 
10  *      Andy Doran <ad@psn.ie>.
11  *
12  * For license terms, see the file COPYING in this directory.
13  */
14 #include <sys/types.h>
15 #include <sys/param.h>
16
17 #if (defined(linux) && !defined(INET6_ENABLE)) || defined(__FreeBSD__)
18
19 #include "config.h"
20 #include <stdio.h>
21 #include <string.h>
22 #if defined(STDC_HEADERS)
23 #include <stdlib.h>
24 #endif
25 #if defined(HAVE_UNISTD_H)
26 #include <unistd.h>
27 #endif
28 #include <sys/ioctl.h>
29 #include <sys/socket.h>
30 #include <netinet/in.h>
31 #include <arpa/inet.h>
32 #include <net/if.h>
33 #if defined(__FreeBSD__)
34 #if defined __FreeBSD_USE_KVM
35 #if __FreeBSD_version >= 300001
36 #include <net/if_var.h>
37 #endif
38 #include <kvm.h>
39 #include <nlist.h>
40 #include <sys/fcntl.h>
41 #else
42 #include <sys/sysctl.h>
43 #include <net/route.h>
44 #include <net/if_dl.h>
45 #endif
46 #endif
47 #include "config.h"
48 #include "fetchmail.h"
49 #include "socket.h"
50 #include "i18n.h"
51 #include "tunable.h"
52
53 typedef struct {
54         struct in_addr addr, dstaddr, netmask;
55         int rx_packets, tx_packets;
56 } ifinfo_t;
57
58 struct interface_pair_s {
59         struct in_addr interface_address;
60         struct in_addr interface_mask;
61 } *interface_pair;
62
63 static char *netdevfmt;
64
65 /*
66  * Count of packets to see on an interface before monitor considers it up.
67  * Needed because when pppd shuts down the link, the packet counts go up
68  * by two (one rx and one tx?, maybe).  A value of 2 seems to do the trick,
69  * but we'll give it some extra.
70  */
71 #define MONITOR_SLOP            5
72
73 #if defined(linux)
74
75 void interface_init(void)
76 /* figure out which /proc/dev/net format to use */
77 {
78     FILE *fp = popen("uname -r", "r");  /* still wins if /proc is out */
79
80     /* pre-linux-2.2 format -- transmit packet count in 8th field */
81     netdevfmt = "%d %d %*d %*d %*d %d %*d %d %*d %*d %*d %*d %d";
82
83     if (!fp)
84         return;
85     else
86     {
87         int major, minor;
88
89         if (fscanf(fp, "%d.%d.%*d", &major, &minor) >= 2
90                                         && major >= 2 && minor >= 2)
91             /* Linux 2.2 -- transmit packet count in 10th field */
92             netdevfmt = "%d %d %*d %*d %*d %d %*d %*d %*d %d %*d %*d %d";
93         pclose(fp);
94     }
95 }
96
97 static int _get_ifinfoGT_(int socket_fd, FILE *stats_file, const char *ifname,
98                 ifinfo_t *ifinfo)
99 /* get active network interface information - return non-zero upon success */
100 {
101         int namelen = strlen(ifname);
102         struct ifreq request;
103         char *cp, buffer[256];
104         int found = 0;
105         int counts[4];
106
107         /* initialize result */
108         memset((char *) ifinfo, 0, sizeof(ifinfo_t));
109
110         /* get the packet I/O counts */
111         while (fgets(buffer, sizeof(buffer) - 1, stats_file)) {
112                 for (cp = buffer; *cp && *cp == ' '; ++cp);
113                 if (!strncmp(cp, ifname, namelen) &&
114                                 cp[namelen] == ':') {
115                         cp += namelen + 1;
116                         if (sscanf(cp, netdevfmt,
117                                    counts, counts+1, counts+2, 
118                                    counts+3,&found)>4) { /* found = dummy */
119                                 /* newer kernel with byte counts */
120                                 ifinfo->rx_packets=counts[1];
121                                 ifinfo->tx_packets=counts[3];
122                         } else {
123                                 /* older kernel, no byte counts */
124                                 ifinfo->rx_packets=counts[0];
125                                 ifinfo->tx_packets=counts[2];
126                         }
127                         found = 1;
128                 }
129         }
130         if (!found) return (FALSE);
131
132         /* see if the interface is up */
133         strcpy(request.ifr_name, ifname);
134         if (ioctl(socket_fd, SIOCGIFFLAGS, &request) < 0)
135                 return(FALSE);
136         if (!(request.ifr_flags & IFF_RUNNING))
137                 return(FALSE);
138
139         /* get the (local) IP address */
140         strcpy(request.ifr_name, ifname);
141         if (ioctl(socket_fd, SIOCGIFADDR, &request) < 0)
142                 return(FALSE);
143         ifinfo->addr = ((struct sockaddr_in *) (&request.ifr_addr))->sin_addr;
144
145         /* get the PPP destination (remote) IP address */
146         ifinfo->dstaddr.s_addr = 0;
147         strcpy(request.ifr_name, ifname);
148         if (ioctl(socket_fd, SIOCGIFDSTADDR, &request) >= 0)
149                 ifinfo->dstaddr = ((struct sockaddr_in *)
150                                         (&request.ifr_dstaddr))->sin_addr;
151
152         /* get the netmask */
153         strcpy(request.ifr_name, ifname);
154         if (ioctl(socket_fd, SIOCGIFNETMASK, &request) >= 0) {
155           ifinfo->netmask = ((struct sockaddr_in *)
156                              (&request.ifr_netmask))->sin_addr;
157           return (TRUE);
158         }
159
160         return(FALSE);
161 }
162
163 static int get_ifinfo(const char *ifname, ifinfo_t *ifinfo)
164 {
165         int socket_fd = socket(AF_INET, SOCK_DGRAM, 0);
166         FILE *stats_file = fopen("/proc/net/dev", "r");
167         int result;
168
169         if (socket_fd < 0 || !stats_file)
170                 result = FALSE;
171         else
172         {
173             char        *sp = strchr(ifname, '/');
174
175             if (sp)
176                 *sp = '\0';
177             result = _get_ifinfoGT_(socket_fd, stats_file, ifname, ifinfo);
178             if (sp)
179                 *sp = '/';
180         }
181         if (socket_fd >= 0)
182             SockClose(socket_fd);
183         if (stats_file)
184             fclose(stats_file); /* not checking should be safe, mode was "r" */
185         return(result);
186 }
187
188 #elif defined __FreeBSD__
189
190 #if defined __FreeBSD_USE_KVM
191
192 static kvm_t *kvmfd;
193 static struct nlist symbols[] = 
194 {
195         {"_ifnet"},
196         {NULL}
197 };
198 static u_long   ifnet_savedaddr;
199 static gid_t    if_rgid;
200 static gid_t    if_egid;
201
202 void 
203 interface_set_gids(gid_t egid, gid_t rgid)
204 {
205         if_rgid = rgid;
206         if_egid = egid;
207 }
208
209 static int 
210 openkvm(void)
211 {
212         if ((kvmfd = kvm_open(NULL, NULL, NULL, O_RDONLY, NULL)) == NULL)
213                 return FALSE;
214         
215         if (kvm_nlist(kvmfd, symbols) < 0)
216                 return FALSE;
217            
218         if (kvm_read(kvmfd, (unsigned long) symbols[0].n_value, &ifnet_savedaddr, sizeof(unsigned long)) == -1)
219                 return FALSE;
220                 
221         return TRUE;
222 }
223
224 static int 
225 get_ifinfo(const char *ifname, ifinfo_t *ifinfo)
226 {
227         char                    tname[16];
228         char                    iname[16];
229         struct ifnet            ifnet;
230         unsigned long           ifnet_addr = ifnet_savedaddr;
231 #if __FreeBSD_version >= 300001
232         struct ifnethead        ifnethead;
233         struct ifaddrhead       ifaddrhead;
234 #endif
235         struct ifaddr           ifaddr;
236         unsigned long           ifaddr_addr;
237         struct sockaddr         sa;
238         unsigned long           sa_addr;
239         uint                    i;
240         
241         if (if_egid)
242                 setegid(if_egid);
243         
244         for (i = 0; ifname[i] && ifname[i] != '/'; i++)
245                 iname[i] = ifname[i];
246                 
247         iname[i] = '\0';
248         
249         if (!kvmfd)
250         {
251                 if (!openkvm())
252                 {
253                         report(stderr, 0, GT_("Unable to open kvm interface. Make sure fetchmail is SGID kmem."));
254                         if (if_egid)
255                                 setegid(if_rgid);
256                         exit(1);
257                 }
258         }
259
260 #if __FreeBSD_version >= 300001
261         kvm_read(kvmfd, ifnet_savedaddr, (char *) &ifnethead, sizeof ifnethead);
262         ifnet_addr = (u_long) ifnethead.tqh_first;
263 #else
264         ifnet_addr = ifnet_savedaddr;
265 #endif
266
267         while (ifnet_addr)
268         {
269                 kvm_read(kvmfd, ifnet_addr, &ifnet, sizeof(ifnet));
270                 kvm_read(kvmfd, (unsigned long) ifnet.if_name, tname, sizeof tname);
271                 snprintf(tname, sizeof tname, "%s%d", tname, ifnet.if_unit);
272
273                 if (!strcmp(tname, iname))
274                 {
275                         if (!(ifnet.if_flags & IFF_UP))
276                         {
277                                 if (if_egid)
278                                         setegid(if_rgid);
279                                 return 0;
280                         }
281                                 
282                         ifinfo->rx_packets = ifnet.if_ipackets;
283                         ifinfo->tx_packets = ifnet.if_opackets;
284
285 #if __FreeBSD_version >= 300001
286                         ifaddr_addr = (u_long) ifnet.if_addrhead.tqh_first;
287 #else
288                         ifaddr_addr = (u_long) ifnet.if_addrlist;
289 #endif
290                         
291                         while(ifaddr_addr)
292                         {
293                                 kvm_read(kvmfd, ifaddr_addr, &ifaddr, sizeof(ifaddr));
294                                 kvm_read(kvmfd, (u_long)ifaddr.ifa_addr, &sa, sizeof(sa));
295                                 
296                                 if (sa.sa_family != AF_INET)
297                                 {
298 #if __FreeBSD_version >= 300001
299                                         ifaddr_addr = (u_long) ifaddr.ifa_link.tqe_next;
300 #else
301                                         ifaddr_addr = (u_long) ifaddr.ifa_next;
302 #endif
303                                         continue;
304                                 }
305                         
306                                 ifinfo->addr.s_addr = *(u_long *)(sa.sa_data + 2);
307                                 kvm_read(kvmfd, (u_long)ifaddr.ifa_dstaddr, &sa, sizeof(sa));
308                                 ifinfo->dstaddr.s_addr = *(u_long *)(sa.sa_data + 2);
309                                 kvm_read(kvmfd, (u_long)ifaddr.ifa_netmask, &sa, sizeof(sa));
310                                 ifinfo->netmask.s_addr = *(u_long *)(sa.sa_data + 2);
311
312                                 if (if_egid)
313                                         setegid(if_rgid);
314
315                                 return 1;
316                         }
317                         
318                         if (if_egid)
319                                 setegid(if_rgid);
320                         
321                         return 0;
322                 }
323
324 #if __FreeBSD_version >= 300001
325                 ifnet_addr = (u_long) ifnet.if_link.tqe_next;
326 #else
327                 ifnet_addr = (unsigned long) ifnet.if_next;
328 #endif
329         }
330
331         if (if_egid)
332                 setegid(if_rgid);
333         
334         return 0;
335 }
336
337 #else /* Do not use KVM on FreeBSD */
338
339 /*
340  * Expand the compacted form of addresses as returned via the
341  * configuration read via sysctl().
342  */
343
344 static void
345 rt_xaddrs(caddr_t cp, caddr_t cplim, struct rt_addrinfo *rtinfo)
346 {
347     struct sockaddr *sa;
348     int i;
349
350 #define ROUNDUP(a) \
351         ((a) > 0 ? (1 + (((a) - 1) | (sizeof(long) - 1))) : sizeof(long))
352 #define ADVANCE(x, n) (x += ROUNDUP((n)->sa_len))
353
354     memset(rtinfo->rti_info, 0, sizeof(rtinfo->rti_info));
355     for (i = 0; (i < RTAX_MAX) && (cp < cplim); i++) {
356         if ((rtinfo->rti_addrs & (1 << i)) == 0)
357             continue;
358         rtinfo->rti_info[i] = sa = (struct sockaddr *)cp;
359         ADVANCE(cp, sa);
360     }
361
362 #undef ROUNDUP
363 #undef ADVANCE
364 }
365
366 static int
367 get_ifinfo(const char *ifname, ifinfo_t *ifinfo)
368 {
369     uint                i;
370     int                 rc = 0;
371     int                 ifindex = -1;
372     size_t              needed;
373     char                *buf = NULL;
374     char                *lim = NULL;
375     char                *next = NULL;
376     struct if_msghdr    *ifm;
377     struct ifa_msghdr   *ifam;
378     struct sockaddr_in  *sin;
379     struct sockaddr_dl  *sdl;
380     struct rt_addrinfo  info;
381     char                iname[16];
382     int                 mib[6];
383
384     memset(ifinfo, 0, sizeof(ifinfo));
385
386     /* trim interface name */
387
388     for (i = 0; i < sizeof(iname) && ifname[i] && ifname[i] != '/'; i++)
389         iname[i] = ifname[i];
390         
391     if (i == 0 || i == sizeof(iname))
392     {
393         report(stderr, GT_("Unable to parse interface name from %s"), ifname);
394         return 0;
395     }
396
397     iname[i] = 0;
398
399
400     /* get list of existing interfaces */
401
402     mib[0] = CTL_NET;
403     mib[1] = PF_ROUTE;
404     mib[2] = 0;
405     mib[3] = AF_INET;           /* Only IP addresses please. */
406     mib[4] = NET_RT_IFLIST;
407     mib[5] = 0;                 /* List all interfaces. */
408
409
410     /* Get interface data. */
411
412     if (sysctl(mib, 6, NULL, &needed, NULL, 0) == -1)
413     {
414         report(stderr, 
415             GT_("get_ifinfo: sysctl (iflist estimate) failed"));
416         exit(1);
417     }
418     if ((buf = malloc(needed)) == NULL)
419     {
420         report(stderr, 
421             GT_("get_ifinfo: malloc failed"));
422         exit(1);
423     }
424     if (sysctl(mib, 6, buf, &needed, NULL, 0) == -1)
425     {
426         report(stderr, 
427             GT_("get_ifinfo: sysctl (iflist) failed"));
428         exit(1);
429     }
430
431     lim = buf+needed;
432
433
434     /* first look for the interface information */
435
436     next = buf;
437     while (next < lim)
438     {
439         ifm = (struct if_msghdr *)next;
440         next += ifm->ifm_msglen;
441
442         if (ifm->ifm_version != RTM_VERSION) 
443         {
444             report(stderr, 
445                 GT_("Routing message version %d not understood."),
446                 ifm->ifm_version);
447             exit(1);
448         }
449
450         if (ifm->ifm_type == RTM_IFINFO)
451         {
452             sdl = (struct sockaddr_dl *)(ifm + 1);
453
454             if (!(strlen(iname) == sdl->sdl_nlen 
455                 && strncmp(iname, sdl->sdl_data, sdl->sdl_nlen) == 0))
456             {
457                 continue;
458             }
459
460             if ( !(ifm->ifm_flags & IFF_UP) )
461             {
462                 /* the interface is down */
463                 goto get_ifinfo_end;
464             }
465
466             ifindex = ifm->ifm_index;
467             ifinfo->rx_packets = ifm->ifm_data.ifi_ipackets;
468             ifinfo->tx_packets = ifm->ifm_data.ifi_opackets;
469
470             break;
471         }
472     }
473
474     if (ifindex < 0)
475     {
476         /* we did not find an interface with a matching name */
477         report(stderr, GT_("No interface found with name %s"), iname);
478         goto get_ifinfo_end;
479     }
480
481     /* now look for the interface's IP address */
482
483     next = buf;
484     while (next < lim)
485     {
486         ifam = (struct ifa_msghdr *)next;
487         next += ifam->ifam_msglen;
488
489         if (ifindex > 0
490             && ifam->ifam_type == RTM_NEWADDR
491             && ifam->ifam_index == ifindex)
492         {
493             /* Expand the compacted addresses */
494             info.rti_addrs = ifam->ifam_addrs;
495             rt_xaddrs((char *)(ifam + 1), 
496                         ifam->ifam_msglen + (char *)ifam,
497                         &info);
498
499             /* Check for IPv4 address information only */
500             if (info.rti_info[RTAX_IFA]->sa_family != AF_INET)
501             {
502                 continue;
503             }
504
505             rc = 1;
506
507             sin = (struct sockaddr_in *)info.rti_info[RTAX_IFA];
508             if (sin)
509             {
510                 ifinfo->addr = sin->sin_addr;
511             }
512
513             sin = (struct sockaddr_in *)info.rti_info[RTAX_NETMASK];
514             if (!sin)
515             {
516                 ifinfo->netmask = sin->sin_addr;
517             }
518
519             /* note: RTAX_BRD contains the address at the other
520              * end of a point-to-point link or the broadcast address
521              * of non point-to-point link
522              */
523             sin = (struct sockaddr_in *)info.rti_info[RTAX_BRD];
524             if (!sin)
525             {
526                 ifinfo->dstaddr = sin->sin_addr;
527             }
528
529             break;
530         }
531     }
532
533     if (rc == 0)
534     {
535         report(stderr, GT_("No IP address found for %s"), iname);
536     }
537
538 get_ifinfo_end:
539     free(buf);
540     return rc;
541 }
542
543 #endif /* __FREEBSD_USE_SYSCTL_GET_IFFINFO */
544
545 #endif /* defined __FreeBSD__ */
546
547
548 #ifndef HAVE_INET_ATON
549 /*
550  * Note: This is not a true replacement for inet_aton(), as it won't
551  * do the right thing on "255.255.255.255" (which translates to -1 on
552  * most machines).  Fortunately this code will be used only if you're
553  * on an older Linux that lacks a real implementation.
554  */
555 #ifdef HAVE_NETINET_IN_SYSTM_H
556 # include <sys/types.h>
557 # include <netinet/in_systm.h>
558 #endif
559
560 #include <netinet/in.h>
561 #include <netinet/ip.h>
562 #include <arpa/inet.h>
563 #include <string.h>
564
565 static int inet_aton(const char *cp, struct in_addr *inp) {
566     long addr;
567
568     addr = inet_addr(cp);
569     if (addr == ((long) -1)) return 0;
570
571     memcpy(inp, &addr, sizeof(addr));
572     return 1;
573 }
574 #endif /* HAVE_INET_ATON */
575
576 void interface_parse(char *buf, struct hostdata *hp)
577 /* parse 'interface' specification */
578 {
579         char *cp1, *cp2;
580
581         hp->interface = xstrdup(buf);
582
583         /* find and isolate just the IP address */
584         if (!(cp1 = strchr(buf, '/')))
585         {
586                 (void) report(stderr,
587                               GT_("missing IP interface address\n"));
588                 exit(PS_SYNTAX);
589         }
590         *cp1++ = '\000';
591
592         /* find and isolate just the netmask */
593         if (!(cp2 = strchr(cp1, '/')))
594                 cp2 = "255.255.255.255";
595         else
596                 *cp2++ = '\000';
597
598         /* convert IP address and netmask */
599         hp->interface_pair = (struct interface_pair_s *)xmalloc(sizeof(struct interface_pair_s));
600         if (!inet_aton(cp1, &hp->interface_pair->interface_address))
601         {
602                 (void) report(stderr,
603                               GT_("invalid IP interface address\n"));
604                 exit(PS_SYNTAX);
605         }
606         if (!inet_aton(cp2, &hp->interface_pair->interface_mask))
607         {
608                 (void) report(stderr,
609                               GT_("invalid IP interface mask\n"));
610                 exit(PS_SYNTAX);
611         }
612         /* apply the mask now to the IP address (range) required */
613         hp->interface_pair->interface_address.s_addr &=
614                 hp->interface_pair->interface_mask.s_addr;
615
616         /* restore original interface string (for configuration dumper) */
617         *--cp1 = '/';
618         return;
619 }
620
621 void interface_note_activity(struct hostdata *hp)
622 /* save interface I/O counts */
623 {
624         ifinfo_t ifinfo;
625         struct query *ctl;
626
627         /* if not monitoring link, all done */
628         if (!hp->monitor)
629                 return;
630
631         /* get the current I/O stats for the monitored link */
632         if (get_ifinfo(hp->monitor, &ifinfo))
633                 /* update this and preceeding host entries using the link
634                    (they were already set during this pass but the I/O
635                    count has now changed and they need to be re-updated)
636                 */
637                 for (ctl = querylist; ctl; ctl = ctl->next) {
638                         if (ctl->server.monitor && !strcmp(hp->monitor, ctl->server.monitor))
639                                 ctl->server.monitor_io =
640                                         ifinfo.rx_packets + ifinfo.tx_packets;
641                         /* do NOT update host entries following this one */
642                         if (&ctl->server == hp)
643                                 break;
644                 }
645
646 #ifdef  ACTIVITY_DEBUG
647         (void) report(stdout, 
648                       GT_("activity on %s -noted- as %d\n"), 
649                       hp->monitor, hp->monitor_io);
650 #endif
651 }
652
653 int interface_approve(struct hostdata *hp, flag domonitor)
654 /* return TRUE if OK to poll, FALSE otherwise */
655 {
656         ifinfo_t ifinfo;
657
658         /* check interface IP address (range), if specified */
659         if (hp->interface) {
660                 /* get interface info */
661                 if (!get_ifinfo(hp->interface, &ifinfo)) {
662                         (void) report(stdout, 
663                                       GT_("skipping poll of %s, %s down\n"),
664                                       hp->pollname, hp->interface);
665                         return(FALSE);
666                 }
667                 /* check the IP addresses (range) */
668                 if      (!(
669                                 /* check remote IP address */
670                                 ((ifinfo.dstaddr.s_addr != 0) &&
671                                 (ifinfo.dstaddr.s_addr &
672                                 hp->interface_pair->interface_mask.s_addr) ==
673                                 hp->interface_pair->interface_address.s_addr)
674                                 ||
675                                 /* check local IP address */
676                                 ((ifinfo.addr.s_addr &
677                                 hp->interface_pair->interface_mask.s_addr) ==
678                                 hp->interface_pair->interface_address.s_addr)
679                         ) )
680                 {
681                         (void) report(stdout,
682                                 GT_("skipping poll of %s, %s IP address excluded\n"),
683                                 hp->pollname, hp->interface);
684                         return(FALSE);
685                 }
686         }
687
688         /* if not monitoring link, all done */
689         if (!domonitor || !hp->monitor)
690                 return(TRUE);
691
692 #ifdef  ACTIVITY_DEBUG
693         (void) report(stdout, 
694                       GT_("activity on %s checked as %d\n"), 
695                       hp->monitor, hp->monitor_io);
696 #endif
697         /* if monitoring, check link for activity if it is up */
698         if (get_ifinfo(hp->monitor, &ifinfo))
699         {
700             int diff = (ifinfo.rx_packets + ifinfo.tx_packets)
701                                                         - hp->monitor_io;
702
703             /*
704              * There are three cases here:
705              *
706              * (a) If the new packet count is less than the recorded one,
707              * probably pppd was restarted while fetchmail was running.
708              * Don't skip.
709              *
710              * (b) newpacket count is greater than the old packet count,
711              * but the difference is small and may just reflect the overhead
712              * of a link shutdown.  Skip.
713              *
714              * (c) newpacket count is greater than the old packet count,
715              * and the difference is large. Connection is live.  Don't skip.
716              */
717             if (diff >= 0 && diff <= MONITOR_SLOP)
718             {
719                 (void) report(stdout, 
720                               GT_("skipping poll of %s, %s inactive\n"),
721                               hp->pollname, hp->monitor);
722                 return(FALSE);
723             }
724         }
725
726 #ifdef ACTIVITY_DEBUG
727        report(stdout, GT_("activity on %s was %d, is %d\n"),
728              hp->monitor, hp->monitor_io,
729              ifinfo.rx_packets + ifinfo.tx_packets);
730 #endif
731
732         return(TRUE);
733 }
734 #endif /* (defined(linux) && !defined(INET6_ENABLE)) || defined(__FreeBSD__) */