utils.c (27077) | utils.c (27079) |
---|---|
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 --- 25 unchanged lines hidden (view full) --- 34 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 35 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 36 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 37 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 38 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 39 * SUCH DAMAGE. 40 * 41 * from: @(#)utils.c 8.1 (Berkeley) 6/4/93 | 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 --- 25 unchanged lines hidden (view full) --- 34 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 35 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 36 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 37 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 38 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 39 * SUCH DAMAGE. 40 * 41 * from: @(#)utils.c 8.1 (Berkeley) 6/4/93 |
42 * $Id$ | 42 * $Id: utils.c,v 1.2 1997/06/29 19:00:29 steve Exp $ |
43 * 44 * From: Utah Hdr: utils.c 3.1 92/07/06 45 * Author: Jeff Forys, University of Utah CSS 46 */ 47 48#ifndef lint 49static const char sccsid[] = "@(#)utils.c 8.1 (Berkeley) 6/4/93"; 50#endif /* not lint */ --- 28 unchanged lines hidden (view full) --- 79DispPkt(rconn, direct) 80 RMPCONN *rconn; 81 int direct; 82{ 83 static char BootFmt[] = "\t\tRetCode:%u SeqNo:%lx SessID:%x Vers:%u"; 84 static char ReadFmt[] = "\t\tRetCode:%u Offset:%lx SessID:%x\n"; 85 86 struct tm *tmp; | 43 * 44 * From: Utah Hdr: utils.c 3.1 92/07/06 45 * Author: Jeff Forys, University of Utah CSS 46 */ 47 48#ifndef lint 49static const char sccsid[] = "@(#)utils.c 8.1 (Berkeley) 6/4/93"; 50#endif /* not lint */ --- 28 unchanged lines hidden (view full) --- 79DispPkt(rconn, direct) 80 RMPCONN *rconn; 81 int direct; 82{ 83 static char BootFmt[] = "\t\tRetCode:%u SeqNo:%lx SessID:%x Vers:%u"; 84 static char ReadFmt[] = "\t\tRetCode:%u Offset:%lx SessID:%x\n"; 85 86 struct tm *tmp; |
87 register struct rmp_packet *rmp; | 87 struct rmp_packet *rmp; |
88 int i, omask; 89 u_int32_t t; 90 91 /* 92 * Since we will be working with RmpConns as well as DbgFp, we 93 * must block signals that can affect either. 94 */ 95 omask = sigblock(sigmask(SIGHUP)|sigmask(SIGUSR1)|sigmask(SIGUSR2)); --- 109 unchanged lines hidden (view full) --- 205** be copied if it's to be saved. 206*/ 207char * 208GetEtherAddr(addr) 209 u_int8_t *addr; 210{ 211 static char Hex[] = "0123456789abcdef"; 212 static char etherstr[RMP_ADDRLEN*3]; | 88 int i, omask; 89 u_int32_t t; 90 91 /* 92 * Since we will be working with RmpConns as well as DbgFp, we 93 * must block signals that can affect either. 94 */ 95 omask = sigblock(sigmask(SIGHUP)|sigmask(SIGUSR1)|sigmask(SIGUSR2)); --- 109 unchanged lines hidden (view full) --- 205** be copied if it's to be saved. 206*/ 207char * 208GetEtherAddr(addr) 209 u_int8_t *addr; 210{ 211 static char Hex[] = "0123456789abcdef"; 212 static char etherstr[RMP_ADDRLEN*3]; |
213 register int i; 214 register char *cp; | 213 int i; 214 char *cp; |
215 216 /* 217 * For each byte in `addr', convert it to "<hexchar><hexchar>:". 218 * The last byte does not get a trailing `:' appended. 219 */ 220 i = 0; 221 cp = etherstr; 222 for(;;) { --- 19 unchanged lines hidden (view full) --- 242** Returns: 243** Nothing. 244** 245** Side Effects: 246** - Characters are sent to `DbgFp'. 247*/ 248void 249DspFlnm(size, flnm) | 215 216 /* 217 * For each byte in `addr', convert it to "<hexchar><hexchar>:". 218 * The last byte does not get a trailing `:' appended. 219 */ 220 i = 0; 221 cp = etherstr; 222 for(;;) { --- 19 unchanged lines hidden (view full) --- 242** Returns: 243** Nothing. 244** 245** Side Effects: 246** - Characters are sent to `DbgFp'. 247*/ 248void 249DspFlnm(size, flnm) |
250 register u_int size; 251 register char *flnm; | 250 u_int size; 251 char *flnm; |
252{ | 252{ |
253 register int i; | 253 int i; |
254 255 (void) fprintf(DbgFp, "\n\t\tFile Name (%u): <", size); 256 for (i = 0; i < size; i++) 257 (void) fputc(*flnm++, DbgFp); 258 (void) fputs(">\n", DbgFp); 259} 260 261 --- 17 unchanged lines hidden (view full) --- 279 CLIENT *ctmp; 280 281 if ((ctmp = (CLIENT *) malloc(sizeof(CLIENT))) == NULL) { 282 syslog(LOG_ERR, "NewClient: out of memory (%s)", 283 GetEtherAddr(addr)); 284 return(NULL); 285 } 286 | 254 255 (void) fprintf(DbgFp, "\n\t\tFile Name (%u): <", size); 256 for (i = 0; i < size; i++) 257 (void) fputc(*flnm++, DbgFp); 258 (void) fputs(">\n", DbgFp); 259} 260 261 --- 17 unchanged lines hidden (view full) --- 279 CLIENT *ctmp; 280 281 if ((ctmp = (CLIENT *) malloc(sizeof(CLIENT))) == NULL) { 282 syslog(LOG_ERR, "NewClient: out of memory (%s)", 283 GetEtherAddr(addr)); 284 return(NULL); 285 } 286 |
287 bzero(ctmp, sizeof(CLIENT)); 288 bcopy(addr, &ctmp->addr[0], RMP_ADDRLEN); | 287 memset(ctmp, 0, sizeof(CLIENT)); 288 memmove(&ctmp->addr[0], addr, RMP_ADDRLEN); |
289 return(ctmp); 290} 291 292/* 293** FreeClient -- free linked list of Clients. 294** 295** Parameters: 296** None. --- 6 unchanged lines hidden (view full) --- 303** CLIENTS will be free'd; `Clients' will be set to NULL. 304** 305** Warnings: 306** - This routine must be called with SIGHUP blocked. 307*/ 308void 309FreeClients() 310{ | 289 return(ctmp); 290} 291 292/* 293** FreeClient -- free linked list of Clients. 294** 295** Parameters: 296** None. --- 6 unchanged lines hidden (view full) --- 303** CLIENTS will be free'd; `Clients' will be set to NULL. 304** 305** Warnings: 306** - This routine must be called with SIGHUP blocked. 307*/ 308void 309FreeClients() 310{ |
311 register CLIENT *ctmp; | 311 CLIENT *ctmp; |
312 313 while (Clients != NULL) { 314 ctmp = Clients; 315 Clients = Clients->next; 316 FreeClient(ctmp); 317 } 318} 319 --- 61 unchanged lines hidden (view full) --- 381 rtmp = LastFree; 382 LastFree = NULL; 383 } 384 385 /* 386 * Copy template into `rtmp', init file descriptor to `-1' and 387 * set ptr to next elem NULL. 388 */ | 312 313 while (Clients != NULL) { 314 ctmp = Clients; 315 Clients = Clients->next; 316 FreeClient(ctmp); 317 } 318} 319 --- 61 unchanged lines hidden (view full) --- 381 rtmp = LastFree; 382 LastFree = NULL; 383 } 384 385 /* 386 * Copy template into `rtmp', init file descriptor to `-1' and 387 * set ptr to next elem NULL. 388 */ |
389 bcopy((char *)rconn, (char *)rtmp, sizeof(RMPCONN)); | 389 memmove((char *)rtmp, (char *)rconn, sizeof(RMPCONN)); |
390 rtmp->bootfd = -1; 391 rtmp->next = NULL; 392 393 return(rtmp); 394} 395 396/* 397** FreeConn -- Free memory associated with an RMPCONN connection. --- 5 unchanged lines hidden (view full) --- 403** Nothing. 404** 405** Side Effects: 406** - Memory associated with `rtmp' may be free'd (or cached). 407** - File desc associated with `rtmp->bootfd' will be closed. 408*/ 409void 410FreeConn(rtmp) | 390 rtmp->bootfd = -1; 391 rtmp->next = NULL; 392 393 return(rtmp); 394} 395 396/* 397** FreeConn -- Free memory associated with an RMPCONN connection. --- 5 unchanged lines hidden (view full) --- 403** Nothing. 404** 405** Side Effects: 406** - Memory associated with `rtmp' may be free'd (or cached). 407** - File desc associated with `rtmp->bootfd' will be closed. 408*/ 409void 410FreeConn(rtmp) |
411 register RMPCONN *rtmp; | 411 RMPCONN *rtmp; |
412{ 413 /* 414 * If the file descriptor is in use, close the file. 415 */ 416 if (rtmp->bootfd >= 0) { 417 (void) close(rtmp->bootfd); 418 rtmp->bootfd = -1; 419 } --- 19 unchanged lines hidden (view full) --- 439** - If LastFree is != NULL, it too will be free'd & NULL'd. 440** 441** Warnings: 442** - This routine must be called with SIGHUP blocked. 443*/ 444void 445FreeConns() 446{ | 412{ 413 /* 414 * If the file descriptor is in use, close the file. 415 */ 416 if (rtmp->bootfd >= 0) { 417 (void) close(rtmp->bootfd); 418 rtmp->bootfd = -1; 419 } --- 19 unchanged lines hidden (view full) --- 439** - If LastFree is != NULL, it too will be free'd & NULL'd. 440** 441** Warnings: 442** - This routine must be called with SIGHUP blocked. 443*/ 444void 445FreeConns() 446{ |
447 register RMPCONN *rtmp; | 447 RMPCONN *rtmp; |
448 449 while (RmpConns != NULL) { 450 rtmp = RmpConns; 451 RmpConns = RmpConns->next; 452 FreeConn(rtmp); 453 } 454 455 if (LastFree != NULL) { --- 14 unchanged lines hidden (view full) --- 470** Side Effects: 471** - RmpConn will point to new connection. 472** 473** Warnings: 474** - This routine must be called with SIGHUP blocked. 475*/ 476void 477AddConn(rconn) | 448 449 while (RmpConns != NULL) { 450 rtmp = RmpConns; 451 RmpConns = RmpConns->next; 452 FreeConn(rtmp); 453 } 454 455 if (LastFree != NULL) { --- 14 unchanged lines hidden (view full) --- 470** Side Effects: 471** - RmpConn will point to new connection. 472** 473** Warnings: 474** - This routine must be called with SIGHUP blocked. 475*/ 476void 477AddConn(rconn) |
478 register RMPCONN *rconn; | 478 RMPCONN *rconn; |
479{ 480 if (RmpConns != NULL) 481 rconn->next = RmpConns; 482 RmpConns = rconn; 483} 484 485/* 486** FindConn -- Find a connection in the linked list of connections. --- 11 unchanged lines hidden (view full) --- 498** Side Effects: 499** None. 500** 501** Warnings: 502** - This routine must be called with SIGHUP blocked. 503*/ 504RMPCONN * 505FindConn(rconn) | 479{ 480 if (RmpConns != NULL) 481 rconn->next = RmpConns; 482 RmpConns = rconn; 483} 484 485/* 486** FindConn -- Find a connection in the linked list of connections. --- 11 unchanged lines hidden (view full) --- 498** Side Effects: 499** None. 500** 501** Warnings: 502** - This routine must be called with SIGHUP blocked. 503*/ 504RMPCONN * 505FindConn(rconn) |
506 register RMPCONN *rconn; | 506 RMPCONN *rconn; |
507{ | 507{ |
508 register RMPCONN *rtmp; | 508 RMPCONN *rtmp; |
509 510 for (rtmp = RmpConns; rtmp != NULL; rtmp = rtmp->next) 511 if (bcmp((char *)&rconn->rmp.hp_hdr.saddr[0], 512 (char *)&rtmp->rmp.hp_hdr.saddr[0], RMP_ADDRLEN) == 0) 513 break; 514 515 return(rtmp); 516} --- 11 unchanged lines hidden (view full) --- 528** - If found, an RMPCONN will cease to exist and it will 529** be removed from the linked list. 530** 531** Warnings: 532** - This routine must be called with SIGHUP blocked. 533*/ 534void 535RemoveConn(rconn) | 509 510 for (rtmp = RmpConns; rtmp != NULL; rtmp = rtmp->next) 511 if (bcmp((char *)&rconn->rmp.hp_hdr.saddr[0], 512 (char *)&rtmp->rmp.hp_hdr.saddr[0], RMP_ADDRLEN) == 0) 513 break; 514 515 return(rtmp); 516} --- 11 unchanged lines hidden (view full) --- 528** - If found, an RMPCONN will cease to exist and it will 529** be removed from the linked list. 530** 531** Warnings: 532** - This routine must be called with SIGHUP blocked. 533*/ 534void 535RemoveConn(rconn) |
536 register RMPCONN *rconn; | 536 RMPCONN *rconn; |
537{ | 537{ |
538 register RMPCONN *thisrconn, *lastrconn; | 538 RMPCONN *thisrconn, *lastrconn; |
539 540 if (RmpConns == rconn) { /* easy case */ 541 RmpConns = RmpConns->next; 542 FreeConn(rconn); 543 } else { /* must traverse linked list */ 544 lastrconn = RmpConns; /* set back ptr */ 545 thisrconn = lastrconn->next; /* set current ptr */ 546 while (thisrconn != NULL) { 547 if (rconn == thisrconn) { /* found it */ 548 lastrconn->next = thisrconn->next; 549 FreeConn(thisrconn); 550 break; 551 } 552 lastrconn = thisrconn; 553 thisrconn = thisrconn->next; 554 } 555 } 556} | 539 540 if (RmpConns == rconn) { /* easy case */ 541 RmpConns = RmpConns->next; 542 FreeConn(rconn); 543 } else { /* must traverse linked list */ 544 lastrconn = RmpConns; /* set back ptr */ 545 thisrconn = lastrconn->next; /* set current ptr */ 546 while (thisrconn != NULL) { 547 if (rconn == thisrconn) { /* found it */ 548 lastrconn->next = thisrconn->next; 549 FreeConn(thisrconn); 550 break; 551 } 552 lastrconn = thisrconn; 553 thisrconn = thisrconn->next; 554 } 555 } 556} |