]>
git.saurik.com Git - apple/network_cmds.git/blob - bootparams/bootparamd.tproj/bootparamd.c
2 * Copyright (c) 1999 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights
7 * Reserved. This file contains Original Code and/or Modifications of
8 * Original Code as defined in and that are subject to the Apple Public
9 * Source License Version 1.0 (the 'License'). You may not use this file
10 * except in compliance with the License. Please obtain a copy of the
11 * License at http://www.apple.com/publicsource and read it before using
14 * The Original Code and all software distributed under the License are
15 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
16 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
17 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
19 * License for the specific language governing rights and limitations
22 * @APPLE_LICENSE_HEADER_END@
26 * Copyright 1998, Apple Computer Inc. Unpublished.
28 * Written by Marc Majka
35 #include <rpc/pmap_clnt.h>
36 #include "bootparam_prot.h"
37 #include <sys/types.h>
38 #include <sys/socket.h>
42 #include <netinet/in.h>
43 #include <arpa/inet.h>
48 unsigned long route_addr
;
49 char domain_name
[MAXHOSTNAMELEN
];
52 extern void bootparamprog_1();
54 extern int getdomainname(char*, int);
59 fprintf(stderr
, "usage: %s [-d] [-r router]\n", progname
);
64 main(int argc
, char *argv
[])
72 progname
= strrchr(argv
[0],'/');
73 if (progname
) progname
++;
74 else progname
= argv
[0];
78 for (i
= 1; i
< argc
; i
++)
80 if (!strcmp(argv
[i
], "-d"))
84 else if (!strcmp(argv
[i
], "-r"))
87 if (i
>= argc
) usage();
89 route_addr
= inet_addr(argv
[i
]);
92 h
= gethostbyname(argv
[i
]);
95 fprintf(stderr
, "%s: Can't find host %s\n",
100 bcopy(h
->h_addr
, (char *)&route_addr
, sizeof(route_addr
));
108 fp
= popen("/usr/sbin/netstat -r -n", "r");
109 while (NULL
!= fgets(str
, 256, fp
))
111 if (strncmp(str
, "default ", 8)) continue;
112 if (!strncmp(str
+ 17, "link", 4)) continue;
113 route_addr
= inet_addr(str
+17);
119 domain_name
[0] = '\0';
120 if (getdomainname(domain_name
, sizeof(domain_name
)) != 0)
121 domain_name
[0] = '\0';
123 if (debug
== 0) daemon(0,0);
125 openlog(progname
, 0, LOG_DAEMON
);
126 pmap_unset(BOOTPARAMPROG
, BOOTPARAMVERS
);
128 transp
= svcudp_create(RPC_ANYSOCK
);
131 syslog(LOG_ERR
, "Can't create udp service.");
135 if (!svc_register(transp
, BOOTPARAMPROG
, BOOTPARAMVERS
, bootparamprog_1
, IPPROTO_UDP
))
137 syslog(LOG_ERR
, "Can't register service.");
143 syslog(LOG_ERR
, "svc_run returned");