| 1 |
/* ifconfig.c -- network interface configuration utility |
| 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/types.h> |
| 41 |
#include <sys/socket.h> |
| 42 |
#include <sys/ioctl.h> |
| 43 |
#include <net/if.h> |
| 44 |
#include <netinet/in.h> |
| 45 |
#include <arpa/inet.h> |
| 46 |
#include <progname.h> |
| 47 |
#include "ifconfig.h" |
| 48 |
|
| 49 |
int |
| 50 |
main (int argc, char *argv[]) |
| 51 |
{ |
| 52 |
int err = 0; |
| 53 |
int sfd; |
| 54 |
struct ifconfig *ifp; |
| 55 |
set_program_name (argv[0]); |
| 56 |
parse_cmdline (argc, argv); |
| 57 |
|
| 58 |
sfd = socket (AF_INET, SOCK_STREAM, 0); |
| 59 |
if (sfd < 0) |
| 60 |
{ |
| 61 |
error (0, errno, "socket error"); |
| 62 |
exit (EXIT_FAILURE); |
| 63 |
} |
| 64 |
|
| 65 |
for (ifp = ifs; ifp < ifs + nifs; ifp++) |
| 66 |
{ |
| 67 |
if (list_mode) |
| 68 |
{ |
| 69 |
/* Protect against mistakes in use of `-i'. */ |
| 70 |
if (!if_nametoindex (ifp->name)) |
| 71 |
continue; |
| 72 |
|
| 73 |
/* Use ERR as a marker of previous output. |
| 74 |
* It will never interfere with a call to configure_if(). */ |
| 75 |
if (err++) |
| 76 |
putchar (' '); |
| 77 |
printf ("%s", ifp->name); |
| 78 |
continue; |
| 79 |
} |
| 80 |
|
| 81 |
err = configure_if (sfd, ifp); |
| 82 |
if (err) |
| 83 |
break; |
| 84 |
} |
| 85 |
|
| 86 |
if (list_mode && err) |
| 87 |
putchar ('\n'); |
| 88 |
|
| 89 |
close (sfd); |
| 90 |
return err; |
| 91 |
} |