2 * nas.c Functions to do with a NASLIST. This is here because
3 * radzap needs it as well.
5 * Version: @(#)nas.c 1.00 08-Aug-1999 miquels@cistron.nl
10 "@(#)nas.c 1.00 Copyright 1999 Cistron Internet Services B.V.";
14 #include <sys/types.h>
32 static void nas_free(NAS *cl)
46 int read_naslist_file(char *file)
60 if ((fp = fopen(file, "r")) == NULL) {
61 log(L_CONS|L_ERR, "cannot open %s", file);
64 while(fgets(buffer, 256, fp) != NULL) {
66 if (buffer[0] == '#' || buffer[0] == '\n')
69 if (!getword(&p, hostnm, sizeof(hostnm)) ||
70 !getword(&p, shortnm, sizeof(shortnm))) {
71 log(L_ERR, "%s[%d]: syntax error", file, lineno);
74 (void)getword(&p, nastype, sizeof(nastype));
76 if ((c = malloc(sizeof(NAS))) == NULL) {
77 log(L_CONS|L_ERR, "%s[%d]: out of memory",
82 c->ipaddr = ip_getaddr(hostnm);
83 strcpy(c->nastype, nastype);
84 strcpy(c->shortname, shortnm);
85 strcpy(c->longname, ip_hostname(c->ipaddr));
97 * Find a nas in the NAS list.
99 NAS *nas_find(UINT4 ipaddr)
103 for (cl = naslist; cl; cl = cl->next)
104 if (ipaddr == cl->ipaddr)
112 * Find a nas by name.
114 NAS *nas_findbyname(char *nasname)
118 for (nas = naslist; nas; nas = nas->next) {
119 if (strcmp(nasname, nas->shortname) == 0 ||
120 strcmp(nasname, nas->longname) == 0)
129 * Find the name of a nas (prefer short name).
131 char *nas_name(UINT4 ipaddr)
135 if ((cl = nas_find(ipaddr)) != NULL) {
136 if (cl->shortname[0])
137 return cl->shortname;
141 return ip_hostname(ipaddr);
145 * Find the name of a nas (prefer short name) based on the request.
147 char *nas_name2(RADIUS_PACKET *packet)
153 if ((pair = pairfind(packet->vps, PW_NAS_IP_ADDRESS)) != NULL)
154 ipaddr = pair->lvalue;
156 ipaddr = packet->src_ipaddr;
158 if ((cl = nas_find(ipaddr)) != NULL) {
159 if (cl->shortname[0])
160 return cl->shortname;
164 return ip_hostname(ipaddr);