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 90377 2002-02-07 23:57:01Z imp $"; |
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(RMPCONN *rconn, int direct) |
83{ 84 static const char BootFmt[] = "\t\tRetCode:%u SeqNo:%lx SessID:%x Vers:%u"; 85 static const char ReadFmt[] = "\t\tRetCode:%u Offset:%lx SessID:%x\n"; 86 87 struct tm *tmp; 88 struct rmp_packet *rmp; 89 int i, omask; 90 u_int32_t t; --- 110 unchanged lines hidden (view full) --- 201** Side Effects: 202** None. 203** 204** Warnings: 205** - The return value points to a static buffer; it must 206** be copied if it's to be saved. 207*/ 208char * |
209GetEtherAddr(u_int8_t *addr) |
210{ 211 static char Hex[] = "0123456789abcdef"; 212 static char etherstr[RMP_ADDRLEN*3]; 213 int i; 214 char *cp; 215 216 /* 217 * For each byte in `addr', convert it to "<hexchar><hexchar>:". --- 23 unchanged lines hidden (view full) --- 241** 242** Returns: 243** Nothing. 244** 245** Side Effects: 246** - Characters are sent to `DbgFp'. 247*/ 248void |
249DspFlnm(u_int size, char *flnm) |
250{ 251 int i; 252 253 (void) fprintf(DbgFp, "\n\t\tFile Name (%u): <", size); 254 for (i = 0; i < size; i++) 255 (void) fputc(*flnm++, DbgFp); 256 (void) fputs(">\n", DbgFp); 257} --- 8 unchanged lines hidden (view full) --- 266** Returns: 267** Ptr to new CLIENT or NULL if we ran out of memory. 268** 269** Side Effects: 270** - Memory will be malloc'd for the new CLIENT. 271** - If malloc() fails, a log message will be generated. 272*/ 273CLIENT * |
274NewClient(u_int8_t *addr) |
275{ 276 CLIENT *ctmp; 277 278 if ((ctmp = (CLIENT *) malloc(sizeof(CLIENT))) == NULL) { 279 syslog(LOG_ERR, "NewClient: out of memory (%s)", 280 GetEtherAddr(addr)); 281 return(NULL); 282 } --- 15 unchanged lines hidden (view full) --- 298** Side Effects: 299** - All malloc'd memory associated with the linked list of 300** CLIENTS will be free'd; `Clients' will be set to NULL. 301** 302** Warnings: 303** - This routine must be called with SIGHUP blocked. 304*/ 305void |
306FreeClients(void) |
307{ 308 CLIENT *ctmp; 309 310 while (Clients != NULL) { 311 ctmp = Clients; 312 Clients = Clients->next; 313 FreeClient(ctmp); 314 } --- 8 unchanged lines hidden (view full) --- 323** Returns: 324** Ptr to new character array or NULL if we ran out of memory. 325** 326** Side Effects: 327** - Memory will be malloc'd for the new character array. 328** - If malloc() fails, a log message will be generated. 329*/ 330char * |
331NewStr(char *str) |
332{ 333 char *stmp; 334 335 if ((stmp = (char *)malloc((unsigned) (strlen(str)+1))) == NULL) { 336 syslog(LOG_ERR, "NewStr: out of memory (%s)", str); 337 return(NULL); 338 } 339 --- 17 unchanged lines hidden (view full) --- 357** Returns: 358** Ptr to new RMPCONN or NULL if we ran out of memory. 359** 360** Side Effects: 361** - Memory may be malloc'd for the new RMPCONN (if not cached). 362** - If malloc() fails, a log message will be generated. 363*/ 364RMPCONN * |
365NewConn(RMPCONN *rconn) |
366{ 367 RMPCONN *rtmp; 368 369 if (LastFree == NULL) { /* nothing cached; make a new one */ 370 if ((rtmp = (RMPCONN *) malloc(sizeof(RMPCONN))) == NULL) { 371 syslog(LOG_ERR, "NewConn: out of memory (%s)", 372 EnetStr(rconn)); 373 return(NULL); --- 23 unchanged lines hidden (view full) --- 397** Returns: 398** Nothing. 399** 400** Side Effects: 401** - Memory associated with `rtmp' may be free'd (or cached). 402** - File desc associated with `rtmp->bootfd' will be closed. 403*/ 404void |
405FreeConn(RMPCONN *rtmp) |
406{ 407 /* 408 * If the file descriptor is in use, close the file. 409 */ 410 if (rtmp->bootfd >= 0) { 411 (void) close(rtmp->bootfd); 412 rtmp->bootfd = -1; 413 } --- 17 unchanged lines hidden (view full) --- 431** - All malloc'd memory associated with the linked list of 432** connections will be free'd; `RmpConns' will be set to NULL. 433** - If LastFree is != NULL, it too will be free'd & NULL'd. 434** 435** Warnings: 436** - This routine must be called with SIGHUP blocked. 437*/ 438void |
439FreeConns(void) |
440{ 441 RMPCONN *rtmp; 442 443 while (RmpConns != NULL) { 444 rtmp = RmpConns; 445 RmpConns = RmpConns->next; 446 FreeConn(rtmp); 447 } --- 15 unchanged lines hidden (view full) --- 463** 464** Side Effects: 465** - RmpConn will point to new connection. 466** 467** Warnings: 468** - This routine must be called with SIGHUP blocked. 469*/ 470void |
471AddConn(RMPCONN *rconn) |
472{ 473 if (RmpConns != NULL) 474 rconn->next = RmpConns; 475 RmpConns = rconn; 476} 477 478/* 479** FindConn -- Find a connection in the linked list of connections. --- 10 unchanged lines hidden (view full) --- 490** 491** Side Effects: 492** None. 493** 494** Warnings: 495** - This routine must be called with SIGHUP blocked. 496*/ 497RMPCONN * |
498FindConn(RMPCONN *rconn) |
499{ 500 RMPCONN *rtmp; 501 502 for (rtmp = RmpConns; rtmp != NULL; rtmp = rtmp->next) 503 if (bcmp((char *)&rconn->rmp.hp_hdr.saddr[0], 504 (char *)&rtmp->rmp.hp_hdr.saddr[0], RMP_ADDRLEN) == 0) 505 break; 506 --- 12 unchanged lines hidden (view full) --- 519** Side Effects: 520** - If found, an RMPCONN will cease to exist and it will 521** be removed from the linked list. 522** 523** Warnings: 524** - This routine must be called with SIGHUP blocked. 525*/ 526void |
527RemoveConn(RMPCONN *rconn) |
528{ 529 RMPCONN *thisrconn, *lastrconn; 530 531 if (RmpConns == rconn) { /* easy case */ 532 RmpConns = RmpConns->next; 533 FreeConn(rconn); 534 } else { /* must traverse linked list */ 535 lastrconn = RmpConns; /* set back ptr */ --- 12 unchanged lines hidden --- |