Deleted Added
sdiff udiff text old ( 69252 ) new ( 90377 )
full compact
1/*
2 * Copyright (c) 1988, 1992 The University of Utah and the Center
3 * for Software Science (CSS).
4 * Copyright (c) 1992, 1993
5 * The Regents of the University of California. All rights reserved.
6 *
7 * This code is derived from software contributed to Berkeley by
8 * the Center for Software Science of the University of Utah Computer

--- 35 unchanged lines hidden (view full) ---

44 * Author: Jeff Forys, University of Utah CSS
45 */
46
47#ifndef lint
48#if 0
49static const char sccsid[] = "@(#)utils.c 8.1 (Berkeley) 6/4/93";
50#endif
51static const char rcsid[] =
52 "$FreeBSD: head/libexec/rbootd/utils.c 69252 2000-11-27 07:21:37Z kris $";
53#endif /* not lint */
54
55#include <sys/param.h>
56#include <sys/time.h>
57
58#include <fcntl.h>
59#include <signal.h>
60#include <stdio.h>

--- 13 unchanged lines hidden (view full) ---

74**
75** Returns:
76** Nothing.
77**
78** Side Effects:
79** None.
80*/
81void
82DispPkt(rconn, direct)
83 RMPCONN *rconn;
84 int direct;
85{
86 static const char BootFmt[] = "\t\tRetCode:%u SeqNo:%lx SessID:%x Vers:%u";
87 static const char ReadFmt[] = "\t\tRetCode:%u Offset:%lx SessID:%x\n";
88
89 struct tm *tmp;
90 struct rmp_packet *rmp;
91 int i, omask;
92 u_int32_t t;

--- 110 unchanged lines hidden (view full) ---

203** Side Effects:
204** None.
205**
206** Warnings:
207** - The return value points to a static buffer; it must
208** be copied if it's to be saved.
209*/
210char *
211GetEtherAddr(addr)
212 u_int8_t *addr;
213{
214 static char Hex[] = "0123456789abcdef";
215 static char etherstr[RMP_ADDRLEN*3];
216 int i;
217 char *cp;
218
219 /*
220 * For each byte in `addr', convert it to "<hexchar><hexchar>:".

--- 23 unchanged lines hidden (view full) ---

244**
245** Returns:
246** Nothing.
247**
248** Side Effects:
249** - Characters are sent to `DbgFp'.
250*/
251void
252DspFlnm(size, flnm)
253 u_int size;
254 char *flnm;
255{
256 int i;
257
258 (void) fprintf(DbgFp, "\n\t\tFile Name (%u): <", size);
259 for (i = 0; i < size; i++)
260 (void) fputc(*flnm++, DbgFp);
261 (void) fputs(">\n", DbgFp);
262}

--- 8 unchanged lines hidden (view full) ---

271** Returns:
272** Ptr to new CLIENT or NULL if we ran out of memory.
273**
274** Side Effects:
275** - Memory will be malloc'd for the new CLIENT.
276** - If malloc() fails, a log message will be generated.
277*/
278CLIENT *
279NewClient(addr)
280 u_int8_t *addr;
281{
282 CLIENT *ctmp;
283
284 if ((ctmp = (CLIENT *) malloc(sizeof(CLIENT))) == NULL) {
285 syslog(LOG_ERR, "NewClient: out of memory (%s)",
286 GetEtherAddr(addr));
287 return(NULL);
288 }

--- 15 unchanged lines hidden (view full) ---

304** Side Effects:
305** - All malloc'd memory associated with the linked list of
306** CLIENTS will be free'd; `Clients' will be set to NULL.
307**
308** Warnings:
309** - This routine must be called with SIGHUP blocked.
310*/
311void
312FreeClients()
313{
314 CLIENT *ctmp;
315
316 while (Clients != NULL) {
317 ctmp = Clients;
318 Clients = Clients->next;
319 FreeClient(ctmp);
320 }

--- 8 unchanged lines hidden (view full) ---

329** Returns:
330** Ptr to new character array or NULL if we ran out of memory.
331**
332** Side Effects:
333** - Memory will be malloc'd for the new character array.
334** - If malloc() fails, a log message will be generated.
335*/
336char *
337NewStr(str)
338 char *str;
339{
340 char *stmp;
341
342 if ((stmp = (char *)malloc((unsigned) (strlen(str)+1))) == NULL) {
343 syslog(LOG_ERR, "NewStr: out of memory (%s)", str);
344 return(NULL);
345 }
346

--- 17 unchanged lines hidden (view full) ---

364** Returns:
365** Ptr to new RMPCONN or NULL if we ran out of memory.
366**
367** Side Effects:
368** - Memory may be malloc'd for the new RMPCONN (if not cached).
369** - If malloc() fails, a log message will be generated.
370*/
371RMPCONN *
372NewConn(rconn)
373 RMPCONN *rconn;
374{
375 RMPCONN *rtmp;
376
377 if (LastFree == NULL) { /* nothing cached; make a new one */
378 if ((rtmp = (RMPCONN *) malloc(sizeof(RMPCONN))) == NULL) {
379 syslog(LOG_ERR, "NewConn: out of memory (%s)",
380 EnetStr(rconn));
381 return(NULL);

--- 23 unchanged lines hidden (view full) ---

405** Returns:
406** Nothing.
407**
408** Side Effects:
409** - Memory associated with `rtmp' may be free'd (or cached).
410** - File desc associated with `rtmp->bootfd' will be closed.
411*/
412void
413FreeConn(rtmp)
414 RMPCONN *rtmp;
415{
416 /*
417 * If the file descriptor is in use, close the file.
418 */
419 if (rtmp->bootfd >= 0) {
420 (void) close(rtmp->bootfd);
421 rtmp->bootfd = -1;
422 }

--- 17 unchanged lines hidden (view full) ---

440** - All malloc'd memory associated with the linked list of
441** connections will be free'd; `RmpConns' will be set to NULL.
442** - If LastFree is != NULL, it too will be free'd & NULL'd.
443**
444** Warnings:
445** - This routine must be called with SIGHUP blocked.
446*/
447void
448FreeConns()
449{
450 RMPCONN *rtmp;
451
452 while (RmpConns != NULL) {
453 rtmp = RmpConns;
454 RmpConns = RmpConns->next;
455 FreeConn(rtmp);
456 }

--- 15 unchanged lines hidden (view full) ---

472**
473** Side Effects:
474** - RmpConn will point to new connection.
475**
476** Warnings:
477** - This routine must be called with SIGHUP blocked.
478*/
479void
480AddConn(rconn)
481 RMPCONN *rconn;
482{
483 if (RmpConns != NULL)
484 rconn->next = RmpConns;
485 RmpConns = rconn;
486}
487
488/*
489** FindConn -- Find a connection in the linked list of connections.

--- 10 unchanged lines hidden (view full) ---

500**
501** Side Effects:
502** None.
503**
504** Warnings:
505** - This routine must be called with SIGHUP blocked.
506*/
507RMPCONN *
508FindConn(rconn)
509 RMPCONN *rconn;
510{
511 RMPCONN *rtmp;
512
513 for (rtmp = RmpConns; rtmp != NULL; rtmp = rtmp->next)
514 if (bcmp((char *)&rconn->rmp.hp_hdr.saddr[0],
515 (char *)&rtmp->rmp.hp_hdr.saddr[0], RMP_ADDRLEN) == 0)
516 break;
517

--- 12 unchanged lines hidden (view full) ---

530** Side Effects:
531** - If found, an RMPCONN will cease to exist and it will
532** be removed from the linked list.
533**
534** Warnings:
535** - This routine must be called with SIGHUP blocked.
536*/
537void
538RemoveConn(rconn)
539 RMPCONN *rconn;
540{
541 RMPCONN *thisrconn, *lastrconn;
542
543 if (RmpConns == rconn) { /* easy case */
544 RmpConns = RmpConns->next;
545 FreeConn(rconn);
546 } else { /* must traverse linked list */
547 lastrconn = RmpConns; /* set back ptr */

--- 12 unchanged lines hidden ---