| 977 | DEF_CMD("ifdstaddr", 0, setifdstaddr); |
| 978 | |
| 979 | static int |
| 980 | ifconfig(int argc, char *const *argv, int iscreate, const struct afswtch *uafp) |
| 981 | { |
| 982 | const struct afswtch *afp, *nafp; |
| 983 | const struct cmd *p; |
| 984 | struct callback *cb; |
| 985 | int s; |
| 986 | |
| 987 | strlcpy(ifr.ifr_name, name, sizeof ifr.ifr_name); |
| 988 | afp = NULL; |
| 989 | if (uafp != NULL) |
| 990 | afp = uafp; |
| 991 | /* |
| 992 | * This is the historical "accident" allowing users to configure IPv4 |
| 993 | * addresses without the "inet" keyword which while a nice feature has |
| 994 | * proven to complicate other things. We cannot remove this but only |
| 995 | * make sure we will never have a similar implicit default for IPv6 or |
| 996 | * any other address familiy. We need a fallback though for |
| 997 | * ifconfig IF up/down etc. to work without INET support as people |
| 998 | * never used ifconfig IF link up/down, etc. either. |
| 999 | */ |
| 1000 | #ifndef RESCUE |
| 1001 | #ifdef INET |
| 1002 | if (afp == NULL && feature_present("inet")) |
| 1003 | afp = af_getbyname("inet"); |
| 1004 | #endif |
| 1005 | #endif |
| 1006 | if (afp == NULL) |
| 1007 | afp = af_getbyname("link"); |
| 1008 | if (afp == NULL) { |
| 1009 | warnx("Please specify an address_family."); |
| 1010 | usage(); |
| 1011 | } |
| 1012 | top: |
| 1013 | ifr.ifr_addr.sa_family = |
| 1014 | afp->af_af == AF_LINK || afp->af_af == AF_UNSPEC ? |
| 1015 | AF_LOCAL : afp->af_af; |
| 1016 | |
| 1017 | if ((s = socket(ifr.ifr_addr.sa_family, SOCK_DGRAM, 0)) < 0 && |
| 1018 | (uafp != NULL || errno != EAFNOSUPPORT || |
| 1019 | (s = socket(AF_LOCAL, SOCK_DGRAM, 0)) < 0)) |
| 1020 | err(1, "socket(family %u,SOCK_DGRAM)", ifr.ifr_addr.sa_family); |
| 1021 | |
| 1022 | while (argc > 0) { |
| 1023 | p = cmd_lookup(*argv, iscreate); |
| 1024 | if (iscreate && p == NULL) { |
| 1025 | /* |
| 1026 | * Push the clone create callback so the new |
| 1027 | * device is created and can be used for any |
| 1028 | * remaining arguments. |
| 1029 | */ |
| 1030 | cb = callbacks; |
| 1031 | if (cb == NULL) |
| 1032 | errx(1, "internal error, no callback"); |
| 1033 | callbacks = cb->cb_next; |
| 1034 | cb->cb_func(s, cb->cb_arg); |
| 1035 | iscreate = 0; |
| 1036 | /* |
no test coverage detected