Deleted Added
full compact
main.c (6752) main.c (8857)
1/*
2
1/*
2
3This code is not copyright, and is placed in the public domain. Feel free to
3This code is not copyright, and is placed in the public domain. Feel free to
4use and modify. Please send modifications and/or suggestions + bug fixes to
5
6 Klas Heggemann <klas@nada.kth.se>
7
8
4use and modify. Please send modifications and/or suggestions + bug fixes to
5
6 Klas Heggemann <klas@nada.kth.se>
7
8
9 $Id$
9 $Id: main.c,v 1.1.1.1 1995/02/26 23:40:52 wpaul Exp $
10
11*/
12
13#include <syslog.h>
14#include <stdio.h>
15#include <sys/ioctl.h>
16#include <rpc/rpc.h>
17#include "bootparam_prot.h"
18#include <sys/types.h>
19#include <sys/stat.h>
20#include <sys/socket.h>
21#include <netdb.h>
22#include <ctype.h>
23
24int debug = 0;
25int dolog = 0;
26unsigned long route_addr = -1, inet_addr();
27struct sockaddr_in my_addr;
28char *progname;
29char *bootpfile = "/etc/bootparams";
30
31extern void bootparamprog_1();
32
33extern char *optarg;
34extern int optind;
35
36main(argc, argv)
37int argc;
38char **argv;
39{
40 SVCXPRT *transp;
41 int i,s, pid;
42 char *rindex();
43 struct hostent *he;
44 struct stat buf;
45 char *optstring;
46 char c;
47
48 progname = rindex(argv[0],'/');
49 if ( progname ) progname++;
50 else progname = argv[0];
51
52 while ((c = getopt(argc, argv,"dsr:f:")) != EOF)
53 switch (c) {
54 case 'd':
55 debug = 1;
56 break;
57 case 'r':
58 if ( isdigit( *optarg)) {
59 route_addr = inet_addr(optarg);
60 break;
61 } else {
62 he = gethostbyname(optarg);
63 if (he) {
64 bcopy(he->h_addr, (char *)&route_addr, sizeof(route_addr));
65 break;
66 } else {
67 fprintf(stderr,"%s: No such host %s\n", progname, argv[i]);
68 exit(1);
69 }
70 }
71 case 'f':
72 bootpfile = optarg;
73 break;
74 case 's':
75 dolog = 1;
10
11*/
12
13#include <syslog.h>
14#include <stdio.h>
15#include <sys/ioctl.h>
16#include <rpc/rpc.h>
17#include "bootparam_prot.h"
18#include <sys/types.h>
19#include <sys/stat.h>
20#include <sys/socket.h>
21#include <netdb.h>
22#include <ctype.h>
23
24int debug = 0;
25int dolog = 0;
26unsigned long route_addr = -1, inet_addr();
27struct sockaddr_in my_addr;
28char *progname;
29char *bootpfile = "/etc/bootparams";
30
31extern void bootparamprog_1();
32
33extern char *optarg;
34extern int optind;
35
36main(argc, argv)
37int argc;
38char **argv;
39{
40 SVCXPRT *transp;
41 int i,s, pid;
42 char *rindex();
43 struct hostent *he;
44 struct stat buf;
45 char *optstring;
46 char c;
47
48 progname = rindex(argv[0],'/');
49 if ( progname ) progname++;
50 else progname = argv[0];
51
52 while ((c = getopt(argc, argv,"dsr:f:")) != EOF)
53 switch (c) {
54 case 'd':
55 debug = 1;
56 break;
57 case 'r':
58 if ( isdigit( *optarg)) {
59 route_addr = inet_addr(optarg);
60 break;
61 } else {
62 he = gethostbyname(optarg);
63 if (he) {
64 bcopy(he->h_addr, (char *)&route_addr, sizeof(route_addr));
65 break;
66 } else {
67 fprintf(stderr,"%s: No such host %s\n", progname, argv[i]);
68 exit(1);
69 }
70 }
71 case 'f':
72 bootpfile = optarg;
73 break;
74 case 's':
75 dolog = 1;
76#ifndef LOG_DAEMON
76#ifndef LOG_DAEMON
77 openlog(progname, 0 , 0);
78#else
79 openlog(progname, 0 , LOG_DAEMON);
80 setlogmask(LOG_UPTO(LOG_NOTICE));
81#endif
82 break;
83 default:
77 openlog(progname, 0 , 0);
78#else
79 openlog(progname, 0 , LOG_DAEMON);
80 setlogmask(LOG_UPTO(LOG_NOTICE));
81#endif
82 break;
83 default:
84 fprintf(stderr,
84 fprintf(stderr,
85 "Usage: %s [-d ] [ -s ] [ -r router ] [ -f bootparmsfile ]\n");
86 exit(1);
87 }
88
89 if ( stat(bootpfile, &buf ) ) {
90 fprintf(stderr,"%s: ", progname);
91 perror(bootpfile);
92 exit(1);
93 }
94
95
96 if (route_addr == -1) {
97 get_myaddress(&my_addr);
98 bcopy(&my_addr.sin_addr.s_addr, &route_addr, sizeof (route_addr));
99 }
100
101 if (!debug) {
102 pid = fork();
103 if ( pid < 0) {
104 perror("bootparamd: fork");
105 exit(1);
106 }
107 if (pid) exit(0); /* parent */
108
109 /* child */
110 for ( s = 0; s < 20 ; s++) close(s);
111 open("/", 0);
112 dup2(0, 1);
113 dup2(0, 2);
114 s = open("/dev/tty",2);
115 if ( s >= 0 ) {
116 ioctl(s, TIOCNOTTY, 0);
117 close(s);
118 }
119 }
85 "Usage: %s [-d ] [ -s ] [ -r router ] [ -f bootparmsfile ]\n");
86 exit(1);
87 }
88
89 if ( stat(bootpfile, &buf ) ) {
90 fprintf(stderr,"%s: ", progname);
91 perror(bootpfile);
92 exit(1);
93 }
94
95
96 if (route_addr == -1) {
97 get_myaddress(&my_addr);
98 bcopy(&my_addr.sin_addr.s_addr, &route_addr, sizeof (route_addr));
99 }
100
101 if (!debug) {
102 pid = fork();
103 if ( pid < 0) {
104 perror("bootparamd: fork");
105 exit(1);
106 }
107 if (pid) exit(0); /* parent */
108
109 /* child */
110 for ( s = 0; s < 20 ; s++) close(s);
111 open("/", 0);
112 dup2(0, 1);
113 dup2(0, 2);
114 s = open("/dev/tty",2);
115 if ( s >= 0 ) {
116 ioctl(s, TIOCNOTTY, 0);
117 close(s);
118 }
119 }
120
121
120
121
122 (void)pmap_unset(BOOTPARAMPROG, BOOTPARAMVERS);
123
124 transp = svcudp_create(RPC_ANYSOCK);
125 if (transp == NULL) {
126 (void)fprintf(stderr, "cannot create udp service.\n");
127 exit(1);
128 }
129 if (!svc_register(transp, BOOTPARAMPROG, BOOTPARAMVERS, bootparamprog_1, IPPROTO_UDP)) {
130 (void)fprintf(stderr, "unable to register (BOOTPARAMPROG, BOOTPARAMVERS, udp).\n");
131 exit(1);
132 }
133
134 svc_run();
135 (void)fprintf(stderr, "svc_run returned\n");
136 exit(1);
137}
138
139
122 (void)pmap_unset(BOOTPARAMPROG, BOOTPARAMVERS);
123
124 transp = svcudp_create(RPC_ANYSOCK);
125 if (transp == NULL) {
126 (void)fprintf(stderr, "cannot create udp service.\n");
127 exit(1);
128 }
129 if (!svc_register(transp, BOOTPARAMPROG, BOOTPARAMVERS, bootparamprog_1, IPPROTO_UDP)) {
130 (void)fprintf(stderr, "unable to register (BOOTPARAMPROG, BOOTPARAMVERS, udp).\n");
131 exit(1);
132 }
133
134 svc_run();
135 (void)fprintf(stderr, "svc_run returned\n");
136 exit(1);
137}
138
139