1/* 2 * Copyright (c) 1999 Apple Inc. All rights reserved. 3 * 4 * @APPLE_LICENSE_HEADER_START@ 5 * 6 * This file contains Original Code and/or Modifications of Original Code 7 * as defined in and that are subject to the Apple Public Source License 8 * Version 2.0 (the 'License'). You may not use this file except in 9 * compliance with the License. Please obtain a copy of the License at 10 * http://www.opensource.apple.com/apsl/ and read it before using this 11 * file. 12 * 13 * The Original Code and all software distributed under the License are 14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER 15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, 16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, 17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. 18 * Please see the License for the specific language governing rights and 19 * limitations under the License. 20 * 21 * @APPLE_LICENSE_HEADER_END@ 22 */ 23/* 24 * hostlist.h 25 * - definitions for host list structures and functions 26 */ 27 28#ifndef _S_HOSTLIST_H 29#define _S_HOSTLIST_H 30 31#include <netinet/in.h> 32 33struct hosts { 34 struct hosts *next; 35 struct hosts *prev; 36 struct in_addr iaddr; /* internet address */ 37 u_char htype; /* hardware type */ 38 u_char hlen; /* hardware length */ 39 union { /* hardware address */ 40 struct ether_addr en; 41 u_char generic[256]; 42 } haddr; 43 char * hostname; /* host name (and suffix) */ 44 char * bootfile; /* default boot file name */ 45 struct timeval tv; /* time-in */ 46 47 u_long lease; /* lease (dhcp only) */ 48}; 49 50struct hosts * hostadd(struct hosts * * hosts, struct timeval * tv_p, 51 int htype, char * haddr, int hlen, 52 struct in_addr * iaddr_p, char * host_name, 53 char * bootfile); 54void hostfree(struct hosts * * hosts, struct hosts * hp); 55void hostinsert(struct hosts * * hosts, struct hosts * hp); 56void hostprint(struct hosts * hp); 57void hostremove(struct hosts * * hosts, struct hosts * hp); 58 59typedef boolean_t subnet_match_func_t(void * arg, struct in_addr iaddr); 60 61static __inline__ struct hosts * 62hostbyip(struct hosts * hosts, struct in_addr iaddr) 63{ 64 struct hosts * hp; 65 for (hp = hosts; hp; hp = hp->next) { 66 if (iaddr.s_addr == hp->iaddr.s_addr) 67 return (hp); 68 } 69 return (NULL); 70} 71 72static __inline__ struct hosts * 73hostbyaddr(struct hosts * hosts, u_char hwtype, void * hwaddr, int hwlen, 74 subnet_match_func_t * func, void * arg) 75{ 76 struct hosts * hp; 77 78 for (hp = hosts; hp; hp = hp->next) { 79 if (hwtype == hp->htype 80 && hwlen == hp->hlen 81 && bcmp(hwaddr, &hp->haddr, hwlen) == 0) { 82 if (func == NULL 83 || (*func)(arg, hp->iaddr)) { 84 return (hp); 85 } 86 } 87 } 88 return (NULL); 89} 90 91 92#endif /* _S_HOSTLIST_H */ 93