]> git.proxmox.com Git - mirror_edk2.git/blob - AppPkg/Applications/Sockets/SetHostName/SetHostName.c
EmbeddedPkg: Extend NvVarStoreFormattedLib LIBRARY_CLASS
[mirror_edk2.git] / AppPkg / Applications / Sockets / SetHostName / SetHostName.c
1 /** @file
2 Set the host name
3
4 Copyright (c) 2011-2012, Intel Corporation. All rights reserved.
5 SPDX-License-Identifier: BSD-2-Clause-Patent
6
7 **/
8
9 #include <errno.h>
10 #include <string.h>
11 #include <Uefi.h>
12 #include <unistd.h>
13
14 #include <Library/DebugLib.h>
15 #include <Library/UefiLib.h>
16
17 #include <sys/socket.h>
18
19 char mBuffer[65536];
20
21
22 /**
23 Set the host name
24
25 @param [in] Argc The number of arguments
26 @param [in] Argv The argument value array
27
28 @retval 0 The application exited normally.
29 @retval Other An error occurred.
30 **/
31 int
32 main (
33 IN int Argc,
34 IN char **Argv
35 )
36 {
37 int AppStatus;
38
39 DEBUG (( DEBUG_INFO,
40 "%a starting\r\n",
41 Argv[0]));
42
43 //
44 // Determine if the host name is specified
45 //
46 AppStatus = 0;
47 if ( 1 < Argc ) {
48 //
49 // Set the host name
50 //
51 AppStatus = sethostname ( Argv[1], strlen ( Argv[1]));
52 if ( -1 == AppStatus ) {
53 switch ( errno ) {
54 default:
55 Print ( L"ERROR - errno: %d\r\n", errno );
56 break;
57
58 case ENODEV:
59 Print ( L"WARNING - Plarform does not support permanent storage!\r\n" );
60 break;
61
62 case ENOMEM:
63 Print ( L"ERROR - Insufficient storage to save host name!\r\n" );
64 break;
65
66 case ENOTSUP:
67 Print ( L"ERROR - Platform does not support environment variable storage!\r\n" );
68 break;
69 }
70 }
71 }
72 else {
73 //
74 // Display the current host name
75 //
76 AppStatus = gethostname ( &mBuffer[0], sizeof ( mBuffer ));
77 if ( -1 == AppStatus ) {
78 Print ( L"ERROR - Unable to get host name, errno: %d\r\n", errno );
79 }
80 else {
81 if ( 0 == mBuffer[0]) {
82 Print ( L"Host name is not set!\r\n" );
83 }
84 else {
85 Print ( L"Host name: %a", &mBuffer[0]);
86 }
87 }
88 }
89
90 //
91 // All done
92 //
93 return errno;
94 }