雷火电竞-中国电竞赛事及体育赛事平台

歡迎來到入門教程網(wǎng)!

C語言

當(dāng)前位置:主頁 > 軟件編程 > C語言 >

C語言中網(wǎng)絡(luò)地址與二進(jìn)制數(shù)之間轉(zhuǎn)換的函數(shù)小結(jié)

來源:本站原創(chuàng)|時間:2020-01-10|欄目:C語言|點(diǎn)擊:

C語言inet_ntoa()函數(shù):將網(wǎng)絡(luò)二進(jìn)制的數(shù)字轉(zhuǎn)換成網(wǎng)絡(luò)地址
頭文件:

 #include <sys/socket.h>  #include <netinet/in.h>  #include <arpa/inet.h>

定義函數(shù):

char * inet_ntoa(struct in_addr in);

函數(shù)說明:inet_ntoa()用來將參數(shù)in 所指的網(wǎng)絡(luò)二進(jìn)制的數(shù)字轉(zhuǎn)換成網(wǎng)絡(luò)地址, 然后將指向此網(wǎng)絡(luò)地址字符串的指針返回.

返回值:成功則返回字符串指針, 失敗則返回NULL.

C語言inet_aton()函數(shù):將網(wǎng)絡(luò)地址轉(zhuǎn)成網(wǎng)絡(luò)二進(jìn)制的數(shù)字
頭文件:

#include <sys/scoket.h>  #include <netinet/in.h>  #include <arpa/inet.h>

定義函數(shù):

int inet_aton(const char * cp, struct in_addr *inp);

函數(shù)說明:inet_aton()用來將參數(shù)cp 所指的網(wǎng)絡(luò)地址字符串轉(zhuǎn)換成網(wǎng)絡(luò)使用的二進(jìn)制的數(shù)字, 然后存于參數(shù)inp 所指的in_addr 結(jié)構(gòu)中.

結(jié)構(gòu)in_addr 定義如下

struct in_addr
{
  unsigned long int s_addr;
};

返回值:成功則返回非0 值, 失敗則返回0.

C語言inet_addr()函數(shù):將網(wǎng)絡(luò)地址轉(zhuǎn)成二進(jìn)制的數(shù)字
頭文件:

#include <sys/socket.h>  #include <netinet/in.h>  #include <arpa/inet.h>

定義函數(shù):

unsigned long int inet_addr(const char *cp);

函數(shù)說明:inet_addr()用來將參數(shù)cp 所指的網(wǎng)絡(luò)地址字符串轉(zhuǎn)換成網(wǎng)絡(luò)所使用的二進(jìn)制數(shù)字. 網(wǎng)絡(luò)地址字符串是以數(shù)字和點(diǎn)組成的字符串, 例如:"163. 13. 132. 68".

返回值:成功則返回對應(yīng)的網(wǎng)絡(luò)二進(jìn)制的數(shù)字, 失敗返回-1.

上一篇:C語言中g(shù)etopt()函數(shù)和select()函數(shù)的使用方法

欄    目:C語言

下一篇:C語言的isatty函數(shù)和ttyname函數(shù)以及sendmsg函數(shù)用法

本文標(biāo)題:C語言中網(wǎng)絡(luò)地址與二進(jìn)制數(shù)之間轉(zhuǎn)換的函數(shù)小結(jié)

本文地址:http://www.jygsgssxh.com/a1/Cyuyan/2773.html

網(wǎng)頁制作CMS教程網(wǎng)絡(luò)編程軟件編程腳本語言數(shù)據(jù)庫服務(wù)器

如果侵犯了您的權(quán)利,請與我們聯(lián)系,我們將在24小時內(nèi)進(jìn)行處理、任何非本站因素導(dǎo)致的法律后果,本站均不負(fù)任何責(zé)任。

聯(lián)系QQ:835971066 | 郵箱:835971066#qq.com(#換成@)

Copyright © 2002-2020 腳本教程網(wǎng) 版權(quán)所有