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
24Hostname::Hostname(int argc, char **argv)
25 : POSIXApplication(argc, argv)
26{
27 parser().setDescription("Print the system hostname");
28}
29
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}
Result
Result codes.
Definition Application.h:54
ArgumentParser & parser()
Get program arguments parser.
void setDescription(const String &desc)
Set program description.
virtual Result exec()
Execute the application.
Definition Hostname.cpp:34
virtual ~Hostname()
Destructor.
Definition Hostname.cpp:30
Hostname(int argc, char **argv)
Constructor.
Definition Hostname.cpp:24
POSIX-compatible application.
C int gethostname(char *name, size_t namelen)
Get name of current host.
C int printf(const char *format,...)
Output a formatted string to standard output.
Definition printf.cpp:22