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