⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 hostlib.c

📁 vxworks的完整的源代码
💻 C
📖 第 1 页 / 共 2 页
字号:
	    KHEAP_FREE(pHostEntry->hostName.name);	    KHEAP_FREE((char *) pHostEntry);	    return (OK);	    }        else 	    /* given name is an alias */	    {	    for (pHostNamePrev = pHostName = &pHostEntry->hostName;		 pHostName != NULL;		 pHostNamePrev = pHostName, pHostName = pHostName->link)		{		pHostNameNext = pHostName->link;		if (strcmp (pHostName->name, name) == 0)	/* found alias */		    {		    pHostNamePrev->link = pHostNameNext;		    semGive (hostListSem);		    KHEAP_FREE(pHostName->name);		    KHEAP_FREE((char *) pHostName);		    return (OK);		    }		}	    }	}    errnoSet (S_hostLib_UNKNOWN_HOST);    semGive (hostListSem);    return (ERROR);    }/********************************************************************************* hostTblSearchByName - look up a host in the host table by its name** This routine returns the Internet address of a host that has* been added to the host table by hostAdd().** RETURNS* The Internet address (as an integer in network byte order), or ERROR if the * host is unknown.** NOMANUAL** INTERNAL* This function is used by the resolver to search the static host table.*/int hostTblSearchByName    (    char *name          /* name of host */    )    {    HOSTNAME  *pHostName;    HOSTENTRY *pHostEntry;    int retAddr = ERROR;    semTake (hostListSem, WAIT_FOREVER);    for (pHostEntry = (HOSTENTRY *)lstFirst (&hostList);	 pHostEntry != NULL;	 pHostEntry = (HOSTENTRY *)lstNext (&pHostEntry->node))	{	/* check official name */	if (strcmp (pHostEntry->hostName.name, name) == 0)	    {	    retAddr = (int)pHostEntry->netAddr.s_addr;	    break;	    }	/* check aliases */	for (pHostName = pHostEntry->hostName.link;	     pHostName != NULL;	     pHostName = pHostName->link)	    {	    if (strcmp (pHostName->name, name) == 0)		{		retAddr = (int)pHostEntry->netAddr.s_addr;		/* force termination of outer loop */		pHostEntry = (HOSTENTRY *)lstLast (&hostList);		break;		}	    }	}    semGive (hostListSem);    return (retAddr);    }/********************************************************************************* hostGetByName - look up a host in the host table by its name** This routine returns the Internet address of a host that has* been added to the host table by hostAdd().  If the DNS resolver library* resolvLib has been configured in the vxWorks image, a query for the host* IP address is sent to the DNS server, if the name was not found in the local* host table.** RETURNS: The Internet address (as an integer), or ERROR if the host is*          unknown.** ERRNO: S_hostLib_INVALID_PARAMETER, S_hostLib_UNKNOWN_HOST*/int hostGetByName    (    char *name          /* name of host */    )    {    int retAddr;    if (name == (char *) NULL)        {        errnoSet (S_hostLib_INVALID_PARAMETER);        return (ERROR);        }    /* Search the host table using the host name as the key */    retAddr = hostTblSearchByName (name);    if ((retAddr == ERROR) && (_presolvHostLibGetByName != NULL))	{	/*	 * If host address was not found in the local table.  Try to get the	 * IP from the DNS server, if and only if the resolver library has	 * been linked with the Vxworks image.	 */	retAddr = (*_presolvHostLibGetByName) (name);	}    if (retAddr == ERROR)	errnoSet (S_hostLib_UNKNOWN_HOST);    return (retAddr);    }/********************************************************************************* hostTblSearchByAddr - look up a host in the host table by its Internet address** This routine finds the host name by its Internet address and copies it to* <name>.  The buffer <name> should be preallocated with (MAXHOSTNAMELEN + 1)* bytes of memory and is NULL-terminated unless insufficient space is* provided.** WARNING* This routine does not look for aliases.  Host names are limited to* MAXHOSTNAMELEN (from hostLib.h) characters.** RETURNS* OK, or ERROR if the host is unknown.** NOMANUAL** INTERNAL* This function is used by the resolver to search the static host table.*/STATUS hostTblSearchByAddr    (    int addr,           /* inet address of host */    char *name          /* buffer to hold name */    )    {    HOSTENTRY *pHostEntry;    struct in_addr netAddr;    STATUS status = ERROR;    int n;    netAddr.s_addr = addr;    semTake (hostListSem, WAIT_FOREVER);    /* search for internet address */    for (pHostEntry = (HOSTENTRY *)lstFirst (&hostList);	 pHostEntry != NULL;	 pHostEntry = (HOSTENTRY *)lstNext (&pHostEntry->node))	{	if (pHostEntry->netAddr.s_addr == netAddr.s_addr)	    {	    n = strlen (pHostEntry->hostName.name);	    strncpy (name, pHostEntry->hostName.name,			min (n + 1 , MAXHOSTNAMELEN +1));	    status = OK;	    break;	    }  	}    semGive (hostListSem);    return (status);    }/********************************************************************************* hostGetByAddr - look up a host in the host table by its Internet address** This routine finds the host name by its Internet address and copies it to* <name>.  The buffer <name> should be preallocated with (MAXHOSTNAMELEN + 1)* bytes of memory and is NULL-terminated unless insufficient space is* provided.  If the DNS resolver library resolvLib has been configured in the* vxWorks image, a query for the host name is sent to the DNS server, if the* name was not found in the local host table.** WARNING* This routine does not look for aliases.  Host names are limited to* MAXHOSTNAMELEN (from hostLib.h) characters.** RETURNS* OK, or ERROR if buffer is invalid or the host is unknown.** SEE ALSO* hostGetByName()*/STATUS hostGetByAddr    (    int addr,           /* inet address of host */    char *name          /* buffer to hold name */    )    {    STATUS status;    if (name == NULL)        {        errnoSet (S_hostLib_INVALID_PARAMETER);        return (ERROR);        }    /* Search the host table using the host address as the key */    status = hostTblSearchByAddr (addr, name);    if ((status != OK) && (_presolvHostLibGetByAddr != NULL))	{	/*	 * If host name was not found in the local table.  Try to get the	 * name from the DNS server, if and only if the resolver library has	 * been linked with the Vxworks image.	 */	status = (*_presolvHostLibGetByAddr) (addr, name);	}    if (status != OK)	errnoSet (S_hostLib_UNKNOWN_HOST);    return (status);    }/********************************************************************************* hostNameFill - fill in host name** RETURNS: OK or ERROR if out of memory*/LOCAL STATUS hostNameFill    (    FAST HOSTNAME *pHostName,    char *newHostName    )    {    FAST char *pName = (char *) KHEAP_ALLOC((unsigned) (strlen (newHostName) + 1));    if (pName == NULL)	return (ERROR);    strcpy (pName, newHostName);    pHostName->name = pName;    pHostName->link = NULL;    return (OK);    }/********************************************************************************* sethostname - set the symbolic name of this machine** This routine sets the target machine's symbolic name, which can be used* for identification.** RETURNS: OK or ERROR.*/int sethostname    (    char *name,                 /* machine name */    int  nameLen                /* length of name */    )    {#ifdef VIRTUAL_STACK    if (name != NULL && nameLen < sizeof (_targetName))	{        strcpy (_targetName, name);#else    if (name != NULL && nameLen < sizeof (targetName))	{        strcpy (targetName, name);#endif	return (0);	}    return (-1);    }/******************************************************************************** gethostname - get the symbolic name of this machine** This routine gets the target machine's symbolic name, which can be used* for identification.** RETURNS: OK or ERROR.*/int gethostname    (    char *name,  /* machine name */    int   nameLen  /* length of name */    )    {#ifdef VIRTUAL_STACK    if (name != NULL && strlen (_targetName) < nameLen)	{        strcpy (name, _targetName);#else    if (name != NULL && strlen (targetName) < nameLen)	{        strcpy (name, targetName);#endif	return (0);	}    return (-1);    }

⌨️ 快捷键说明

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