Lines 27-33
Link Here
|
27 |
#include <unistd.h> |
27 |
#include <unistd.h> |
28 |
#include <sys/types.h> |
28 |
#include <sys/types.h> |
29 |
#include <sys/socket.h> |
29 |
#include <sys/socket.h> |
30 |
extern int debug, dolog; |
30 |
#include <netinet/in.h> |
|
|
31 |
#include <ifaddrs.h> |
32 |
extern int debug, dolog, route_set; |
31 |
extern unsigned long route_addr; |
33 |
extern unsigned long route_addr; |
32 |
extern char *bootpfile; |
34 |
extern char *bootpfile; |
33 |
|
35 |
|
Lines 42-47
Link Here
|
42 |
|
44 |
|
43 |
int getthefile __P((char *, char *, char *, int)); |
45 |
int getthefile __P((char *, char *, char *, int)); |
44 |
int checkhost __P((char *, char *, int)); |
46 |
int checkhost __P((char *, char *, int)); |
|
|
47 |
unsigned long myaddr __P((unsigned long)); |
45 |
|
48 |
|
46 |
bp_whoami_res * |
49 |
bp_whoami_res * |
47 |
bootparamproc_whoami_1_svc(whoami, req) |
50 |
bootparamproc_whoami_1_svc(whoami, req) |
Lines 79-88
Link Here
|
79 |
getdomainname(domain_name, MAX_MACHINE_NAME); |
82 |
getdomainname(domain_name, MAX_MACHINE_NAME); |
80 |
res.domain_name = domain_name; |
83 |
res.domain_name = domain_name; |
81 |
|
84 |
|
82 |
if ( res.router_address.address_type != IP_ADDR_TYPE ) { |
85 |
if (!route_set) { |
|
|
86 |
route_addr = myaddr(haddr); |
87 |
} |
88 |
|
89 |
if ( (res.router_address.address_type != IP_ADDR_TYPE) && route_set ) { |
83 |
res.router_address.address_type = IP_ADDR_TYPE; |
90 |
res.router_address.address_type = IP_ADDR_TYPE; |
84 |
bcopy( &route_addr, &res.router_address.bp_address_u.ip_addr, 4); |
91 |
bcopy( &route_addr, &res.router_address.bp_address_u.ip_addr, 4); |
85 |
} |
92 |
} |
|
|
93 |
|
86 |
if (debug) fprintf(stderr, |
94 |
if (debug) fprintf(stderr, |
87 |
"Returning %s %s %d.%d.%d.%d\n", |
95 |
"Returning %s %s %d.%d.%d.%d\n", |
88 |
res.client_name, |
96 |
res.client_name, |
Lines 139-146
Link Here
|
139 |
hostname[where - buffer] = '\0'; |
147 |
hostname[where - buffer] = '\0'; |
140 |
where++; |
148 |
where++; |
141 |
strcpy(path, where); |
149 |
strcpy(path, where); |
142 |
he = gethostbyname(hostname); |
150 |
|
143 |
if ( !he ) goto failed; |
151 |
/* support null hostnames which are useful for solaris jumpstart */ |
|
|
152 |
if (strlen(hostname)==0) { |
153 |
bzero(&res.server_address.bp_address_u.ip_addr,4); |
154 |
} |
155 |
else { |
156 |
he = gethostbyname(hostname); |
157 |
if ( !he ) goto failed; |
158 |
} |
159 |
|
144 |
bcopy( he->h_addr, &res.server_address.bp_address_u.ip_addr, 4); |
160 |
bcopy( he->h_addr, &res.server_address.bp_address_u.ip_addr, 4); |
145 |
res.server_name = hostname; |
161 |
res.server_name = hostname; |
146 |
res.server_path = path; |
162 |
res.server_path = path; |
Lines 355-358
Link Here
|
355 |
} |
371 |
} |
356 |
if (fclose(bpf)) { warnx("could not close %s", bootpfile); } |
372 |
if (fclose(bpf)) { warnx("could not close %s", bootpfile); } |
357 |
return(res); |
373 |
return(res); |
|
|
374 |
} |
375 |
|
376 |
/* Check the client address against the networks we are |
377 |
listening on to have a more intelligent version of |
378 |
get_myaddress(), which always returns localhost */ |
379 |
|
380 |
unsigned long |
381 |
myaddr(unsigned long clientip) { |
382 |
struct ifaddrs *ifap, *ifaorig; |
383 |
int i; |
384 |
char* ifname = NULL; |
385 |
unsigned long ifip, netmask; |
386 |
|
387 |
getifaddrs(&ifaorig); |
388 |
ifap = ifaorig; |
389 |
|
390 |
while(ifap != NULL) { |
391 |
if(ifap->ifa_addr->sa_family == AF_INET) { |
392 |
bcopy(&ifap->ifa_addr->sa_data[2], &ifip, 4); |
393 |
bcopy(&ifap->ifa_netmask->sa_data[2], &netmask, 4); |
394 |
|
395 |
if((ifip & netmask) == (clientip & netmask)) |
396 |
goto done; |
397 |
} |
398 |
|
399 |
ifap = ifap->ifa_next; |
400 |
} |
401 |
|
402 |
ifip = INADDR_LOOPBACK; |
403 |
|
404 |
done: |
405 |
freeifaddrs(ifaorig); |
406 |
return ifip; |
358 |
} |
407 |
} |