]>
git.saurik.com Git - apple/network_cmds.git/blob - bootparams/bootparamd.tproj/bootparamd.c
91bd1396f65d345b50f1f2334286ec0e1681a577
2 * Copyright (c) 1999 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. Please obtain a copy of the License at
10 * http://www.opensource.apple.com/apsl/ and read it before using this
13 * The Original Code and all software distributed under the License are
14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
18 * Please see the License for the specific language governing rights and
19 * limitations under the License.
21 * @APPLE_LICENSE_HEADER_END@
25 * Copyright 1998, Apple Computer Inc. Unpublished.
27 * Written by Marc Majka
34 #include <rpc/pmap_clnt.h>
35 #include "bootparam_prot.h"
36 #include <sys/types.h>
37 #include <sys/socket.h>
41 #include <netinet/in.h>
42 #include <arpa/inet.h>
47 unsigned long route_addr
;
48 char domain_name
[MAXHOSTNAMELEN
];
51 extern void bootparamprog_1();
53 extern int getdomainname(char*, int);
58 fprintf(stderr
, "usage: %s [-d] [-r router]\n", progname
);
63 main(int argc
, char *argv
[])
71 progname
= strrchr(argv
[0],'/');
72 if (progname
) progname
++;
73 else progname
= argv
[0];
77 for (i
= 1; i
< argc
; i
++)
79 if (!strcmp(argv
[i
], "-d"))
83 else if (!strcmp(argv
[i
], "-r"))
86 if (i
>= argc
) usage();
88 route_addr
= inet_addr(argv
[i
]);
91 h
= gethostbyname(argv
[i
]);
94 fprintf(stderr
, "%s: Can't find host %s\n",
99 bcopy(h
->h_addr
, (char *)&route_addr
, sizeof(route_addr
));
107 fp
= popen("/usr/sbin/netstat -r -n", "r");
108 while (NULL
!= fgets(str
, 256, fp
))
110 if (strncmp(str
, "default ", 8)) continue;
111 if (!strncmp(str
+ 17, "link", 4)) continue;
112 route_addr
= inet_addr(str
+17);
118 domain_name
[0] = '\0';
119 if (getdomainname(domain_name
, sizeof(domain_name
)) != 0)
120 domain_name
[0] = '\0';
122 if (debug
== 0) daemon(0,0);
124 openlog(progname
, 0, LOG_DAEMON
);
125 pmap_unset(BOOTPARAMPROG
, BOOTPARAMVERS
);
127 transp
= svcudp_create(RPC_ANYSOCK
);
130 syslog(LOG_ERR
, "Can't create udp service.");
134 if (!svc_register(transp
, BOOTPARAMPROG
, BOOTPARAMVERS
, bootparamprog_1
, IPPROTO_UDP
))
136 syslog(LOG_ERR
, "Can't register service.");
142 syslog(LOG_ERR
, "svc_run returned");