Subversion Repositories HelenOS

Rev

Rev 3846 | Rev 4505 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

  1. /*
  2.  * Copyright (c) 2009 Lukas Mejdrech
  3.  * All rights reserved.
  4.  *
  5.  * Redistribution and use in source and binary forms, with or without
  6.  * modification, are permitted provided that the following conditions
  7.  * are met:
  8.  *
  9.  * - Redistributions of source code must retain the above copyright
  10.  *   notice, this list of conditions and the following disclaimer.
  11.  * - Redistributions in binary form must reproduce the above copyright
  12.  *   notice, this list of conditions and the following disclaimer in the
  13.  *   documentation and/or other materials provided with the distribution.
  14.  * - The name of the author may not be used to endorse or promote products
  15.  *   derived from this software without specific prior written permission.
  16.  *
  17.  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
  18.  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  19.  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  20.  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
  21.  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  22.  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  23.  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  24.  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  25.  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  26.  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  27.  */
  28.  
  29. /** @addtogroup net
  30.  *  @{
  31.  */
  32.  
  33. /** @file
  34.  *  
  35.  */
  36.  
  37. #ifndef __NET_SOCKADDR_H__
  38. #define __NET_SOCKADDR_H__
  39.  
  40. #include <sys/types.h>
  41.  
  42. #define INET_ADDRSTRLEN     ( 4 * 3 + 3 )
  43. #define INET6_ADDRSTRLEN    ( 8 * 4 + 7 )
  44.  
  45. typedef struct sockaddr     sockaddr_t;
  46. typedef struct in_addr      in_addr_t;
  47. typedef struct sockaddr_in  sockaddr_in_t;
  48. typedef struct sockaddr_in6 sockaddr_in6_t;
  49. typedef struct addrinfo     addrinfo_t;
  50.  
  51. int inet_ntop( uint16_t family, const uint8_t * data, char * address, size_t length );
  52. int inet_pton( uint16_t family, const char * address, uint8_t * data );
  53.  
  54. struct sockaddr{
  55.     uint16_t        sa_family;      // address family, AF_xxx
  56.     uint8_t         sa_data[ 14 ];  // 14 bytes of protocol address
  57. };
  58.  
  59. struct in_addr{
  60.     uint32_t        s_addr;         // that's a 32-bit int (4 bytes)
  61. };
  62.  
  63. struct sockaddr_in{
  64.     uint16_t        sin_family;     // Address family, AF_INET
  65.     uint16_t        sin_port;       // Port number
  66.     struct in_addr  sin_addr;       // Internet address
  67.     uint8_t         sin_zero[ 8 ];  // Same size as struct sockaddr
  68. };
  69.  
  70. struct in6_addr{
  71.     unsigned char   s6_addr[ 16 ];  // IPv6 address
  72. };
  73.  
  74. struct sockaddr_in6{
  75.     uint16_t        sin6_family;    // address family, AF_INET6
  76.     uint16_t        sin6_port;      // port number, Network Byte Order
  77.     uint32_t        sin6_flowinfo;  // IPv6 flow information
  78.     struct in6_addr sin6_addr;      // IPv6 address
  79.     uint32_t        sin6_scope_id;  // Scope ID
  80. };
  81.  
  82. struct addrinfo{
  83.     int             ai_flags;       // AI_PASSIVE, AI_CANONNAME, etc.
  84.     uint16_t        ai_family;      // AF_INET, AF_INET6, AF_UNSPEC
  85.     int             ai_socktype;    // SOCK_STREAM, SOCK_DGRAM
  86.     int             ai_protocol;    // use 0 for "any"
  87.     size_t          ai_addrlen;     // size of ai_addr in bytes
  88.     struct sockaddr *   ai_addr;    // struct sockaddr_in or _in6
  89.     char *          ai_canonname;   // full canonical hostname
  90.     struct addrinfo *   ai_next;    // linked list, next node
  91. };
  92.  
  93. /*int getaddrinfo(const char *node, // e.g. "www.example.com" or IP
  94. const char *service, // e.g. "http" or port number
  95. const struct addrinfo *hints,
  96. struct addrinfo **res);
  97.  
  98. getnameinfo
  99. */
  100.  
  101. #endif
  102.  
  103. /** @}
  104.  */
  105.