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