博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
inet_ntoa()
阅读量:4049 次
发布时间:2019-05-25

本文共 942 字,大约阅读时间需要 3 分钟。

功能:
将一个IP转换成一个互联网标准点分格式的字符串。
原型:
char FAR * inet_ntoa( struct in_addr in);
头文件:

arpa/inet.h

inet_ntoa()返回的字符串是临时装在一个静态分配的缓冲区里面,下一次调用此函数的时候缓冲区会被重写 

源码如下:

char *inet_ntoa (struct in_addr in){  __libc_once_define (static, once);  char *buffer;  unsigned char *bytes;  /* If we have not yet initialized the buffer do it now.  */  __libc_once (once, init);  if (static_buf != NULL)    buffer = static_buf;  else    {      /* We don't use the static buffer and so we have a key.  Use it	 to get the thread-specific buffer.  */      buffer = __libc_getspecific (key);      if (buffer == NULL)	{	  /* No buffer allocated so far.  */	  buffer = malloc (18);	  if (buffer == NULL)	    /* No more memory available.  We use the static buffer.  */	    buffer = local_buf;	  else	    __libc_setspecific (key, buffer);	}    }  bytes = (unsigned char *) ∈  __snprintf (buffer, 18, "%d.%d.%d.%d",	      bytes[0], bytes[1], bytes[2], bytes[3]);  return buffer;}

转载地址:http://utcci.baihongyu.com/

你可能感兴趣的文章
iSecret 1.1 正在审核中
查看>>
IOS开发的开源库
查看>>
IOS开发的开源库
查看>>
Jenkins - sonarqube 代码审查
查看>>
Jenkins + Docker + SpringCloud 微服务持续集成(一)
查看>>
Jenkins + Docker + SpringCloud 微服务持续集成 - 单机部署(二)
查看>>
Jenkins + Docker + SpringCloud 微服务持续集成 - 高可用集群部署(三)
查看>>
Golang struct 指针引用用法(声明入门篇)
查看>>
Linux 粘滞位 suid sgid
查看>>
C#控件集DotNetBar安装及破解
查看>>
Winform皮肤控件IrisSkin4.dll使用
查看>>
Winform多线程
查看>>
C# 托管与非托管
查看>>
Node.js中的事件驱动编程详解
查看>>
mongodb 命令
查看>>
MongoDB基本使用
查看>>
mongodb管理与安全认证
查看>>
nodejs内存控制
查看>>
nodejs Stream使用中的陷阱
查看>>
MongoDB 数据文件备份与恢复
查看>>