]>
git.saurik.com Git - apple/network_cmds.git/blob - bootparams/bootparamd.tproj/bootparam_proc.c
b9e752e551c87f1722c69c875d96f319a2c5cc67
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
31 #include "bootparam_prot.h"
36 #include <sys/types.h>
37 #include <sys/socket.h>
39 #include <bootparams.h>
43 extern unsigned long route_addr
;
44 extern char domain_name
[];
47 static char hostname
[MAXHOSTNAMELEN
];
50 bootparamproc_whoami_1_svc(whoami
, req
)
51 bp_whoami_arg
*whoami
;
55 static bp_whoami_res res
;
56 struct bootparamsent
*bp
;
60 fprintf(stderr
,"whoami %d.%d.%d.%d\n",
61 255 & whoami
->client_address
.bp_address_u
.ip_addr
.net
,
62 255 & whoami
->client_address
.bp_address_u
.ip_addr
.host
,
63 255 & whoami
->client_address
.bp_address_u
.ip_addr
.lh
,
64 255 & whoami
->client_address
.bp_address_u
.ip_addr
.impno
);
67 bcopy((char *)&whoami
->client_address
.bp_address_u
.ip_addr
,
68 (char *)&haddr
, sizeof(haddr
));
69 h
= gethostbyaddr((char *)&haddr
, sizeof(haddr
), AF_INET
);
72 if (debug
) fprintf(stderr
,"whoami failed: gethostbyaddr\n");
76 /* check whether subsequent bpgetfile requests would succeed */
77 bp
= bootparams_getbyname(h
->h_name
);
80 fprintf(stderr
, "whoami failed: bootparams_getbyname\n");
84 sprintf(hostname
, "%s", h
->h_name
);
85 res
.client_name
= hostname
;
87 res
.domain_name
= domain_name
;
89 res
.router_address
.address_type
= IP_ADDR_TYPE
;
90 bcopy(&route_addr
, &res
.router_address
.bp_address_u
.ip_addr
, 4);
94 fprintf(stderr
, "whoami name=%s domain=%s router=%d.%d.%d.%d\n",
97 255 & res
.router_address
.bp_address_u
.ip_addr
.net
,
98 255 & res
.router_address
.bp_address_u
.ip_addr
.host
,
99 255 & res
.router_address
.bp_address_u
.ip_addr
.lh
,
100 255 & res
.router_address
.bp_address_u
.ip_addr
.impno
);
107 bootparamproc_getfile_1_svc(getfile
, req
)
108 bp_getfile_arg
*getfile
;
111 static bp_getfile_res res
;
112 struct bootparamsent
*bp
;
119 fprintf(stderr
, "getfile %s %s\n",
120 getfile
->client_name
, getfile
->file_id
);
123 bp
= bootparams_getbyname(getfile
->client_name
);
128 fprintf(stderr
, "can't find bootparams for %s\n",
129 getfile
->client_name
);
130 fprintf(stderr
, "getfile failed\n");
135 len
= strlen(getfile
->file_id
) + 1;
136 sprintf(s
, "%s=", getfile
->file_id
);
138 for (i
= 0; bp
->bp_bootparams
[i
] != NULL
; i
++)
140 if (!strncmp(s
, bp
->bp_bootparams
[i
], len
)) break;
143 if (bp
->bp_bootparams
[i
] == NULL
)
147 fprintf(stderr
, "can't find bootparam %s\n", getfile
->file_id
);
148 fprintf(stderr
, "getfile failed\n");
153 sprintf(s
, bp
->bp_bootparams
[i
] + len
);
155 if ((p
== NULL
) || (p
== s
))
158 res
.server_name
= hostname
;
159 res
.server_address
.bp_address_u
.ip_addr
.net
= 0;
160 res
.server_address
.bp_address_u
.ip_addr
.host
= 0;
161 res
.server_address
.bp_address_u
.ip_addr
.lh
= 0;
162 res
.server_address
.bp_address_u
.ip_addr
.impno
= 0;
163 res
.server_address
.address_type
= 1;
165 if (p
== NULL
) res
.server_path
= s
;
166 else res
.server_path
= s
+ 1;
170 fprintf(stderr
, "getfile server=%s (%d.%d.%d.%d) path=%s\n",
172 255 & res
.server_address
.bp_address_u
.ip_addr
.net
,
173 255 & res
.server_address
.bp_address_u
.ip_addr
.host
,
174 255 & res
.server_address
.bp_address_u
.ip_addr
.lh
,
175 255 & res
.server_address
.bp_address_u
.ip_addr
.impno
,
183 h
= gethostbyname(s
);
188 fprintf(stderr
, "can't find server %s\n", s
);
189 fprintf(stderr
, "getfile failed\n");
196 bcopy(h
->h_addr
, &res
.server_address
.bp_address_u
.ip_addr
, h
->h_length
);
197 res
.server_address
.address_type
= IP_ADDR_TYPE
;
201 fprintf(stderr
, "getfile server=%s (%d.%d.%d.%d) path=%s\n",
203 255 & res
.server_address
.bp_address_u
.ip_addr
.net
,
204 255 & res
.server_address
.bp_address_u
.ip_addr
.host
,
205 255 & res
.server_address
.bp_address_u
.ip_addr
.lh
,
206 255 & res
.server_address
.bp_address_u
.ip_addr
.impno
,