]>
git.proxmox.com Git - mirror_edk2.git/blob - AppPkg/Applications/Sockets/OobTx/OobTx.c
2 Windows version of the OOB Transmit application
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
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.
21 Transmit out-of-band messages to the remote system.
23 @param [in] ArgC Argument count
24 @param [in] ArgV Argument value array
26 @retval 0 Successfully operation
36 ssize_t BytesTransmitted
;
38 struct sockaddr_in LocalPort
;
41 UINT32 RemoteAddress
[4];
42 struct sockaddr_in RemotePort
;
44 UINT32 TransmittedAfter
;
45 UINT32 TransmittedBefore
;
46 UINT32 TransmittedOob
;
52 s
= socket ( AF_INET
, SOCK_STREAM
, IPPROTO_TCP
);
55 printf ( "ERROR - socket error, errno: %d\r\n", RetVal
);
59 // Use for/break; instead of goto
63 // Validate the arguments
66 || ( 4 != sscanf ( ArgV
[1],
72 || ( 224 < RemoteAddress
[0])
73 || ( 255 < RemoteAddress
[1])
74 || ( 255 < RemoteAddress
[2])
75 || ( 255 < RemoteAddress
[3])
76 || (( 0 == RemoteAddress
[0])
77 && ( 0 == RemoteAddress
[1])
78 && ( 0 == RemoteAddress
[2])
79 && ( 0 == RemoteAddress
[3]))) {
80 printf ( "%s <remote IP address> [optional: enables in-line OOB]\r\n", ArgV
[0]);
86 // Bind the socket to a local port
88 memset ( &LocalPort
, 0, sizeof ( LocalPort
));
89 SIN_LEN ( LocalPort
) = sizeof ( LocalPort
);
90 SIN_FAMILY ( LocalPort
) = AF_INET
;
91 SIN_ADDR ( LocalPort
) = 0;
92 SIN_PORT ( LocalPort
) = 0;
94 (struct sockaddr
*)&LocalPort
,
95 sizeof ( LocalPort
));
98 printf ( "ERROR - bind error, errno: %d\r\n", RetVal
);
103 // Specify the remote port
105 PortNumber
= OOB_RX_PORT
;
106 memset ( &RemotePort
, 0, sizeof ( RemotePort
));
107 SIN_LEN ( RemotePort
) = sizeof ( RemotePort
);
108 SIN_FAMILY ( RemotePort
) = AF_INET
;
109 SIN_ADDR ( RemotePort
) = ( RemoteAddress
[3] << 24 )
110 | ( RemoteAddress
[2] << 16 )
111 | ( RemoteAddress
[1] << 8 )
113 SIN_PORT ( RemotePort
) = htons ( PortNumber
);
116 // Connect to the remote server
118 RetVal
= connect ( s
, (struct sockaddr
*)&RemotePort
, sizeof ( RemotePort
));
119 if ( -1 == RetVal
) {
121 printf ( "ERROR - connect error, errno: %d\r\n", RetVal
);
126 // Select the OOB processing
128 OobInLine
= ( 2 < ArgC
);
129 RetVal
= setsockopt ( s
,
133 sizeof ( OobInLine
));
134 if ( -1 == RetVal
) {
136 printf ( "ERROR - setsockopt OOBINLINE error, errno: %d\r\n", RetVal
);
139 printf ( "%s\r\n", ( 0 != OobInLine
) ? "OOB messages are in-line"
140 : "OOB messages move to the head of the queue" );
143 // Initialize the messages
145 memset ( &mBuffer
[0], 0, sizeof ( mBuffer
));
146 memset ( &mOob
[0], 0x11, sizeof ( mOob
));
149 // Send the data before the out-of-band message
151 TransmittedBefore
= 0;
152 for ( Index
= 0; TX_MSGS_BEFORE
> Index
; Index
++ ) {
155 BytesTransmitted
= send ( s
,
157 sizeof ( mBuffer
) - BytesSent
,
159 if ( -1 == BytesTransmitted
) {
161 printf ( "ERROR - send before error, errno: %d\r\n", RetVal
);
164 BytesSent
+= (UINT32
)BytesTransmitted
;
166 } while ( sizeof ( mBuffer
) > BytesSent
);
170 TransmittedBefore
+= BytesSent
;
177 // Send the out-of-band message
181 BytesTransmitted
= send ( s
,
183 sizeof ( mOob
) - BytesSent
,
185 if ( -1 == BytesTransmitted
) {
187 printf ( "ERROR - send OOB error, errno: %d\r\n", RetVal
);
190 BytesSent
+= (UINT32
)BytesTransmitted
;
192 } while ( sizeof ( mOob
) > BytesSent
);
196 TransmittedOob
= BytesSent
;
199 // Send the data after the out-of-band message
201 TransmittedAfter
= 0;
202 for ( Index
= 0; TX_MSGS_AFTER
> Index
; Index
++ ) {
205 BytesTransmitted
= send ( s
,
207 sizeof ( mBuffer
) - BytesSent
,
209 if ( -1 == BytesTransmitted
) {
211 printf ( "ERROR - send after error, errno: %d\r\n", RetVal
);
214 BytesSent
+= (UINT32
)BytesTransmitted
;
216 } while ( sizeof ( mBuffer
) > BytesSent
);
220 TransmittedAfter
+= BytesSent
;
224 // Test completed successfully
227 printf ( "Bytes before OOB: %8d\r\n", TransmittedBefore
);
228 printf ( "Out-of-band bytes: %8d\r\n", TransmittedOob
);
229 printf ( "Bytes after OOB: %8d\r\n", TransmittedAfter
);
230 printf ( " --------\r\n" );
231 printf ( "Total Bytes: %8d\r\n", TransmittedBefore
233 + TransmittedAfter
);
245 // Return the operation status