]>
git.saurik.com Git - apple/network_cmds.git/blob - bootparams/bootparamd.tproj/bootparam_proc.c
b7a64c31bfba489678af1e653071590abdefdf0e
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
33 #include "bootparam_prot.h"
38 #include <sys/types.h>
39 #include <sys/socket.h>
41 #include <bootparams.h>
45 extern unsigned long route_addr
;
46 extern char domain_name
[];
49 static char hostname
[MAXHOSTNAMELEN
];
52 bootparamproc_whoami_1_svc(whoami
, req
)
53 bp_whoami_arg
*whoami
;
57 static bp_whoami_res res
;
58 struct bootparamsent
*bp
;
62 fprintf(stderr
,"whoami %d.%d.%d.%d\n",
63 255 & whoami
->client_address
.bp_address_u
.ip_addr
.net
,
64 255 & whoami
->client_address
.bp_address_u
.ip_addr
.host
,
65 255 & whoami
->client_address
.bp_address_u
.ip_addr
.lh
,
66 255 & whoami
->client_address
.bp_address_u
.ip_addr
.impno
);
69 bcopy((char *)&whoami
->client_address
.bp_address_u
.ip_addr
,
70 (char *)&haddr
, sizeof(haddr
));
71 h
= gethostbyaddr((char *)&haddr
, sizeof(haddr
), AF_INET
);
74 if (debug
) fprintf(stderr
,"whoami failed: gethostbyaddr\n");
78 /* check whether subsequent bpgetfile requests would succeed */
79 bp
= bootparams_getbyname(h
->h_name
);
82 fprintf(stderr
, "whoami failed: bootparams_getbyname\n");
86 sprintf(hostname
, "%s", h
->h_name
);
87 res
.client_name
= hostname
;
89 res
.domain_name
= domain_name
;
91 res
.router_address
.address_type
= IP_ADDR_TYPE
;
92 bcopy(&route_addr
, &res
.router_address
.bp_address_u
.ip_addr
, 4);
96 fprintf(stderr
, "whoami name=%s domain=%s router=%d.%d.%d.%d\n",
99 255 & res
.router_address
.bp_address_u
.ip_addr
.net
,
100 255 & res
.router_address
.bp_address_u
.ip_addr
.host
,
101 255 & res
.router_address
.bp_address_u
.ip_addr
.lh
,
102 255 & res
.router_address
.bp_address_u
.ip_addr
.impno
);
109 bootparamproc_getfile_1_svc(getfile
, req
)
110 bp_getfile_arg
*getfile
;
113 static bp_getfile_res res
;
114 struct bootparamsent
*bp
;
121 fprintf(stderr
, "getfile %s %s\n",
122 getfile
->client_name
, getfile
->file_id
);
125 bp
= bootparams_getbyname(getfile
->client_name
);
130 fprintf(stderr
, "can't find bootparams for %s\n",
131 getfile
->client_name
);
132 fprintf(stderr
, "getfile failed\n");
137 len
= strlen(getfile
->file_id
) + 1;
138 sprintf(s
, "%s=", getfile
->file_id
);
140 for (i
= 0; bp
->bp_bootparams
[i
] != NULL
; i
++)
142 if (!strncmp(s
, bp
->bp_bootparams
[i
], len
)) break;
145 if (bp
->bp_bootparams
[i
] == NULL
)
149 fprintf(stderr
, "can't find bootparam %s\n", getfile
->file_id
);
150 fprintf(stderr
, "getfile failed\n");
155 sprintf(s
, bp
->bp_bootparams
[i
] + len
);
160 res
.server_name
= hostname
;
161 res
.server_address
.bp_address_u
.ip_addr
.net
= 0;
162 res
.server_address
.bp_address_u
.ip_addr
.host
= 0;
163 res
.server_address
.bp_address_u
.ip_addr
.lh
= 0;
164 res
.server_address
.bp_address_u
.ip_addr
.impno
= 0;
165 res
.server_address
.address_type
= 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
,