📄 nis.c
字号:
/* * * bootpd_nis: simple BOOTP server with NIS maps support * Copyright (C) 2005 <bfleisch@users.sourceforge.net> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * * * $Id: nis.c,v 1.3 2005/03/02 21:10:50 bfleisch Exp $ * */#include "nis.h"host_info*get_host_info_nis(const char* hwaddr){ int err; char *nisdomain; char hw[3 * 6]; int i; char *tmp; int tmp_len; static host_info hinfo; char ip[4*3+3+1]; memset(&hinfo, 0, sizeof(hinfo)); err = yp_get_default_domain (&nisdomain); if (err || !nisdomain) { log_msg(LOG_ERR, "NIS domain undefined"); return NULL; } if (g_flags & F_DEBUG) log_msg(LOG_DEBUG, "NIS domain name : %s", nisdomain); memset (hw, 0, 3 * 6); for (i = 0; i < 6; i++) sprintf (hw + strlen (hw), "%0x:", (unsigned char)hwaddr[i]); hw[strlen (hw) - 1] = '\0'; if ( g_flags & F_DEBUG) log_msg(LOG_DEBUG, "Querying NIS table %s for %s", ETHERS_NISTABLE, hw); err = yp_match (nisdomain, ETHERS_NISTABLE, hw, strlen (hw), &tmp, &tmp_len); if (err ||!tmp) { log_msg(LOG_NOTICE, "%s: no such key in %s (err=%s)\n", hw, ETHERS_NISTABLE, yperr_string(err)); if (tmp) free(tmp); return NULL; } sscanf (tmp, "%*s %256s", hinfo.hostname); free(tmp); if ( g_flags & F_DEBUG) log_msg(LOG_DEBUG, "Querying NIS table %s for %s ", HOSTS_NISTABLE, hinfo.hostname ); err = yp_match (nisdomain, HOSTS_NISTABLE, hinfo.hostname, strlen (hinfo.hostname), &tmp, &tmp_len); if (err || ! tmp) { log_msg (LOG_NOTICE, "%s: no such key in %s (err=%s)\n", hinfo.hostname, HOSTS_NISTABLE, yperr_string(err)); if (tmp) free(tmp); return NULL; } sscanf(tmp, "%16s", ip); free(tmp); log_msg(LOG_INFO, "HW=%s, HOST=%s, IP=%s\n", hw, hinfo.hostname, ip); hinfo.addr.s_addr = inet_addr(ip); return &hinfo; }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -