Im using sockets, but I have a problem entering the IP adress.
I want to enter an IP adress by number.
gethostbyname("www.website.com") does not solve it, I need IP adress of a computer, not a website.
Problem is, the format I have to enter it is complicated.
I can't just use an int/float/whatever.
I found the "solution" here:
http://msdn.microsoft.com/en-us/library/aa922011.aspx
But I don't understand it. Not a single letter of it.
Struct within a struct with variables between or something?
I never used structs, only simple classes.
Is there an alternative to all this quantum mechanics?
How do I solve this?
1 2 3 4 5
|
SOCKADDR_IN SockAddr;
SockAddr.sin_port = htons(80);
SockAddr.sin_family = AF_INET;
SockAddr.sin_addr.s_addr = // I want the IP adress here.. as simple as possible
|
EDIT: applied solution, new error:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
|
#include "Winsock2.h"
#include <iostream>
#include <sstream>
#include "Mstcpip.h"
#include "Ws2tcpip.h"
//#include <istream>
//using namespace std;
//#pragma comment(lib, "Ws2_32.lib")
std::string char2string(char[]);
int main()
{
std::stringstream ss;
std::cout << "Main called." << std::endl << "Enter IP adress..." << std::endl;
char input[100];
std::cin.getline(input, 12);
//std::cout << char2string(input) << std::endl;
SOCKADDR_IN SockAddr;
SockAddr.sin_port = htons(80);
SockAddr.sin_family = AF_INET;
inet_pton(AF_INET, input, &(SockAddr.sin_addr));
unsigned long adres = inet_addr(input);
std::cout << "Ip adress: " << adres << std::endl;
//system("pause");
return 0;
}
|
4 errors, all saying unresolved externals, they dont mention any line of code, just the .exe and 3 obj files... help?
Error 1 error LNK2019: unresolved external symbol __imp__htons@4 referenced in function _main D:\vsprojects\chatapplication\chatapplication\main.obj chatapplication
Error 2 error LNK2019: unresolved external symbol __imp__inet_addr@4 referenced in function _main D:\vsprojects\chatapplication\chatapplication\main.obj chatapplication