Chinaunix首页 | 论坛 | 博客
  • 博客访问: 78754
  • 博文数量: 18
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 228
  • 用 户 组: 普通用户
  • 注册时间: 2014-04-15 16:53
文章分类
文章存档

2015年(4)

2014年(14)

我的朋友

分类: 嵌入式

2015-02-26 10:07:33

#include
#include
#include
#include
#include
#include
#include
#include
#include
#include






/*****************************************************


struct sockaddr_in {
short int sin_family;
unsigned short int sin_port;
struct in_addr sin_addr;
unsigned char sin_zero[8];
};




struct in_addr {
    in_addr_t s_addr;
};


????


1.????×????ò?°??×???????
* unsigned short int htons(unsigned short int hostshort):
?÷?ú×????ò×?????????×????ò??????·???????4×???


2?÷?ú×????ò×?????????×????ò??????·???????8×???
* unsigned long int htonl(unsigned long int hostlong):


3.????×????ò×??????÷?ú×????ò
* unsigned short int ntohs(unsigned short int netshort)
* unsigned long int ntohl(unsigned long int netlong)


????
IP???·×???????3??


????×?????????×?·???IP???·×?????????×????ò????????IP???·
1.
struct sockaddr_in ina??
ina.sin_addr.s_addr=inet_addr("202.206.17.101")??


unsigned long int inet_addr(const char *cp);??????????????×?????±í????IP???·×?·???????×?????????·????¤????????????????????????×????ò????????


2.int inet_aton(const char *cp, struct in_addr *inp); ???????????????????????ù??????·???1???§°?·???0




3??char *inet_nota(struct in_addr in);????????????????IP×?????????????×???±í????×?·?????????




????
?à×??????í??SOCKET???·???à??????????×???
1.void bzero(void * s,int n);??s???¨?????·?°n×????è??0
2.void bcopy(const void * src,void * dest,int n)????src???¨?????????ò??±???dst??????
3.int bcmp(const void * s1,const void * s2,int n);????±??????????à??·???0??·??ò·???·?0


**********************************************************************************************/


int main(int argc, char **argv)
{
struct sockaddr_in sockadd;
int i = 0;
sockadd.sin_addr.s_addr = inet_addr("192.168.0.244");//将点字符串格式的IP转换为unsigned int 型的
char *p;
p = (char *)&sockadd.sin_addr.s_addr;


for(i = 0 ;i< 4;i++){
printf("0x%2x\n",*p);//打印每个字节的数据
p++;
}


//sockaddr.sin_addr.s_addr = 0x012BA8C0;


printf("%s\n",inet_ntoa(sockadd.sin_addr));//将unsigned int 类型的IP转换为点字符串型的


}

阅读(2573) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~