[C] Sockety - Linux a Windows

0

Witajcie!
Muszę na Windowsie uruchomic program, ktory wiem ze dzialal pod Linuxem. Program łączy sie z innym kompem poprzez socketa (ip i port podawane z linii poleceń jako argumenty) i pobiera czekające tam na niego dane. Wiem że to działało pod Linuxem, ale czy pójdzie jak to skompiluje(i czy w ogole sie skompiluje?) i odpale pod Winda? Moglibyscie zerknąć na kod i mi powiedziec czy to zadziala, czy moze trzeba cos przerobic?
Bede wdzieczny za pomoc
Pozdrawiam.

#include<stdio.h>
#include<stdlib.h>
#include<unistd.h>
#include<sys/socket.h>
#include<sys/types.h>
#include<netinet/in.h>
#include<strings.h>
#include<arpa/inet.h>
#include<string.h>

#define ERROR	-1
#define BUFFER	10000


main(int argc, char **argv)
{
	struct sockaddr_in remote_server;
	int sock;
	char input[BUFFER];
	char output[BUFFER];
	int len;
	
	
	if((sock = socket(AF_INET, SOCK_STREAM, 0)) == ERROR)
	{
		perror("socket");
		exit(-1);
	}
		
	remote_server.sin_family = AF_INET;
	remote_server.sin_port = htons(atoi(argv[2]));
	remote_server.sin_addr.s_addr = inet_addr(argv[1]);
	bzero(&remote_server.sin_zero, 8);
	
	if((connect(sock, (struct sockaddr *)&remote_server, sizeof(struct sockaddr_in))) == ERROR)
	{
		perror("connect");
		exit(-1);
	}
	
		len = recv(sock, output, BUFFER, 0);
		output[len] = '\0';
		printf("%s\n", output);
	
	close(sock);
		
}
0

Robilem coś takiego, żeby działało pod dwoma systemami:

#define linux (!defined (__WIN32__) || defined (_POSIX_VERSION))

#if linux

#include <sys/socket.h>
#include <sys/signal.h>
#include <fcntl.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <unistd.h>

#else
#include <winsock2.h>
#define socklen_t int
#endif

Oprócz tego pod windowsem zamiast close użyłem closesocket, a podczas przełączania gniazda w tryb nieblokujący robilem coś takiego:

#if linux
fcntl(socket,F_SETFL,O_NONBLOCK|fcntl(socket,F_GETFL,0));
#else
unsigned long nonblocking = 1;
ioctlsocket(socket, FIONBIO, (unsigned long*) &nonblocking);
#endif

1 użytkowników online, w tym zalogowanych: 0, gości: 1