MCPcopy Create free account
hub / github.com/F-Stack/f-stack / ifconfig

Function ifconfig

tools/ifconfig/ifconfig.c:979–1140  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

977 DEF_CMD("ifdstaddr", 0, setifdstaddr);
978
979static int
980ifconfig(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 }
1012top:
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 /*

Callers 1

mainFunction · 0.85

Calls 10

feature_presentFunction · 0.85
af_getbynameFunction · 0.85
cmd_lookupFunction · 0.85
ioctl_vaFunction · 0.85
PerrorFunction · 0.85
usageFunction · 0.70
strlcpyFunction · 0.50
socketClass · 0.50
closeFunction · 0.50
ioctlFunction · 0.50

Tested by

no test coverage detected