免费视频淫片aa毛片_日韩高清在线亚洲专区vr_日韩大片免费观看视频播放_亚洲欧美国产精品完整版

打開APP
userphoto
未登錄

開通VIP,暢享免費(fèi)電子書等14項(xiàng)超值服

開通VIP
htonl、ntohl、htons、ntohs函數(shù)實(shí)現(xiàn)

htonl、ntohl、htons、ntohs函數(shù)實(shí)現(xiàn)

2012年02月24日 12:15:25 閱讀數(shù):14216 標(biāo)簽: 網(wǎng)絡(luò) 更多
個(gè)人分類: C/C++ 網(wǎng)絡(luò)通信

typedef unsigned short int uint16;

typedef unsigned long int uint32;

 

// 短整型大小端互換

#define BigLittleSwap16(A)  ((((uint16)(A) & 0xff00) >> 8) | \

                            (((uint16)(A) & 0x00ff) << 8))

 // 長(zhǎng)整型大小端互換

 

#define BigLittleSwap32(A)  ((((uint32)(A) & 0xff000000) >> 24) | \

                            (((uint32)(A) & 0x00ff0000) >> 8) | \

                            (((uint32)(A) & 0x0000ff00) << 8) | \

                            (((uint32)(A) & 0x000000ff) << 24))


 // 本機(jī)大端返回1,小端返回0

int checkCPUendian()

{

       union{

              unsigned long int i;

              unsigned char s[4];

       }c;

 

       c.i = 0x12345678;

       return (0x12 == c.s[0]);

}

 

// 模擬htonl函數(shù),本機(jī)字節(jié)序轉(zhuǎn)網(wǎng)絡(luò)字節(jié)序

unsigned long int t_htonl(unsigned long int h)

{

       // 若本機(jī)為大端,與網(wǎng)絡(luò)字節(jié)序同,直接返回

       // 若本機(jī)為小端,轉(zhuǎn)換成大端再返回

       return checkCPUendian() ? h : BigLittleSwap32(h);

}

 

// 模擬ntohl函數(shù),網(wǎng)絡(luò)字節(jié)序轉(zhuǎn)本機(jī)字節(jié)序

unsigned long int t_ntohl(unsigned long int n)

{

       // 若本機(jī)為大端,與網(wǎng)絡(luò)字節(jié)序同,直接返回

       // 若本機(jī)為小端,網(wǎng)絡(luò)數(shù)據(jù)轉(zhuǎn)換成小端再返回

       return checkCPUendian() ? n : BigLittleSwap32(n);

}

 

// 模擬htons函數(shù),本機(jī)字節(jié)序轉(zhuǎn)網(wǎng)絡(luò)字節(jié)序

unsigned short int t_htons(unsigned short int h)

{

       // 若本機(jī)為大端,與網(wǎng)絡(luò)字節(jié)序同,直接返回

       // 若本機(jī)為小端,轉(zhuǎn)換成大端再返回

       return checkCPUendian() ? h : BigLittleSwap16(h);

}

 

// 模擬ntohs函數(shù),網(wǎng)絡(luò)字節(jié)序轉(zhuǎn)本機(jī)字節(jié)序

unsigned short int t_ntohs(unsigned short int n)

{

       // 若本機(jī)為大端,與網(wǎng)絡(luò)字節(jié)序同,直接返回

       // 若本機(jī)為小端,網(wǎng)絡(luò)數(shù)據(jù)轉(zhuǎn)換成小端再返回

       return checkCPUendian() ? n : BigLittleSwap16(n);

}

本站僅提供存儲(chǔ)服務(wù),所有內(nèi)容均由用戶發(fā)布,如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請(qǐng)點(diǎn)擊舉報(bào)。
打開APP,閱讀全文并永久保存 查看更多類似文章
猜你喜歡
類似文章
高低字節(jié)序轉(zhuǎn)換(htonl、ntohl、htons、ntohs函數(shù))
網(wǎng)絡(luò)通信之htonl()、htons()、ntohl()、ntohs()四個(gè)函數(shù)以及小端大端(小尾大尾)模式
htonl,htons,ntohl,ntohs的詳解
字節(jié)序(byte order)和位序(bit order)
字節(jié)存儲(chǔ)排序:大端和小端的判別及轉(zhuǎn)換
進(jìn)擊的小白Day015——char與int互相轉(zhuǎn)換
更多類似文章 >>
生活服務(wù)
分享 收藏 導(dǎo)長(zhǎng)圖 關(guān)注 下載文章
綁定賬號(hào)成功
后續(xù)可登錄賬號(hào)暢享VIP特權(quán)!
如果VIP功能使用有故障,
可點(diǎn)擊這里聯(lián)系客服!

聯(lián)系客服