[ DALIBORSUHANJI @ 06.06.2008. 09:49 ] @
Kako u c++ d adobijem adresu (IP ) racunara. Koristim dev c++ kao razvojno okruzenje
[ X Files @ 06.06.2008. 10:36 ] @
Na primetr:

Dev C++ : Project > Project Options > Parameters > Add Library or Object > [pronadji i selektuj] libwsock32.a > Ok

Code:

#include <cstdlib>
#include <iostream>

#include <winsock2.h>
using namespace std;

int main(int argc, char *argv[])
{
    WORD wVersionRequested;
    WSADATA wsaData;

    wVersionRequested = MAKEWORD(1, 1);
    WSAStartup(wVersionRequested, &wsaData);

    hostent *p;
    char s[128];
    char *p2;

    // Naziv racunara
    gethostname(s, 128);
    p = gethostbyname(s);
    cout << p->h_name << endl;

    // IP adresa
    p2 = inet_ntoa(*((in_addr *)p->h_addr));
    cout << p2 << endl;

    WSACleanup();

    system("PAUSE");
    return EXIT_SUCCESS;
}
[ Burgos @ 06.06.2008. 10:46 ] @
UTFG

Code:

// class.cpp : Defines the entry point for the console application.
//

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

#include <winsock2.h>

// Add 'ws2_32.lib' to your linker options







int _tmain(int argc, _TCHAR* argv[])
{
    WSADATA WSAData;

    // Initialize winsock dll
    if(::WSAStartup(MAKEWORD(1, 0), &WSAData))
    {
        // Error handling
    }

    // Get local host name
    char szHostName[128] = "";

    if(::gethostname(szHostName, sizeof(szHostName)))
    {
        // Error handling -> call 'WSAGetLastError()'
    }

    // Get local IP addresses
    struct sockaddr_in SocketAddress;
    struct hostent     *pHost        = 0;

    pHost = ::gethostbyname(szHostName);
    if(!pHost)
    {
        // Error handling -> call 'WSAGetLastError()'
    }

    char aszIPAddresses[10][16]; // maximum of ten IP addresses

    for(int iCnt = 0; ((pHost->h_addr_list[iCnt]) && (iCnt < 10)); ++iCnt)
    {
        memcpy(&SocketAddress.sin_addr, pHost->h_addr_list[iCnt], pHost->h_length);
        strcpy_s(aszIPAddresses[iCnt], inet_ntoa(SocketAddress.sin_addr));
        std::cout << aszIPAddresses[iCnt] << std::endl;
    }

    
    // Cleanup
    WSACleanup();
}

[ DALIBORSUHANJI @ 06.06.2008. 10:51 ] @
hvala svima na brzom odgovoru. Ovo radi
[ DALIBORSUHANJI @ 06.06.2008. 21:52 ] @
a kako da niteram visual c++ da ovo pokrene
[ X Files @ 07.06.2008. 07:08 ] @
Burgos ti je vec rekao: UTFG (Use The Fucking Google)

Sve je to isto, obicno je razlika donekle u verziji include datoteka i/ili biblioteka koje se ukljucuju u projekat.

http://tangentsoft.net/wskfaq/examples/ipaddr.html