求一小程序的注释

来源:百度知道 编辑:UC知道 时间:2024/06/07 14:39:44
这是一个获得本地IP地址的程序,由于本人不懂winsock,求高手给上注释,最好每一行都注释上。
#include <windows.h>
#include <WINSOCK.H>
#include "stdio.h"
#include "stdlib.h"
#pragma comment(lib, "Ws2_32.lib")
void main()
{
char host[50],i[50],a=12;
struct hostent *hostent;
unsigned long *ip;
struct in_addr in;
WORD wVersionRequested;
WSADATA wsaData;
int err,num;
wVersionRequested = MAKEWORD( 2, 0 );
err = WSAStartup( wVersionRequested, &wsaData );
if ( err != 0 ) {
return;
}

num=gethostname(host,20);
hostent=gethostbyname(host);
in.S_un.S_addr=inet_addr("10.10.74.254");
ip=(unsigned long *)hostent->h_addr_list[0];
in.S_un.S_addr=(*ip);
printf("%s\n",hostent->h_name);

#include <windows.h>
#include <WINSOCK.H>//网络库
#include "stdio.h"
#include "stdlib.h"
#pragma comment(lib, "Ws2_32.lib")//把Ws2_32.lib加入项目
void main()
{
char host[50],i[50],a=12;
struct hostent *hostent;
unsigned long *ip;
struct in_addr in;
WORD wVersionRequested;
WSADATA wsaData;
int err,num;
wVersionRequested = MAKEWORD( 2, 0 );//用winsock2版
err = WSAStartup( wVersionRequested, &wsaData );//建立
if ( err != 0 ) {
return;//如果建立失败,退出
}

num=gethostname(host,20);//获取host的计算机名
hostent=gethostbyname(host);//获取host的IP
in.S_un.S_addr=inet_addr("10.10.74.254");//IP
ip=(unsigned long *)hostent->h_addr_list[0];//IP
in.S_un.S_addr=(*ip);
printf("%s\n",hostent->h_name);//打印主机名
printf("%s\n",inet_ntoa(in));//打印IP

}

让我先看看.....再帮你写注释