ifconfig.c (138593) | ifconfig.c (138671) |
---|---|
1/* 2 * Copyright (c) 1983, 1993 3 * The Regents of the University of California. All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 24 unchanged lines hidden (view full) --- 33 The Regents of the University of California. All rights reserved.\n"; 34#endif /* not lint */ 35 36#ifndef lint 37#if 0 38static char sccsid[] = "@(#)ifconfig.c 8.2 (Berkeley) 2/16/94"; 39#endif 40static const char rcsid[] = | 1/* 2 * Copyright (c) 1983, 1993 3 * The Regents of the University of California. All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 24 unchanged lines hidden (view full) --- 33 The Regents of the University of California. All rights reserved.\n"; 34#endif /* not lint */ 35 36#ifndef lint 37#if 0 38static char sccsid[] = "@(#)ifconfig.c 8.2 (Berkeley) 2/16/94"; 39#endif 40static const char rcsid[] = |
41 "$FreeBSD: head/sbin/ifconfig/ifconfig.c 138593 2004-12-08 19:18:07Z sam $"; | 41 "$FreeBSD: head/sbin/ifconfig/ifconfig.c 138671 2004-12-11 02:33:33Z sam $"; |
42#endif /* not lint */ 43 44#include <sys/param.h> 45#include <sys/ioctl.h> 46#include <sys/socket.h> 47#include <sys/sysctl.h> 48#include <sys/time.h> 49#include <sys/module.h> --- 391 unchanged lines hidden (view full) --- 441 442 for (p = cmds; p != NULL; p = p->c_next) 443 if (strcmp(name, p->c_name) == 0) 444 return p; 445 return NULL; 446#undef N 447} 448 | 42#endif /* not lint */ 43 44#include <sys/param.h> 45#include <sys/ioctl.h> 46#include <sys/socket.h> 47#include <sys/sysctl.h> 48#include <sys/time.h> 49#include <sys/module.h> --- 391 unchanged lines hidden (view full) --- 441 442 for (p = cmds; p != NULL; p = p->c_next) 443 if (strcmp(name, p->c_name) == 0) 444 return p; 445 return NULL; 446#undef N 447} 448 |
449struct callback { 450 callback_func *cb_func; 451 void *cb_arg; 452 struct callback *cb_next; 453}; 454static struct callback *callbacks = NULL; 455 456void 457callback_register(callback_func *func, void *arg) 458{ 459 struct callback *cb; 460 461 cb = malloc(sizeof(struct callback)); 462 if (cb == NULL) 463 errx(1, "unable to allocate memory for callback"); 464 cb->cb_func = func; 465 cb->cb_arg = arg; 466 cb->cb_next = callbacks; 467 callbacks = cb; 468} 469 |
|
449/* specially-handled comamnds */ 450static void setifaddr(const char *, int, int, const struct afswtch *); 451static const struct cmd setifaddr_cmd = DEF_CMD("ifaddr", 0, setifaddr); 452 453static void setifdstaddr(const char *, int, int, const struct afswtch *); 454static const struct cmd setifdstaddr_cmd = 455 DEF_CMD("ifdstaddr", 0, setifdstaddr); 456 457static int 458ifconfig(int argc, char *const *argv, const struct afswtch *afp) 459{ | 470/* specially-handled comamnds */ 471static void setifaddr(const char *, int, int, const struct afswtch *); 472static const struct cmd setifaddr_cmd = DEF_CMD("ifaddr", 0, setifaddr); 473 474static void setifdstaddr(const char *, int, int, const struct afswtch *); 475static const struct cmd setifdstaddr_cmd = 476 DEF_CMD("ifdstaddr", 0, setifdstaddr); 477 478static int 479ifconfig(int argc, char *const *argv, const struct afswtch *afp) 480{ |
481 struct callback *cb; |
|
460 int s; 461 462 if (afp == NULL) 463 afp = af_getbyname("inet"); 464 ifr.ifr_addr.sa_family = 465 afp->af_af == AF_LINK || afp->af_af == AF_UNSPEC ? 466 AF_INET : afp->af_af; 467 strncpy(ifr.ifr_name, name, sizeof ifr.ifr_name); --- 68 unchanged lines hidden (view full) --- 536 newaddr = 0; 537 } 538 } 539 if (newaddr && (setaddr || setmask)) { 540 strncpy(afp->af_addreq, name, sizeof ifr.ifr_name); 541 if (ioctl(s, afp->af_aifaddr, afp->af_addreq) < 0) 542 Perror("ioctl (SIOCAIFADDR)"); 543 } | 482 int s; 483 484 if (afp == NULL) 485 afp = af_getbyname("inet"); 486 ifr.ifr_addr.sa_family = 487 afp->af_af == AF_LINK || afp->af_af == AF_UNSPEC ? 488 AF_INET : afp->af_af; 489 strncpy(ifr.ifr_name, name, sizeof ifr.ifr_name); --- 68 unchanged lines hidden (view full) --- 558 newaddr = 0; 559 } 560 } 561 if (newaddr && (setaddr || setmask)) { 562 strncpy(afp->af_addreq, name, sizeof ifr.ifr_name); 563 if (ioctl(s, afp->af_aifaddr, afp->af_addreq) < 0) 564 Perror("ioctl (SIOCAIFADDR)"); 565 } |
566 567 /* 568 * Do deferred callbacks registered while processing 569 * command-line arguments. 570 */ 571 for (cb = callbacks; cb != NULL; cb = cb->cb_next) 572 cb->cb_func(s, cb->cb_arg); 573 |
|
544 close(s); 545 return(0); 546} 547 548/*ARGSUSED*/ 549static void 550setifaddr(const char *addr, int param, int s, const struct afswtch *afp) 551{ --- 464 unchanged lines hidden --- | 574 close(s); 575 return(0); 576} 577 578/*ARGSUSED*/ 579static void 580setifaddr(const char *addr, int param, int s, const struct afswtch *afp) 581{ --- 464 unchanged lines hidden --- |