| 1 |
/* solaris.c -- Solaris specific code for ifconfig |
| 2 |
Copyright (C) 2001-2026 Free Software Foundation, Inc. |
| 3 |
|
| 4 |
This file is part of GNU Inetutils. |
| 5 |
|
| 6 |
GNU Inetutils is free software: you can redistribute it and/or modify |
| 7 |
it under the terms of the GNU General Public License as published by |
| 8 |
the Free Software Foundation, either version 3 of the License, or (at |
| 9 |
your option) any later version. |
| 10 |
|
| 11 |
GNU Inetutils is distributed in the hope that it will be useful, but |
| 12 |
WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 14 |
General Public License for more details. |
| 15 |
|
| 16 |
You should have received a copy of the GNU General Public License |
| 17 |
along with this program. If not, see `http://www.gnu.org/licenses/'. */ |
| 18 |
|
| 19 |
/* Written by Marcus Brinkmann. */ |
| 20 |
|
| 21 |
#include <config.h> |
| 22 |
|
| 23 |
#include <sys/stat.h> |
| 24 |
#include <stdio.h> |
| 25 |
#include <errno.h> |
| 26 |
|
| 27 |
#include <unistd.h> |
| 28 |
|
| 29 |
#include <string.h> |
| 30 |
|
| 31 |
#if STDC_HEADERS |
| 32 |
# include <stdlib.h> |
| 33 |
#else |
| 34 |
# ifndef HAVE_STRCHR |
| 35 |
# define strchr index |
| 36 |
# define strrchr rindex |
| 37 |
# endif |
| 38 |
#endif |
| 39 |
|
| 40 |
#include <sys/socket.h> |
| 41 |
#include <sys/ioctl.h> |
| 42 |
#include <netinet/in.h> |
| 43 |
#include <net/if.h> |
| 44 |
#include <net/if_arp.h> |
| 45 |
#include <netinet/if_ether.h> |
| 46 |
|
| 47 |
#include <attribute.h> |
| 48 |
|
| 49 |
#include "../ifconfig.h" |
| 50 |
|
| 51 |
|
| 52 |
/* Output format stuff. */ |
| 53 |
|
| 54 |
const char *system_default_format = "unix"; |
| 55 |
|
| 56 |
|
| 57 |
/* Argument parsing stuff. */ |
| 58 |
|
| 59 |
const char *system_help = "\ |
| 60 |
NAME [ADDR [DSTADDR]] [broadcast BRDADDR] [netmask MASK] " "[metric N] [mtu N] [up|down]"; |
| 61 |
|
| 62 |
struct argp_child system_argp_child; |
| 63 |
|
| 64 |
int |
| 65 |
system_parse_opt (struct ifconfig **ifp MAYBE_UNUSED, |
| 66 |
char option MAYBE_UNUSED, char *optarg MAYBE_UNUSED) |
| 67 |
{ |
| 68 |
return 0; |
| 69 |
} |
| 70 |
|
| 71 |
int |
| 72 |
system_parse_opt_rest (struct ifconfig **ifp, int argc, char *argv[]) |
| 73 |
{ |
| 74 |
int i = 0, mask, rev; |
| 75 |
enum |
| 76 |
{ |
| 77 |
EXPECT_NOTHING, |
| 78 |
EXPECT_AF, |
| 79 |
EXPECT_BROADCAST, |
| 80 |
EXPECT_NETMASK, |
| 81 |
EXPECT_METRIC, |
| 82 |
EXPECT_MTU |
| 83 |
} expect = EXPECT_AF; |
| 84 |
|
| 85 |
*ifp = parse_opt_new_ifs (argv[0]); |
| 86 |
|
| 87 |
while (++i < argc) |
| 88 |
{ |
| 89 |
switch (expect) |
| 90 |
{ |
| 91 |
case EXPECT_BROADCAST: |
| 92 |
parse_opt_set_brdaddr (*ifp, argv[i]); |
| 93 |
break; |
| 94 |
|
| 95 |
case EXPECT_NETMASK: |
| 96 |
parse_opt_set_netmask (*ifp, argv[i]); |
| 97 |
break; |
| 98 |
|
| 99 |
case EXPECT_MTU: |
| 100 |
parse_opt_set_mtu (*ifp, argv[i]); |
| 101 |
break; |
| 102 |
|
| 103 |
case EXPECT_METRIC: |
| 104 |
parse_opt_set_metric (*ifp, argv[i]); |
| 105 |
break; |
| 106 |
|
| 107 |
case EXPECT_AF: |
| 108 |
expect = EXPECT_NOTHING; |
| 109 |
if (!strcmp (argv[i], "inet")) |
| 110 |
continue; |
| 111 |
else if (!strcmp (argv[i], "inet6")) |
| 112 |
{ |
| 113 |
error (0, 0, "%s is not a supported address family", argv[i]); |
| 114 |
return 0; |
| 115 |
} |
| 116 |
break; |
| 117 |
|
| 118 |
case EXPECT_NOTHING: |
| 119 |
break; |
| 120 |
} |
| 121 |
|
| 122 |
if (expect != EXPECT_NOTHING) |
| 123 |
expect = EXPECT_NOTHING; |
| 124 |
else if (!strcmp (argv[i], "broadcast")) |
| 125 |
expect = EXPECT_BROADCAST; |
| 126 |
else if (!strcmp (argv[i], "netmask")) |
| 127 |
expect = EXPECT_NETMASK; |
| 128 |
else if (!strcmp (argv[i], "metric")) |
| 129 |
expect = EXPECT_METRIC; |
| 130 |
else if (!strcmp (argv[i], "mtu")) |
| 131 |
expect = EXPECT_MTU; |
| 132 |
else if (!strcmp (argv[i], "up")) |
| 133 |
parse_opt_set_flag (*ifp, IFF_UP | IFF_RUNNING, 0); |
| 134 |
else if (!strcmp (argv[i], "down")) |
| 135 |
parse_opt_set_flag (*ifp, IFF_UP, 1); |
| 136 |
else if (((mask = if_nameztoflag (argv[i], &rev)) |
| 137 |
& ~IU_IFF_CANTCHANGE) != 0) |
| 138 |
parse_opt_set_flag (*ifp, mask, rev); |
| 139 |
else |
| 140 |
{ |
| 141 |
/* Also auto-revarp, plumb, unplumb. */ |
| 142 |
if (!((*ifp)->valid & IF_VALID_ADDR)) |
| 143 |
parse_opt_set_address (*ifp, argv[i]); |
| 144 |
else if (!((*ifp)->valid & IF_VALID_DSTADDR)) |
| 145 |
parse_opt_set_dstaddr (*ifp, argv[i]); |
| 146 |
} |
| 147 |
} |
| 148 |
|
| 149 |
switch (expect) |
| 150 |
{ |
| 151 |
case EXPECT_BROADCAST: |
| 152 |
error (0, 0, "option `broadcast' requires an argument"); |
| 153 |
break; |
| 154 |
|
| 155 |
case EXPECT_NETMASK: |
| 156 |
error (0, 0, "option `netmask' requires an argument"); |
| 157 |
break; |
| 158 |
|
| 159 |
case EXPECT_METRIC: |
| 160 |
error (0, 0, "option `metric' requires an argument"); |
| 161 |
break; |
| 162 |
|
| 163 |
case EXPECT_MTU: |
| 164 |
error (0, 0, "option `mtu' requires an argument"); |
| 165 |
break; |
| 166 |
|
| 167 |
case EXPECT_AF: |
| 168 |
case EXPECT_NOTHING: |
| 169 |
return 1; |
| 170 |
} |
| 171 |
return 0; |
| 172 |
} |
| 173 |
|
| 174 |
int |
| 175 |
system_preconfigure (int sfd MAYBE_UNUSED, struct ifreq *ifr MAYBE_UNUSED) |
| 176 |
{ |
| 177 |
return 0; |
| 178 |
} |
| 179 |
|
| 180 |
int |
| 181 |
system_configure (int sfd, struct ifreq *ifr, struct system_ifconfig *ifs) |
| 182 |
{ |
| 183 |
#ifdef IF_VALID_TXQLEN |
| 184 |
if (ifs->valid & IF_VALID_TXQLEN) |
| 185 |
{ |
| 186 |
# ifndef SIOCSIFTXQLEN |
| 187 |
error (0, 0, "don't know how to set the txqlen on this system"); |
| 188 |
return -1; |
| 189 |
# else/* SIOCSIFTXQLEN */ |
| 190 |
int err = 0; |
| 191 |
|
| 192 |
ifr->ifr_qlen = ifs->txqlen; |
| 193 |
err = ioctl (sfd, SIOCSIFTXQLEN, ifr); |
| 194 |
if (err < 0) |
| 195 |
error (0, errno, "SIOCSIFTXQLEN failed"); |
| 196 |
if (verbose) |
| 197 |
printf ("Set txqlen value of `%s' to `%i'.\n", |
| 198 |
ifr->ifr_name, ifr->ifr_qlen); |
| 199 |
# endif/* SIOCSIFTXQLEN */ |
| 200 |
} |
| 201 |
#else /* !IF_VALID_TXQLEN */ |
| 202 |
(void) sfd; |
| 203 |
(void) ifr; |
| 204 |
(void) ifs; |
| 205 |
#endif /* !IF_VALID_TXQLEN */ |
| 206 |
return 0; |
| 207 |
} |
| 208 |
|
| 209 |
|
| 210 |
|
| 211 |
/* System hooks. */ |
| 212 |
|
| 213 |
struct if_nameindex *(*system_if_nameindex) (void) = if_nameindex; |