Ignore:
Timestamp:
Nov 18, 2016, 2:58:30 PM (7 years ago)
Author:
coas-nagasima
Message:

uIPを更新
プロジェクトファイルを更新

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uKadecot/trunk/uip/net/ip/uip.h

    r158 r262  
    1515 *
    1616 */
    17 
    1817
    1918/*
     
    5756
    5857/**
    59  * Repressentation of an IP address.
    60  *
    61  */
    62 typedef uint16_t uip_ip4addr_t[2];
    63 typedef uint16_t uip_ip6addr_t[8];
     58 * Representation of an IP address.
     59 *
     60 */
    6461#if UIP_CONF_IPV6
     62typedef union uip_ip6addr_t {
     63  uint8_t  u8[16];                      /* Initializer, must come first!!! */
     64  uint16_t u16[8];
     65} uip_ip6addr_t;
     66
    6567typedef uip_ip6addr_t uip_ipaddr_t;
    6668#else /* UIP_CONF_IPV6 */
     69typedef union uip_ip4addr_t {
     70  uint8_t  u8[4];                       /* Initializer, must come first!!! */
     71  uint16_t u16[2];
     72#if 0
     73  uint32_t u32;
     74#endif
     75} uip_ip4addr_t;
    6776typedef uip_ip4addr_t uip_ipaddr_t;
    6877#endif /* UIP_CONF_IPV6 */
     
    7382 * handled by the following three functions.
    7483 */
    75 
    7684/**
    7785 * \defgroup uipconffunc uIP configuration functions
     
    104112 * \hideinitializer
    105113 */
    106 #define uip_sethostaddr(addr) uip_ipaddr_copy(uip_hostaddr, (addr))
     114#define uip_sethostaddr(addr) uip_ipaddr_copy(&uip_hostaddr, (addr))
    107115
    108116/**
     
    124132 * \hideinitializer
    125133 */
    126 #define uip_gethostaddr(addr) uip_ipaddr_copy((addr), uip_hostaddr)
     134#define uip_gethostaddr(addr) uip_ipaddr_copy((addr), &uip_hostaddr)
    127135
    128136/**
     
    136144 * \hideinitializer
    137145 */
    138 #define uip_setdraddr(addr) uip_ipaddr_copy(uip_draddr, (addr))
     146#define uip_setdraddr(addr) uip_ipaddr_copy(&uip_draddr, (addr))
    139147
    140148/**
     
    148156 * \hideinitializer
    149157 */
    150 #define uip_setnetmask(addr) uip_ipaddr_copy(uip_netmask, (addr))
     158#define uip_setnetmask(addr) uip_ipaddr_copy(&uip_netmask, (addr))
    151159
    152160
     
    159167 * \hideinitializer
    160168 */
    161 #define uip_getdraddr(addr) uip_ipaddr_copy((addr), uip_draddr)
     169#define uip_getdraddr(addr) uip_ipaddr_copy((addr), &uip_draddr)
    162170
    163171/**
     
    169177 * \hideinitializer
    170178 */
    171 #define uip_getnetmask(addr) uip_ipaddr_copy((addr), uip_netmask)
     179#define uip_getnetmask(addr) uip_ipaddr_copy((addr), &uip_netmask)
    172180
    173181/** @} */
     
    238246  uip_len = ethernet_devicedrver_poll();
    239247  if(uip_len > 0) {
    240     if(BUF->type == HTONS(UIP_ETHTYPE_IP)) {
     248    if(BUF->type == UIP_HTONS(UIP_ETHTYPE_IP)) {
    241249      uip_arp_ipin();
    242250      uip_input();
     
    245253        ethernet_devicedriver_send();
    246254      }
    247     } else if(BUF->type == HTONS(UIP_ETHTYPE_ARP)) {
     255    } else if(BUF->type == UIP_HTONS(UIP_ETHTYPE_ARP)) {
    248256      uip_arp_arpin();
    249257      if(uip_len > 0) {
     
    257265#define uip_input()        uip_process(UIP_DATA)
    258266
     267
    259268/**
    260269 * Periodic processing for a connection identified by its number.
     
    270279 * should be called to send out the packet.
    271280 *
    272  * The ususal way of calling the function is through a for() loop like
     281 * The usual way of calling the function is through a for() loop like
    273282 * this:
    274283 \code
     
    325334
    326335/**
    327  * Reuqest that a particular connection should be polled.
     336 * Request that a particular connection should be polled.
    328337 *
    329338 * Similar to uip_periodic_conn() but does not perform any timer
     
    390399#define uip_udp_periodic_conn(conn) do { uip_udp_conn = conn; \
    391400                                         uip_process(UIP_UDP_TIMER); } while (0)
    392 
    393 
    394401#endif /* UIP_UDP */
    395402
     
    444451 *
    445452 * \note Since this function expects the port number in network byte
    446  * order, a conversion using HTONS() or htons() is necessary.
    447  *
    448  \code
    449  uip_listen(HTONS(80));
     453 * order, a conversion using UIP_HTONS() or uip_htons() is necessary.
     454 *
     455 \code
     456 uip_listen(UIP_HTONS(80));
    450457 \endcode
    451458 *
     
    458465 *
    459466 * \note Since this function expects the port number in network byte
    460  * order, a conversion using HTONS() or htons() is necessary.
    461  *
    462  \code
    463  uip_unlisten(HTONS(80));
     467 * order, a conversion using UIP_HTONS() or uip_htons() is necessary.
     468 *
     469 \code
     470 uip_unlisten(UIP_HTONS(80));
    464471 \endcode
    465472 *
     
    472479 *
    473480 * This function is used to start a new connection to the specified
    474  * port on the specied host. It allocates a new connection identifier,
     481 * port on the specified host. It allocates a new connection identifier,
    475482 * sets the connection to the SYN_SENT state and sets the
    476483 * retransmission timer to 0. This will cause a TCP SYN segment to be
     
    479486 * uip_connect().
    480487 *
    481  * \note This function is avaliable only if support for active open
     488 * \note This function is available only if support for active open
    482489 * has been configured by defining UIP_ACTIVE_OPEN to 1 in uipopt.h.
    483490 *
    484491 * \note Since this function requires the port number to be in network
    485  * byte order, a conversion using HTONS() or htons() is necessary.
     492 * byte order, a conversion using UIP_HTONS() or uip_htons() is necessary.
    486493 *
    487494 \code
     
    489496
    490497 uip_ipaddr(&ipaddr, 192,168,1,2);
    491  uip_connect(&ipaddr, HTONS(80));
    492  \endcode
    493  *
    494  * \param ripaddr The IP address of the remote hot.
     498 uip_connect(&ipaddr, UIP_HTONS(80));
     499 \endcode
     500 *
     501 * \param ripaddr The IP address of the remote host.
    495502 *
    496503 * \param port A 16-bit port number in network byte order.
     
    523530 *
    524531 * The amount of data that actually is sent out after a call to this
    525  * funcion is determined by the maximum amount of data TCP allows. uIP
     532 * function is determined by the maximum amount of data TCP allows. uIP
    526533 * will automatically crop the data so that only the appropriate
    527534 * amount of data is sent. The function uip_mss() can be used to query
     
    543550
    544551/**
    545  * The length of any incoming data that is currently avaliable (if avaliable)
     552 * The length of any incoming data that is currently available (if available)
    546553 * in the uip_appdata buffer.
    547554 *
     
    578585 *
    579586 * This function will abort (reset) the current connection, and is
    580  * usually used when an error has occured that prevents using the
     587 * usually used when an error has occurred that prevents using the
    581588 * uip_close() function.
    582589 *
     
    635642 * Will reduce to non-zero if there is new data for the application
    636643 * present at the uip_appdata pointer. The size of the data is
    637  * avaliable through the uip_len variable.
     644 * available through the uip_len variable.
    638645 *
    639646 * \hideinitializer
     
    721728
    722729/**
    723  * Get the initial maxium segment size (MSS) of the current
     730 * Get the initial maximum segment size (MSS) of the current
    724731 * connection.
    725732 *
     
    729736
    730737/**
    731  * Get the current maxium segment size that can be sent on the current
     738 * Get the current maximum segment size that can be sent on the current
    732739 * connection.
    733740 *
    734  * The current maxiumum segment size that can be sent on the
     741 * The current maximum segment size that can be sent on the
    735742 * connection is computed from the receiver's window and the MSS of
    736743 * the connection (which also is available by calling
     
    756763
    757764 uip_ipaddr(&addr, 192,168,2,1);
    758  c = uip_udp_new(&addr, HTONS(12345));
     765 c = uip_udp_new(&addr, UIP_HTONS(12345));
    759766 if(c != NULL) {
    760    uip_udp_bind(c, HTONS(12344));
     767   uip_udp_bind(c, UIP_HTONS(12344));
    761768 }
    762769 \endcode
     
    768775 * if no connection could be allocated.
    769776 */
    770 struct uip_udp_conn *uip_udp_new(uip_ipaddr_t *ripaddr, uint16_t rport);
     777struct uip_udp_conn *uip_udp_new(const uip_ipaddr_t *ripaddr, uint16_t rport);
    771778
    772779/**
     
    829836
    830837 uip_ipaddr(&ipaddr, 192,168,1,2);
    831  c = uip_connect(&ipaddr, HTONS(80));
     838 c = uip_connect(&ipaddr, UIP_HTONS(80));
    832839 \endcode
    833840 *
     
    842849 * \hideinitializer
    843850 */
    844 #define uip_ipaddr(addr, addr0,addr1,addr2,addr3) do { \
    845                      ((uint16_t *)(addr))[0] = HTONS(((addr0) << 8) | (addr1)); \
    846                      ((uint16_t *)(addr))[1] = HTONS(((addr2) << 8) | (addr3)); \
     851#define uip_ipaddr(addr, addr0,addr1,addr2,addr3) do {  \
     852    (addr)->u8[0] = addr0;                              \
     853    (addr)->u8[1] = addr1;                              \
     854    (addr)->u8[2] = addr2;                              \
     855    (addr)->u8[3] = addr3;                              \
    847856                  } while(0)
    848857
     
    855864 */
    856865#define uip_ip6addr(addr, addr0,addr1,addr2,addr3,addr4,addr5,addr6,addr7) do { \
    857                      ((uint16_t *)(addr))[0] = HTONS((addr0)); \
    858                      ((uint16_t *)(addr))[1] = HTONS((addr1)); \
    859                      ((uint16_t *)(addr))[2] = HTONS((addr2)); \
    860                      ((uint16_t *)(addr))[3] = HTONS((addr3)); \
    861                      ((uint16_t *)(addr))[4] = HTONS((addr4)); \
    862                      ((uint16_t *)(addr))[5] = HTONS((addr5)); \
    863                      ((uint16_t *)(addr))[6] = HTONS((addr6)); \
    864                      ((uint16_t *)(addr))[7] = HTONS((addr7)); \
     866    (addr)->u16[0] = UIP_HTONS(addr0);                                      \
     867    (addr)->u16[1] = UIP_HTONS(addr1);                                      \
     868    (addr)->u16[2] = UIP_HTONS(addr2);                                      \
     869    (addr)->u16[3] = UIP_HTONS(addr3);                                      \
     870    (addr)->u16[4] = UIP_HTONS(addr4);                                      \
     871    (addr)->u16[5] = UIP_HTONS(addr5);                                      \
     872    (addr)->u16[6] = UIP_HTONS(addr6);                                      \
     873    (addr)->u16[7] = UIP_HTONS(addr7);                                      \
    865874                  } while(0)
    866875
     
    883892 * \hideinitializer
    884893 */
    885 #if !UIP_CONF_IPV6
    886 #define uip_ipaddr_copy(dest, src) do { \
    887                      ((uint16_t *)dest)[0] = ((uint16_t *)src)[0]; \
    888                      ((uint16_t *)dest)[1] = ((uint16_t *)src)[1]; \
    889                   } while(0)
    890 #else /* !UIP_CONF_IPV6 */
    891 #define uip_ipaddr_copy(dest, src) memcpy(dest, src, sizeof(uip_ip6addr_t))
    892 #endif /* !UIP_CONF_IPV6 */
     894#ifndef uip_ipaddr_copy
     895#define uip_ipaddr_copy(dest, src) (*(dest) = *(src))
     896#endif
    893897
    894898/**
     
    913917 */
    914918#if !UIP_CONF_IPV6
    915 #define uip_ipaddr_cmp(addr1, addr2) (((uint16_t *)addr1)[0] == ((uint16_t *)addr2)[0] && \
    916                                       ((uint16_t *)addr1)[1] == ((uint16_t *)addr2)[1])
     919#define uip_ipaddr_cmp(addr1, addr2) ((addr1)->u16[0] == (addr2)->u16[0] && \
     920                                      (addr1)->u16[1] == (addr2)->u16[1])
    917921#else /* !UIP_CONF_IPV6 */
    918922#define uip_ipaddr_cmp(addr1, addr2) (memcmp(addr1, addr2, sizeof(uip_ip6addr_t)) == 0)
     
    9971001 * \hideinitializer
    9981002 */
    999 #define uip_ipaddr1(addr) (htons(((uint16_t *)(addr))[0]) >> 8)
     1003#define uip_ipaddr1(addr) ((addr)->u8[0])
    10001004
    10011005/**
     
    10171021 * \hideinitializer
    10181022 */
    1019 #define uip_ipaddr2(addr) (htons(((uint16_t *)(addr))[0]) & 0xff)
     1023#define uip_ipaddr2(addr) ((addr)->u8[1])
    10201024
    10211025/**
     
    10371041 * \hideinitializer
    10381042 */
    1039 #define uip_ipaddr3(addr) (htons(((uint16_t *)(addr))[1]) >> 8)
     1043#define uip_ipaddr3(addr) ((addr)->u8[2])
    10401044
    10411045/**
     
    10571061 * \hideinitializer
    10581062 */
    1059 #define uip_ipaddr4(addr) (htons(((uint16_t *)(addr))[1]) & 0xff)
     1063#define uip_ipaddr4(addr) ((addr)->u8[3])
    10601064
    10611065/**
     
    10641068 * This macro is primarily used for converting constants from host
    10651069 * byte order to network byte order. For converting variables to
    1066  * network byte order, use the htons() function instead.
    1067  *
    1068  * \hideinitializer
    1069  */
    1070 #ifndef HTONS
     1070 * network byte order, use the uip_htons() function instead.
     1071 *
     1072 * \hideinitializer
     1073 */
     1074#ifndef UIP_HTONS
    10711075#   if UIP_BYTE_ORDER == UIP_BIG_ENDIAN
    1072 #      define HTONS(n) (n)
     1076#      define UIP_HTONS(n) (n)
     1077#      define UIP_HTONL(n) (n)
    10731078#   else /* UIP_BYTE_ORDER == UIP_BIG_ENDIAN */
    1074 #      define HTONS(n) (uint16_t)((((uint16_t) (n)) << 8) | (((uint16_t) (n)) >> 8))
     1079#      define UIP_HTONS(n) (uint16_t)((((uint16_t) (n)) << 8) | (((uint16_t) (n)) >> 8))
     1080#      define UIP_HTONL(n) (((uint32_t)UIP_HTONS(n) << 16) | UIP_HTONS((uint32_t)(n) >> 16))
    10751081#   endif /* UIP_BYTE_ORDER == UIP_BIG_ENDIAN */
    10761082#else
    1077 #error "HTONS already defined!"
    1078 #endif /* HTONS */
     1083#error "UIP_HTONS already defined!"
     1084#endif /* UIP_HTONS */
    10791085
    10801086/**
     
    10831089 * This function is primarily used for converting variables from host
    10841090 * byte order to network byte order. For converting constants to
    1085  * network byte order, use the HTONS() macro instead.
    1086  */
    1087 #ifndef htons
    1088 uint16_t htons(uint16_t val);
    1089 #endif /* htons */
    1090 #ifndef ntohs
    1091 #define ntohs htons
     1091 * network byte order, use the UIP_HTONS() macro instead.
     1092 */
     1093#ifndef uip_htons
     1094uint16_t uip_htons(uint16_t val);
     1095#endif /* uip_htons */
     1096#ifndef uip_ntohs
     1097#define uip_ntohs uip_htons
    10921098#endif
    10931099
     
    11501156 * The uip_conn structure is used for identifying a connection. All
    11511157 * but one field in the structure are to be considered read-only by an
    1152  * application. The only exception is the appstate field whos purpose
     1158 * application. The only exception is the appstate field whose purpose
    11531159 * is to let the application store application-specific state (e.g.,
    11541160 * file pointers) for the connection. The type of this field is
     
    11921198 * connection.
    11931199 */
     1200
    11941201extern struct uip_conn *uip_conn;
    11951202/* The array containing all uIP connections. */
     
    12041211 */
    12051212extern uint8_t uip_acc32[4];
    1206 
    12071213/** @} */
    12081214
     
    12361242struct uip_stats {
    12371243  struct {
    1238     uip_stats_t drop;     /**< Number of dropped packets at the IP
    1239                              layer. */
    12401244    uip_stats_t recv;     /**< Number of received packets at the IP
    12411245                             layer. */
    12421246    uip_stats_t sent;     /**< Number of sent packets at the IP
     1247                             layer. */
     1248    uip_stats_t drop;     /**< Number of dropped packets at the IP
    12431249                             layer. */
    12441250    uip_stats_t vhlerr;   /**< Number of packets dropped due to wrong
     
    12561262  } ip;                   /**< IP statistics. */
    12571263  struct {
    1258     uip_stats_t drop;     /**< Number of dropped ICMP packets. */
    12591264    uip_stats_t recv;     /**< Number of received ICMP packets. */
    12601265    uip_stats_t sent;     /**< Number of sent ICMP packets. */
     1266    uip_stats_t drop;     /**< Number of dropped ICMP packets. */
    12611267    uip_stats_t typeerr;  /**< Number of ICMP packets with a wrong
    12621268                             type. */
    12631269  } icmp;                 /**< ICMP statistics. */
    12641270  struct {
    1265     uip_stats_t drop;     /**< Number of dropped TCP segments. */
    12661271    uip_stats_t recv;     /**< Number of recived TCP segments. */
    12671272    uip_stats_t sent;     /**< Number of sent TCP segments. */
     1273    uip_stats_t drop;     /**< Number of dropped TCP segments. */
    12681274    uip_stats_t chkerr;   /**< Number of TCP segments with a bad
    12691275                             checksum. */
     
    12731279    uip_stats_t rexmit;   /**< Number of retransmitted TCP segments. */
    12741280    uip_stats_t syndrop;  /**< Number of dropped SYNs due to too few
    1275                              connections was avaliable. */
     1281                             connections was available. */
    12761282    uip_stats_t synrst;   /**< Number of SYNs for closed ports,
    12771283                             triggering a RST. */
     
    13011307 */
    13021308/*---------------------------------------------------------------------------*/
     1309
     1310
     1311
    13031312/* uint8_t uip_flags:
    13041313 *
    13051314 * When the application is called, uip_flags will contain the flags
    13061315 * that are defined in this file. Please read below for more
    1307  * infomation.
     1316 * information.
    13081317 */
    13091318extern uint8_t uip_flags;
     
    13121321   before calling the application callback. The UIP_ACKDATA,
    13131322   UIP_NEWDATA, and UIP_CLOSE flags may both be set at the same time,
    1314    whereas the others are mutualy exclusive. Note that these flags
     1323   whereas the others are mutually exclusive. Note that these flags
    13151324   should *NOT* be accessed directly, but only through the uIP
    13161325   functions/macros. */
     
    13561365   incoming data that should be processed, or because the periodic
    13571366   timer has fired. These values are never used directly, but only in
    1358    the macrose defined in this file. */
     1367   the macros defined in this file. */
    13591368
    13601369#define UIP_DATA          1     /* Tells uIP that there is incoming
     
    14131422    proto;
    14141423  uint16_t ipchksum;
    1415   uint16_t srcipaddr[2],
    1416     destipaddr[2];
     1424  uip_ipaddr_t srcipaddr, destipaddr;
    14171425#endif /* UIP_CONF_IPV6 */
    14181426
     
    14501458    proto;
    14511459  uint16_t ipchksum;
    1452   uint16_t srcipaddr[2],
    1453     destipaddr[2];
     1460  uip_ipaddr_t srcipaddr, destipaddr;
    14541461#endif /* UIP_CONF_IPV6 */
    14551462
    1456   /* ICMP (echo) header. */
     1463  /* ICMP header. */
    14571464  uint8_t type, icode;
    14581465  uint16_t icmpchksum;
    14591466#if !UIP_CONF_IPV6
    14601467  uint16_t id, seqno;
    1461 #else /* !UIP_CONF_IPV6 */
    14621468  uint8_t flags, reserved1, reserved2, reserved3;
    14631469  uint8_t icmp6data[16];
     
    14871493    proto;
    14881494  uint16_t ipchksum;
    1489   uint16_t srcipaddr[2],
    1490     destipaddr[2];
     1495  uip_ipaddr_t srcipaddr, destipaddr;
    14911496#endif /* UIP_CONF_IPV6 */
    14921497
     
    15481553extern uip_ipaddr_t uip_hostaddr, uip_netmask, uip_draddr;
    15491554#endif /* UIP_FIXEDADDR */
     1555extern const uip_ipaddr_t uip_broadcast_addr;
     1556extern const uip_ipaddr_t uip_all_zeroes_addr;
    15501557
    15511558
Note: See TracChangeset for help on using the changeset viewer.