2 Raw IP4 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.
20 Transmit raw IP4 packets to the remote system.
22 @param [in] ArgC Argument count
23 @param [in] ArgV Argument value array
25 @retval 0 Successfully operation
35 ssize_t BytesTransmitted
;
36 struct sockaddr_in LocalPort
;
37 UINT32 RemoteAddress
[4];
38 struct sockaddr_in RemotePort
;
46 s
= socket ( AF_INET
, SOCK_RAW
, RAW_PROTOCOL
);
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>\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 memset ( &RemotePort
, 0, sizeof ( RemotePort
));
100 SIN_LEN ( RemotePort
) = sizeof ( RemotePort
);
101 SIN_FAMILY ( RemotePort
) = AF_INET
;
102 SIN_ADDR ( RemotePort
) = ( RemoteAddress
[3] << 24 )
103 | ( RemoteAddress
[2] << 16 )
104 | ( RemoteAddress
[1] << 8 )
106 SIN_PORT ( RemotePort
) = 0;
109 // Initialize the messages
111 memset ( &mBuffer
[0], 0, sizeof ( mBuffer
));
114 // Send the data before the out-of-band message
119 BytesTransmitted
= sendto ( s
,
121 sizeof ( mBuffer
) - BytesSent
,
123 (struct sockaddr
*)&RemotePort
,
124 sizeof ( RemotePort
));
125 if ( -1 == BytesTransmitted
) {
127 printf ( "ERROR - send before error, errno: %d\r\n", RetVal
);
130 BytesSent
+= (UINT32
)BytesTransmitted
;
132 } while ( sizeof ( mBuffer
) > BytesSent
);
136 TotalSent
+= BytesSent
;
139 // Test completed successfully
142 printf ( "Bytes sent: %8d\r\n", TotalSent
);
154 // Return the operation status