先总结一下求职面试必看的几本书:《编程之美》、《剑指offer》、《Unix环境编程》、《Unix网络编程》、《POSIX多线程编程》,突然感觉心里很踏实,不再像以前迷茫,终于知道计算机专业毕业的我到底能干什么,既然这样就认认真真的学习吧,争取拿到bat的实习offer,加油。
网络字节序:
由于不同的计算机系统采用不同的字节序存储数据,同样一个4字节的32位整数,在内存中存储的方式就不同. 字节序分为小尾字节序(Little Endian)和大尾字节序(Big Endian), Intel处理器大多数使用小尾字节序, Motorola处理器大多数使用大尾(Big Endian)字节序;
TCP/IP各层协议将字节序定义为大尾,因此TCP/IP协议中使用的字节序通常称之为网络字节序。
1、将IP转换成16进制数
/*************************************************************************
> File Name: my_atoh.c
> Author: Comst
> Mail:750145240@qq.com
> Created Time: Sat 07 Feb 2015 04:56:54 PM CST
************************************************************************/
#include<stdio.h>
#include<string.h>
#include<sys/socket.h>
#include<netinet/in.h>
#include<arpa/inet.h>
#define IP "180.97.33.107"// B461216B
int main(int argc, char* argv[])
{
struct in_addr addr ;
memset(&addr, 0, sizeof(addr));
inet_aton(IP, &addr);
memset(&addr, 0, sizeof(addr));
addr.s_addr = inet_addr(IP);
char* pstr = inet_ntoa(addr);
return 0 ;
}
2、查看域名的详细信息
/*************************************************************************
> File Name: my_host.c
> Author: Comst
> Mail:750145240@qq.com
> Created Time: Sat 07 Feb 2015 05:23:46 PM CST
************************************************************************/
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<netdb.h>
#include<sys/socket.h>
#include<netinet/in.h>
#include<arpa/inet.h>
int main(int argc, char* argv[])
{
struct hostent* pent ;
int i ;
pent = gethostbyname(argv[1]) ;
if(pent == NULL)
{
perror("host");
}
printf("h_name: %s\n", pent ->h_name);
for(i = 0; pent ->h_aliases[i] != NULL; i ++)
{
printf("aliase %d: %s\n", i, pent ->h_aliases[i]);
}
printf("addr_type: %d, len: %d\n", pent ->h_addrtype, pent ->h_length );
for(i = 0; pent ->h_addr_list[i] != NULL; i ++)
{
printf("ip %d: %s\n ", i, inet_ntoa( *(struct in_addr*)pent ->h_addr_list[i]) );
}
return 0 ;
}