📄 nisplus.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: nisplus.c,v 1.2 2005/03/02 21:03:41 bfleisch Exp $ * */#include "nisplus.h"host_info*get_host_info_nisplus(const char* hwaddr){ static host_info hinfo; nis_result *res; nis_result *res2; struct entry_obj *entry; struct entry_col *col; nis_object* obj; char req[NIS_MAXNAMELEN]; char hw[3 * 6]; int i,j; memset(&hinfo, 0, sizeof(hinfo)); 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'; snprintf(req, NIS_MAXNAMELEN, ETHERS_NISPLUSQUERY, hw ); if (g_flags & F_DEBUG) log_msg(LOG_DEBUG, "NIS+ lookup: %s", req); res = nis_list(req, FOLLOW_LINKS |FOLLOW_PATH | EXPAND_NAME | RETURN_RESULT, NULL, NULL); if ((! res) || ( ! _NIS_SUCCESS(res->status))) { if (res) log_msg(LOG_NOTICE, "NIS+ error: %s (=%i)", nis_sperrno(res->status), res->status); else log_msg(LOG_NOTICE, "NIS+ error: nis_lookup() returns NULL !"); if (res) nis_freeresult(res); return NULL; } for (i=0; i < res->objects.objects_len ; i++) { obj =&(res->objects.objects_val[i]); if (obj->zo_data.zo_type != ENTRY_OBJ) continue; if (!ENTRY_VAL(obj, 1)) continue; snprintf(hinfo.hostname, 256, ENTRY_VAL (obj, 1)); /* * now lookup IP address for this host * */ snprintf(req, NIS_MAXNAMELEN, HOSTS_NISPLUSQUERY, hinfo.hostname); if (g_flags & F_DEBUG) log_msg(LOG_DEBUG, "NIS+ lookup: %s", req); res2 = nis_list(req, FOLLOW_LINKS |FOLLOW_PATH | EXPAND_NAME | RETURN_RESULT, NULL, NULL); if ((! res2) || ( ! _NIS_SUCCESS(res2->status))) { if (res2) log_msg(LOG_NOTICE, "NIS+ error: %s (=%i)", nis_sperrno(res2->status), res2->status); else log_msg(LOG_NOTICE, "NIS+ error: nis_lookup() returns NULL !"); if (res2) nis_freeresult(res2); nis_freeresult(res); return NULL; } for (j=0; j < res2->objects.objects_len ; j++) { obj =&(res2->objects.objects_val[j]); if (obj->zo_data.zo_type != ENTRY_OBJ) continue; if (!ENTRY_VAL(obj, 2)) continue; hinfo.addr.s_addr = inet_addr ( (char*) ENTRY_VAL(obj, 2)); log_msg(LOG_DEBUG, "NIS+ found entry: ip=%s, hostname=%s", (char*) ENTRY_VAL(obj, 2), hinfo.hostname); nis_freeresult(res); nis_freeresult(res2); return &hinfo; } } nis_freeresult(res); return NULL;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -