您的位置:首页 > 其它

h_errno

2016-06-16 15:04 369 查看
#include <stdio.h>
#include <netdb.h>
#include <iostream>
#include <string.h>
#include <errno.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>

using namespace std;

int main(int argc, char *argv [])
{
char sz [] = "Hello, World!";	//Hover mouse over "sz" while debugging to see its contents
cout << sz << endl;	//<================= Put a breakpoint here

//打印错误网络信息
char szError [] = "err:";
herror(szError);

extern int h_errno;

for (int i=0;i<5;i++)
{
printf("%d---%s\n", i, hstrerror(i));
}

int port = 1234;
printf("%d\n", htons(port));		//转换网络字节序 //53764
printf("%d\n", ntohs(htons(port))); //转换本地字节序 //1234

struct in_addr ip;
ip.s_addr = 16777343;
printf("%s\n", inet_ntoa(ip));	//127.0.0.1

char szip [] = "127.0.0.1";
printf("%d\n", inet_addr(szip));//16777343
return 0;
}

/*
Hello, World!
err:: Resolver Error 0 (no error)
0---Resolver Error 0 (no error)
1---Unknown host
2---Host name lookup failure
3---Unknown server error
4---No address associated with name
53764
1234
127.0.0.1
16777343

*/
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: