]>
git.saurik.com Git - apple/network_cmds.git/blob - bootparams/bootparamd.tproj/bootparam_proc.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
32 #include "bootparam_prot.h"
37 #include <sys/types.h>
38 #include <sys/socket.h>
40 #include <bootparams.h>
44 extern unsigned long route_addr
;
45 extern char domain_name
[];
48 static char hostname
[MAXHOSTNAMELEN
];
51 bootparamproc_whoami_1_svc(whoami
, req
)
52 bp_whoami_arg
*whoami
;
56 static bp_whoami_res res
;
57 struct bootparamsent
*bp
;
61 fprintf(stderr
,"whoami %d.%d.%d.%d\n",
62 255 & whoami
->client_address
.bp_address_u
.ip_addr
.net
,
63 255 & whoami
->client_address
.bp_address_u
.ip_addr
.host
,
64 255 & whoami
->client_address
.bp_address_u
.ip_addr
.lh
,
65 255 & whoami
->client_address
.bp_address_u
.ip_addr
.impno
);
68 bcopy((char *)&whoami
->client_address
.bp_address_u
.ip_addr
,
69 (char *)&haddr
, sizeof(haddr
));
70 h
= gethostbyaddr((char *)&haddr
, sizeof(haddr
), AF_INET
);
73 if (debug
) fprintf(stderr
,"whoami failed: gethostbyaddr\n");
77 /* check whether subsequent bpgetfile requests would succeed */
78 bp
= bootparams_getbyname(h
->h_name
);
81 fprintf(stderr
, "whoami failed: bootparams_getbyname\n");
85 sprintf(hostname
, "%s", h
->h_name
);
86 res
.client_name
= hostname
;
88 res
.domain_name
= domain_name
;
90 res
.router_address
.address_type
= IP_ADDR_TYPE
;
91 bcopy(&route_addr
, &res
.router_address
.bp_address_u
.ip_addr
, 4);
95 fprintf(stderr
, "whoami name=%s domain=%s router=%d.%d.%d.%d\n",
98 255 & res
.router_address
.bp_address_u
.ip_addr
.net
,
99 255 & res
.router_address
.bp_address_u
.ip_addr
.host
,
100 255 & res
.router_address
.bp_address_u
.ip_addr
.lh
,
101 255 & res
.router_address
.bp_address_u
.ip_addr
.impno
);
108 bootparamproc_getfile_1_svc(getfile
, req
)
109 bp_getfile_arg
*getfile
;
112 static bp_getfile_res res
;
113 struct bootparamsent
*bp
;
120 fprintf(stderr
, "getfile %s %s\n",
121 getfile
->client_name
, getfile
->file_id
);
124 bp
= bootparams_getbyname(getfile
->client_name
);
129 fprintf(stderr
, "can't find bootparams for %s\n",
130 getfile
->client_name
);
131 fprintf(stderr
, "getfile failed\n");
136 len
= strlen(getfile
->file_id
) + 1;
137 sprintf(s
, "%s=", getfile
->file_id
);
139 for (i
= 0; bp
->bp_bootparams
[i
] != NULL
; i
++)
141 if (!strncmp(s
, bp
->bp_bootparams
[i
], len
)) break;
144 if (bp
->bp_bootparams
[i
] == NULL
)
148 fprintf(stderr
, "can't find bootparam %s\n", getfile
->file_id
);
149 fprintf(stderr
, "getfile failed\n");
154 sprintf(s
, bp
->bp_bootparams
[i
] + len
);
156 if ((p
== NULL
) || (p
== s
))
159 res
.server_name
= hostname
;
160 res
.server_address
.bp_address_u
.ip_addr
.net
= 0;
161 res
.server_address
.bp_address_u
.ip_addr
.host
= 0;
162 res
.server_address
.bp_address_u
.ip_addr
.lh
= 0;
163 res
.server_address
.bp_address_u
.ip_addr
.impno
= 0;
164 res
.server_address
.address_type
= 1;
166 if (p
== NULL
) res
.server_path
= s
;
167 else res
.server_path
= s
+ 1;
171 fprintf(stderr
, "getfile server=%s (%d.%d.%d.%d) path=%s\n",
173 255 & res
.server_address
.bp_address_u
.ip_addr
.net
,
174 255 & res
.server_address
.bp_address_u
.ip_addr
.host
,
175 255 & res
.server_address
.bp_address_u
.ip_addr
.lh
,
176 255 & res
.server_address
.bp_address_u
.ip_addr
.impno
,
184 h
= gethostbyname(s
);
189 fprintf(stderr
, "can't find server %s\n", s
);
190 fprintf(stderr
, "getfile failed\n");
197 bcopy(h
->h_addr
, &res
.server_address
.bp_address_u
.ip_addr
, h
->h_length
);
198 res
.server_address
.address_type
= IP_ADDR_TYPE
;
202 fprintf(stderr
, "getfile server=%s (%d.%d.%d.%d) path=%s\n",
204 255 & res
.server_address
.bp_address_u
.ip_addr
.net
,
205 255 & res
.server_address
.bp_address_u
.ip_addr
.host
,
206 255 & res
.server_address
.bp_address_u
.ip_addr
.lh
,
207 255 & res
.server_address
.bp_address_u
.ip_addr
.impno
,