]>
git.proxmox.com Git - mirror_edk2.git/blob - AppPkg/Applications/Sockets/RawIp4Tx/RawIp4Tx.c
2 Raw IP4 transmit application
4 Copyright (c) 2011-2012, Intel Corporation. All rights reserved.
5 SPDX-License-Identifier: BSD-2-Clause-Patent
14 Transmit raw IP4 packets to the remote system.
16 @param [in] ArgC Argument count
17 @param [in] ArgV Argument value array
19 @retval 0 Successfully operation
29 ssize_t BytesTransmitted
;
30 struct sockaddr_in LocalPort
;
31 UINT32 RemoteAddress
[4];
32 struct sockaddr_in RemotePort
;
40 s
= socket ( AF_INET
, SOCK_RAW
, RAW_PROTOCOL
);
43 printf ( "ERROR - socket error, errno: %d\r\n", RetVal
);
47 // Use for/break; instead of goto
51 // Validate the arguments
54 || ( 4 != sscanf ( ArgV
[1],
60 || ( 224 < RemoteAddress
[0])
61 || ( 255 < RemoteAddress
[1])
62 || ( 255 < RemoteAddress
[2])
63 || ( 255 < RemoteAddress
[3])
64 || (( 0 == RemoteAddress
[0])
65 && ( 0 == RemoteAddress
[1])
66 && ( 0 == RemoteAddress
[2])
67 && ( 0 == RemoteAddress
[3]))) {
68 printf ( "%s <remote IP address>\r\n", ArgV
[0]);
74 // Bind the socket to a local port
76 memset ( &LocalPort
, 0, sizeof ( LocalPort
));
77 SIN_LEN ( LocalPort
) = sizeof ( LocalPort
);
78 SIN_FAMILY ( LocalPort
) = AF_INET
;
79 SIN_ADDR ( LocalPort
) = 0;
80 SIN_PORT ( LocalPort
) = 0;
82 (struct sockaddr
*)&LocalPort
,
83 sizeof ( LocalPort
));
86 printf ( "ERROR - bind error, errno: %d\r\n", RetVal
);
91 // Specify the remote port
93 memset ( &RemotePort
, 0, sizeof ( RemotePort
));
94 SIN_LEN ( RemotePort
) = sizeof ( RemotePort
);
95 SIN_FAMILY ( RemotePort
) = AF_INET
;
96 SIN_ADDR ( RemotePort
) = ( RemoteAddress
[3] << 24 )
97 | ( RemoteAddress
[2] << 16 )
98 | ( RemoteAddress
[1] << 8 )
100 SIN_PORT ( RemotePort
) = 0;
103 // Initialize the messages
105 memset ( &mBuffer
[0], 0, sizeof ( mBuffer
));
108 // Send the data before the out-of-band message
113 BytesTransmitted
= sendto ( s
,
115 sizeof ( mBuffer
) - BytesSent
,
117 (struct sockaddr
*)&RemotePort
,
118 sizeof ( RemotePort
));
119 if ( -1 == BytesTransmitted
) {
121 printf ( "ERROR - send before error, errno: %d\r\n", RetVal
);
124 BytesSent
+= (UINT32
)BytesTransmitted
;
126 } while ( sizeof ( mBuffer
) > BytesSent
);
130 TotalSent
+= BytesSent
;
133 // Test completed successfully
136 printf ( "Bytes sent: %8d\r\n", TotalSent
);
148 // Return the operation status