]>
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. All rights reserved.
5 SPDX-License-Identifier: BSD-2-Clause-Patent
15 Transmit out-of-band messages to the remote system.
17 @param [in] ArgC Argument count
18 @param [in] ArgV Argument value array
20 @retval 0 Successfully operation
30 ssize_t BytesTransmitted
;
32 struct sockaddr_in LocalPort
;
35 UINT32 RemoteAddress
[4];
36 struct sockaddr_in RemotePort
;
38 UINT32 TransmittedAfter
;
39 UINT32 TransmittedBefore
;
40 UINT32 TransmittedOob
;
46 s
= socket ( AF_INET
, SOCK_STREAM
, IPPROTO_TCP
);
49 printf ( "ERROR - socket error, errno: %d\r\n", RetVal
);
53 // Use for/break; instead of goto
57 // Validate the arguments
60 || ( 4 != sscanf ( ArgV
[1],
66 || ( 224 < RemoteAddress
[0])
67 || ( 255 < RemoteAddress
[1])
68 || ( 255 < RemoteAddress
[2])
69 || ( 255 < RemoteAddress
[3])
70 || (( 0 == RemoteAddress
[0])
71 && ( 0 == RemoteAddress
[1])
72 && ( 0 == RemoteAddress
[2])
73 && ( 0 == RemoteAddress
[3]))) {
74 printf ( "%s <remote IP address> [optional: enables in-line OOB]\r\n", ArgV
[0]);
80 // Bind the socket to a local port
82 memset ( &LocalPort
, 0, sizeof ( LocalPort
));
83 SIN_LEN ( LocalPort
) = sizeof ( LocalPort
);
84 SIN_FAMILY ( LocalPort
) = AF_INET
;
85 SIN_ADDR ( LocalPort
) = 0;
86 SIN_PORT ( LocalPort
) = 0;
88 (struct sockaddr
*)&LocalPort
,
89 sizeof ( LocalPort
));
92 printf ( "ERROR - bind error, errno: %d\r\n", RetVal
);
97 // Specify the remote port
99 PortNumber
= OOB_RX_PORT
;
100 memset ( &RemotePort
, 0, sizeof ( RemotePort
));
101 SIN_LEN ( RemotePort
) = sizeof ( RemotePort
);
102 SIN_FAMILY ( RemotePort
) = AF_INET
;
103 SIN_ADDR ( RemotePort
) = ( RemoteAddress
[3] << 24 )
104 | ( RemoteAddress
[2] << 16 )
105 | ( RemoteAddress
[1] << 8 )
107 SIN_PORT ( RemotePort
) = htons ( PortNumber
);
110 // Connect to the remote server
112 RetVal
= connect ( s
, (struct sockaddr
*)&RemotePort
, sizeof ( RemotePort
));
113 if ( -1 == RetVal
) {
115 printf ( "ERROR - connect error, errno: %d\r\n", RetVal
);
120 // Select the OOB processing
122 OobInLine
= ( 2 < ArgC
);
123 RetVal
= setsockopt ( s
,
127 sizeof ( OobInLine
));
128 if ( -1 == RetVal
) {
130 printf ( "ERROR - setsockopt OOBINLINE error, errno: %d\r\n", RetVal
);
133 printf ( "%s\r\n", ( 0 != OobInLine
) ? "OOB messages are in-line"
134 : "OOB messages move to the head of the queue" );
137 // Initialize the messages
139 memset ( &mBuffer
[0], 0, sizeof ( mBuffer
));
140 memset ( &mOob
[0], 0x11, sizeof ( mOob
));
143 // Send the data before the out-of-band message
145 TransmittedBefore
= 0;
146 for ( Index
= 0; TX_MSGS_BEFORE
> Index
; Index
++ ) {
149 BytesTransmitted
= send ( s
,
151 sizeof ( mBuffer
) - BytesSent
,
153 if ( -1 == BytesTransmitted
) {
155 printf ( "ERROR - send before error, errno: %d\r\n", RetVal
);
158 BytesSent
+= (UINT32
)BytesTransmitted
;
160 } while ( sizeof ( mBuffer
) > BytesSent
);
164 TransmittedBefore
+= BytesSent
;
171 // Send the out-of-band message
175 BytesTransmitted
= send ( s
,
177 sizeof ( mOob
) - BytesSent
,
179 if ( -1 == BytesTransmitted
) {
181 printf ( "ERROR - send OOB error, errno: %d\r\n", RetVal
);
184 BytesSent
+= (UINT32
)BytesTransmitted
;
186 } while ( sizeof ( mOob
) > BytesSent
);
190 TransmittedOob
= BytesSent
;
193 // Send the data after the out-of-band message
195 TransmittedAfter
= 0;
196 for ( Index
= 0; TX_MSGS_AFTER
> Index
; Index
++ ) {
199 BytesTransmitted
= send ( s
,
201 sizeof ( mBuffer
) - BytesSent
,
203 if ( -1 == BytesTransmitted
) {
205 printf ( "ERROR - send after error, errno: %d\r\n", RetVal
);
208 BytesSent
+= (UINT32
)BytesTransmitted
;
210 } while ( sizeof ( mBuffer
) > BytesSent
);
214 TransmittedAfter
+= BytesSent
;
218 // Test completed successfully
221 printf ( "Bytes before OOB: %8d\r\n", TransmittedBefore
);
222 printf ( "Out-of-band bytes: %8d\r\n", TransmittedOob
);
223 printf ( "Bytes after OOB: %8d\r\n", TransmittedAfter
);
224 printf ( " --------\r\n" );
225 printf ( "Total Bytes: %8d\r\n", TransmittedBefore
227 + TransmittedAfter
);
239 // Return the operation status