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

📄 database.c

📁 VXWORKS源代码
💻 C
📖 第 1 页 / 共 5 页
字号:
    return;    }/********************************************************************************* proc_sname - extract the DHCP server name** This routine sets the TFTP server name field of the lease descriptor to the* value specified by a "snam" field in the address pool database. The field * is cleared when "snam@", specifying deletion, is encountered.** RETURNS: 0, always.** ERRNO: N/A** NOMANUAL*/int proc_sname    (    int code, 			/* resource code for address pool field */    int optype, 		/* operation type (addition or deletion) */    char **symbol, 		/* current location in input string */    struct dhcp_resource *rp 	/* pointer to lease descriptor */    )    {    char tmpstr [MAXSTRINGLEN];    if (optype == OP_ADDITION)         {        get_string (symbol, tmpstr);        if (strlen (tmpstr) > MAX_SNAME)            {            bcopy (tmpstr, rp->sname, MAX_SNAME);            rp->sname [MAX_SNAME] = '\0';            }        else            {            bcopy (tmpstr, rp->sname, strlen (tmpstr));            rp->sname [strlen (tmpstr)] = '\0';            }        }     else         rp->sname[0] = '\0';    return (0);    }/********************************************************************************* proc_file - extract the boot image filename** This routine sets the bootfile name field of the lease descriptor to the* value specified by a "file" field in the address pool database. The* field is cleared when "file@", specifying deletion, is encountered.** RETURNS: 0, always.** ERRNO: N/A** NOMANUAL*/int proc_file    (    int code, 			/* resource code for address pool field */    int optype, 		/* operation type (addition or deletion) */    char **symbol, 		/* current location in input string */    struct dhcp_resource *rp 	/* pointer to lease descriptor */    )    {    char tmpstr [MAXSTRINGLEN];    if (optype == OP_ADDITION)         {        get_string (symbol, tmpstr);        if (strlen (tmpstr) > MAX_FILE)            {            bcopy (tmpstr, rp->file, MAX_FILE);            rp->file [MAX_FILE] = '\0';            }        else            {            bcopy (tmpstr, rp->file, strlen (tmpstr));            rp->file [strlen (tmpstr)] = '\0';            }        }     else        rp->file[0] = '\0';    return (0);    }/********************************************************************************* proc_clid - handle the client identifier** This routine updates the lease descriptor and internal data structures * after extracting a client identifier from "clid" or "pmid" entries in * the address pool database. The "clid" symbol specifies a manual lease * which will only be issued to a specific client on the appropriate subnet. * The "pmid" symbol is included in a lease descriptor specifying additional * parameters to be provided to a specific client along with a dynamic lease. ** RETURNS: 0 if update completed, or -1 on error.** ERRNO: N/A** NOMANUAL*/int proc_clid    (    int code, 			/* resource code for address pool field */    int optype, 		/* operation type (addition or deletion) */    char **symbol, 		/* current location in input string */    struct dhcp_resource *rp 	/* pointer to lease descriptor */    )    {    char bufptr[MAXSTRINGLEN];    struct in_addr tmpsubnet;    struct dhcp_binding *binding;    char *target;    int result;    /* For client ID (manual lease), return immediately if no IP address. */    if (code == S_CLIENT_ID && rp->ip_addr.s_addr == 0)        return (-1);    /* For parameter ID, return error if client or class already specified. */        if (ISSET (rp->valid, S_PARAM_ID) || ISSET (rp->valid, S_CLASS_ID))        return (-1);     if (rp->binding != NULL)        return (-1);    /* Create a lease record to store the identifier information. */    binding = (struct dhcp_binding *)calloc (1, sizeof (struct dhcp_binding));    if (binding == NULL)         {#ifdef DHCPS_DEBUG        logMsg ("Warning: memory allocation error reading identifier.\n",                 0, 0, 0, 0, 0, 0);#endif        return (-1);        }    target = (char *)bufptr;    get_string (symbol, target);    if (bufptr[0] == '\0')         {        if (code == S_CLIENT_ID)            free (binding);        return (-1);        }    /* read client identifier type */    if (read_idtype (&target, &binding->cid.idtype) != 0)        {        free (binding);        return (-1);        }    /* read client identifier value */    adjust (&target);    if (read_cid (&target, &binding->cid) != 0)        {        free (binding);        return (-1);        }    /* For manual leases, fill all fields in associated lease record. */    if (code == S_CLIENT_ID)        {        /* get subnet number */        if (rp->subnet_mask.s_addr != 0)            binding->cid.subnet.s_addr =                                rp->ip_addr.s_addr & rp->subnet_mask.s_addr;          else             {            default_netmask (&rp->ip_addr, &tmpsubnet);            binding->cid.subnet.s_addr = rp->ip_addr.s_addr & tmpsubnet.s_addr;            }        /* hardware address is unknown, so use client identifer */        binding->haddr.htype = binding->cid.idtype;        if (binding->cid.idlen > MAX_HLEN)            {            binding->haddr.hlen = MAX_HLEN;            bcopy (binding->cid.id, binding->haddr.haddr, MAX_HLEN);            }        else            {            binding->haddr.hlen = binding->cid.idlen;            bcopy (binding->cid.id, binding->haddr.haddr, binding->cid.idlen);            }        /* Expiration is meaningless for client-specific leases. */        binding->expire_epoch = 0xffffffff;        /* Store name of associated lease descriptor. */        bcopy (rp->entryname, binding->res_name, strlen (rp->entryname));        binding->res_name [strlen (rp->entryname)] = '\0';        }    /* Link identifier record to lease descriptor. */    binding->res = rp;    binding->res->binding = binding;    /* Add entry for manual lease descriptor to appropriate hash table. */    if (code == S_CLIENT_ID)         {        binding->flag = (COMPLETE_ENTRY | STATIC_ENTRY);        result = hash_ins (&cidhashtable, binding->cid.id, binding->cid.idlen,	                   bindcidcmp, &binding->cid, binding);        if (result < 0)             {#ifdef DHCPS_DEBUG            logMsg ("Warning: hash table insertion failed for client ID.\n",                     0, 0, 0, 0, 0, 0);#endif            free (binding);            return (-1);            }        result = add_bind (binding);        if (result != 0)            {            free (binding);            return (-1);            }        }    else     /* For "pmid", insert into parameters hash table */        {        result = hash_ins (&paramhashtable,                            binding->cid.id, binding->cid.idlen,	                   paramcidcmp, &binding->cid, rp);        if (result < 0)             {#ifdef DHCPS_DEBUG            logMsg ("Warning: hash table insertion failed for client ID.\n",                     0, 0, 0, 0, 0, 0);#endif            free (binding);            return (-1);            }        }    return (0);    }/********************************************************************************* proc_class - handle the class identifier** This routine updates the lease descriptor and internal data structures after* extracting a class identifier from "clas" field in the address pool database.* The class identifier is included in an address pool entry specifying * additional parameters to be provided to any client which is a member of the * class.** RETURNS: 0 if update completed, or -1 on error.** ERRNO: N/A** NOMANUAL*/int proc_class    (    int code, 			/* resource code for address pool field */    int optype, 		/* operation type (always OP_ADDITION) */    char **symbol, 		/* current location in input string */    struct dhcp_resource *rp 	/* pointer to lease descriptor */    )    {    char buffer[MAXSTRINGLEN];    struct dhcp_binding *binding;    char *target;    int result;    /* Return error if descriptor already has client or class parameters. */    if (ISSET (rp->valid, S_PARAM_ID) || ISSET (rp->valid, S_CLASS_ID))        return (-1);    if (rp->binding != NULL)        return (-1);    target = (char *)buffer;    get_string (symbol, target);    /* Create a lease record to store the identifier information. */    binding = (struct dhcp_binding *)calloc (1, sizeof (struct dhcp_binding));    if (binding == NULL)         {#ifdef DHCPS_DEBUG        logMsg ("Warning: memory allocation error reading identifier.\n",                 0, 0, 0, 0, 0, 0);#endif        return (-1);        }    target = (char *)buffer;    get_string (symbol, target);    /*     * Record class identifier. The type remains 0, which is unused by     * client identifiers.     */    if (strlen (buffer) > MAXOPT - 1)        {        binding->cid.idlen = MAXOPT - 1;         bcopy (buffer, binding->cid.id, MAXOPT - 1);        binding->cid.id[MAXOPT - 1] = '\0';        }    else        {        binding->cid.idlen = strlen (buffer);        bcopy (buffer, binding->cid.id, strlen (buffer));        binding->cid.id [strlen (buffer)] = '\0';        }    /* Link identifier record to lease descriptor. */    binding->res = rp;    binding->res->binding = binding;    /* Add entry to parameters hash table. */    result = hash_ins (&paramhashtable,                        binding->cid.id, binding->cid.idlen,                       paramcidcmp, &binding->cid, rp);    if (result < 0)         {#ifdef DHCPS_DEBUG        logMsg ("Warning: hash table insertion failed for client ID.\n",                 0, 0, 0, 0, 0, 0);#endif        free (binding);        return (-1);        }    return (0);    }/********************************************************************************* proc_tblc - handle inclusion of address pool entries** This routine processes entry quotation specified by a "tblc" (table* continuation) entry in the address pool database. After retrieving the* named descriptor, any values in the existing entry not already specified in* the database are copied from the quoted entry.** RETURNS: 0 if quotation completed, or -1 if matching entry not found.** ERRNO: N/A** NOMANUAL*/int proc_tblc    (    int code, 			/* resource code for address pool field */    int optype, 		/* operation type (always OP_ADDITION) */    char **symbol, 		/* current location in input string */    struct dhcp_resource *rp1	/* pointer to lease descriptor */    )    {    struct dhcp_resource *rp2 = NULL;    char tmpstr [MAXSTRINGLEN];    char *pTmp;    int i = 0;    get_string (symbol, tmpstr);    pTmp = tmpstr;    rp2 = (struct dhcp_resource *) hash_find (&nmhashtable, pTmp,                                              strlen (pTmp), resnmcmp, pTmp);    if (rp2 == NULL)         {#ifdef DHCPS_DEBUG        logMsg ("Warning: Can't find table entry \"%s\"\n", (int)tmpstr,                 0, 0, 0, 0, 0);#endif        return (-1);        }    if (ISCLR (rp1->valid, S_SNAME))         strcpy (rp1->sname, rp2->sname);    if (ISCLR (rp1->valid, S_FILE))         strcpy (rp1->file, rp2->file);    if (ISCLR (rp1->valid, S_SIADDR))        rp1->siaddr = rp2->siaddr;

⌨️ 快捷键说明

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