summaryrefslogtreecommitdiffstats
path: root/usr.sbin/bootparamd/bootparamd/main.c
blob: 7484bec9c17138e0d7eb064ca89224711383887b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
/*

This code is not copyright, and is placed in the public domain. Feel free to
use and modify. Please send modifications and/or suggestions + bug fixes to

        Klas Heggemann <klas@nada.kth.se>

*/

#ifndef lint
static const char rcsid[] =
	"$Id: main.c,v 1.7 1997/09/04 11:49:28 charnier Exp $";
#endif /* not lint */

#include <ctype.h>
#include <err.h>
#include <netdb.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <syslog.h>
#include <unistd.h>
#include <rpc/rpc.h>
#include <rpc/pmap_clnt.h>
#include <sys/ioctl.h>
#include <sys/socket.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include "bootparam_prot.h"

int debug = 0;
int dolog = 0;
unsigned long route_addr = -1;
struct sockaddr_in my_addr;
char *bootpfile = "/etc/bootparams";

extern  void bootparamprog_1();
static void usage __P((void));

int
main(argc, argv)
int argc;
char **argv;
{
	SVCXPRT *transp;
	int i;
	struct hostent *he;
	struct stat buf;
	char c;

	while ((c = getopt(argc, argv,"dsr:f:")) != -1)
	  switch (c) {
	  case 'd':
	    debug = 1;
	    break;
	  case 'r':
	      if ( isdigit( *optarg)) {
		route_addr = inet_addr(optarg);
		break;
	      } else {
		he = gethostbyname(optarg);
		if (he) {
		   bcopy(he->h_addr, (char *)&route_addr, sizeof(route_addr));
		   break;
		} else {
		   errx(1, "no such host %s", argv[i]);
		}
	      }
	  case 'f':
	    bootpfile = optarg;
	    break;
	  case 's':
	    dolog = 1;
#ifndef LOG_DAEMON
	    openlog("bootparamd", 0 , 0);
#else
	    openlog("bootparamd", 0 , LOG_DAEMON);
	    setlogmask(LOG_UPTO(LOG_NOTICE));
#endif
	    break;
	  default:
	    usage();
	  }

	if ( stat(bootpfile, &buf ) )
	  err(1, "%s", bootpfile);

	if (route_addr == -1) {
	  get_myaddress(&my_addr);
	  bcopy(&my_addr.sin_addr.s_addr, &route_addr, sizeof (route_addr));
	}

	if (!debug) {
	  if (daemon(0,0))
	    err(1, "fork");
	}


	(void)pmap_unset(BOOTPARAMPROG, BOOTPARAMVERS);

	transp = svcudp_create(RPC_ANYSOCK);
	if (transp == NULL)
		errx(1, "cannot create udp service");
	if (!svc_register(transp, BOOTPARAMPROG, BOOTPARAMVERS, bootparamprog_1, IPPROTO_UDP))
		errx(1, "unable to register (BOOTPARAMPROG, BOOTPARAMVERS, udp)");

	svc_run();
	errx(1, "svc_run returned");
}

static void
usage()
{
	fprintf(stderr,
		"usage: bootparamd [-d] [-s] [-r router] [-f bootparmsfile]\n");
	exit(1);
}
OpenPOWER on IntegriCloud