2 Unix SMB/Netbios implementation.
4 NBT netbios routines and daemon - version 2
5 Copyright (C) Jeremy Allison 1994-1998
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23 Handle lmhosts file reading.
29 extern int DEBUGLEVEL;
31 /****************************************************************************
33 ****************************************************************************/
34 void load_lmhosts_file(char *fname)
38 struct in_addr ipaddr;
39 FILE *fp = startlmhosts( fname );
42 DEBUG(2,("load_lmhosts_file: Can't open lmhosts file %s. Error was %s\n",
43 fname, strerror(errno)));
47 while (getlmhostsent(fp, name, &name_type, &ipaddr) )
49 struct subnet_record *subrec = NULL;
50 enum name_source source = LMHOSTS_NAME;
52 /* We find a relevent subnet to put this entry on, then add it. */
53 /* Go through all the broadcast subnets and see if the mask matches. */
54 for (subrec = FIRST_SUBNET; subrec ; subrec = NEXT_SUBNET_EXCLUDING_UNICAST(subrec))
56 if(same_net(ipaddr, subrec->bcast_ip, subrec->mask_ip))
60 /* If none match add the name to the remote_broadcast_subnet. */
62 subrec = remote_broadcast_subnet;
66 /* Add the (0) and (0x20) names directly into the namelist for this subnet. */
67 add_name_to_subnet(subrec,name,0x00,(uint16)NB_ACTIVE,PERMANENT_TTL,source,1,&ipaddr);
68 add_name_to_subnet(subrec,name,0x20,(uint16)NB_ACTIVE,PERMANENT_TTL,source,1,&ipaddr);
72 /* Add the given name type to the subnet namelist. */
73 add_name_to_subnet(subrec,name,name_type,(uint16)NB_ACTIVE,PERMANENT_TTL,source,1,&ipaddr);
80 /****************************************************************************
81 Find a name read from the lmhosts file. We secretly check the names on
82 the remote_broadcast_subnet as if the name was added to a regular broadcast
83 subnet it will be found by normal name query processing.
84 ****************************************************************************/
86 BOOL find_name_in_lmhosts(struct nmb_name *nmbname, struct name_record **namerecp)
88 struct name_record *namerec;
92 if((namerec = find_name_on_subnet(remote_broadcast_subnet, nmbname,
93 FIND_ANY_NAME))==NULL)
96 if(!NAME_IS_ACTIVE(namerec) || (namerec->source != LMHOSTS_NAME))