Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C++ header files for UDP in Windows?

I have a linux applications which sends data over UDP protocol. It uses these header files:

#include <stdio.h>
/* standard C i/o facilities */
#include <stdlib.h>
/* needed for atoi() */
#include <unistd.h>

/* defines STDIN_FILENO, system calls,etc */
#include <sys/types.h> /* system data type definitions */
#include <sys/socket.h> /* socket specific definitions */
#include <netinet/in.h> /* INET constants and stuff */
#include <arpa/inet.h> /* IP address conversion stuff */
#include <netdb.h>
#include <string.h> /* for string and memset etc */
/* gethostbyname */
#include <iostream>

#include <fstream>

#include <opencv/highgui.h>
#include <opencv/cv.h>
#include <opencv/cxcore.h> 

I want to make a WIndows version of my app. But some of the above header files do not work in WIndows, especially those for UDP.

Which header files should I substitute them for in Windows (Visual Studio 2010)?

UPDATE:

Ok, so my header now looks like this:

#include <iostream>
#include <fstream>
#include "stdafx.h"

#include <cv.h>
#include <cxcore.h>
#include <highgui.h>

#include <winsock2.h>

I get this error when trying to compile (and many other similar errors):

Error   13  error C2011: 'fd_set' : 'struct' type redefinition  c:\program files (x86)\microsoft sdks\windows\v7.0a\include\winsock2.h  132 1   Client
like image 945
Richard Knop Avatar asked Dec 13 '10 20:12

Richard Knop


1 Answers

At compile-time, you need to use Winsock2.h instead of the Unix headers.

At link-time, include ws2_32.lib to provide linkage to the required system DLL.

like image 169
Steve Townsend Avatar answered Sep 27 '22 23:09

Steve Townsend