套接字编程获取本机的ip地址
#include "WinSock.h"
#include <iostream>
using namespace std;
#pragma comment(lib, "ws2_32.lib")
int main()
{
char*ip;
char name[32];
WSADATA wsaData;
WORD sv = MAKEWORD(2, 0);
WSAStartup(sv, &wsaData);
PHOSTENT hostname;
gethostname (name, sizeof(name));
hostname = gethostbyname(name);
ip = inet_ntoa (*(struct in_addr *)*hostname->h_addr_list);
cout<<"IP:"<<ip<<endl<<"Name:"<<name<<endl;
return 0;
}
为了明天所以选择坚定的执着今天。