Folge dem Video um zu sehen, wie unsere Website als Web-App auf dem Startbildschirm installiert werden kann.
Anmerkung: Diese Funktion ist in einigen Browsern möglicherweise nicht verfügbar.
#include "stdafx.h"
#include <iostream>
#include <winsock.h>
#include <windows.h>
int main(void)
{
int sock_fd = socket( AF_INET , SOCK_DGRAM , 0 );
if( sock_fd == -1 ) { printf("Error: creating socket.\n"); exit(1); }
struct ifreq ifr;
strcpy( ifr.ifr_name , interface );
if( ioctl( sock_fd , SIOCGIFADDR , &ifr ) == -1 ) { printf("problems with ioctl.\n"); exit(1); }
ip->saddr = inet_addr( inet_ntoa( ((struct sockaddr_in *) (&ifr.ifr_addr))->sin_addr ) );
close( sock_fd );
}
Warning 1 warning C4244: 'initializing' : conversion from 'SOCKET' to 'int', possible loss of data c:\c++ u c#\c++\projekte\ip\ip\ip.cpp 14
Error 6 error C3861: 'ioctl': identifier not found c:\c++ u c#\c++\projekte\ip\ip\ip.cpp 18
Error 11 error C3861: 'close': identifier not found c:\c++ u c#\c++\projekte\ip\ip\ip.cpp 20
Error 3 error C2228: left of '.ifr_name' must have class/struct/union c:\c++ u c#\c++\projekte\ip\ip\ip.cpp 17
Error 9 error C2228: left of '.ifr_addr' must have class/struct/union c:\c++ u c#\c++\projekte\ip\ip\ip.cpp 19
Error 10 error C2227: left of '->sin_addr' must point to class/struct/union/generic type c:\c++ u c#\c++\projekte\ip\ip\ip.cpp 19
Error 8 error C2227: left of '->saddr' must point to class/struct/union/generic type c:\c++ u c#\c++\projekte\ip\ip\ip.cpp 19
Error 2 error C2079: 'ifr' uses undefined struct 'main::ifreq' c:\c++ u c#\c++\projekte\ip\ip\ip.cpp 16
Error 5 error C2065: 'SIOCGIFADDR' : undeclared identifier c:\c++ u c#\c++\projekte\ip\ip\ip.cpp 18
Error 7 error C2065: 'ip' : undeclared identifier c:\c++ u c#\c++\projekte\ip\ip\ip.cpp 19
Error 4 error C2065: 'interface' : undeclared identifier c:\c++ u c#\c++\projekte\ip\ip\ip.cpp 17
#include "stdafx.h"
#include <conio.h>
#include <iostream.h>
#include <windows.h>
#pragma comment(lib,"ws2_32.lib") // für MSV C++
int main(int argc, char* argv[])
{
char hostname[255];
char *szIPAddress;
WORD wVer;
WSADATA wData;
PHOSTENT hostinfo;
wVer = MAKEWORD( 2, 0 );
if ( WSAStartup( wVer, &wData ) == 0 )
{
if( gethostname ( hostname, sizeof(hostname)) == 0)
{
if((hostinfo = gethostbyname(hostname)) != NULL)
{
szIPAddress = inet_ntoa (*(struct in_addr *)*hostinfo->h_addr_list);
}
}
WSACleanup();
}
cout<<szIPAddress<<endl;
getch();
return 0;
}
Die Datei brauchst du eigentlich nicht. Die wird vom Visual Studio automatisch generiert.Hey
woher bekomme ich die : stdafx.h ?
Error 4 error C2065: 'PHOSTENT' : undeclared identifier c:\c++ u c#\c++\projekte\ip\ip\ip.cpp 17
Error 3 error C2065: 'wData' : undeclared identifier c:\c++ u c#\c++\projekte\ip\ip\ip.cpp 16
Error 1 error C2065: 'WSADATA' : undeclared identifier c:\c++ u c#\c++\projekte\ip\ip\ip.cpp 16
Error 5 error C2146: syntax error : missing ';' before identifier 'hostinfo' c:\c++ u c#\c++\projekte\ip\ip\ip.cpp 17
Error 2 error C2146: syntax error : missing ';' before identifier 'wData' c:\c++ u c#\c++\projekte\ip\ip\ip.cpp 16
Error 10 error C2227: left of '->h_addr_list' must point to class/struct/union/generic type c:\c++ u c#\c++\projekte\ip\ip\ip.cpp 26
Error 9 error C3861: 'gethostbyname': identifier not found c:\c++ u c#\c++\projekte\ip\ip\ip.cpp 24
Error 8 error C3861: 'gethostname': identifier not found c:\c++ u c#\c++\projekte\ip\ip\ip.cpp 22
Error 11 error C3861: 'inet_ntoa': identifier not found c:\c++ u c#\c++\projekte\ip\ip\ip.cpp 26
Error 12 error C3861: 'WSACleanup': identifier not found c:\c++ u c#\c++\projekte\ip\ip\ip.cpp 29
Error 7 error C3861: 'WSAStartup': identifier not found c:\c++ u c#\c++\projekte\ip\ip\ip.cpp 20