]>
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> 
  39 #include <sys/param.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");