Changeset 262 for uKadecot/trunk/uip


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

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

Location:
uKadecot/trunk/uip
Files:
17 edited

Legend:

Unmodified
Added
Removed
  • uKadecot/trunk/uip/apps/dhcpc/dhcpc.c

    r158 r262  
    160160  memcpy(m->xid, xid, sizeof(m->xid));
    161161  m->secs = 0;
    162   m->flags = HTONS(BOOTP_BROADCAST); /*  Broadcast bit. */
    163   /*  uip_ipaddr_copy(m->ciaddr, uip_hostaddr);*/
    164   memcpy(m->ciaddr, uip_hostaddr, sizeof(m->ciaddr));
     162  m->flags = UIP_HTONS(BOOTP_BROADCAST); /*  Broadcast bit. */
     163  /*  uip_ipaddr_copy(&m->ciaddr, &uip_hostaddr);*/
     164  memcpy(m->ciaddr, &uip_hostaddr, sizeof(m->ciaddr));
    165165  memset(m->yiaddr, 0, sizeof(m->yiaddr));
    166166  memset(m->siaddr, 0, sizeof(m->siaddr));
     
    329329         uip_ipaddr3(s->default_router), uip_ipaddr4(s->default_router));
    330330  printf("Lease expires in %ld seconds\n",
    331          ntohs(s->lease_time[0])*65536ul + ntohs(s->lease_time[1]));
     331         uip_ntohs(s->lease_time[0])*65536ul + uip_ntohs(s->lease_time[1]));
    332332#endif
    333333
     
    356356  uip_ipaddr_t addr;
    357357
    358   uip_ipaddr(addr, 255,255,255,255);
    359   conn = uip_udp_new(&addr, HTONS(DHCPC_SERVER_PORT));
     358  uip_ipaddr(&addr, 255,255,255,255);
     359  conn = uip_udp_new(&addr, UIP_HTONS(DHCPC_SERVER_PORT));
    360360  if(conn != NULL) {
    361361    s = &conn->appstate.parblk.dhcpc;
     
    367367    s->conn->appstate.udp_callback = dhcpc_appcall;
    368368
    369     uip_udp_bind(conn, HTONS(DHCPC_CLIENT_PORT));
     369    uip_udp_bind(conn, UIP_HTONS(DHCPC_CLIENT_PORT));
    370370
    371371    PT_INIT(&s->pt);
     
    386386dhcpc_request(struct dhcpc_state *s)
    387387{
    388   uint16_t ipaddr[2];
     388  uip_ipaddr_t ipaddr;
    389389
    390390  s->state = STATE_REQUEST;
    391   uip_ipaddr(ipaddr, 0,0,0,0);
    392   uip_sethostaddr(ipaddr);
     391  uip_ipaddr(&ipaddr, 0,0,0,0);
     392  uip_sethostaddr(&ipaddr);
    393393  uip_udp_conn = s->conn;
    394394  uip_process(UIP_UDP_TIMER);
  • uKadecot/trunk/uip/apps/webserver/httpd.c

    r158 r262  
    545545httpd_init(void)
    546546{
    547   uip_listen(HTONS(41314));
     547  uip_listen(UIP_HTONS(41314));
    548548
    549549  httpd_fs_init();
  • uKadecot/trunk/uip/net/ip/psock.h

    r158 r262  
    111111  uint8_t *readptr;         /* Pointer to the next data to be read. */
    112112
    113   char *bufptr;          /* Pointer to the buffer used for buffering
     113  uint8_t *bufptr;          /* Pointer to the buffer used for buffering
    114114                            incoming data. */
    115115
     
    124124};
    125125
    126 void psock_init(struct psock *psock, char *buffer, unsigned int buffersize);
     126void psock_init(struct psock *psock, uint8_t *buffer, unsigned int buffersize);
    127127/**
    128128 * Initialize a protosocket.
     
    135135 * initialized
    136136 *
    137  * \param buffer (char *) A pointer to the input buffer for the
     137 * \param buffer (uint8_t *) A pointer to the input buffer for the
    138138 * protosocket.
    139139 *
     
    158158#define PSOCK_BEGIN(psock) PT_BEGIN(&((psock)->pt))
    159159
    160 PT_THREAD(psock_send(struct psock *psock, const char *buf, unsigned int len));
     160PT_THREAD(psock_send(struct psock *psock, const uint8_t *buf, unsigned int len));
    161161/**
    162162 * Send data.
     
    169169 * data is to be sent.
    170170 *
    171  * \param data (char *) A pointer to the data that is to be sent.
     171 * \param data (uint8_t *) A pointer to the data that is to be sent.
    172172 *
    173173 * \param datalen (unsigned int) The length of the data that is to be
     
    190190 */
    191191#define PSOCK_SEND_STR(psock, str)                      \
    192     PT_WAIT_THREAD(&((psock)->pt), psock_send(psock, str, strlen(str)))
     192  PT_WAIT_THREAD(&((psock)->pt), psock_send(psock, (uint8_t *)str, strlen(str)))
    193193
    194194PT_THREAD(psock_generator_send(struct psock *psock,
     
    257257 * This macro will block waiting for data and read the data into the
    258258 * input buffer specified with the call to PSOCK_INIT(). Data is only
    259  * read until the specifieed character appears in the data stream.
     259 * read until the specified character appears in the data stream.
    260260 *
    261261 * \param psock (struct psock *) A pointer to the protosocket from which
     
    353353   PSOCK_BEGIN(s);
    354354
    355    PSOCK_WAIT_UNTIL(s, PSOCK_NEWADATA(s) || timer_expired(t));
     355   PSOCK_WAIT_UNTIL(s, PSOCK_NEWDATA(s) || timer_expired(t));
    356356
    357357   if(PSOCK_NEWDATA(s)) {
     
    379379
    380380/** @} */
     381/** @} */
  • 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
  • uKadecot/trunk/uip/net/ip/uiplib.c

    r158 r262  
    4040
    4141/*-----------------------------------------------------------------------------------*/
    42 unsigned char
    43 uiplib_ipaddrconv(char *addrstr, unsigned char *ipaddr)
     42int
     43uiplib_ipaddrconv(const char *addrstr, uip_ipaddr_t *ipaddr)
    4444{
    4545  unsigned char tmp;
     
    5858      }
    5959      if(c == '.' || c == 0) {
    60         *ipaddr = tmp;
    61         ++ipaddr;
     60        ipaddr->u8[i] = tmp;
    6261        tmp = 0;
    6362      } else if(c >= '0' && c <= '9') {
  • uKadecot/trunk/uip/net/ip/uiplib.h

    r157 r262  
    5353 *
    5454 * This function takes a textual representation of an IP address in
    55  * the form a.b.c.d and converts it into a 4-byte array that can be
    56  * used by other uIP functions.
     55 * the form a.b.c.d for IPv4 or a:b:c:d:e:f:g:h for IPv6 and converts
     56 * it into a numeric IP address representation that can be used by
     57 * other uIP functions.
    5758 *
    5859 * \param addrstr A pointer to a string containing the IP address in
    5960 * textual form.
    6061 *
    61  * \param addr A pointer to a 4-byte array that will be filled in with
     62 * \param addr A pointer to a uip_ipaddr_t that will be filled in with
    6263 * the numerical representation of the address.
    6364 *
     
    6566 * \retval Non-zero If the IP address was parsed.
    6667 */
    67 unsigned char uiplib_ipaddrconv(char *addrstr, unsigned char *addr);
     68int uiplib_ipaddrconv(const char *addrstr, uip_ipaddr_t *addr);
    6869
    6970/** @} */
  • uKadecot/trunk/uip/net/ipv4/uip-fw.c

    r158 r262  
    8686    proto;
    8787  uint16_t ipchksum;
    88   uint16_t srcipaddr[2],
    89     destipaddr[2];
     88  uip_ipaddr_t srcipaddr, destipaddr;
    9089 
    9190  /* TCP header. */
     
    112111    proto;
    113112  uint16_t ipchksum;
    114   uint16_t srcipaddr[2],
    115     destipaddr[2];
     113  uip_ipaddr_t srcipaddr, destipaddr;
    116114  /* ICMP (echo) header. */
    117115  uint8_t type, icode;
     
    144142  uint16_t timer;
    145143 
    146   uint16_t srcipaddr[2];
    147   uint16_t destipaddr[2];
     144  uip_ipaddr_t srcipaddr;
     145  uip_ipaddr_t destipaddr;
    148146  uint16_t ipid;
    149147  uint8_t proto;
     
    217215/*------------------------------------------------------------------------------*/
    218216static unsigned char
    219 ipaddr_maskcmp(uint16_t *ipaddr, uint16_t *netipaddr, uint16_t *netmask)
    220 {
    221   return (ipaddr[0] & netmask [0]) == (netipaddr[0] & netmask[0]) &&
    222     (ipaddr[1] & netmask[1]) == (netipaddr[1] & netmask[1]);
     217ipaddr_maskcmp(uip_ipaddr_t *ipaddr,
     218               uip_ipaddr_t *netipaddr,
     219               uip_ipaddr_t *netmask)
     220{
     221  return (ipaddr->u16[0] & netmask->u16[0]) == (netipaddr->u16[0] & netmask->u16[0]) &&
     222    (ipaddr->u16[1] & netmask->u16[1]) == (netipaddr->u16[1] & netmask->u16[1]);
    223223}
    224224/*------------------------------------------------------------------------------*/
     
    254254  /* Set the IP destination address to be the source address of the
    255255     original packet. */
    256   tmp16= BUF->destipaddr[0];
    257   BUF->destipaddr[0] = BUF->srcipaddr[0];
    258   BUF->srcipaddr[0] = tmp16;
    259   tmp16 = BUF->destipaddr[1];
    260   BUF->destipaddr[1] = BUF->srcipaddr[1];
    261   BUF->srcipaddr[1] = tmp16;
     256  uip_ipaddr_copy(&BUF->destipaddr, &BUF->srcipaddr);
    262257
    263258  /* Set our IP address as the source address. */
    264   BUF->srcipaddr[0] = uip_hostaddr[0];
    265   BUF->srcipaddr[1] = uip_hostaddr[1];
     259  uip_ipaddr_copy(&BUF->srcipaddr, &uip_hostaddr);
    266260
    267261  /* The size of the ICMP time exceeded packet is 36 + the size of the
     
    269263  uip_len = 56;
    270264  ICMPBUF->len[0] = 0;
    271   ICMPBUF->len[1] = uip_len;
     265  ICMPBUF->len[1] = (uint8_t)uip_len;
    272266
    273267  /* Fill in the other fields in the IP header. */
     
    313307  fw->timer = FW_TIME;
    314308  fw->ipid = BUF->ipid;
    315   fw->srcipaddr[0] = BUF->srcipaddr[0];
    316   fw->srcipaddr[1] = BUF->srcipaddr[1];
    317   fw->destipaddr[0] = BUF->destipaddr[0];
    318   fw->destipaddr[1] = BUF->destipaddr[1];
     309  uip_ipaddr_copy(&fw->srcipaddr, &BUF->srcipaddr);
     310  uip_ipaddr_copy(&fw->destipaddr, &BUF->destipaddr);
    319311  fw->proto = BUF->proto;
    320312#if notdef
     
    340332  /* Walk through every network interface to check for a match. */
    341333  for(netif = netifs; netif != NULL; netif = netif->next) {
    342     if(ipaddr_maskcmp(BUF->destipaddr, netif->ipaddr,
    343                       netif->netmask)) {
     334    if(ipaddr_maskcmp(&BUF->destipaddr, &netif->ipaddr,
     335                      &netif->netmask)) {
    344336      /* If there was a match, we break the loop. */
    345337      return netif;
     
    371363{
    372364  struct uip_fw_netif *netif;
     365#if UIP_BROADCAST
     366  const struct uip_udpip_hdr *udp = (void *)BUF;
     367#endif /* UIP_BROADCAST */
    373368
    374369  if(uip_len == 0) {
     
    380375#if UIP_BROADCAST
    381376  /* Link local broadcasts go out on all interfaces. */
    382   if(/*BUF->proto == UIP_PROTO_UDP &&*/
    383      BUF->destipaddr[0] == 0xffff &&
    384      BUF->destipaddr[1] == 0xffff) {
     377  if(uip_ipaddr_cmp(&udp->destipaddr, &uip_broadcast_addr)) {
    385378    if(defaultnetif != NULL) {
    386379      defaultnetif->output();
     
    422415  /* First check if the packet is destined for ourselves and return 0
    423416     to indicate that the packet should be processed locally. */
    424   if(BUF->destipaddr[0] == uip_hostaddr[0] &&
    425      BUF->destipaddr[1] == uip_hostaddr[1]) {
     417  if(uip_ipaddr_cmp(&BUF->destipaddr, &uip_hostaddr)) {
    426418    return UIP_FW_LOCAL;
    427419  }
     
    430422     not yet configured, we should intercept all ICMP echo packets. */
    431423#if UIP_PINGADDRCONF
    432   if((uip_hostaddr[0] | uip_hostaddr[1]) == 0 &&
     424  if(uip_ipaddr_cmp(&uip_hostaddr, &uip_all_zeroes_addr) &&
    433425     BUF->proto == UIP_PROTO_ICMP &&
    434426     ICMPBUF->type == ICMP_ECHO) {
     
    447439#endif
    448440       fw->ipid == BUF->ipid &&
    449        fw->srcipaddr[0] == BUF->srcipaddr[0] &&
    450        fw->srcipaddr[1] == BUF->srcipaddr[1] &&
    451        fw->destipaddr[0] == BUF->destipaddr[0] &&
    452        fw->destipaddr[1] == BUF->destipaddr[1] &&
     441       uip_ipaddr_cmp(&fw->srcipaddr, &BUF->srcipaddr) &&
     442       uip_ipaddr_cmp(&fw->destipaddr, &BUF->destipaddr) &&
    453443#if notdef
    454444       fw->payload[0] == BUF->srcport &&
     
    464454     in the uip_buf buffer and forward that packet back to the sender
    465455     of the packet. */
     456
    466457  if(BUF->ttl <= 1) {
    467458    /* No time exceeded for broadcasts and multicasts! */
    468     if(BUF->destipaddr[0] == 0xffff && BUF->destipaddr[1] == 0xffff) {
     459    if(uip_ipaddr_cmp(&BUF->destipaddr, &uip_broadcast_addr)) {
    469460      return UIP_FW_LOCAL;
    470461    }
     
    476467 
    477468  /* Update the IP checksum. */
    478   if(BUF->ipchksum >= HTONS(0xffff - 0x0100)) {
    479     BUF->ipchksum = BUF->ipchksum + HTONS(0x0100) + 1;
     469  if(BUF->ipchksum >= UIP_HTONS(0xffff - 0x0100)) {
     470    BUF->ipchksum = BUF->ipchksum + UIP_HTONS(0x0100) + 1;
    480471  } else {
    481     BUF->ipchksum = BUF->ipchksum + HTONS(0x0100);
     472    BUF->ipchksum = BUF->ipchksum + UIP_HTONS(0x0100);
    482473  }
    483474
     
    488479
    489480#if UIP_BROADCAST
    490   if(BUF->destipaddr[0] == 0xffff && BUF->destipaddr[1] == 0xffff) {
     481  if(uip_ipaddr_cmp(&BUF->destipaddr, &uip_broadcast_addr)) {
    491482    return UIP_FW_LOCAL;
    492483  }
  • uKadecot/trunk/uip/net/ipv4/uip-fw.h

    r158 r262  
    5555  struct uip_fw_netif *next;  /**< Pointer to the next interface when
    5656                                 linked in a list. */
    57   uint16_t ipaddr[2];            /**< The IP address of this interface. */
    58   uint16_t netmask[2];           /**< The netmask of the interface. */
     57  uip_ipaddr_t ipaddr;            /**< The IP address of this interface. */
     58  uip_ipaddr_t netmask;           /**< The netmask of the interface. */
    5959  uint8_t (* output)(void);
    6060                              /**< A pointer to the function that
     
    6363
    6464/**
    65  * Intantiating macro for a uIP network interface.
     65 * Instantiating macro for a uIP network interface.
    6666 *
    6767 * Example:
     
    8080#define UIP_FW_NETIF(ip1,ip2,ip3,ip4, nm1,nm2,nm3,nm4, outputfunc) \
    8181        NULL, \
    82         {HTONS((ip1 << 8) | ip2), HTONS((ip3 << 8) | ip4)}, \
    83         {HTONS((nm1 << 8) | nm2), HTONS((nm3 << 8) | nm4)}, \
     82        { {ip1, ip2, ip3, ip4} }, \
     83        { {nm1, nm2, nm3, nm4} }, \
    8484        outputfunc
    8585
  • uKadecot/trunk/uip/net/ipv4/uip-neighbor.c

    r158 r262  
    8383/*---------------------------------------------------------------------------*/
    8484void
    85 uip_neighbor_add(uip_ipaddr_t ipaddr, struct uip_neighbor_addr *addr)
     85uip_neighbor_add(uip_ipaddr_t *ipaddr, struct uip_neighbor_addr *addr)
    8686{
    8787  int i, oldest;
     
    100100      break;
    101101    }
    102     if(uip_ipaddr_cmp(entries[i].ipaddr, addr)) {
     102    if(uip_ipaddr_cmp(&entries[i].ipaddr, ipaddr)) {
    103103      oldest = i;
    104104      break;
     
    113113     "oldest" variable). */
    114114  entries[oldest].time = 0;
    115   uip_ipaddr_copy(entries[oldest].ipaddr, ipaddr);
     115  uip_ipaddr_copy(&entries[oldest].ipaddr, ipaddr);
    116116  memcpy(&entries[oldest].addr, addr, sizeof(struct uip_neighbor_addr));
    117117}
    118118/*---------------------------------------------------------------------------*/
    119119static struct neighbor_entry *
    120 find_entry(uip_ipaddr_t ipaddr)
     120find_entry(uip_ipaddr_t *ipaddr)
    121121{
    122122  int i;
    123123 
    124124  for(i = 0; i < ENTRIES; ++i) {
    125     if(uip_ipaddr_cmp(entries[i].ipaddr, ipaddr)) {
     125    if(uip_ipaddr_cmp(&entries[i].ipaddr, ipaddr)) {
    126126      return &entries[i];
    127127    }
     
    131131/*---------------------------------------------------------------------------*/
    132132void
    133 uip_neighbor_update(uip_ipaddr_t ipaddr)
     133uip_neighbor_update(uip_ipaddr_t *ipaddr)
    134134{
    135135  struct neighbor_entry *e;
     
    142142/*---------------------------------------------------------------------------*/
    143143struct uip_neighbor_addr *
    144 uip_neighbor_lookup(uip_ipaddr_t ipaddr)
     144uip_neighbor_lookup(uip_ipaddr_t *ipaddr)
    145145{
    146146  struct neighbor_entry *e;
  • uKadecot/trunk/uip/net/ipv4/uip-neighbor.h

    r158 r262  
    5454
    5555void uip_neighbor_init(void);
    56 void uip_neighbor_add(uip_ipaddr_t ipaddr, struct uip_neighbor_addr *addr);
    57 void uip_neighbor_update(uip_ipaddr_t ipaddr);
    58 struct uip_neighbor_addr *uip_neighbor_lookup(uip_ipaddr_t ipaddr);
     56void uip_neighbor_add(uip_ipaddr_t *ipaddr, struct uip_neighbor_addr *addr);
     57void uip_neighbor_update(uip_ipaddr_t *ipaddr);
     58struct uip_neighbor_addr *uip_neighbor_lookup(uip_ipaddr_t *ipaddr);
    5959void uip_neighbor_periodic(void);
    6060
  • uKadecot/trunk/uip/net/ipv4/uip.c

    r158 r262  
    9999#if UIP_FIXEDADDR > 0
    100100const uip_ipaddr_t uip_hostaddr =
    101   {HTONS((UIP_IPADDR0 << 8) | UIP_IPADDR1),
    102    HTONS((UIP_IPADDR2 << 8) | UIP_IPADDR3)};
     101  { UIP_IPADDR0, UIP_IPADDR1, UIP_IPADDR2, UIP_IPADDR3 };
    103102const uip_ipaddr_t uip_draddr =
    104   {HTONS((UIP_DRIPADDR0 << 8) | UIP_DRIPADDR1),
    105    HTONS((UIP_DRIPADDR2 << 8) | UIP_DRIPADDR3)};
     103  { UIP_DRIPADDR0, UIP_DRIPADDR1, UIP_DRIPADDR2, UIP_DRIPADDR3 };
    106104const uip_ipaddr_t uip_netmask =
    107   {HTONS((UIP_NETMASK0 << 8) | UIP_NETMASK1),
    108    HTONS((UIP_NETMASK2 << 8) | UIP_NETMASK3)};
     105  { UIP_NETMASK0, UIP_NETMASK1, UIP_NETMASK2, UIP_NETMASK3 };
    109106#else
    110107uip_ipaddr_t uip_hostaddr, uip_draddr, uip_netmask;
    111108#endif /* UIP_FIXEDADDR */
    112109
    113 static const uip_ipaddr_t all_ones_addr =
     110const uip_ipaddr_t uip_broadcast_addr =
    114111#if UIP_CONF_IPV6
    115   {0xffff,0xffff,0xffff,0xffff,0xffff,0xffff,0xffff,0xffff};
     112  { { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
     113      0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff } };
    116114#else /* UIP_CONF_IPV6 */
    117   {0xffff,0xffff};
     115  { { 0xff, 0xff, 0xff, 0xff } };
    118116#endif /* UIP_CONF_IPV6 */
    119 static const uip_ipaddr_t all_zeroes_addr =
    120 #if UIP_CONF_IPV6
    121   {0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000};
    122 #else /* UIP_CONF_IPV6 */
    123   {0x0000,0x0000};
    124 #endif /* UIP_CONF_IPV6 */
    125 
     117const uip_ipaddr_t uip_all_zeroes_addr = { { 0x0, /* rest is 0 */ } };
    126118
    127119#if UIP_FIXEDETHADDR
    128 const struct uip_eth_addr uip_ethaddr = {{UIP_ETHADDR0,
     120const struct uip_eth_addr uip_lladdr = {{UIP_ETHADDR0,
    129121                                          UIP_ETHADDR1,
    130122                                          UIP_ETHADDR2,
     
    133125                                          UIP_ETHADDR5}};
    134126#else
    135 struct uip_eth_addr uip_ethaddr = {{0,0,0,0,0,0}};
     127struct uip_eth_addr uip_lladdr = {{0,0,0,0,0,0}};
    136128#endif
    137129
     
    311303uip_chksum(uint16_t *data, uint16_t len)
    312304{
    313   return htons(chksum(0, (uint8_t *)data, len));
     305  return uip_htons(chksum(0, (uint8_t *)data, len));
    314306}
    315307/*---------------------------------------------------------------------------*/
     
    322314  sum = chksum(0, &uip_buf[UIP_LLH_LEN], UIP_IPH_LEN);
    323315  DEBUG_PRINTF("uip_ipchksum: sum 0x%04x\n", sum);
    324   return (sum == 0) ? 0xffff : htons(sum);
     316  return (sum == 0) ? 0xffff : uip_htons(sum);
    325317}
    326318#endif
     
    343335  sum = upper_layer_len + proto;
    344336  /* Sum IP source and destination addresses. */
    345   sum = chksum(sum, (uint8_t *)&BUF->srcipaddr[0], 2 * sizeof(uip_ipaddr_t));
     337  sum = chksum(sum, (uint8_t *)&BUF->srcipaddr, 2 * sizeof(uip_ipaddr_t));
    346338
    347339  /* Sum TCP header and data. */
     
    349341               upper_layer_len);
    350342
    351   return (sum == 0) ? 0xffff : htons(sum);
     343  return (sum == 0) ? 0xffff : uip_htons(sum);
    352344}
    353345/*---------------------------------------------------------------------------*/
     
    375367#endif /* UIP_UDP_CHECKSUMS */
    376368#endif /* UIP_ARCH_CHKSUM */
    377 uint8_t
    378 uip_ismulticast(uip_ipaddr_t ipaddr)
    379 {
    380 #if UIP_CONF_IPV6
    381   return 0;
    382 #else
    383   static const uint16_t multicast_ipaddr[2] = { 0x00e0, 0x0000 };
    384   static const uint16_t multicast_mask[2] = { 0x00f0, 0x0000 };
    385   return uip_ipaddr_maskcmp(ipaddr, multicast_ipaddr, multicast_mask);
    386 #endif
    387 }
    388369/*---------------------------------------------------------------------------*/
    389370void
     
    433414    conn = &uip_conns[c];
    434415    if(conn->tcpstateflags != UIP_CLOSED &&
    435        conn->lport == htons(lastport)) {
     416       conn->lport == uip_htons(lastport)) {
    436417      goto again;
    437418    }
     
    472453  conn->sa = 0;
    473454  conn->sv = 16;   /* Initial value of the RTT variance. */
    474   conn->lport = htons(lastport);
     455  conn->lport = uip_htons(lastport);
    475456  conn->rport = rport;
    476457  uip_ipaddr_copy(&conn->ripaddr, ripaddr);
     
    482463#if UIP_UDP
    483464struct uip_udp_conn *
    484 uip_udp_new(uip_ipaddr_t *ripaddr, uint16_t rport)
     465uip_udp_new(const uip_ipaddr_t *ripaddr, uint16_t rport)
    485466{
    486467  register struct uip_udp_conn *conn;
     
    495476
    496477  for(c = 0; c < UIP_UDP_CONNS; ++c) {
    497     if(uip_udp_conns[c].lport == htons(lastport)) {
     478    if(uip_udp_conns[c].lport == uip_htons(lastport)) {
    498479      goto again;
    499480    }
     
    513494  }
    514495
    515   conn->lport = HTONS(lastport);
     496  conn->lport = UIP_HTONS(lastport);
    516497  conn->rport = rport;
    517498  if(ripaddr == NULL) {
    518     memset(conn->ripaddr, 0, sizeof(uip_ipaddr_t));
     499    memset(&conn->ripaddr, 0, sizeof(uip_ipaddr_t));
    519500  } else {
    520501    uip_ipaddr_copy(&conn->ripaddr, ripaddr);
     
    748729         connection's timer and see if it has reached the RTO value
    749730         in which case we retransmit. */
     731
    750732      if(uip_outstanding(uip_connr)) {
    751733        if(uip_connr->timer-- == 0) {
     
    901883#endif /* UIP_CONF_IPV6 */
    902884
    903   if(uip_ipaddr_cmp(uip_hostaddr, all_zeroes_addr)) {
     885  if(uip_ipaddr_cmp(&uip_hostaddr, &uip_all_zeroes_addr)) {
    904886    /* If we are configured to use ping IP address configuration and
    905887       hasn't been assigned an IP address yet, we accept all ICMP
     
    921903    DEBUG_PRINTF("UDP IP checksum 0x%04x\n", uip_ipchksum());
    922904    if(BUF->proto == UIP_PROTO_UDP &&
    923        (uip_ipaddr_cmp(BUF->destipaddr, all_ones_addr) ||
    924        uip_ismulticast(BUF->destipaddr))
    925        /*&&
    926          uip_ipchksum() == 0xffff*/) {
     905       (uip_ipaddr_cmp(&BUF->destipaddr, &uip_broadcast_addr) ||
     906        (BUF->destipaddr.u8[0] & 224) == 224)) {  /* XXX this is a
     907                                                     hack to be able
     908                                                     to receive UDP
     909                                                     multicast
     910                                                     packets. We check
     911                                                     for the bit
     912                                                     pattern of the
     913                                                     multicast
     914                                                     prefix. */
    927915      goto udp_input;
    928916    }
     
    931919    /* Check if the packet is destined for our IP address. */
    932920#if !UIP_CONF_IPV6
    933     if(!uip_ipaddr_cmp(BUF->destipaddr, uip_hostaddr)) {
     921    if(!uip_ipaddr_cmp(&BUF->destipaddr, &uip_hostaddr)) {
    934922      UIP_STAT(++uip_stat.ip.drop);
    935923      goto drop;
     
    941929       address) as well. However, we will cheat here and accept all
    942930       multicast packets that are sent to the ff02::/16 addresses. */
    943     if(!uip_ipaddr_cmp(BUF->destipaddr, uip_hostaddr) &&
    944        BUF->destipaddr[0] != HTONS(0xff02)) {
     931    if(!uip_ipaddr_cmp(&BUF->destipaddr, &uip_hostaddr) &&
     932       BUF->destipaddr.u16[0] != UIP_HTONS(0xff02)) {
    945933      UIP_STAT(++uip_stat.ip.drop);
    946934      goto drop;
     
    1000988     ourself. */
    1001989#if UIP_PINGADDRCONF
    1002   if((uip_hostaddr[0] | uip_hostaddr[1]) == 0) {
    1003     uip_hostaddr[0] = BUF->destipaddr[0];
    1004     uip_hostaddr[1] = BUF->destipaddr[1];
     990  if(uip_ipaddr_cmp(&uip_hostaddr, &uip_all_zeroes_addr)) {
     991    uip_hostaddr = BUF->destipaddr;
    1005992  }
    1006993#endif /* UIP_PINGADDRCONF */
     
    1008995  ICMPBUF->type = ICMP_ECHO_REPLY;
    1009996
    1010   if(ICMPBUF->icmpchksum >= HTONS(0xffff - (ICMP_ECHO << 8))) {
    1011     ICMPBUF->icmpchksum += HTONS(ICMP_ECHO << 8) + 1;
     997  if(ICMPBUF->icmpchksum >= UIP_HTONS(0xffff - (ICMP_ECHO << 8))) {
     998    ICMPBUF->icmpchksum += UIP_HTONS(ICMP_ECHO << 8) + 1;
    1012999  } else {
    1013     ICMPBUF->icmpchksum += HTONS(ICMP_ECHO << 8);
     1000    ICMPBUF->icmpchksum += UIP_HTONS(ICMP_ECHO << 8);
    10141001  }
    10151002
    10161003  /* Swap IP addresses. */
    1017   uip_ipaddr_copy(BUF->destipaddr, BUF->srcipaddr);
    1018   uip_ipaddr_copy(BUF->srcipaddr, uip_hostaddr);
     1004  uip_ipaddr_copy(&BUF->destipaddr, &BUF->srcipaddr);
     1005  uip_ipaddr_copy(&BUF->srcipaddr, &uip_hostaddr);
    10191006
    10201007  UIP_STAT(++uip_stat.icmp.sent);
    1021   goto send;
     1008  BUF->ttl = UIP_TTL;
     1009  goto ip_send_nolen;
    10221010
    10231011  /* End of IPv4 input header processing code. */
     
    10401028     a neighbor advertisement message back. */
    10411029  if(ICMPBUF->type == ICMP6_NEIGHBOR_SOLICITATION) {
    1042     if(uip_ipaddr_cmp(ICMPBUF->icmp6data, uip_hostaddr)) {
     1030    if(uip_ipaddr_cmp(&ICMPBUF->icmp6data, &uip_hostaddr)) {
    10431031
    10441032      if(ICMPBUF->options[0] == ICMP6_OPTION_SOURCE_LINK_ADDRESS) {
    10451033        /* Save the sender's address in our neighbor list. */
    1046         uip_neighbor_add(ICMPBUF->srcipaddr, &(ICMPBUF->options[2]));
     1034        uip_neighbor_add(&ICMPBUF->srcipaddr, &(ICMPBUF->options[2]));
    10471035      }
    10481036
     
    10541042      ICMPBUF->reserved1 = ICMPBUF->reserved2 = ICMPBUF->reserved3 = 0;
    10551043
    1056       uip_ipaddr_copy(ICMPBUF->destipaddr, ICMPBUF->srcipaddr);
    1057       uip_ipaddr_copy(ICMPBUF->srcipaddr, uip_hostaddr);
     1044      uip_ipaddr_copy(&ICMPBUF->destipaddr, &ICMPBUF->srcipaddr);
     1045      uip_ipaddr_copy(&ICMPBUF->srcipaddr, &uip_hostaddr);
    10581046      ICMPBUF->options[0] = ICMP6_OPTION_TARGET_LINK_ADDRESS;
    10591047      ICMPBUF->options[1] = 1;  /* Options length, 1 = 8 bytes. */
    1060       memcpy(&(ICMPBUF->options[2]), &uip_ethaddr, sizeof(uip_ethaddr));
     1048      memcpy(&(ICMPBUF->options[2]), &uip_lladdr, sizeof(uip_lladdr));
    10611049      ICMPBUF->icmpchksum = 0;
    10621050      ICMPBUF->icmpchksum = ~uip_icmp6chksum();
     1051
    10631052      goto send;
    10641053
     
    10721061    ICMPBUF->type = ICMP6_ECHO_REPLY;
    10731062
    1074     uip_ipaddr_copy(BUF->destipaddr, BUF->srcipaddr);
    1075     uip_ipaddr_copy(BUF->srcipaddr, uip_hostaddr);
     1063    uip_ipaddr_copy(&BUF->destipaddr, &BUF->srcipaddr);
     1064    uip_ipaddr_copy(&BUF->srcipaddr, &uip_hostaddr);
    10761065    ICMPBUF->icmpchksum = 0;
    10771066    ICMPBUF->icmpchksum = ~uip_icmp6chksum();
     
    11101099  uip_len = uip_len - UIP_IPUDPH_LEN;
    11111100#endif /* UIP_UDP_CHECKSUMS */
     1101
     1102  /* Make sure that the UDP destination port number is not zero. */
     1103  if(UDPBUF->destport == 0) {
     1104    UIP_LOG("udp: zero port.");
     1105    goto drop;
     1106  }
    11121107
    11131108  /* Demultiplex this UDP packet between the UDP "connections". */
     
    11261121       (uip_udp_conn->rport == 0 ||
    11271122        UDPBUF->srcport == uip_udp_conn->rport) &&
    1128        (uip_ipaddr_cmp(uip_udp_conn->ripaddr, all_zeroes_addr) ||
    1129         uip_ipaddr_cmp(uip_udp_conn->ripaddr, all_ones_addr) ||
    1130         uip_ipaddr_cmp(BUF->srcipaddr, uip_udp_conn->ripaddr))) {
     1123       (uip_ipaddr_cmp(&uip_udp_conn->ripaddr, &uip_all_zeroes_addr) ||
     1124        uip_ipaddr_cmp(&uip_udp_conn->ripaddr, &uip_broadcast_addr) ||
     1125        uip_ipaddr_cmp(&BUF->srcipaddr, &uip_udp_conn->ripaddr))) {
    11311126      goto udp_found;
    11321127    }
     
    11411136  uip_slen = 0;
    11421137  UIP_UDP_APPCALL();
     1138
    11431139 udp_send:
    11441140  if(uip_slen == 0) {
     
    11601156  BUF->proto = UIP_PROTO_UDP;
    11611157
    1162   UDPBUF->udplen = HTONS(uip_slen + UIP_UDPH_LEN);
     1158  UDPBUF->udplen = UIP_HTONS(uip_slen + UIP_UDPH_LEN);
    11631159  UDPBUF->udpchksum = 0;
    11641160
     
    11661162  BUF->destport = uip_udp_conn->rport;
    11671163
    1168   uip_ipaddr_copy(BUF->srcipaddr, uip_hostaddr);
    1169   uip_ipaddr_copy(BUF->destipaddr, uip_udp_conn->ripaddr);
     1164  uip_ipaddr_copy(&BUF->srcipaddr, &uip_hostaddr);
     1165  uip_ipaddr_copy(&BUF->destipaddr, &uip_udp_conn->ripaddr);
    11701166
    11711167  uip_appdata = &uip_buf[UIP_LLH_LEN + UIP_IPTCPH_LEN];
     
    11961192  }
    11971193
     1194  /* Make sure that the TCP port number is not zero. */
     1195  if(BUF->destport == 0 || BUF->srcport == 0) {
     1196    UIP_LOG("tcp: zero port.");
     1197    goto drop;
     1198  }
    11981199
    11991200  /* Demultiplex this segment. */
     
    12041205       BUF->destport == uip_connr->lport &&
    12051206       BUF->srcport == uip_connr->rport &&
    1206        uip_ipaddr_cmp(BUF->srcipaddr, uip_connr->ripaddr)) {
     1207       uip_ipaddr_cmp(&BUF->srcipaddr, &uip_connr->ripaddr)) {
    12071208      goto found;
    12081209    }
     
    12201221  /* Next, check listening connections. */
    12211222  for(c = 0; c < UIP_LISTENPORTS; ++c) {
    1222     if(tmp16 == uip_listenports[c])
     1223    if(tmp16 == uip_listenports[c]) {
    12231224      goto found_listen;
     1225    }
    12241226  }
    12251227
    12261228  /* No matching connection found, so we send a RST packet. */
    12271229  UIP_STAT(++uip_stat.tcp.synrst);
     1230
    12281231 reset:
    1229 
    12301232  /* We do not send resets in response to resets. */
    12311233  if(BUF->flags & TCP_RST) {
     
    12731275
    12741276  /* Swap IP addresses. */
    1275   uip_ipaddr_copy(BUF->destipaddr, BUF->srcipaddr);
    1276   uip_ipaddr_copy(BUF->srcipaddr, uip_hostaddr);
     1277  uip_ipaddr_copy(&BUF->destipaddr, &BUF->srcipaddr);
     1278  uip_ipaddr_copy(&BUF->srcipaddr, &uip_hostaddr);
    12771279
    12781280  /* And send out the RST packet! */
     
    12831285     connection and send a SYNACK in return. */
    12841286 found_listen:
    1285   /* First we check if there are any connections avaliable. Unused
     1287  /* First we check if there are any connections available. Unused
    12861288     connections are kept in the same table as used connections, but
    12871289     unused ones have the tcpstate set to CLOSED. Also, connections in
     
    13201322  uip_connr->lport = BUF->destport;
    13211323  uip_connr->rport = BUF->srcport;
    1322   uip_ipaddr_copy(uip_connr->ripaddr, BUF->srcipaddr);
     1324  uip_ipaddr_copy(&uip_connr->ripaddr, &BUF->srcipaddr);
    13231325  uip_connr->tcpstateflags = UIP_SYN_RCVD;
    13241326
     
    14061408    goto drop;
    14071409  }
    1408   /* Calculated the length of the data, if the application has sent
     1410  /* Calculate the length of the data, if the application has sent
    14091411     any data to us. */
    14101412  c = (BUF->tcpoffset >> 4) << 2;
     
    14161418  /* First, check if the sequence number of the incoming packet is
    14171419     what we're expecting next. If not, we send out an ACK with the
    1418      correct numbers in. */
    1419   if(!(((uip_connr->tcpstateflags & UIP_TS_MASK) == UIP_SYN_SENT) &&
    1420        ((BUF->flags & TCP_CTL) == (TCP_SYN | TCP_ACK)))) {
     1420     correct numbers in, unless we are in the SYN_RCVD state and
     1421     receive a SYN, in which case we should retransmit our SYNACK
     1422     (which is done futher down). */
     1423  if(!((((uip_connr->tcpstateflags & UIP_TS_MASK) == UIP_SYN_SENT) &&
     1424        ((BUF->flags & TCP_CTL) == (TCP_SYN | TCP_ACK))) ||
     1425       (((uip_connr->tcpstateflags & UIP_TS_MASK) == UIP_SYN_RCVD) &&
     1426        ((BUF->flags & TCP_CTL) == TCP_SYN)))) {
    14211427    if((uip_len > 0 || ((BUF->flags & (TCP_SYN | TCP_FIN)) != 0)) &&
    14221428       (BUF->seqno[0] != uip_connr->rcv_nxt[0] ||
     
    14441450      uip_connr->snd_nxt[2] = uip_acc32[2];
    14451451      uip_connr->snd_nxt[3] = uip_acc32[3];
    1446 
    14471452
    14481453      /* Do RTT estimation, unless we have done retransmissions. */
     
    14951500      goto appsend;
    14961501    }
     1502    /* We need to retransmit the SYNACK */
     1503    if((BUF->flags & TCP_CTL) == TCP_SYN) {
     1504      goto tcp_send_synack;
     1505    }
    14971506    goto drop;
    14981507#if UIP_ACTIVE_OPEN
     
    17981807  goto drop;
    17991808
    1800 
    18011809  /* We jump here when we are ready to send the packet, and just want
    18021810     to set the appropriate TCP sequence numbers in the TCP header. */
    18031811 tcp_send_ack:
    18041812  BUF->flags = TCP_ACK;
     1813
    18051814 tcp_send_nodata:
    18061815  uip_len = UIP_IPTCPH_LEN;
     1816
    18071817 tcp_send_noopts:
    18081818  BUF->tcpoffset = (UIP_TCPH_LEN / 4) << 4;
    1809  tcp_send:
     1819
    18101820  /* We're done with the input processing. We are now ready to send a
    18111821     reply. Our job is to fill in all the fields of the TCP and IP
    18121822     headers before calculating the checksum and finally send the
    18131823     packet. */
     1824 tcp_send:
    18141825  BUF->ackno[0] = uip_connr->rcv_nxt[0];
    18151826  BUF->ackno[1] = uip_connr->rcv_nxt[1];
     
    18271838  BUF->destport = uip_connr->rport;
    18281839
    1829   uip_ipaddr_copy(BUF->srcipaddr, uip_hostaddr);
    1830   uip_ipaddr_copy(BUF->destipaddr, uip_connr->ripaddr);
     1840  uip_ipaddr_copy(&BUF->srcipaddr, &uip_hostaddr);
     1841  uip_ipaddr_copy(&BUF->destipaddr, &uip_connr->ripaddr);
    18311842
    18321843  if(uip_connr->tcpstateflags & UIP_STOPPED) {
     
    18581869
    18591870 ip_send_nolen:
    1860 
    18611871#if UIP_CONF_IPV6
    18621872  BUF->vtc = 0x60;
     
    18751885  DEBUG_PRINTF("uip ip_send_nolen: chkecum 0x%04x\n", uip_ipchksum());
    18761886#endif /* UIP_CONF_IPV6 */
    1877 
    18781887  UIP_STAT(++uip_stat.tcp.sent);
     1888#if UIP_CONF_IPV6
    18791889 send:
     1890#endif /* UIP_CONF_IPV6 */
    18801891  DEBUG_PRINTF("Sending packet with length %d (%d)\n", uip_len,
    18811892               (BUF->len[0] << 8) | BUF->len[1]);
     
    18851896  uip_flags = 0;
    18861897  return;
     1898
    18871899 drop:
    18881900  uip_len = 0;
     
    18921904/*---------------------------------------------------------------------------*/
    18931905uint16_t
    1894 htons(uint16_t val)
     1906uip_htons(uint16_t val)
    18951907{
    1896   return HTONS(val);
     1908  return UIP_HTONS(val);
    18971909}
    18981910/*---------------------------------------------------------------------------*/
  • uKadecot/trunk/uip/net/ipv4/uip_arp.c

    r158 r262  
    7878  uint16_t opcode;
    7979  struct uip_eth_addr shwaddr;
    80   uint16_t sipaddr[2];
     80  uip_ipaddr_t sipaddr;
    8181  struct uip_eth_addr dhwaddr;
    82   uint16_t dipaddr[2];
     82  uip_ipaddr_t dipaddr;
    8383};
    8484
     
    9494    proto;
    9595  uint16_t ipchksum;
    96   uint16_t srcipaddr[2],
    97     destipaddr[2];
     96  uip_ipaddr_t srcipaddr, destipaddr;
    9897};
    9998
     
    110109
    111110struct arp_entry {
    112   uint16_t ipaddr[2];
     111  uip_ipaddr_t ipaddr;
    113112  struct uip_eth_addr ethaddr;
    114113  uint8_t time;
     
    118117  {{0xff,0xff,0xff,0xff,0xff,0xff}};
    119118static const uint16_t broadcast_ipaddr[2] = {0xffff,0xffff};
    120 static const uint16_t multicast_ipaddr[2] = { 0x00e0, 0x0000 };
    121 static const uint16_t multicast_mask[2] = { 0x00f0, 0x0000 };
    122119
    123120static struct arp_entry arp_table[UIP_ARPTAB_SIZE];
    124 static uint16_t ipaddr[2];
     121static uip_ipaddr_t ipaddr;
    125122static uint8_t i, c;
    126123
     
    140137{
    141138  for(i = 0; i < UIP_ARPTAB_SIZE; ++i) {
    142     memset(arp_table[i].ipaddr, 0, 4);
     139    memset(&arp_table[i].ipaddr, 0, 4);
    143140  }
    144141}
     
    161158  for(i = 0; i < UIP_ARPTAB_SIZE; ++i) {
    162159    tabptr = &arp_table[i];
    163     if((tabptr->ipaddr[0] | tabptr->ipaddr[1]) != 0 &&
     160    if(uip_ipaddr_cmp(&tabptr->ipaddr, &uip_all_zeroes_addr) &&
    164161       arptime - tabptr->time >= UIP_ARP_MAXAGE) {
    165       memset(tabptr->ipaddr, 0, 4);
    166     }
    167   }
    168 
    169 }
     162      memset(&tabptr->ipaddr, 0, 4);
     163    }
     164  }
     165
     166}
     167
    170168/*-----------------------------------------------------------------------------------*/
    171169static void
    172 uip_arp_update(uint16_t *ipaddr, struct uip_eth_addr *ethaddr)
    173 {
    174   register struct arp_entry *tabptr = NULL;
     170uip_arp_update(uip_ipaddr_t *ipaddr, struct uip_eth_addr *ethaddr)
     171{
     172  register struct arp_entry *tabptr = arp_table;
     173
    175174  /* Walk through the ARP mapping table and try to find an entry to
    176175     update. If none is found, the IP -> MAC address mapping is
    177176     inserted in the ARP table. */
    178177  for(i = 0; i < UIP_ARPTAB_SIZE; ++i) {
    179 
    180178    tabptr = &arp_table[i];
     179
    181180    /* Only check those entries that are actually in use. */
    182     if(tabptr->ipaddr[0] != 0 &&
    183        tabptr->ipaddr[1] != 0) {
     181    if(!uip_ipaddr_cmp(&tabptr->ipaddr, &uip_all_zeroes_addr)) {
    184182
    185183      /* Check if the source IP address of the incoming packet matches
    186184         the IP address in this ARP table entry. */
    187       if(ipaddr[0] == tabptr->ipaddr[0] &&
    188          ipaddr[1] == tabptr->ipaddr[1]) {
     185      if(uip_ipaddr_cmp(ipaddr, &tabptr->ipaddr)) {
    189186
    190187        /* An old entry found, update this and return. */
     
    203200  for(i = 0; i < UIP_ARPTAB_SIZE; ++i) {
    204201    tabptr = &arp_table[i];
    205     if(tabptr->ipaddr[0] == 0 &&
    206        tabptr->ipaddr[1] == 0) {
     202    if(uip_ipaddr_cmp(&tabptr->ipaddr, &uip_all_zeroes_addr)) {
    207203      break;
    208204    }
     
    227223  /* Now, i is the ARP table entry which we will fill with the new
    228224     information. */
    229   memcpy(tabptr->ipaddr, ipaddr, 4);
     225  uip_ipaddr_copy(&tabptr->ipaddr, ipaddr);
    230226  memcpy(tabptr->ethaddr.addr, ethaddr->addr, 6);
    231227  tabptr->time = arptime;
     
    300296
    301297  switch(BUF->opcode) {
    302   case HTONS(ARP_REQUEST):
     298  case UIP_HTONS(ARP_REQUEST):
    303299    /* ARP request. If it asked for our address, we send out a
    304300       reply. */
    305     if(uip_ipaddr_cmp(BUF->dipaddr, uip_hostaddr)) {
     301    if(uip_ipaddr_cmp(&BUF->dipaddr, &uip_hostaddr)) {
    306302      /* First, we register the one who made the request in our ARP
    307303         table, since it is likely that we will do more communication
    308304         with this host in the future. */
    309       uip_arp_update(BUF->sipaddr, &BUF->shwaddr);
     305      uip_arp_update(&BUF->sipaddr, &BUF->shwaddr);
    310306
    311307      /* The reply opcode is 2. */
    312       BUF->opcode = HTONS(2);
     308      BUF->opcode = UIP_HTONS(2);
    313309
    314310      memcpy(BUF->dhwaddr.addr, BUF->shwaddr.addr, 6);
    315       memcpy(BUF->shwaddr.addr, uip_ethaddr.addr, 6);
    316       memcpy(BUF->ethhdr.src.addr, uip_ethaddr.addr, 6);
     311      memcpy(BUF->shwaddr.addr, uip_lladdr.addr, 6);
     312      memcpy(BUF->ethhdr.src.addr, uip_lladdr.addr, 6);
    317313      memcpy(BUF->ethhdr.dest.addr, BUF->dhwaddr.addr, 6);
    318314
    319       BUF->dipaddr[0] = BUF->sipaddr[0];
    320       BUF->dipaddr[1] = BUF->sipaddr[1];
    321       BUF->sipaddr[0] = uip_hostaddr[0];
    322       BUF->sipaddr[1] = uip_hostaddr[1];
    323 
    324       BUF->ethhdr.type = HTONS(UIP_ETHTYPE_ARP);
     315      uip_ipaddr_copy(&BUF->dipaddr, &BUF->sipaddr);
     316      uip_ipaddr_copy(&BUF->sipaddr, &uip_hostaddr);
     317
     318      BUF->ethhdr.type = UIP_HTONS(UIP_ETHTYPE_ARP);
    325319      uip_len = sizeof(struct arp_hdr);
    326320    }
    327321    break;
    328   case HTONS(ARP_REPLY):
     322  case UIP_HTONS(ARP_REPLY):
    329323    /* ARP reply. We insert or update the ARP table if it was meant
    330324       for us. */
    331     if(uip_ipaddr_cmp(BUF->dipaddr, uip_hostaddr)) {
    332       uip_arp_update(BUF->sipaddr, &BUF->shwaddr);
     325    if(uip_ipaddr_cmp(&BUF->dipaddr, &uip_hostaddr)) {
     326      uip_arp_update(&BUF->sipaddr, &BUF->shwaddr);
    333327    }
    334328    break;
     
    378372
    379373  /* First check if destination is a local broadcast. */
    380   if(uip_ipaddr_cmp(IPBUF->destipaddr, broadcast_ipaddr)) {
     374  if(uip_ipaddr_cmp(&IPBUF->destipaddr, &uip_broadcast_addr)) {
    381375    memcpy(IPBUF->ethhdr.dest.addr, broadcast_ethaddr.addr, 6);
    382   }
    383   else if(uip_ipaddr_maskcmp(IPBUF->destipaddr, multicast_ipaddr, multicast_mask)) {
     376  } else if(IPBUF->destipaddr.u8[0] == 224) {
     377    /* Multicast. */
    384378    IPBUF->ethhdr.dest.addr[0] = 0x01;
    385379    IPBUF->ethhdr.dest.addr[1] = 0x00;
    386     IPBUF->ethhdr.dest.addr[2] = 0x5E;
    387     IPBUF->ethhdr.dest.addr[3] = uip_ipaddr2(IPBUF->destipaddr) & 0x7F;
    388     IPBUF->ethhdr.dest.addr[4] = uip_ipaddr3(IPBUF->destipaddr);
    389     IPBUF->ethhdr.dest.addr[5] = uip_ipaddr4(IPBUF->destipaddr);
     380    IPBUF->ethhdr.dest.addr[2] = 0x5e;
     381    IPBUF->ethhdr.dest.addr[3] = IPBUF->destipaddr.u8[1];
     382    IPBUF->ethhdr.dest.addr[4] = IPBUF->destipaddr.u8[2];
     383    IPBUF->ethhdr.dest.addr[5] = IPBUF->destipaddr.u8[3];
    390384  } else {
    391385    /* Check if the destination address is on the local network. */
    392     if(!uip_ipaddr_maskcmp(IPBUF->destipaddr, uip_hostaddr, uip_netmask)) {
     386    if(!uip_ipaddr_maskcmp(&IPBUF->destipaddr, &uip_hostaddr, &uip_netmask)) {
    393387      /* Destination address was not on the local network, so we need to
    394388         use the default router's IP address instead of the destination
    395389         address when determining the MAC address. */
    396       uip_ipaddr_copy(ipaddr, uip_draddr);
     390      uip_ipaddr_copy(&ipaddr, &uip_draddr);
    397391    } else {
    398392      /* Else, we use the destination IP address. */
    399       uip_ipaddr_copy(ipaddr, IPBUF->destipaddr);
    400     }
    401 
     393      uip_ipaddr_copy(&ipaddr, &IPBUF->destipaddr);
     394    }
    402395    for(i = 0; i < UIP_ARPTAB_SIZE; ++i) {
    403396      tabptr = &arp_table[i];
    404       if(uip_ipaddr_cmp(ipaddr, tabptr->ipaddr)) {
     397      if(uip_ipaddr_cmp(&ipaddr, &tabptr->ipaddr)) {
    405398        break;
    406399      }
     
    413406      memset(BUF->ethhdr.dest.addr, 0xff, 6);
    414407      memset(BUF->dhwaddr.addr, 0x00, 6);
    415       memcpy(BUF->ethhdr.src.addr, uip_ethaddr.addr, 6);
    416       memcpy(BUF->shwaddr.addr, uip_ethaddr.addr, 6);
    417 
    418       uip_ipaddr_copy(BUF->dipaddr, ipaddr);
    419       uip_ipaddr_copy(BUF->sipaddr, uip_hostaddr);
    420       BUF->opcode = HTONS(ARP_REQUEST); /* ARP request. */
    421       BUF->hwtype = HTONS(ARP_HWTYPE_ETH);
    422       BUF->protocol = HTONS(UIP_ETHTYPE_IP);
     408      memcpy(BUF->ethhdr.src.addr, uip_lladdr.addr, 6);
     409      memcpy(BUF->shwaddr.addr, uip_lladdr.addr, 6);
     410
     411      uip_ipaddr_copy(&BUF->dipaddr, &ipaddr);
     412      uip_ipaddr_copy(&BUF->sipaddr, &uip_hostaddr);
     413      BUF->opcode = UIP_HTONS(ARP_REQUEST); /* ARP request. */
     414      BUF->hwtype = UIP_HTONS(ARP_HWTYPE_ETH);
     415      BUF->protocol = UIP_HTONS(UIP_ETHTYPE_IP);
    423416      BUF->hwlen = 6;
    424417      BUF->protolen = 4;
    425       BUF->ethhdr.type = HTONS(UIP_ETHTYPE_ARP);
     418      BUF->ethhdr.type = UIP_HTONS(UIP_ETHTYPE_ARP);
    426419
    427420      uip_appdata = &uip_buf[UIP_TCPIP_HLEN + UIP_LLH_LEN];
     
    434427    memcpy(IPBUF->ethhdr.dest.addr, tabptr->ethaddr.addr, 6);
    435428  }
    436   memcpy(IPBUF->ethhdr.src.addr, uip_ethaddr.addr, 6);
    437 
    438   IPBUF->ethhdr.type = HTONS(UIP_ETHTYPE_IP);
     429  memcpy(IPBUF->ethhdr.src.addr, uip_lladdr.addr, 6);
     430
     431  IPBUF->ethhdr.type = UIP_HTONS(UIP_ETHTYPE_IP);
    439432
    440433  uip_len += sizeof(struct uip_eth_hdr);
     
    444437/** @} */
    445438/** @} */
     439
  • uKadecot/trunk/uip/net/ipv4/uip_arp.h

    r158 r262  
    6161#endif
    6262
    63 extern struct uip_eth_addr uip_ethaddr;
     63extern struct uip_eth_addr uip_lladdr;
    6464
    6565/**
     
    143143 * \hideinitializer
    144144 */
    145 #define uip_setethaddr(eaddr) do {uip_ethaddr.addr[0] = eaddr.addr[0]; \
    146                               uip_ethaddr.addr[1] = eaddr.addr[1];\
    147                               uip_ethaddr.addr[2] = eaddr.addr[2];\
    148                               uip_ethaddr.addr[3] = eaddr.addr[3];\
    149                               uip_ethaddr.addr[4] = eaddr.addr[4];\
    150                               uip_ethaddr.addr[5] = eaddr.addr[5];} while(0)
     145#define uip_setethaddr(eaddr) do {uip_lladdr.addr[0] = eaddr.addr[0]; \
     146                              uip_lladdr.addr[1] = eaddr.addr[1];\
     147                              uip_lladdr.addr[2] = eaddr.addr[2];\
     148                              uip_lladdr.addr[3] = eaddr.addr[3];\
     149                              uip_lladdr.addr[4] = eaddr.addr[4];\
     150                              uip_lladdr.addr[5] = eaddr.addr[5];} while(0)
    151151
    152152/** @} */
    153 /** @} */
     153
    154154
    155155#endif /* __UIP_ARP_H__ */
     156/** @} */
  • uKadecot/trunk/uip/target/if_rx62n/if_rx62n.c

    r158 r262  
    251251        rx62n_bus_init();
    252252
    253         memcpy(uip_ethaddr.addr, mac_addr, sizeof(uip_ethaddr.addr));
     253        memcpy(uip_lladdr.addr, mac_addr, sizeof(uip_lladdr.addr));
    254254}
    255255
  • uKadecot/trunk/uip/task/uip_adpt.c

    r158 r262  
    9191
    9292        start = buf;
    93         buf += convert_hexdigit(buf, (uint_t)((ipaddr[0] >> 0) & 0xff), 10, 0, ' ');
     93        buf += convert_hexdigit(buf, (uint_t)((ipaddr.u16[0] >> 0) & 0xff), 10, 0, ' ');
    9494        *(buf ++) = '.';
    95         buf += convert_hexdigit(buf, (uint_t)((ipaddr[0] >> 8) & 0xff), 10, 0, ' ');
     95        buf += convert_hexdigit(buf, (uint_t)((ipaddr.u16[0] >> 8) & 0xff), 10, 0, ' ');
    9696        *(buf ++) = '.';
    97         buf += convert_hexdigit(buf, (uint_t)((ipaddr[1] >> 0) & 0xff), 10, 0, ' ');
     97        buf += convert_hexdigit(buf, (uint_t)((ipaddr.u16[1] >> 0) & 0xff), 10, 0, ' ');
    9898        *(buf ++) = '.';
    99         buf += convert_hexdigit(buf, (uint_t)((ipaddr[1] >> 8) & 0xff), 10, 0, ' ');
     99        buf += convert_hexdigit(buf, (uint_t)((ipaddr.u16[1] >> 8) & 0xff), 10, 0, ' ');
    100100        *buf = '\0';
    101101
  • uKadecot/trunk/uip/task/uip_task.c

    r158 r262  
    106106        IF_ETHER_NIC_INIT(ic);
    107107
    108         uip_sethostaddr(my_ip);
    109         uip_setnetmask(my_netmask);
    110         uip_setdraddr(my_default_router);
     108        uip_sethostaddr((uip_ipaddr_t *)&my_ip);
     109        uip_setnetmask((uip_ipaddr_t *)&my_netmask);
     110        uip_setdraddr((uip_ipaddr_t *)&my_default_router);
    111111
    112112        timer_set(&uiptsk->periodic_timer, CLOCK_SECOND / 2);
     
    116116#ifdef __DHCPC_H__
    117117        if(dhcp_enable){
    118                 dhcpc = dhcpc_init(uip_ethaddr.addr, sizeof(uip_ethaddr.addr));
     118                dhcpc = dhcpc_init(uip_lladdr.addr, sizeof(uip_lladdr.addr));
    119119        }
    120120#endif
     
    172172                        uip_len = IF_ETHER_NIC_READ(ic, (void **)&uip_buf);
    173173                        if ((uip_len > 0) && (uip_buf != NULL)){
    174                                 if (((struct uip_eth_hdr *)uip_buf)->type == htons(UIP_ETHTYPE_IP)) {
     174                                if (((struct uip_eth_hdr *)uip_buf)->type == uip_htons(UIP_ETHTYPE_IP)) {
    175175                                        uip_arp_ipin();
    176176                                        uip_input();
     
    190190                                        }
    191191                                }
    192                                 else if (((struct uip_eth_hdr *)uip_buf)->type == htons(UIP_ETHTYPE_ARP)) {
     192                                else if (((struct uip_eth_hdr *)uip_buf)->type == uip_htons(UIP_ETHTYPE_ARP)) {
    193193                                        uip_arp_arpin();
    194194                                        /* If the above function invocation resulted in data that
     
    215215                        sil_wrb_mem((uint8_t *)0x0008C02A, sil_reb_mem((uint8_t *)0x0008C02A) | 0x02);
    216216
    217                         uip_ipaddr_copy(cepid->ripaddr, buf->ripaddr);
     217                        uip_ipaddr_copy(&cepid->ripaddr, &buf->ripaddr);
    218218                        cepid->rport = buf->rport;
    219219                        uip_buf = buf->data;
     
    222222                        uip_udp_conn = cepid;
    223223                        uip_process(UIP_UDP_SEND_CONN);
    224                         uip_ipaddr(cepid->ripaddr, 0, 0, 0, 0);
     224                        uip_ipaddr(&cepid->ripaddr, 0, 0, 0, 0);
    225225                        cepid->rport = 0;
    226226                        uip_arp_out();
     
    346346        struct uip_conn *cepid;
    347347
    348         cepid = uip_connect((uip_ipaddr_t *)&pk_ccep->ripaddr, htons(pk_ccep->rport));
     348        cepid = uip_connect((uip_ipaddr_t *)&pk_ccep->ripaddr, uip_htons(pk_ccep->rport));
    349349        if (cepid != NULL) {
    350350                //cepid->appstate.tcp_callback = pk_ccep->callback;
     
    361361        if (buf->len == 0) {
    362362                buf->cepid.tcp = cepid;
    363                 uip_ipaddr_copy(buf->ripaddr, p_dstaddr->ipaddr);
    364                 buf->rport = htons(p_dstaddr->portno);
     363                uip_ipaddr_copy(&buf->ripaddr, &p_dstaddr->ipaddr);
     364                buf->rport = uip_htons(p_dstaddr->portno);
    365365                memcpy(&buf->data[UIP_IPTCPH_LEN + UIP_LLH_LEN], data, len);
    366366                uip_out_buf[uip_out_wpos].len = len;
     
    389389                rlen = len;
    390390
    391         uip_ipaddr_copy(p_srcaddr->ipaddr, ((struct uip_tcpip_hdr *)&uip_buf[UIP_LLH_LEN])->srcipaddr);
    392         p_srcaddr->portno = ntohs(((struct uip_tcpip_hdr *)&uip_buf[UIP_LLH_LEN])->srcport);
     391        uip_ipaddr_copy(&p_srcaddr->ipaddr, &((struct uip_tcpip_hdr *)&uip_buf[UIP_LLH_LEN])->srcipaddr);
     392        p_srcaddr->portno = uip_ntohs(((struct uip_tcpip_hdr *)&uip_buf[UIP_LLH_LEN])->srcport);
    393393        memcpy(data, uip_appdata, rlen);
    394394
     
    408408        struct uip_udp_conn *cepid;
    409409
    410         cepid = uip_udp_new((uip_ipaddr_t *)&pk_ccep->ripaddr, htons(pk_ccep->rport));
     410        cepid = uip_udp_new((uip_ipaddr_t *)&pk_ccep->ripaddr, uip_htons(pk_ccep->rport));
    411411        if (cepid != NULL) {
    412412                cepid->appstate.udp_callback = pk_ccep->callback;
    413                 uip_udp_bind(cepid, htons(pk_ccep->lport));
     413                uip_udp_bind(cepid, uip_htons(pk_ccep->lport));
    414414        }
    415415
     
    424424        if (buf->len == 0) {
    425425                buf->cepid.udp = cepid;
    426                 uip_ipaddr_copy(buf->ripaddr, p_dstaddr->ipaddr);
    427                 buf->rport = htons(p_dstaddr->portno);
     426                uip_ipaddr_copy(&buf->ripaddr, &p_dstaddr->ipaddr);
     427                buf->rport = uip_htons(p_dstaddr->portno);
    428428                memcpy(&buf->data[UIP_IPUDPH_LEN + UIP_LLH_LEN], data, len);
    429429                uip_out_buf[uip_out_wpos].len = len;
     
    452452                rlen = len;
    453453
    454         uip_ipaddr_copy(p_srcaddr->ipaddr, ((struct uip_udpip_hdr *)&uip_buf[UIP_LLH_LEN])->srcipaddr);
    455         p_srcaddr->portno = ntohs(((struct uip_udpip_hdr *)&uip_buf[UIP_LLH_LEN])->srcport);
     454        uip_ipaddr_copy(&p_srcaddr->ipaddr, &((struct uip_udpip_hdr *)&uip_buf[UIP_LLH_LEN])->srcipaddr);
     455        p_srcaddr->portno = uip_ntohs(((struct uip_udpip_hdr *)&uip_buf[UIP_LLH_LEN])->srcport);
    456456        memcpy(data, uip_appdata, rlen);
    457457
     
    476476{
    477477        sil_wrb_mem((uint8_t *)0x0008C02A, sil_reb_mem((uint8_t *)0x0008C02A) & ~0x04);
    478         uip_sethostaddr(s->ipaddr);
    479         uip_setnetmask(s->netmask);
    480         uip_setdraddr(s->default_router);
     478        uip_sethostaddr((uip_ipaddr_t *)&s->ipaddr);
     479        uip_setnetmask((uip_ipaddr_t *)&s->netmask);
     480        uip_setdraddr((uip_ipaddr_t *)&s->default_router);
    481481        // resolv_conf(s->dnsaddr);
    482482        DHCP4_CLI_SET_ADDR_CALLBACK();
Note: See TracChangeset for help on using the changeset viewer.