utils.c (69252) | utils.c (90377) |
---|---|
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[] = | 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 $"; | 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 | 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; | 82DispPkt(RMPCONN *rconn, 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 * | 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 * |
211GetEtherAddr(addr) 212 u_int8_t *addr; | 209GetEtherAddr(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 | 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 |
252DspFlnm(size, flnm) 253 u_int size; 254 char *flnm; | 249DspFlnm(u_int size, 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 * | 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 * |
279NewClient(addr) 280 u_int8_t *addr; | 274NewClient(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 | 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 |
312FreeClients() | 306FreeClients(void) |
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 * | 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 * |
337NewStr(str) 338 char *str; | 331NewStr(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 * | 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 * |
372NewConn(rconn) 373 RMPCONN *rconn; | 365NewConn(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 | 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 |
413FreeConn(rtmp) 414 RMPCONN *rtmp; | 405FreeConn(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 | 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 |
448FreeConns() | 439FreeConns(void) |
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 | 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 |
480AddConn(rconn) 481 RMPCONN *rconn; | 471AddConn(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 * | 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 * |
508FindConn(rconn) 509 RMPCONN *rconn; | 498FindConn(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 | 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 |
538RemoveConn(rconn) 539 RMPCONN *rconn; | 527RemoveConn(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 --- | 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 --- |