#include <WinSock2.h>
#include <WinSock.h>
#include <process.h>
#include <time.h>
#include <iostream>
using namespace std;
class PoPSocket
{
public:
void Socket()
{
const int iReqWinsockVer = 2; // Minimum winsock version required
WSAData wsaData;
if (WSAStartup(MAKEWORD(iReqWinsockVer,0), &wsaData)==0)
{
// Check if major version is at least iReqWinsockVer
if (LOBYTE(wsaData.wVersion) >= iReqWinsockVer)
{
SOCKET hSocket;
hSocket = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
if (hSocket==INVALID_SOCKET)
{
// error handling code
MessageBox(0,"Invail Socket Handler",0,MB_ICONERROR);
closesocket(hSocket);
}
else
{
struct sockaddr
{
u_short sa_family;
char sa_data[14];
};
struct sockaddr_in
{
short sin_family;
u_short sin_port;
struct in_addr sin_addr;
char sin_zero[8];
};
// Convert a u_short from host to TCP/IP network byte order.
u_short htons(u_short hostshort);
}
}
else
{
// Required version not available
MessageBox(0,"Required version of WinSoc not available",0,MB_ICONERROR);
}
// Cleanup winsock
if (WSACleanup()!=0)
{
// cleanup failed
MessageBox(0,"Winsoc cleanup failed",0,MB_ICONERROR);
}
}
else
{
MessageBox(0,"Socket startup failed!",0,MB_ICONERROR);
}
}
};
so i can call it in the main.cpp as
PoPSocket soc;
soc.Socket();
but when am trying to finish the socket its keeping say
Error
Error 1 error C2373: 'htons' : redefinition; different type modifiers
2 IntelliSense: linkage specification is incompatible with previous "htons" (declared at line 1760 of "C:\Program Files\Microsoft SDKs\Windows\v7.0A\include\WinSock2.h")
can anyone please help me?!