Skocz do zawartości
  • 👋 Witaj na MPCForum!

    Przeglądasz forum jako gość, co oznacza, że wiele świetnych funkcji jest jeszcze przed Tobą! 😎

    • Pełny dostęp do działów i ukrytych treści
    • Możliwość pisania i odpowiadania w tematach
    • System prywatnych wiadomości
    • Zbieranie reputacji i rozwijanie swojego profilu
    • Członkostwo w jednej z największych społeczności graczy

    👉 Dołączenie zajmie Ci mniej niż minutę – a zyskasz znacznie więcej!

    Zarejestruj się teraz

Winsock problem z gethostbyname


Rekomendowane odpowiedzi

Opublikowano

Witam zacząłem nauke winsocka, i wystąpiła pierwsza przeszkoda przy nauce ten błąd :

error C4996: 'gethostbyname': Use getaddrinfo() or GetAddrInfoW() instead or define _WINSOCK_DEPRECATED_NO_WARNINGS to disable deprecated API warnings.

a tu kod :

	if((host=gethostbyname("localhost"))==NULL)
	{
		std::cout << "Nie mozna rozpoznac nazwy hosta\r\n";
		WSACleanup();
		system("PAUSE");
		return 0;
	}

Niby problem powinien minąć po zmianie gethostbyname na getaddrinfo() lub GetAddrInfoW()

ale potem pojawia sie nastepny error 

Dla getaddrinfo
if ((host=getaddrinfo("localhost")) == NULL)
error C3861: 'getaddrinfo': identifier not found
IntelliSense: identifier "getaddrinfo" is undefined


Dla GetAddrIndoW
if ((host=GetAddrInfoW("localhost")) == NULL)
error C3861: 'GetAddrInfoW': identifier not found
IntelliSense: identifier "GetAddrInfoW" is undefined

Jak takie błędy naprawic?

 

Bilbioteki jakich używam : 

#include "stdafx.h"
#include <iostream>
#include <WinSock2.h>
#pragma comment(lib,"ws2_32.lib")
Opublikowano

IntelliSense: identifier "GetAddrInfoW" is undefined

znaczy ze visual nie wie co to znaczy - rownie dobrze mozesz napisac int x = asdhasdjasdsa(1,2,3,4,5) i visual tez nie bedzie wiedzial co to - poszukaj w jakim includzie znajduje sie ta funkcja.

 

cytat z stackoverflow:

 

 

On Windows, instead of the includes you have mentioned, the following should suffice:

#include <winsock2.h>

#include <windows.h>

You'll also have to link to ws2_32.lib. It's kind of ugly to do it this way, but for VC++ you can do this via: #pragma comment(lib, "ws2_32.lib")

Some other differences between Winsock and POSIX include:

  • You will have to call WSAStartup() before using any socket functions.

  • close() is now called closesocket().

  • Instead of passing sockets as int, there is a typedef SOCKET equal to the size of a pointer. You can still use comparisons with -1 for error, though Microsoft has a macro called INVALID_SOCKET to hide this.

  • For things like setting non-blocking flags, you'll use ioctlsocket() instead of fcntl().

  • You'll have to use send() and recv() instead of write() and read().

Zarchiwizowany

Ten temat przebywa obecnie w archiwum. Dodawanie nowych odpowiedzi zostało zablokowane.

×
×
  • Dodaj nową pozycję...