getnet.c

来自「TCP-IP红宝书源代码」· C语言 代码 · 共 33 行

C
33
字号
/* getnet.c - getnet, getinet */

#include <conf.h>
#include <kernel.h>
#include <network.h>

/*------------------------------------------------------------------------
 *  getnet  -  obtain the network portion of this system's IP address
 *------------------------------------------------------------------------
 */
IPaddr
getnet()
{
	return getiaddr(NI_PRIMARY);
}

/*------------------------------------------------------------------------
 *  getinet  -  obtain the network portion of this interface's IP address
 *------------------------------------------------------------------------
 */
IPaddr
getinet(int inum)
{
	struct netif	*pif;

	if (inum < 0 || inum >= Net.nif)
		return (IPaddr)SYSERR;
	pif = &nif[inum];
	if (!pif->ni_ivalid && getiaddr(inum) == (IPaddr)SYSERR)
		return (IPaddr)SYSERR;
	return pif->ni_net;
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?