1/* $Id: bootp_subr.c,v 1.4 1997/06/12 14:08:20 tegge Exp $ */ |
2 3/* 4 * Copyright (c) 1995 Gordon Ross, Adam Glass 5 * Copyright (c) 1992 Regents of the University of California. 6 * All rights reserved. 7 * 8 * This software was developed by the Computer Systems Engineering group 9 * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and --- 245 unchanged lines hidden (view full) --- 255 256int 257bootpc_call(call,reply,procp) 258 struct bootp_packet *call; 259 struct bootp_packet *reply; /* output */ 260 struct proc *procp; 261{ 262 struct socket *so; |
263 struct sockaddr_in *sin, sa; 264 struct mbuf *m; |
265 struct uio auio; 266 struct iovec aio; 267 int error, rcvflg, timo, secs, len; 268 u_int tport; 269 |
270 /* 271 * Create socket and set its recieve timeout. 272 */ 273 if ((error = socreate(AF_INET, &so, SOCK_DGRAM, 0,procp))) 274 goto out; 275 276 m = m_get(M_WAIT, MT_SOOPTS); 277 if (m == NULL) { --- 24 unchanged lines hidden (view full) --- 302 *on = 1; 303 if ((error = sosetopt(so, SOL_SOCKET, SO_BROADCAST, m, procp))) 304 goto out; 305 } 306 307 /* 308 * Bind the local endpoint to a bootp client port. 309 */ |
310 sin = &sa; 311 bzero(sin, sizeof *sin); 312 sin->sin_len = sizeof(*sin); |
313 sin->sin_family = AF_INET; 314 sin->sin_addr.s_addr = INADDR_ANY; 315 sin->sin_port = htons(IPPORT_BOOTPC); |
316 error = sobind(so, (struct sockaddr *)sin, procp); |
317 if (error) { 318 printf("bind failed\n"); 319 goto out; 320 } 321 322 /* 323 * Setup socket address for the server. 324 */ |
325 sin = &sa; 326 bzero(sin, sizeof *sin); 327 sin->sin_len = sizeof(*sin); 328 sin->sin_family = AF_INET; |
329 sin->sin_addr.s_addr = INADDR_BROADCAST; 330 sin->sin_port = htons(IPPORT_BOOTPS); 331 |
332 /* 333 * Send it, repeatedly, until a reply is received, 334 * but delay each re-send by an increasing amount. 335 * If the delay hits the maximum, start complaining. 336 */ 337 timo = 0; 338 for (;;) { 339 /* Send BOOTP request (or re-send). */ --- 4 unchanged lines hidden (view full) --- 344 auio.uio_iov = &aio; 345 auio.uio_iovcnt = 1; 346 auio.uio_segflg = UIO_SYSSPACE; 347 auio.uio_rw = UIO_WRITE; 348 auio.uio_offset = 0; 349 auio.uio_resid = sizeof(*call); 350 auio.uio_procp = procp; 351 |
352 error = sosend(so, (struct sockaddr *)sin, &auio, NULL, 353 NULL, 0, procp); |
354 if (error) { 355 printf("bootpc_call: sosend: %d\n", error); 356 goto out; 357 } 358 359 /* Determine new timeout. */ 360 if (timo < MAX_RESEND_DELAY) 361 timo++; --- 51 unchanged lines hidden (view full) --- 413 } /* while secs */ 414 } /* forever send/receive */ 415 416 error = ETIMEDOUT; 417 goto out; 418 419 gotreply: 420 out: |
421 soclose(so); 422 return error; 423} 424 425int 426bootpc_fakeup_interface(struct ifreq *ireq,struct socket *so, 427 struct proc *procp) 428{ --- 827 unchanged lines hidden --- |