FreeNOS
Hostname.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2009 Niek Linnenbank
3  *
4  * This program is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation, either version 3 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program. If not, see <http://www.gnu.org/licenses/>.
16  */
17 
18 #include <stdio.h>
19 #include <stdlib.h>
20 #include <unistd.h>
21 #include <fcntl.h>
22 #include "Hostname.h"
23 
24 Hostname::Hostname(int argc, char **argv)
25  : POSIXApplication(argc, argv)
26 {
27  parser().setDescription("Print the system hostname");
28 }
29 
31 {
32 }
33 
35 {
36  char host[128];
37 
38  // Fetch hostname
39  gethostname(host, sizeof(host));
40 
41  // Output our hostname
42  printf("%s\r\n", host);
43 
44  // Done
45  return Success;
46 }
gethostname
int gethostname(char *name, size_t namelen)
Get name of current host.
Definition: gethostname.cpp:21
Hostname.h
fcntl.h
POSIXApplication
POSIX-compatible application.
Definition: POSIXApplication.h:35
Application::Success
@ Success
Definition: Application.h:55
ArgumentParser::setDescription
void setDescription(const String &desc)
Set program description.
Definition: ArgumentParser.cpp:95
printf
int printf(const char *format,...)
Output a formatted string to standard output.
Definition: printf.cpp:22
Hostname::Hostname
Hostname(int argc, char **argv)
Constructor.
Definition: Hostname.cpp:24
stdio.h
Application::Result
Result
Result codes.
Definition: Application.h:53
unistd.h
Application::parser
ArgumentParser & parser()
Get program arguments parser.
Definition: Application.cpp:102
stdlib.h
Hostname::~Hostname
virtual ~Hostname()
Destructor.
Definition: Hostname.cpp:30
Hostname::exec
virtual Result exec()
Execute the application.
Definition: Hostname.cpp:34