CSDN首页 空间 新闻 论坛 Blog 下载 读书 网摘 搜索 .NET Java 视频 接项目 求职 在线学习 买书 程序员 通知
IBM Rational 系统开发最佳实践工具包 WebSphere MQ 最佳实践 TOP 15
CSDN社区
搜索 收藏 打印 关闭
CSDN社区 >  VC/MFC >  网络编程

connect(..)中有个sockaddr结构,存放有IP地址,如何提取出来,转变成字符串

楼主pc2000(pc)2003-08-02 10:45:21 在 VC/MFC / 网络编程 提问

VC++中sockaddr的定义是这样的:  
  struct   sockaddr   {  
        unsigned   short   sa_family;  
        char   sa_data[14];  
  };  
   
  如果方便的话请分析一下这个结构,小弟初学,谢谢! 问题点数:100、回复次数:2Top

1 楼afc(afc)回复于 2003-08-02 12:49:46 得分 70

inet_ntoa  
   
  The   inet_ntoa   function   converts   an   (Ipv4)   Internet   network   address   into   a   string   in   Internet   standard   dotted   format.  
   
   
  char*   FAR   inet_ntoa(  
      struct       in_addr   in  
  );  
   
  Parameters  
  in    
  [in]   Pointer   to   an   in_addr   structure   that   represents   an   Internet   host   address.    
  Return   Values  
  If   no   error   occurs,   inet_ntoa   returns   a   character   pointer   to   a   static   buffer   containing   the   text   address   in   standard   ".''   notation.   Otherwise,   it   returns   NULL.  
   
  Remarks  
  The   inet_ntoa   function   takes   an   Internet   address   structure   specified   by   the   in   parameter   and   returns   an   ASCII   string   representing   the   address   in   ".''   (dot)   notation   as   in   "a.b.c.d.''   The   string   returned   by   inet_ntoa   resides   in   memory   that   is   allocated   by   Windows   Sockets.   The   application   should   not   make   any   assumptions   about   the   way   in   which   the   memory   is   allocated.   The   data   is   guaranteed   to   be   valid   until   the   next   Windows   Sockets   function   call   within   the   same   thread—but   no   longer.   Therefore,   the   data   should   be   copied   before   another   Windows   Sockets   call   is   made.  
   
  Requirements  
  Client:   Included   in   Windows   XP,   Windows   2000   Professional,   Windows   NT   Workstation,   Windows   Me,   Windows   98,   Windows   95.  
  Server:   Included   in   Windows   .NET   Server   2003,   Windows   2000   Server,   Windows   NT   Server.  
  Header:   Declared   in   Winsock2.h.  
  Library:   Use   Ws2_32.lib.  
   
   
  Top

2 楼c0der()回复于 2003-08-02 13:31:21 得分 30

sockaddr   类型是用来保存socket信息的:    
  struct   sockaddr   {    
    unsigned   short   sa_family;   /*   地址族,   AF_xxx   */    
        char   sa_data[14];   /*   14   字节的协议地址   */    
  };    
  sa_family一般为AF_INET;sa_data则包含该socket的IP地址和端口号。    
  Top

相关问题

  • 如何std::string中存放含有'\0'字符串?
  • 将xml以xslt转换后存放到一个字符串中
  • 如何将字符串型IP转成IP ADDRESS?
  • 得到的IP如何转化成IP字符串了?
  • 如何判断一个CString中存放的字符串是不是数字?
  • zilong:JAVA有专门存放字符串等资源的资源文件吗?
  • 怎样存放30000字节长的字符串?用什么类型?
  • 请问有没有比string类型存放字符串更长的类型
  • 如何运行一条存放于字符串中的Foxpro命令
  • C#有没有办法执行存放在字符串中的命令?

关键词

  • internet
  • sockets
  • ntoa
  • sockaddr
  • inet
  • address
  • function
  • data

得分解答快速导航

  • 帖主:pc2000
  • afc
  • c0der

相关链接

  • Visual C++类图书
  • Visual C++类源码下载

广告也精彩

反馈

请通过下述方式给我们反馈
反馈
提问
网站简介|广告服务|VIP资费标准|银行汇款帐号|网站地图|帮助|联系方式|诚聘英才|English|问题报告
北京创新乐知广告有限公司 版权所有, 京 ICP 证 070598 号
世纪乐知(北京)网络技术有限公司 提供技术支持
Copyright © 2000-2008, CSDN.NET, All Rights Reserved
GongshangLogo