Stuf
This commit is contained in:
parent
485b9550fd
commit
d29edf34d6
68
hostname.c
68
hostname.c
@ -1,9 +1,12 @@
|
|||||||
/*
|
/*
|
||||||
* $Id: hostname.c,v 1.1 1999/12/07 23:14:59 andersen Exp $
|
* $Id: hostname.c,v 1.2 1999/12/08 04:13:44 andersen Exp $
|
||||||
* Mini hostname implementation for busybox
|
* Mini hostname implementation for busybox
|
||||||
*
|
*
|
||||||
* Copyright (C) 1999 by Randolph Chung <tausq@debian.org>
|
* Copyright (C) 1999 by Randolph Chung <tausq@debian.org>
|
||||||
*
|
*
|
||||||
|
* adjusted by Erik Andersen <andersee@debian.org> to remove
|
||||||
|
* use of long options and GNU getopt. Improved the usage info.
|
||||||
|
*
|
||||||
* This program is free software; you can redistribute it and/or modify
|
* This program is free software; you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
* the Free Software Foundation; either version 2 of the License, or
|
* the Free Software Foundation; either version 2 of the License, or
|
||||||
@ -21,27 +24,21 @@
|
|||||||
|
|
||||||
#include "internal.h"
|
#include "internal.h"
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <getopt.h>
|
|
||||||
#include <arpa/inet.h>
|
#include <arpa/inet.h>
|
||||||
#include <netdb.h>
|
#include <netdb.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
static const char* hostname_usage = "hostname [OPTION] {hostname | -F file}\n\n"
|
static const char* hostname_usage =
|
||||||
|
"hostname [OPTION] {hostname | -F file}\n\n"
|
||||||
|
"Get or set the hostname or DNS domain name. If a hostname is given\n"
|
||||||
|
"(or a file with the -F parameter), the host name will be set.\n\n"
|
||||||
"Options:\n"
|
"Options:\n"
|
||||||
"\t-s, --short\t\tshort\n"
|
"\t-s\t\tShort\n"
|
||||||
"\t-i, --ip-address\t\taddresses for the hostname\n"
|
"\t-i\t\tAddresses for the hostname\n"
|
||||||
"\t-d, --domain\t\tDNS domain name\n"
|
"\t-d\t\tDNS domain name\n"
|
||||||
"If a hostname is given, or a file is given with the -F parameter, the host\n"
|
"\t-F file\tUse FILE to specify the hostname\n";
|
||||||
"name will be set\n";
|
|
||||||
|
|
||||||
static char short_opts[] = "sidF:";
|
|
||||||
static const struct option long_opts[] = {
|
|
||||||
{ "short", no_argument, NULL, 's' },
|
|
||||||
{ "ip-address", no_argument, NULL, 'i' },
|
|
||||||
{ "domain", no_argument, NULL, 'd' },
|
|
||||||
{ NULL, 0, NULL, 0 }
|
|
||||||
};
|
|
||||||
|
|
||||||
void do_sethostname(char *s, int isfile)
|
void do_sethostname(char *s, int isfile)
|
||||||
{
|
{
|
||||||
@ -75,11 +72,9 @@ void do_sethostname(char *s, int isfile)
|
|||||||
|
|
||||||
int hostname_main(int argc, char **argv)
|
int hostname_main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
int c;
|
|
||||||
int opt_short = 0;
|
int opt_short = 0;
|
||||||
int opt_domain = 0;
|
int opt_domain = 0;
|
||||||
int opt_ip = 0;
|
int opt_ip = 0;
|
||||||
int opt_file = 0;
|
|
||||||
struct hostent *h;
|
struct hostent *h;
|
||||||
char *filename = NULL;
|
char *filename = NULL;
|
||||||
char buf[255];
|
char buf[255];
|
||||||
@ -87,19 +82,36 @@ int hostname_main(int argc, char **argv)
|
|||||||
|
|
||||||
if (argc < 1) usage(hostname_usage);
|
if (argc < 1) usage(hostname_usage);
|
||||||
|
|
||||||
while ((c = getopt_long(argc, argv, short_opts, long_opts, NULL)) != -1) {
|
while (--argc > 0 && **(++argv) == '-') {
|
||||||
switch (c) {
|
while (*(++(*argv))) {
|
||||||
case 's': opt_short = 1; break;
|
switch (**argv) {
|
||||||
case 'i': opt_ip = 1; break;
|
case 's':
|
||||||
case 'd': opt_domain = 1; break;
|
opt_short = 1;
|
||||||
case 'F': opt_file = 1; filename = optarg; break;
|
break;
|
||||||
default: usage(hostname_usage);
|
case 'i':
|
||||||
|
opt_ip = 1;
|
||||||
|
break;
|
||||||
|
case 'd':
|
||||||
|
opt_domain = 1;
|
||||||
|
break;
|
||||||
|
case 'F':
|
||||||
|
filename = optarg;
|
||||||
|
if (--argc == 0) {
|
||||||
|
usage(hostname_usage);
|
||||||
|
}
|
||||||
|
filename = *(++argv);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
usage(hostname_usage);
|
||||||
|
}
|
||||||
|
if (filename!=NULL)
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (optind < argc) {
|
if (argc >= 1) {
|
||||||
do_sethostname(argv[optind], 0);
|
do_sethostname(*argv, 0);
|
||||||
} else if (opt_file) {
|
} else if (filename!=NULL) {
|
||||||
do_sethostname(filename, 1);
|
do_sethostname(filename, 1);
|
||||||
} else {
|
} else {
|
||||||
gethostname(buf, 255);
|
gethostname(buf, 255);
|
||||||
@ -121,6 +133,6 @@ int hostname_main(int argc, char **argv)
|
|||||||
printf("%s\n", buf);
|
printf("%s\n", buf);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return 0;
|
exit( 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,9 +1,12 @@
|
|||||||
/*
|
/*
|
||||||
* $Id: hostname.c,v 1.1 1999/12/07 23:14:59 andersen Exp $
|
* $Id: hostname.c,v 1.2 1999/12/08 04:13:44 andersen Exp $
|
||||||
* Mini hostname implementation for busybox
|
* Mini hostname implementation for busybox
|
||||||
*
|
*
|
||||||
* Copyright (C) 1999 by Randolph Chung <tausq@debian.org>
|
* Copyright (C) 1999 by Randolph Chung <tausq@debian.org>
|
||||||
*
|
*
|
||||||
|
* adjusted by Erik Andersen <andersee@debian.org> to remove
|
||||||
|
* use of long options and GNU getopt. Improved the usage info.
|
||||||
|
*
|
||||||
* This program is free software; you can redistribute it and/or modify
|
* This program is free software; you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
* the Free Software Foundation; either version 2 of the License, or
|
* the Free Software Foundation; either version 2 of the License, or
|
||||||
@ -21,27 +24,21 @@
|
|||||||
|
|
||||||
#include "internal.h"
|
#include "internal.h"
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <getopt.h>
|
|
||||||
#include <arpa/inet.h>
|
#include <arpa/inet.h>
|
||||||
#include <netdb.h>
|
#include <netdb.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
static const char* hostname_usage = "hostname [OPTION] {hostname | -F file}\n\n"
|
static const char* hostname_usage =
|
||||||
|
"hostname [OPTION] {hostname | -F file}\n\n"
|
||||||
|
"Get or set the hostname or DNS domain name. If a hostname is given\n"
|
||||||
|
"(or a file with the -F parameter), the host name will be set.\n\n"
|
||||||
"Options:\n"
|
"Options:\n"
|
||||||
"\t-s, --short\t\tshort\n"
|
"\t-s\t\tShort\n"
|
||||||
"\t-i, --ip-address\t\taddresses for the hostname\n"
|
"\t-i\t\tAddresses for the hostname\n"
|
||||||
"\t-d, --domain\t\tDNS domain name\n"
|
"\t-d\t\tDNS domain name\n"
|
||||||
"If a hostname is given, or a file is given with the -F parameter, the host\n"
|
"\t-F file\tUse FILE to specify the hostname\n";
|
||||||
"name will be set\n";
|
|
||||||
|
|
||||||
static char short_opts[] = "sidF:";
|
|
||||||
static const struct option long_opts[] = {
|
|
||||||
{ "short", no_argument, NULL, 's' },
|
|
||||||
{ "ip-address", no_argument, NULL, 'i' },
|
|
||||||
{ "domain", no_argument, NULL, 'd' },
|
|
||||||
{ NULL, 0, NULL, 0 }
|
|
||||||
};
|
|
||||||
|
|
||||||
void do_sethostname(char *s, int isfile)
|
void do_sethostname(char *s, int isfile)
|
||||||
{
|
{
|
||||||
@ -75,11 +72,9 @@ void do_sethostname(char *s, int isfile)
|
|||||||
|
|
||||||
int hostname_main(int argc, char **argv)
|
int hostname_main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
int c;
|
|
||||||
int opt_short = 0;
|
int opt_short = 0;
|
||||||
int opt_domain = 0;
|
int opt_domain = 0;
|
||||||
int opt_ip = 0;
|
int opt_ip = 0;
|
||||||
int opt_file = 0;
|
|
||||||
struct hostent *h;
|
struct hostent *h;
|
||||||
char *filename = NULL;
|
char *filename = NULL;
|
||||||
char buf[255];
|
char buf[255];
|
||||||
@ -87,19 +82,36 @@ int hostname_main(int argc, char **argv)
|
|||||||
|
|
||||||
if (argc < 1) usage(hostname_usage);
|
if (argc < 1) usage(hostname_usage);
|
||||||
|
|
||||||
while ((c = getopt_long(argc, argv, short_opts, long_opts, NULL)) != -1) {
|
while (--argc > 0 && **(++argv) == '-') {
|
||||||
switch (c) {
|
while (*(++(*argv))) {
|
||||||
case 's': opt_short = 1; break;
|
switch (**argv) {
|
||||||
case 'i': opt_ip = 1; break;
|
case 's':
|
||||||
case 'd': opt_domain = 1; break;
|
opt_short = 1;
|
||||||
case 'F': opt_file = 1; filename = optarg; break;
|
break;
|
||||||
default: usage(hostname_usage);
|
case 'i':
|
||||||
|
opt_ip = 1;
|
||||||
|
break;
|
||||||
|
case 'd':
|
||||||
|
opt_domain = 1;
|
||||||
|
break;
|
||||||
|
case 'F':
|
||||||
|
filename = optarg;
|
||||||
|
if (--argc == 0) {
|
||||||
|
usage(hostname_usage);
|
||||||
|
}
|
||||||
|
filename = *(++argv);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
usage(hostname_usage);
|
||||||
|
}
|
||||||
|
if (filename!=NULL)
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (optind < argc) {
|
if (argc >= 1) {
|
||||||
do_sethostname(argv[optind], 0);
|
do_sethostname(*argv, 0);
|
||||||
} else if (opt_file) {
|
} else if (filename!=NULL) {
|
||||||
do_sethostname(filename, 1);
|
do_sethostname(filename, 1);
|
||||||
} else {
|
} else {
|
||||||
gethostname(buf, 255);
|
gethostname(buf, 255);
|
||||||
@ -121,6 +133,6 @@ int hostname_main(int argc, char **argv)
|
|||||||
printf("%s\n", buf);
|
printf("%s\n", buf);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return 0;
|
exit( 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user