Chinaunix首页 | 论坛 | 博客
  • 博客访问: 290605
  • 博文数量: 44
  • 博客积分: 2276
  • 博客等级: 大尉
  • 技术积分: 439
  • 用 户 组: 普通用户
  • 注册时间: 2007-03-01 09:07
文章分类

全部博文(44)

文章存档

2010年(1)

2009年(1)

2008年(30)

2007年(12)

分类: LINUX

2007-11-25 14:20:45

socket函数 查阅msdn
 
1. ntohs

the windows sockets ntohs function converts a u_short from tcp/ip network byte order to host byte order (which is big-endian).
    
  u_short ntohs (
      u_short netshort
  );
      
  parameters
  netshort
  [in] a 16-bit number in tcp/ip network byte order.
  remarks
  the ntohs function takes a 16-bit number in tcp/ip network byte order and returns a 16-bit number in host byte order.
    
  return values
  the ntohs function returns the value in host byte order. if the netshort parameter was already in host byte order, then no operation is performed.
    
  quickinfo
      windows nt: yes
      windows: yes
      windows ce: use version 1.0 and later.
      header: declared in winsock2.h.
      import library: link with ws2_32.lib.

 

2.  inet_addr   
 

 the   windows   sockets   inet_addr   function   converts   a   string   containing   an   (ipv4)   internet   protocol   dotted   address   into   a   proper   address   for   the   in_addr   structure.  
   
  unsigned   long   inet_addr   (  
      const   char   far   *   cp      
  );  
     
  parameters  
  cp    
  [in]   a   null-terminated   character   string   representing   a   number   expressed   in   the   internet   standard   ".   (dotted)   notation.    
  remarks  
  the   inet_addr   function   interprets   the   character   string   specified   by   the   cp   parameter.   this   string   represents   a   numeric   internet   address   expressed   in   the   internet   standard   ".   notation.   the   value   returned   is   a   number   suitable   for   use   as   an   internet   address.   all   internet   addresses   are   returned   in   ips   network   order   (bytes   ordered   from   left   to   right).  
   
  internet   addresses  
   
  values   specified   using   the   ".   notation   take   one   of   the   following   forms:  
   
  a.b.c.d   a.b.c   a.b   a  
   
  when   four   parts   are   specified,   each   is   interpreted   as   a   byte   of   data   and   assigned,   from   left   to   right,   to   the   four   bytes   of   an   internet   address.   when   an   internet   address   is   viewed   as   a   32-bit   integer   quantity   on   the   intel   architecture,   the   bytes   referred   to   above   appear   as   "d.c.b.a.   that   is,   the   bytes   on   an   intel   processor   are   ordered   from   right   to   left.  
   
  the   parts   that   make   up   an   address   in   "."   notation   can   be   decimal,   octal   or   hexidecimal   as   specified   in   the   c   language.   numbers   that   start   with   "0x"   or   "0x"   imply   hexidecimal.   numbers   that   start   with   "0"   imply   octal.   all   other   numbers   are   interpreted   at   decimal.  
   
  "4.3.2.16"     decimal    
  "004.003.002.020"     octal    
  "0x4.0x3.0x2.0x10"     hexidecimal    
  "4.003.002.0x10"     mix    
   
   
  note   the   following   notations   are   only   used   by   berkeley,   and   nowhere   else   on   the   internet.   in   the   interests   of   compatibility   with   their   software,   they   are   supported   as   specified.  
   
  when   a   three   part   address   is   specified,   the   last   part   is   interpreted   as   a   16-bit   quantity   and   placed   in   the   right   most   two   bytes   of   the   network   address.   this   makes   the   three   part   address   format   convenient   for   specifying   class   b   network   addresses   as   "128.net.host.  
   
  when   a   two   part   address   is   specified,   the   last   part   is   interpreted   as   a   24-bit   quantity   and   placed   in   the   right   most   three   bytes   of   the   network   address.   this   makes   the   two   part   address   format   convenient   for   specifying   class   a   network   addresses   as   "net.host.  
   
  when   only   one   part   is   given,   the   value   is   stored   directly   in   the   network   address   without   any   byte   rearrangement.  
   
  return   values  
  if   no   error   occurs,   inet_addr   returns   an   unsigned   long   value   containing   a   suitable   binary   representation   of   the   internet   address   given.   if   the   string   in   the   cp   parameter   does   not   contain   a   legitimate   internet   address,   for   example   if   a   portion   of   an   "a.b.c.d"   address   exceeds   255,   inet_addr   returns   the   value   inaddr_none.  
   
  quickinfo  
      windows   nt:   yes  
      windows:   yes  
      windows   ce:   use   version   1.0   and   later.  
      header:   declared   in   winsock2.h.  
      import   library:   link   with   ws2_32.lib.  

 

3. inet_ntoa   
 

the   windows   sockets   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]   a   structure   that   represents   an   internet   host   address.    
  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.  
   
  return   values  
  if   no   error   occurs,   inet_ntoa   returns   a   char   pointer   to   a   static   buffer   containing   the   text   address   in   standard   ".   notation.   otherwise,   it   returns   null.    
   
  quickinfo  
      windows   nt:   yes  
      windows:   yes  
      windows   ce:   use   version   1.0   and   later.  
      header:   declared   in   winsock2.h.  
      import   library:   link   with   ws2_32.lib.  

 

 

4. gethostbyaddr

the   windows   sockets   gethostbyaddr   function   retrieves   the   host   information   corresponding   to   a   network   address.  
   
  struct   hostent   far   *   gethostbyaddr   (  
      const   char   far   *   addr,      
      int   len,                                  
      int   type                                  
  );  
     
  parameters  
  addr    
  [in]   a   pointer   to   an   address   in   network   byte   order.    
  len    
  [in]   the   length   of   the   address.    
  type    
  [in]   the   type   of   the   address.    
  remarks  
  the   gethostbyaddr   function   returns   a   pointer   to   the   hostent   structure   that   contains   the   name   and   address   corresponding   to   the   given   network   address.   all   strings   are   null-terminated.  
   
  return   values  
  if   no   error   occurs,   gethostbyaddr   returns   a   pointer   to   the   hostent   structure.   otherwise,   it   returns   a   null   pointer,   and   a   specific   error   code   can   be   retrieved   by   calling   wsagetlasterror.  
   
  error   codes  
  wsanotinitialised   a   successful   wsastartup   must   occur   before   using   this   function.    
  wsaenetdown   the   network   subsystem   has   failed.    
  wsahost_not_found   authoritative   fabiao   host   not   found.    
  wsatry_again   non-authoritative   host   not   found,   or   server   failed.    
  wsano_recovery   nonrecoverable   error   occurred.    
  wsano_data   valid   name,   no   data   record   of   requested   type.    
  wsaeinprogress   a   blocking   windows   sockets   1.1   call   is   in   progress,   or   the   service   provider   is   still   processing   a   callback   function.    
  wsaeafnosupport   the   type   specified   is   not   supported   by   the   windows   sockets   implementation.    
  wsaefault   the   addr   parameter   is   not   a   valid   part   of   the   user   address   space,   or   the   len   parameter   is   too   small.    
  wsaeintr   a   blocking   windows   socket   1.1   call   was   canceled   through   wsacancelblockingcall.    
   
   
  quickinfo  
      windows   nt:   yes  
      windows:   yes  
      windows   ce:   use   version   1.0   and   later.  
      header:   declared   in   winsock2.h.  
      import   library:   link   with   ws2_32.lib.  

阅读(2144) | 评论(0) | 转发(0) |
0

上一篇:字节顺序问题

下一篇:设置pop收信

给主人留下些什么吧!~~