Merged socket development branch:
[mirror_edk2.git] / AppPkg / Applications / Sockets / WebServer / Ports.c
1 /*++
2 This file contains an 'Intel UEFI Application' and is
3 licensed for Intel CPUs and chipsets under the terms of your
4 license agreement with Intel or your vendor. This file may
5 be modified by the user, subject to additional terms of the
6 license agreement
7 --*/
8 /*++
9
10 Copyright (c) 2011 Intel Corporation. All rights reserved
11 This software and associated documentation (if any) is furnished
12 under a license and may only be used or copied in accordance
13 with the terms of the license. Except as permitted by such
14 license, no part of this software or documentation may be
15 reproduced, stored in a retrieval system, or transmitted in any
16 form or by any means without the express written consent of
17 Intel Corporation.
18
19 --*/
20
21 /** @file
22 Ports response page
23
24 **/
25
26 #include <WebServer.h>
27
28
29 /**
30 Respond with the Ports page
31
32 @param [in] SocketFD The socket's file descriptor to add to the list.
33 @param [in] pPort The WSDT_PORT structure address
34 @param [out] pbDone Address to receive the request completion status
35
36 @retval EFI_SUCCESS The request was successfully processed
37
38 **/
39 EFI_STATUS
40 PortsPage (
41 IN int SocketFD,
42 IN WSDT_PORT * pPort,
43 OUT BOOLEAN * pbDone
44 )
45 {
46 socklen_t AddressLength;
47 struct sockaddr_in6 LocalAddress;
48 DT_WEB_SERVER * pWebServer;
49 EFI_STATUS Status;
50
51 DBG_ENTER ( );
52
53 //
54 // Send the Hello World page
55 //
56 pWebServer = &mWebServer;
57 for ( ; ; ) {
58 //
59 // Send the page header
60 //
61 Status = HttpPageHeader ( SocketFD, pPort, L"Ports" );
62 if ( EFI_ERROR ( Status )) {
63 break;
64 }
65
66 //
67 // Send the page body
68 //
69 Status = HttpSendAnsiString ( SocketFD,
70 pPort,
71 "<h1>Web-Server Ports</h1>\r\n" );
72 if ( EFI_ERROR ( Status )) {
73 break;
74 }
75
76 //
77 // Check for TCP v4
78 //
79 if ( -1 != pWebServer->HttpListenPort ) {
80 AddressLength = sizeof ( LocalAddress );
81 if ( 0 == getsockname ( pWebServer->HttpListenPort,
82 (struct sockaddr *)&LocalAddress,
83 &AddressLength )) {
84 Status = HttpSendAnsiString ( SocketFD,
85 pPort,
86 "<a href=\"http://" );
87 if ( EFI_ERROR ( Status )) {
88 break;
89 }
90 Status = HttpSendIpAddress ( SocketFD,
91 pPort,
92 &LocalAddress );
93 if ( EFI_ERROR ( Status )) {
94 break;
95 }
96 Status = HttpSendAnsiString ( SocketFD,
97 pPort,
98 "\">Tcp4</a><br>\r\n" );
99 if ( EFI_ERROR ( Status )) {
100 break;
101 }
102 }
103 }
104
105 //
106 // Check for TCP v6
107 //
108 if ( -1 != pWebServer->HttpListenPort6 ) {
109 AddressLength = sizeof ( LocalAddress );
110 if ( 0 == getsockname ( pWebServer->HttpListenPort6,
111 (struct sockaddr *)&LocalAddress,
112 &AddressLength )) {
113 Status = HttpSendAnsiString ( SocketFD,
114 pPort,
115 "<a href=\"http://" );
116 if ( EFI_ERROR ( Status )) {
117 break;
118 }
119 Status = HttpSendIpAddress ( SocketFD,
120 pPort,
121 &LocalAddress );
122 if ( EFI_ERROR ( Status )) {
123 break;
124 }
125 Status = HttpSendAnsiString ( SocketFD,
126 pPort,
127 "\">Tcp6</a><br>\r\n" );
128 if ( EFI_ERROR ( Status )) {
129 break;
130 }
131 }
132 }
133
134 //
135 // Send the page trailer
136 //
137 Status = HttpPageTrailer ( SocketFD, pPort, pbDone );
138 break;
139 }
140
141 //
142 // Return the operation status
143 //
144 DBG_EXIT_STATUS ( Status );
145 return Status;
146 }