diff --git a/boot_loader/examples/ethernet/Ethernet_boot/pcsendpkt.c b/boot_loader/examples/ethernet/Ethernet_boot/pcsendpkt.c
index c3c07fd13667b9e3e8f68e744612d2baacf08dfb..685cf462890c79c12890a52a7dc2ad4ad23f91ea 100644 (file)
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*****************************************************************************/
-#include <windows.h>
+
#include <stdio.h>
+#include <stdlib.h>
#include <time.h>
-#include <winsock.h>
+#ifdef __WIN32__
+ #include <windows.h>
+ #include <winsock.h>
+#else
+ #include <sys/types.h>
+ #include <sys/socket.h>
+ #include <netinet/in.h>
+ #include <netdb.h>
+#endif
+
#define UDP_LOW 42
#define UDP_HIGH 1504 // Note: Windows FRAGMENTS higher UDP sizes
int main( int argc, char *argv[] )
{
+
+#ifdef __WIN32__
WORD wVersionRequested;
WSADATA wsaData;
SOCKET s;
+#else
+ int s;
+#endif
+
struct sockaddr_in sin;
unsigned char *pBuf = 0;
int tmp1,tmp2,tmp3,tmp4;
fgets (iline, 131, strin);
fgets (iline, 131, strin);
+#ifdef __WIN32__
wVersionRequested = MAKEWORD(1, 1);
tmp2 = WSAStartup(wVersionRequested, &wsaData);
if (tmp2 != 0)
printf("\r\nUnable to initialize WinSock for host info");
exit(0);
}
+#endif
s = socket( AF_INET, SOCK_DGRAM, 0 );
if( s < 0 )
{
+#ifdef __WIN32__
printf("failed connect (%d)\n",WSAGetLastError());
+#else
+ perror("failed connect");
+#endif
goto end;
}
if ( bind( s, (struct sockaddr *)&sin, sizeof(sin) ) < 0 )
{
+#ifdef __WIN32__
printf("failed bind (%d)\n",WSAGetLastError());
+#else
+ perror("failed bind");
+#endif
goto end;
}
/* send out the packet */
if( sendto( s, pBuf, length, 0, (struct sockaddr *)&sin, sizeof(sin) ) < 0 )
{
- printf("send failed (%d)\n",WSAGetLastError());
+#ifdef __WIN32__
+ printf("send failed (%d)\n",WSAGetLastError());
+#else
+ perror("send failed");
+#endif
break;
}
}
tn = time(0) - ts;
- printf("Exiting . Time = %d seconds, Total Packets = %d",tn,packetno);
+ printf("Exiting . Time = %d seconds, Total Packets = %d\n",(int)tn,packetno);
/* clean up */
end:
if( pBuf )
free( pBuf );
if( s >= 0 )
+#ifdef __WIN32__
closesocket( s );
+#else
+ shutdown(s,SHUT_RDWR);
+#endif
+#ifdef __WIN32__
WSACleanup();
+#endif
}