1 /** @file
2   Set the host name
3 
4   Copyright (c) 2011-2012, Intel Corporation
5   All rights reserved. This program and the accompanying materials
6   are licensed and made available under the terms and conditions of the BSD License
7   which accompanies this distribution.  The full text of the license may be found at
8   http://opensource.org/licenses/bsd-license.php
9 
10   THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11   WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
12 
13 **/
14 
15 #include <errno.h>
16 #include <string.h>
17 #include <Uefi.h>
18 #include <unistd.h>
19 
20 #include <Library/DebugLib.h>
21 #include <Library/UefiLib.h>
22 
23 #include <sys/socket.h>
24 
25 char mBuffer[65536];
26 
27 
28 /**
29   Set the host name
30 
31   @param [in] Argc  The number of arguments
32   @param [in] Argv  The argument value array
33 
34   @retval  0        The application exited normally.
35   @retval  Other    An error occurred.
36 **/
37 int
main(IN int Argc,IN char ** Argv)38 main (
39   IN int Argc,
40   IN char **Argv
41   )
42 {
43   int AppStatus;
44 
45   DEBUG (( DEBUG_INFO,
46             "%a starting\r\n",
47             Argv[0]));
48 
49   //
50   //  Determine if the host name is specified
51   //
52   AppStatus = 0;
53   if ( 1 < Argc ) {
54     //
55     //  Set the host name
56     //
57     AppStatus = sethostname ( Argv[1], strlen ( Argv[1]));
58     if ( -1 == AppStatus ) {
59       switch ( errno ) {
60       default:
61         Print ( L"ERROR - errno: %d\r\n", errno );
62         break;
63 
64       case ENODEV:
65         Print ( L"WARNING - Plarform does not support permanent storage!\r\n" );
66         break;
67 
68       case ENOMEM:
69         Print ( L"ERROR - Insufficient storage to save host name!\r\n" );
70         break;
71 
72       case ENOTSUP:
73         Print ( L"ERROR - Platform does not support environment variable storage!\r\n" );
74         break;
75       }
76     }
77   }
78   else {
79     //
80     //  Display the current host name
81     //
82     AppStatus = gethostname ( &mBuffer[0], sizeof ( mBuffer ));
83     if ( -1 == AppStatus ) {
84       Print ( L"ERROR - Unable to get host name, errno: %d\r\n", errno );
85     }
86     else {
87       if ( 0 == mBuffer[0]) {
88         Print ( L"Host name is not set!\r\n" );
89       }
90       else {
91         Print ( L"Host name: %a", &mBuffer[0]);
92       }
93     }
94   }
95 
96   //
97   //  All done
98   //
99   return errno;
100 }
101