137142Sbrian/*- 237142Sbrian * Copyright (c) 1998 Brian Somers <brian@Awfulhak.org> 337142Sbrian * All rights reserved. 437142Sbrian * 537142Sbrian * Redistribution and use in source and binary forms, with or without 637142Sbrian * modification, are permitted provided that the following conditions 737142Sbrian * are met: 837142Sbrian * 1. Redistributions of source code must retain the above copyright 937142Sbrian * notice, this list of conditions and the following disclaimer. 1037142Sbrian * 2. Redistributions in binary form must reproduce the above copyright 1137142Sbrian * notice, this list of conditions and the following disclaimer in the 1237142Sbrian * documentation and/or other materials provided with the distribution. 1337142Sbrian * 1437142Sbrian * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 1537142Sbrian * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 1637142Sbrian * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 1737142Sbrian * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 1837142Sbrian * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 1937142Sbrian * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 2037142Sbrian * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 2137142Sbrian * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 2237142Sbrian * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 2337142Sbrian * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 2437142Sbrian * SUCH DAMAGE. 2537142Sbrian * 2650479Speter * $FreeBSD$ 2737142Sbrian */ 2837142Sbrian 2937142Sbrian#include <sys/time.h> 3081697Sbrian#include <sys/socket.h> 3181697Sbrian 3281785Sbrian#include <stdio.h> 3337142Sbrian#include <unistd.h> 3437142Sbrian 3537142Sbrian#include "probe.h" 3637142Sbrian#include "log.h" 3781785Sbrian#include "id.h" 3837142Sbrian 3981697Sbrianstruct probe probe; 4081697Sbrian 4137142Sbrian/* Does select() alter the passed time value ? */ 4237142Sbrianstatic int 4337142Sbrianselect_changes_time(void) 4437142Sbrian{ 4537142Sbrian struct timeval t; 4637142Sbrian 4737142Sbrian t.tv_sec = 0; 4837142Sbrian t.tv_usec = 100000; 4937142Sbrian select(0, NULL, NULL, NULL, &t); 5037142Sbrian return t.tv_usec != 100000; 5137142Sbrian} 5237142Sbrian 5381697Sbrian#ifndef NOINET6 5481697Sbrianstatic int 5581697Sbrianipv6_available(void) 5681697Sbrian{ 5781697Sbrian int s; 5881697Sbrian 5989422Sbrian if ((s = ID0socket(PF_INET6, SOCK_DGRAM, 0)) == -1) 6081697Sbrian return 0; 6181697Sbrian 6281697Sbrian close(s); 6381697Sbrian return 1; 6481697Sbrian} 6581697Sbrian#endif 6681697Sbrian 6737142Sbrianvoid 6881697Sbrianprobe_Init() 6937142Sbrian{ 7081697Sbrian probe.select_changes_time = select_changes_time() ? 1 : 0; 7137142Sbrian log_Printf(LogDEBUG, "Select changes time: %s\n", 7281697Sbrian probe.select_changes_time ? "yes" : "no"); 7381697Sbrian#ifndef NOINET6 7481697Sbrian probe.ipv6_available = ipv6_available() ? 1 : 0; 7581697Sbrian log_Printf(LogDEBUG, "IPv6 available: %s\n", 7681697Sbrian probe.ipv6_available ? "yes" : "no"); 7781697Sbrian#endif 7837142Sbrian} 79