]>
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 * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
8 * This file contains Original Code and/or Modifications of Original Code
9 * as defined in and that are subject to the Apple Public Source License
10 * Version 2.0 (the 'License'). You may not use this file except in
11 * compliance with the License. Please obtain a copy of the License at
12 * http://www.opensource.apple.com/apsl/ and read it before using this
15 * The Original Code and all software distributed under the License are
16 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
17 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
18 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
20 * Please see the License for the specific language governing rights and
21 * limitations under the License.
23 * @APPLE_LICENSE_HEADER_END@
27 * Copyright 1998, Apple Computer Inc. Unpublished.
29 * Written by Marc Majka
36 #include <rpc/pmap_clnt.h>
37 #include "bootparam_prot.h"
38 #include <sys/types.h>
39 #include <sys/socket.h>
43 #include <netinet/in.h>
44 #include <arpa/inet.h>
49 unsigned long route_addr
;
50 char domain_name
[MAXHOSTNAMELEN
];
53 extern void bootparamprog_1();
55 extern int getdomainname(char*, int);
60 fprintf(stderr
, "usage: %s [-d] [-r router]\n", progname
);
65 main(int argc
, char *argv
[])
73 progname
= strrchr(argv
[0],'/');
74 if (progname
) progname
++;
75 else progname
= argv
[0];
79 for (i
= 1; i
< argc
; i
++)
81 if (!strcmp(argv
[i
], "-d"))
85 else if (!strcmp(argv
[i
], "-r"))
88 if (i
>= argc
) usage();
90 route_addr
= inet_addr(argv
[i
]);
93 h
= gethostbyname(argv
[i
]);
96 fprintf(stderr
, "%s: Can't find host %s\n",
101 bcopy(h
->h_addr
, (char *)&route_addr
, sizeof(route_addr
));
109 fp
= popen("/usr/sbin/netstat -r -n", "r");
110 while (NULL
!= fgets(str
, 256, fp
))
112 if (strncmp(str
, "default ", 8)) continue;
113 if (!strncmp(str
+ 17, "link", 4)) continue;
114 route_addr
= inet_addr(str
+17);
120 domain_name
[0] = '\0';
121 if (getdomainname(domain_name
, sizeof(domain_name
)) != 0)
122 domain_name
[0] = '\0';
124 if (debug
== 0) daemon(0,0);
126 openlog(progname
, 0, LOG_DAEMON
);
127 pmap_unset(BOOTPARAMPROG
, BOOTPARAMVERS
);
129 transp
= svcudp_create(RPC_ANYSOCK
);
132 syslog(LOG_ERR
, "Can't create udp service.");
136 if (!svc_register(transp
, BOOTPARAMPROG
, BOOTPARAMVERS
, bootparamprog_1
, IPPROTO_UDP
))
138 syslog(LOG_ERR
, "Can't register service.");
144 syslog(LOG_ERR
, "svc_run returned");