View | Details | Raw Unified | Return to bug 89988
Collapse All | Expand All

(-)bootparamd/bootparamd.c (-4 / +53 lines)
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
}
(-)bootparamd/main.c (-6 / +3 lines)
Lines 9-15 Link Here
9
9
10
#ifndef lint
10
#ifndef lint
11
static const char rcsid[] =
11
static const char rcsid[] =
12
  "$FreeBSD: /repoman/r/ncvs/src/usr.sbin/bootparamd/bootparamd/main.c,v 1.10 2004/06/08 12:11:19 stefanf Exp $";
12
  "$FreeBSD: src/usr.sbin/bootparamd/bootparamd/main.c,v 1.10 2004/06/08 12:11:19 stefanf Exp $";
13
#endif /* not lint */
13
#endif /* not lint */
14
14
15
#include <ctype.h>
15
#include <ctype.h>
Lines 32-37 Link Here
32
32
33
int debug = 0;
33
int debug = 0;
34
int dolog = 0;
34
int dolog = 0;
35
int route_set = 0;
35
unsigned long route_addr = -1;
36
unsigned long route_addr = -1;
36
struct sockaddr_in my_addr;
37
struct sockaddr_in my_addr;
37
char *bootpfile = "/etc/bootparams";
38
char *bootpfile = "/etc/bootparams";
Lines 55-60 Link Here
55
	    debug = 1;
56
	    debug = 1;
56
	    break;
57
	    break;
57
	  case 'r':
58
	  case 'r':
59
              route_set = 1;
58
	      if (isdigit((unsigned char)*optarg)) {
60
	      if (isdigit((unsigned char)*optarg)) {
59
		route_addr = inet_addr(optarg);
61
		route_addr = inet_addr(optarg);
60
		break;
62
		break;
Lines 85-95 Link Here
85
87
86
	if ( stat(bootpfile, &buf ) )
88
	if ( stat(bootpfile, &buf ) )
87
	  err(1, "%s", bootpfile);
89
	  err(1, "%s", bootpfile);
88
89
	if (route_addr == -1) {
90
	  get_myaddress(&my_addr);
91
	  bcopy(&my_addr.sin_addr.s_addr, &route_addr, sizeof (route_addr));
92
	}
93
90
94
	if (!debug) {
91
	if (!debug) {
95
	  if (daemon(0,0))
92
	  if (daemon(0,0))

Return to bug 89988