Changeset 262 for uKadecot/trunk/uip
- Timestamp:
- Nov 18, 2016, 2:58:30 PM (7 years ago)
- Location:
- uKadecot/trunk/uip
- Files:
-
- 17 edited
Legend:
- Unmodified
- Added
- Removed
-
uKadecot/trunk/uip/apps/dhcpc/dhcpc.c
r158 r262 160 160 memcpy(m->xid, xid, sizeof(m->xid)); 161 161 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)); 165 165 memset(m->yiaddr, 0, sizeof(m->yiaddr)); 166 166 memset(m->siaddr, 0, sizeof(m->siaddr)); … … 329 329 uip_ipaddr3(s->default_router), uip_ipaddr4(s->default_router)); 330 330 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])); 332 332 #endif 333 333 … … 356 356 uip_ipaddr_t addr; 357 357 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)); 360 360 if(conn != NULL) { 361 361 s = &conn->appstate.parblk.dhcpc; … … 367 367 s->conn->appstate.udp_callback = dhcpc_appcall; 368 368 369 uip_udp_bind(conn, HTONS(DHCPC_CLIENT_PORT));369 uip_udp_bind(conn, UIP_HTONS(DHCPC_CLIENT_PORT)); 370 370 371 371 PT_INIT(&s->pt); … … 386 386 dhcpc_request(struct dhcpc_state *s) 387 387 { 388 ui nt16_t ipaddr[2];388 uip_ipaddr_t ipaddr; 389 389 390 390 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); 393 393 uip_udp_conn = s->conn; 394 394 uip_process(UIP_UDP_TIMER); -
uKadecot/trunk/uip/apps/webserver/httpd.c
r158 r262 545 545 httpd_init(void) 546 546 { 547 uip_listen( HTONS(41314));547 uip_listen(UIP_HTONS(41314)); 548 548 549 549 httpd_fs_init(); -
uKadecot/trunk/uip/net/ip/psock.h
r158 r262 111 111 uint8_t *readptr; /* Pointer to the next data to be read. */ 112 112 113 char*bufptr; /* Pointer to the buffer used for buffering113 uint8_t *bufptr; /* Pointer to the buffer used for buffering 114 114 incoming data. */ 115 115 … … 124 124 }; 125 125 126 void psock_init(struct psock *psock, char*buffer, unsigned int buffersize);126 void psock_init(struct psock *psock, uint8_t *buffer, unsigned int buffersize); 127 127 /** 128 128 * Initialize a protosocket. … … 135 135 * initialized 136 136 * 137 * \param buffer ( char*) A pointer to the input buffer for the137 * \param buffer (uint8_t *) A pointer to the input buffer for the 138 138 * protosocket. 139 139 * … … 158 158 #define PSOCK_BEGIN(psock) PT_BEGIN(&((psock)->pt)) 159 159 160 PT_THREAD(psock_send(struct psock *psock, const char*buf, unsigned int len));160 PT_THREAD(psock_send(struct psock *psock, const uint8_t *buf, unsigned int len)); 161 161 /** 162 162 * Send data. … … 169 169 * data is to be sent. 170 170 * 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. 172 172 * 173 173 * \param datalen (unsigned int) The length of the data that is to be … … 190 190 */ 191 191 #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))) 193 193 194 194 PT_THREAD(psock_generator_send(struct psock *psock, … … 257 257 * This macro will block waiting for data and read the data into the 258 258 * input buffer specified with the call to PSOCK_INIT(). Data is only 259 * read until the specifie ed character appears in the data stream.259 * read until the specified character appears in the data stream. 260 260 * 261 261 * \param psock (struct psock *) A pointer to the protosocket from which … … 353 353 PSOCK_BEGIN(s); 354 354 355 PSOCK_WAIT_UNTIL(s, PSOCK_NEW ADATA(s) || timer_expired(t));355 PSOCK_WAIT_UNTIL(s, PSOCK_NEWDATA(s) || timer_expired(t)); 356 356 357 357 if(PSOCK_NEWDATA(s)) { … … 379 379 380 380 /** @} */ 381 /** @} */ -
uKadecot/trunk/uip/net/ip/uip.h
r158 r262 15 15 * 16 16 */ 17 18 17 19 18 /* … … 57 56 58 57 /** 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 */ 64 61 #if UIP_CONF_IPV6 62 typedef union uip_ip6addr_t { 63 uint8_t u8[16]; /* Initializer, must come first!!! */ 64 uint16_t u16[8]; 65 } uip_ip6addr_t; 66 65 67 typedef uip_ip6addr_t uip_ipaddr_t; 66 68 #else /* UIP_CONF_IPV6 */ 69 typedef 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; 67 76 typedef uip_ip4addr_t uip_ipaddr_t; 68 77 #endif /* UIP_CONF_IPV6 */ … … 73 82 * handled by the following three functions. 74 83 */ 75 76 84 /** 77 85 * \defgroup uipconffunc uIP configuration functions … … 104 112 * \hideinitializer 105 113 */ 106 #define uip_sethostaddr(addr) uip_ipaddr_copy( uip_hostaddr, (addr))114 #define uip_sethostaddr(addr) uip_ipaddr_copy(&uip_hostaddr, (addr)) 107 115 108 116 /** … … 124 132 * \hideinitializer 125 133 */ 126 #define uip_gethostaddr(addr) uip_ipaddr_copy((addr), uip_hostaddr)134 #define uip_gethostaddr(addr) uip_ipaddr_copy((addr), &uip_hostaddr) 127 135 128 136 /** … … 136 144 * \hideinitializer 137 145 */ 138 #define uip_setdraddr(addr) uip_ipaddr_copy( uip_draddr, (addr))146 #define uip_setdraddr(addr) uip_ipaddr_copy(&uip_draddr, (addr)) 139 147 140 148 /** … … 148 156 * \hideinitializer 149 157 */ 150 #define uip_setnetmask(addr) uip_ipaddr_copy( uip_netmask, (addr))158 #define uip_setnetmask(addr) uip_ipaddr_copy(&uip_netmask, (addr)) 151 159 152 160 … … 159 167 * \hideinitializer 160 168 */ 161 #define uip_getdraddr(addr) uip_ipaddr_copy((addr), uip_draddr)169 #define uip_getdraddr(addr) uip_ipaddr_copy((addr), &uip_draddr) 162 170 163 171 /** … … 169 177 * \hideinitializer 170 178 */ 171 #define uip_getnetmask(addr) uip_ipaddr_copy((addr), uip_netmask)179 #define uip_getnetmask(addr) uip_ipaddr_copy((addr), &uip_netmask) 172 180 173 181 /** @} */ … … 238 246 uip_len = ethernet_devicedrver_poll(); 239 247 if(uip_len > 0) { 240 if(BUF->type == HTONS(UIP_ETHTYPE_IP)) {248 if(BUF->type == UIP_HTONS(UIP_ETHTYPE_IP)) { 241 249 uip_arp_ipin(); 242 250 uip_input(); … … 245 253 ethernet_devicedriver_send(); 246 254 } 247 } else if(BUF->type == HTONS(UIP_ETHTYPE_ARP)) {255 } else if(BUF->type == UIP_HTONS(UIP_ETHTYPE_ARP)) { 248 256 uip_arp_arpin(); 249 257 if(uip_len > 0) { … … 257 265 #define uip_input() uip_process(UIP_DATA) 258 266 267 259 268 /** 260 269 * Periodic processing for a connection identified by its number. … … 270 279 * should be called to send out the packet. 271 280 * 272 * The usu sal way of calling the function is through a for() loop like281 * The usual way of calling the function is through a for() loop like 273 282 * this: 274 283 \code … … 325 334 326 335 /** 327 * Re uqest that a particular connection should be polled.336 * Request that a particular connection should be polled. 328 337 * 329 338 * Similar to uip_periodic_conn() but does not perform any timer … … 390 399 #define uip_udp_periodic_conn(conn) do { uip_udp_conn = conn; \ 391 400 uip_process(UIP_UDP_TIMER); } while (0) 392 393 394 401 #endif /* UIP_UDP */ 395 402 … … 444 451 * 445 452 * \note Since this function expects the port number in network byte 446 * order, a conversion using HTONS() orhtons() 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)); 450 457 \endcode 451 458 * … … 458 465 * 459 466 * \note Since this function expects the port number in network byte 460 * order, a conversion using HTONS() orhtons() 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)); 464 471 \endcode 465 472 * … … 472 479 * 473 480 * This function is used to start a new connection to the specified 474 * port on the speci ed host. It allocates a new connection identifier,481 * port on the specified host. It allocates a new connection identifier, 475 482 * sets the connection to the SYN_SENT state and sets the 476 483 * retransmission timer to 0. This will cause a TCP SYN segment to be … … 479 486 * uip_connect(). 480 487 * 481 * \note This function is ava liable only if support for active open488 * \note This function is available only if support for active open 482 489 * has been configured by defining UIP_ACTIVE_OPEN to 1 in uipopt.h. 483 490 * 484 491 * \note Since this function requires the port number to be in network 485 * byte order, a conversion using HTONS() orhtons() is necessary.492 * byte order, a conversion using UIP_HTONS() or uip_htons() is necessary. 486 493 * 487 494 \code … … 489 496 490 497 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 ho t.498 uip_connect(&ipaddr, UIP_HTONS(80)); 499 \endcode 500 * 501 * \param ripaddr The IP address of the remote host. 495 502 * 496 503 * \param port A 16-bit port number in network byte order. … … 523 530 * 524 531 * The amount of data that actually is sent out after a call to this 525 * func ion is determined by the maximum amount of data TCP allows. uIP532 * function is determined by the maximum amount of data TCP allows. uIP 526 533 * will automatically crop the data so that only the appropriate 527 534 * amount of data is sent. The function uip_mss() can be used to query … … 543 550 544 551 /** 545 * The length of any incoming data that is currently ava liable (if avaliable)552 * The length of any incoming data that is currently available (if available) 546 553 * in the uip_appdata buffer. 547 554 * … … 578 585 * 579 586 * This function will abort (reset) the current connection, and is 580 * usually used when an error has occur ed that prevents using the587 * usually used when an error has occurred that prevents using the 581 588 * uip_close() function. 582 589 * … … 635 642 * Will reduce to non-zero if there is new data for the application 636 643 * present at the uip_appdata pointer. The size of the data is 637 * ava liable through the uip_len variable.644 * available through the uip_len variable. 638 645 * 639 646 * \hideinitializer … … 721 728 722 729 /** 723 * Get the initial maxi um segment size (MSS) of the current730 * Get the initial maximum segment size (MSS) of the current 724 731 * connection. 725 732 * … … 729 736 730 737 /** 731 * Get the current maxi um segment size that can be sent on the current738 * Get the current maximum segment size that can be sent on the current 732 739 * connection. 733 740 * 734 * The current maxi umum segment size that can be sent on the741 * The current maximum segment size that can be sent on the 735 742 * connection is computed from the receiver's window and the MSS of 736 743 * the connection (which also is available by calling … … 756 763 757 764 uip_ipaddr(&addr, 192,168,2,1); 758 c = uip_udp_new(&addr, HTONS(12345));765 c = uip_udp_new(&addr, UIP_HTONS(12345)); 759 766 if(c != NULL) { 760 uip_udp_bind(c, HTONS(12344));767 uip_udp_bind(c, UIP_HTONS(12344)); 761 768 } 762 769 \endcode … … 768 775 * if no connection could be allocated. 769 776 */ 770 struct uip_udp_conn *uip_udp_new( uip_ipaddr_t *ripaddr, uint16_t rport);777 struct uip_udp_conn *uip_udp_new(const uip_ipaddr_t *ripaddr, uint16_t rport); 771 778 772 779 /** … … 829 836 830 837 uip_ipaddr(&ipaddr, 192,168,1,2); 831 c = uip_connect(&ipaddr, HTONS(80));838 c = uip_connect(&ipaddr, UIP_HTONS(80)); 832 839 \endcode 833 840 * … … 842 849 * \hideinitializer 843 850 */ 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; \ 847 856 } while(0) 848 857 … … 855 864 */ 856 865 #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); \ 865 874 } while(0) 866 875 … … 883 892 * \hideinitializer 884 893 */ 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 893 897 894 898 /** … … 913 917 */ 914 918 #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]) 917 921 #else /* !UIP_CONF_IPV6 */ 918 922 #define uip_ipaddr_cmp(addr1, addr2) (memcmp(addr1, addr2, sizeof(uip_ip6addr_t)) == 0) … … 997 1001 * \hideinitializer 998 1002 */ 999 #define uip_ipaddr1(addr) ( htons(((uint16_t *)(addr))[0]) >> 8)1003 #define uip_ipaddr1(addr) ((addr)->u8[0]) 1000 1004 1001 1005 /** … … 1017 1021 * \hideinitializer 1018 1022 */ 1019 #define uip_ipaddr2(addr) ( htons(((uint16_t *)(addr))[0]) & 0xff)1023 #define uip_ipaddr2(addr) ((addr)->u8[1]) 1020 1024 1021 1025 /** … … 1037 1041 * \hideinitializer 1038 1042 */ 1039 #define uip_ipaddr3(addr) ( htons(((uint16_t *)(addr))[1]) >> 8)1043 #define uip_ipaddr3(addr) ((addr)->u8[2]) 1040 1044 1041 1045 /** … … 1057 1061 * \hideinitializer 1058 1062 */ 1059 #define uip_ipaddr4(addr) ( htons(((uint16_t *)(addr))[1]) & 0xff)1063 #define uip_ipaddr4(addr) ((addr)->u8[3]) 1060 1064 1061 1065 /** … … 1064 1068 * This macro is primarily used for converting constants from host 1065 1069 * 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 HTONS1070 * network byte order, use the uip_htons() function instead. 1071 * 1072 * \hideinitializer 1073 */ 1074 #ifndef UIP_HTONS 1071 1075 # if UIP_BYTE_ORDER == UIP_BIG_ENDIAN 1072 # define HTONS(n) (n) 1076 # define UIP_HTONS(n) (n) 1077 # define UIP_HTONL(n) (n) 1073 1078 # 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)) 1075 1081 # endif /* UIP_BYTE_ORDER == UIP_BIG_ENDIAN */ 1076 1082 #else 1077 #error " HTONS already defined!"1078 #endif /* HTONS */1083 #error "UIP_HTONS already defined!" 1084 #endif /* UIP_HTONS */ 1079 1085 1080 1086 /** … … 1083 1089 * This function is primarily used for converting variables from host 1084 1090 * byte order to network byte order. For converting constants to 1085 * network byte order, use the HTONS() macro instead.1086 */ 1087 #ifndef htons1088 uint16_t htons(uint16_t val);1089 #endif /* htons */1090 #ifndef ntohs1091 #define ntohshtons1091 * network byte order, use the UIP_HTONS() macro instead. 1092 */ 1093 #ifndef uip_htons 1094 uint16_t uip_htons(uint16_t val); 1095 #endif /* uip_htons */ 1096 #ifndef uip_ntohs 1097 #define uip_ntohs uip_htons 1092 1098 #endif 1093 1099 … … 1150 1156 * The uip_conn structure is used for identifying a connection. All 1151 1157 * but one field in the structure are to be considered read-only by an 1152 * application. The only exception is the appstate field whos purpose1158 * application. The only exception is the appstate field whose purpose 1153 1159 * is to let the application store application-specific state (e.g., 1154 1160 * file pointers) for the connection. The type of this field is … … 1192 1198 * connection. 1193 1199 */ 1200 1194 1201 extern struct uip_conn *uip_conn; 1195 1202 /* The array containing all uIP connections. */ … … 1204 1211 */ 1205 1212 extern uint8_t uip_acc32[4]; 1206 1207 1213 /** @} */ 1208 1214 … … 1236 1242 struct uip_stats { 1237 1243 struct { 1238 uip_stats_t drop; /**< Number of dropped packets at the IP1239 layer. */1240 1244 uip_stats_t recv; /**< Number of received packets at the IP 1241 1245 layer. */ 1242 1246 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 1243 1249 layer. */ 1244 1250 uip_stats_t vhlerr; /**< Number of packets dropped due to wrong … … 1256 1262 } ip; /**< IP statistics. */ 1257 1263 struct { 1258 uip_stats_t drop; /**< Number of dropped ICMP packets. */1259 1264 uip_stats_t recv; /**< Number of received ICMP packets. */ 1260 1265 uip_stats_t sent; /**< Number of sent ICMP packets. */ 1266 uip_stats_t drop; /**< Number of dropped ICMP packets. */ 1261 1267 uip_stats_t typeerr; /**< Number of ICMP packets with a wrong 1262 1268 type. */ 1263 1269 } icmp; /**< ICMP statistics. */ 1264 1270 struct { 1265 uip_stats_t drop; /**< Number of dropped TCP segments. */1266 1271 uip_stats_t recv; /**< Number of recived TCP segments. */ 1267 1272 uip_stats_t sent; /**< Number of sent TCP segments. */ 1273 uip_stats_t drop; /**< Number of dropped TCP segments. */ 1268 1274 uip_stats_t chkerr; /**< Number of TCP segments with a bad 1269 1275 checksum. */ … … 1273 1279 uip_stats_t rexmit; /**< Number of retransmitted TCP segments. */ 1274 1280 uip_stats_t syndrop; /**< Number of dropped SYNs due to too few 1275 connections was ava liable. */1281 connections was available. */ 1276 1282 uip_stats_t synrst; /**< Number of SYNs for closed ports, 1277 1283 triggering a RST. */ … … 1301 1307 */ 1302 1308 /*---------------------------------------------------------------------------*/ 1309 1310 1311 1303 1312 /* uint8_t uip_flags: 1304 1313 * 1305 1314 * When the application is called, uip_flags will contain the flags 1306 1315 * that are defined in this file. Please read below for more 1307 * info mation.1316 * information. 1308 1317 */ 1309 1318 extern uint8_t uip_flags; … … 1312 1321 before calling the application callback. The UIP_ACKDATA, 1313 1322 UIP_NEWDATA, and UIP_CLOSE flags may both be set at the same time, 1314 whereas the others are mutual y exclusive. Note that these flags1323 whereas the others are mutually exclusive. Note that these flags 1315 1324 should *NOT* be accessed directly, but only through the uIP 1316 1325 functions/macros. */ … … 1356 1365 incoming data that should be processed, or because the periodic 1357 1366 timer has fired. These values are never used directly, but only in 1358 the macros edefined in this file. */1367 the macros defined in this file. */ 1359 1368 1360 1369 #define UIP_DATA 1 /* Tells uIP that there is incoming … … 1413 1422 proto; 1414 1423 uint16_t ipchksum; 1415 uint16_t srcipaddr[2], 1416 destipaddr[2]; 1424 uip_ipaddr_t srcipaddr, destipaddr; 1417 1425 #endif /* UIP_CONF_IPV6 */ 1418 1426 … … 1450 1458 proto; 1451 1459 uint16_t ipchksum; 1452 uint16_t srcipaddr[2], 1453 destipaddr[2]; 1460 uip_ipaddr_t srcipaddr, destipaddr; 1454 1461 #endif /* UIP_CONF_IPV6 */ 1455 1462 1456 /* ICMP (echo)header. */1463 /* ICMP header. */ 1457 1464 uint8_t type, icode; 1458 1465 uint16_t icmpchksum; 1459 1466 #if !UIP_CONF_IPV6 1460 1467 uint16_t id, seqno; 1461 #else /* !UIP_CONF_IPV6 */1462 1468 uint8_t flags, reserved1, reserved2, reserved3; 1463 1469 uint8_t icmp6data[16]; … … 1487 1493 proto; 1488 1494 uint16_t ipchksum; 1489 uint16_t srcipaddr[2], 1490 destipaddr[2]; 1495 uip_ipaddr_t srcipaddr, destipaddr; 1491 1496 #endif /* UIP_CONF_IPV6 */ 1492 1497 … … 1548 1553 extern uip_ipaddr_t uip_hostaddr, uip_netmask, uip_draddr; 1549 1554 #endif /* UIP_FIXEDADDR */ 1555 extern const uip_ipaddr_t uip_broadcast_addr; 1556 extern const uip_ipaddr_t uip_all_zeroes_addr; 1550 1557 1551 1558 -
uKadecot/trunk/uip/net/ip/uiplib.c
r158 r262 40 40 41 41 /*-----------------------------------------------------------------------------------*/ 42 unsigned char 43 uiplib_ipaddrconv(c har *addrstr, unsigned char*ipaddr)42 int 43 uiplib_ipaddrconv(const char *addrstr, uip_ipaddr_t *ipaddr) 44 44 { 45 45 unsigned char tmp; … … 58 58 } 59 59 if(c == '.' || c == 0) { 60 *ipaddr = tmp; 61 ++ipaddr; 60 ipaddr->u8[i] = tmp; 62 61 tmp = 0; 63 62 } else if(c >= '0' && c <= '9') { -
uKadecot/trunk/uip/net/ip/uiplib.h
r157 r262 53 53 * 54 54 * 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. 57 58 * 58 59 * \param addrstr A pointer to a string containing the IP address in 59 60 * textual form. 60 61 * 61 * \param addr A pointer to a 4-byte arraythat will be filled in with62 * \param addr A pointer to a uip_ipaddr_t that will be filled in with 62 63 * the numerical representation of the address. 63 64 * … … 65 66 * \retval Non-zero If the IP address was parsed. 66 67 */ 67 unsigned char uiplib_ipaddrconv(char *addrstr, unsigned char*addr);68 int uiplib_ipaddrconv(const char *addrstr, uip_ipaddr_t *addr); 68 69 69 70 /** @} */ -
uKadecot/trunk/uip/net/ipv4/uip-fw.c
r158 r262 86 86 proto; 87 87 uint16_t ipchksum; 88 uint16_t srcipaddr[2], 89 destipaddr[2]; 88 uip_ipaddr_t srcipaddr, destipaddr; 90 89 91 90 /* TCP header. */ … … 112 111 proto; 113 112 uint16_t ipchksum; 114 uint16_t srcipaddr[2], 115 destipaddr[2]; 113 uip_ipaddr_t srcipaddr, destipaddr; 116 114 /* ICMP (echo) header. */ 117 115 uint8_t type, icode; … … 144 142 uint16_t timer; 145 143 146 ui nt16_t srcipaddr[2];147 ui nt16_t destipaddr[2];144 uip_ipaddr_t srcipaddr; 145 uip_ipaddr_t destipaddr; 148 146 uint16_t ipid; 149 147 uint8_t proto; … … 217 215 /*------------------------------------------------------------------------------*/ 218 216 static 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]); 217 ipaddr_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]); 223 223 } 224 224 /*------------------------------------------------------------------------------*/ … … 254 254 /* Set the IP destination address to be the source address of the 255 255 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); 262 257 263 258 /* 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); 266 260 267 261 /* The size of the ICMP time exceeded packet is 36 + the size of the … … 269 263 uip_len = 56; 270 264 ICMPBUF->len[0] = 0; 271 ICMPBUF->len[1] = uip_len;265 ICMPBUF->len[1] = (uint8_t)uip_len; 272 266 273 267 /* Fill in the other fields in the IP header. */ … … 313 307 fw->timer = FW_TIME; 314 308 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); 319 311 fw->proto = BUF->proto; 320 312 #if notdef … … 340 332 /* Walk through every network interface to check for a match. */ 341 333 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)) { 344 336 /* If there was a match, we break the loop. */ 345 337 return netif; … … 371 363 { 372 364 struct uip_fw_netif *netif; 365 #if UIP_BROADCAST 366 const struct uip_udpip_hdr *udp = (void *)BUF; 367 #endif /* UIP_BROADCAST */ 373 368 374 369 if(uip_len == 0) { … … 380 375 #if UIP_BROADCAST 381 376 /* 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)) { 385 378 if(defaultnetif != NULL) { 386 379 defaultnetif->output(); … … 422 415 /* First check if the packet is destined for ourselves and return 0 423 416 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)) { 426 418 return UIP_FW_LOCAL; 427 419 } … … 430 422 not yet configured, we should intercept all ICMP echo packets. */ 431 423 #if UIP_PINGADDRCONF 432 if( (uip_hostaddr[0] | uip_hostaddr[1]) == 0&&424 if(uip_ipaddr_cmp(&uip_hostaddr, &uip_all_zeroes_addr) && 433 425 BUF->proto == UIP_PROTO_ICMP && 434 426 ICMPBUF->type == ICMP_ECHO) { … … 447 439 #endif 448 440 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) && 453 443 #if notdef 454 444 fw->payload[0] == BUF->srcport && … … 464 454 in the uip_buf buffer and forward that packet back to the sender 465 455 of the packet. */ 456 466 457 if(BUF->ttl <= 1) { 467 458 /* 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)) { 469 460 return UIP_FW_LOCAL; 470 461 } … … 476 467 477 468 /* 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; 480 471 } else { 481 BUF->ipchksum = BUF->ipchksum + HTONS(0x0100);472 BUF->ipchksum = BUF->ipchksum + UIP_HTONS(0x0100); 482 473 } 483 474 … … 488 479 489 480 #if UIP_BROADCAST 490 if( BUF->destipaddr[0] == 0xffff && BUF->destipaddr[1] == 0xffff) {481 if(uip_ipaddr_cmp(&BUF->destipaddr, &uip_broadcast_addr)) { 491 482 return UIP_FW_LOCAL; 492 483 } -
uKadecot/trunk/uip/net/ipv4/uip-fw.h
r158 r262 55 55 struct uip_fw_netif *next; /**< Pointer to the next interface when 56 56 linked in a list. */ 57 ui nt16_t ipaddr[2]; /**< The IP address of this interface. */58 ui nt16_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. */ 59 59 uint8_t (* output)(void); 60 60 /**< A pointer to the function that … … 63 63 64 64 /** 65 * In tantiating macro for a uIP network interface.65 * Instantiating macro for a uIP network interface. 66 66 * 67 67 * Example: … … 80 80 #define UIP_FW_NETIF(ip1,ip2,ip3,ip4, nm1,nm2,nm3,nm4, outputfunc) \ 81 81 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} }, \ 84 84 outputfunc 85 85 -
uKadecot/trunk/uip/net/ipv4/uip-neighbor.c
r158 r262 83 83 /*---------------------------------------------------------------------------*/ 84 84 void 85 uip_neighbor_add(uip_ipaddr_t ipaddr, struct uip_neighbor_addr *addr)85 uip_neighbor_add(uip_ipaddr_t *ipaddr, struct uip_neighbor_addr *addr) 86 86 { 87 87 int i, oldest; … … 100 100 break; 101 101 } 102 if(uip_ipaddr_cmp( entries[i].ipaddr,addr)) {102 if(uip_ipaddr_cmp(&entries[i].ipaddr, ipaddr)) { 103 103 oldest = i; 104 104 break; … … 113 113 "oldest" variable). */ 114 114 entries[oldest].time = 0; 115 uip_ipaddr_copy( entries[oldest].ipaddr, ipaddr);115 uip_ipaddr_copy(&entries[oldest].ipaddr, ipaddr); 116 116 memcpy(&entries[oldest].addr, addr, sizeof(struct uip_neighbor_addr)); 117 117 } 118 118 /*---------------------------------------------------------------------------*/ 119 119 static struct neighbor_entry * 120 find_entry(uip_ipaddr_t ipaddr)120 find_entry(uip_ipaddr_t *ipaddr) 121 121 { 122 122 int i; 123 123 124 124 for(i = 0; i < ENTRIES; ++i) { 125 if(uip_ipaddr_cmp( entries[i].ipaddr, ipaddr)) {125 if(uip_ipaddr_cmp(&entries[i].ipaddr, ipaddr)) { 126 126 return &entries[i]; 127 127 } … … 131 131 /*---------------------------------------------------------------------------*/ 132 132 void 133 uip_neighbor_update(uip_ipaddr_t ipaddr)133 uip_neighbor_update(uip_ipaddr_t *ipaddr) 134 134 { 135 135 struct neighbor_entry *e; … … 142 142 /*---------------------------------------------------------------------------*/ 143 143 struct uip_neighbor_addr * 144 uip_neighbor_lookup(uip_ipaddr_t ipaddr)144 uip_neighbor_lookup(uip_ipaddr_t *ipaddr) 145 145 { 146 146 struct neighbor_entry *e; -
uKadecot/trunk/uip/net/ipv4/uip-neighbor.h
r158 r262 54 54 55 55 void 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);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); 59 59 void uip_neighbor_periodic(void); 60 60 -
uKadecot/trunk/uip/net/ipv4/uip.c
r158 r262 99 99 #if UIP_FIXEDADDR > 0 100 100 const 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 }; 103 102 const 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 }; 106 104 const 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 }; 109 106 #else 110 107 uip_ipaddr_t uip_hostaddr, uip_draddr, uip_netmask; 111 108 #endif /* UIP_FIXEDADDR */ 112 109 113 static const uip_ipaddr_t all_ones_addr =110 const uip_ipaddr_t uip_broadcast_addr = 114 111 #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 } }; 116 114 #else /* UIP_CONF_IPV6 */ 117 { 0xffff,0xffff};115 { { 0xff, 0xff, 0xff, 0xff } }; 118 116 #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 117 const uip_ipaddr_t uip_all_zeroes_addr = { { 0x0, /* rest is 0 */ } }; 126 118 127 119 #if UIP_FIXEDETHADDR 128 const struct uip_eth_addr uip_ ethaddr = {{UIP_ETHADDR0,120 const struct uip_eth_addr uip_lladdr = {{UIP_ETHADDR0, 129 121 UIP_ETHADDR1, 130 122 UIP_ETHADDR2, … … 133 125 UIP_ETHADDR5}}; 134 126 #else 135 struct uip_eth_addr uip_ ethaddr = {{0,0,0,0,0,0}};127 struct uip_eth_addr uip_lladdr = {{0,0,0,0,0,0}}; 136 128 #endif 137 129 … … 311 303 uip_chksum(uint16_t *data, uint16_t len) 312 304 { 313 return htons(chksum(0, (uint8_t *)data, len));305 return uip_htons(chksum(0, (uint8_t *)data, len)); 314 306 } 315 307 /*---------------------------------------------------------------------------*/ … … 322 314 sum = chksum(0, &uip_buf[UIP_LLH_LEN], UIP_IPH_LEN); 323 315 DEBUG_PRINTF("uip_ipchksum: sum 0x%04x\n", sum); 324 return (sum == 0) ? 0xffff : htons(sum);316 return (sum == 0) ? 0xffff : uip_htons(sum); 325 317 } 326 318 #endif … … 343 335 sum = upper_layer_len + proto; 344 336 /* 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)); 346 338 347 339 /* Sum TCP header and data. */ … … 349 341 upper_layer_len); 350 342 351 return (sum == 0) ? 0xffff : htons(sum);343 return (sum == 0) ? 0xffff : uip_htons(sum); 352 344 } 353 345 /*---------------------------------------------------------------------------*/ … … 375 367 #endif /* UIP_UDP_CHECKSUMS */ 376 368 #endif /* UIP_ARCH_CHKSUM */ 377 uint8_t378 uip_ismulticast(uip_ipaddr_t ipaddr)379 {380 #if UIP_CONF_IPV6381 return 0;382 #else383 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 #endif387 }388 369 /*---------------------------------------------------------------------------*/ 389 370 void … … 433 414 conn = &uip_conns[c]; 434 415 if(conn->tcpstateflags != UIP_CLOSED && 435 conn->lport == htons(lastport)) {416 conn->lport == uip_htons(lastport)) { 436 417 goto again; 437 418 } … … 472 453 conn->sa = 0; 473 454 conn->sv = 16; /* Initial value of the RTT variance. */ 474 conn->lport = htons(lastport);455 conn->lport = uip_htons(lastport); 475 456 conn->rport = rport; 476 457 uip_ipaddr_copy(&conn->ripaddr, ripaddr); … … 482 463 #if UIP_UDP 483 464 struct uip_udp_conn * 484 uip_udp_new( uip_ipaddr_t *ripaddr, uint16_t rport)465 uip_udp_new(const uip_ipaddr_t *ripaddr, uint16_t rport) 485 466 { 486 467 register struct uip_udp_conn *conn; … … 495 476 496 477 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)) { 498 479 goto again; 499 480 } … … 513 494 } 514 495 515 conn->lport = HTONS(lastport);496 conn->lport = UIP_HTONS(lastport); 516 497 conn->rport = rport; 517 498 if(ripaddr == NULL) { 518 memset( conn->ripaddr, 0, sizeof(uip_ipaddr_t));499 memset(&conn->ripaddr, 0, sizeof(uip_ipaddr_t)); 519 500 } else { 520 501 uip_ipaddr_copy(&conn->ripaddr, ripaddr); … … 748 729 connection's timer and see if it has reached the RTO value 749 730 in which case we retransmit. */ 731 750 732 if(uip_outstanding(uip_connr)) { 751 733 if(uip_connr->timer-- == 0) { … … 901 883 #endif /* UIP_CONF_IPV6 */ 902 884 903 if(uip_ipaddr_cmp( uip_hostaddr,all_zeroes_addr)) {885 if(uip_ipaddr_cmp(&uip_hostaddr, &uip_all_zeroes_addr)) { 904 886 /* If we are configured to use ping IP address configuration and 905 887 hasn't been assigned an IP address yet, we accept all ICMP … … 921 903 DEBUG_PRINTF("UDP IP checksum 0x%04x\n", uip_ipchksum()); 922 904 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. */ 927 915 goto udp_input; 928 916 } … … 931 919 /* Check if the packet is destined for our IP address. */ 932 920 #if !UIP_CONF_IPV6 933 if(!uip_ipaddr_cmp( BUF->destipaddr,uip_hostaddr)) {921 if(!uip_ipaddr_cmp(&BUF->destipaddr, &uip_hostaddr)) { 934 922 UIP_STAT(++uip_stat.ip.drop); 935 923 goto drop; … … 941 929 address) as well. However, we will cheat here and accept all 942 930 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)) { 945 933 UIP_STAT(++uip_stat.ip.drop); 946 934 goto drop; … … 1000 988 ourself. */ 1001 989 #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; 1005 992 } 1006 993 #endif /* UIP_PINGADDRCONF */ … … 1008 995 ICMPBUF->type = ICMP_ECHO_REPLY; 1009 996 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; 1012 999 } else { 1013 ICMPBUF->icmpchksum += HTONS(ICMP_ECHO << 8);1000 ICMPBUF->icmpchksum += UIP_HTONS(ICMP_ECHO << 8); 1014 1001 } 1015 1002 1016 1003 /* 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); 1019 1006 1020 1007 UIP_STAT(++uip_stat.icmp.sent); 1021 goto send; 1008 BUF->ttl = UIP_TTL; 1009 goto ip_send_nolen; 1022 1010 1023 1011 /* End of IPv4 input header processing code. */ … … 1040 1028 a neighbor advertisement message back. */ 1041 1029 if(ICMPBUF->type == ICMP6_NEIGHBOR_SOLICITATION) { 1042 if(uip_ipaddr_cmp( ICMPBUF->icmp6data,uip_hostaddr)) {1030 if(uip_ipaddr_cmp(&ICMPBUF->icmp6data, &uip_hostaddr)) { 1043 1031 1044 1032 if(ICMPBUF->options[0] == ICMP6_OPTION_SOURCE_LINK_ADDRESS) { 1045 1033 /* 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])); 1047 1035 } 1048 1036 … … 1054 1042 ICMPBUF->reserved1 = ICMPBUF->reserved2 = ICMPBUF->reserved3 = 0; 1055 1043 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); 1058 1046 ICMPBUF->options[0] = ICMP6_OPTION_TARGET_LINK_ADDRESS; 1059 1047 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)); 1061 1049 ICMPBUF->icmpchksum = 0; 1062 1050 ICMPBUF->icmpchksum = ~uip_icmp6chksum(); 1051 1063 1052 goto send; 1064 1053 … … 1072 1061 ICMPBUF->type = ICMP6_ECHO_REPLY; 1073 1062 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); 1076 1065 ICMPBUF->icmpchksum = 0; 1077 1066 ICMPBUF->icmpchksum = ~uip_icmp6chksum(); … … 1110 1099 uip_len = uip_len - UIP_IPUDPH_LEN; 1111 1100 #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 } 1112 1107 1113 1108 /* Demultiplex this UDP packet between the UDP "connections". */ … … 1126 1121 (uip_udp_conn->rport == 0 || 1127 1122 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))) { 1131 1126 goto udp_found; 1132 1127 } … … 1141 1136 uip_slen = 0; 1142 1137 UIP_UDP_APPCALL(); 1138 1143 1139 udp_send: 1144 1140 if(uip_slen == 0) { … … 1160 1156 BUF->proto = UIP_PROTO_UDP; 1161 1157 1162 UDPBUF->udplen = HTONS(uip_slen + UIP_UDPH_LEN);1158 UDPBUF->udplen = UIP_HTONS(uip_slen + UIP_UDPH_LEN); 1163 1159 UDPBUF->udpchksum = 0; 1164 1160 … … 1166 1162 BUF->destport = uip_udp_conn->rport; 1167 1163 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); 1170 1166 1171 1167 uip_appdata = &uip_buf[UIP_LLH_LEN + UIP_IPTCPH_LEN]; … … 1196 1192 } 1197 1193 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 } 1198 1199 1199 1200 /* Demultiplex this segment. */ … … 1204 1205 BUF->destport == uip_connr->lport && 1205 1206 BUF->srcport == uip_connr->rport && 1206 uip_ipaddr_cmp( BUF->srcipaddr,uip_connr->ripaddr)) {1207 uip_ipaddr_cmp(&BUF->srcipaddr, &uip_connr->ripaddr)) { 1207 1208 goto found; 1208 1209 } … … 1220 1221 /* Next, check listening connections. */ 1221 1222 for(c = 0; c < UIP_LISTENPORTS; ++c) { 1222 if(tmp16 == uip_listenports[c]) 1223 if(tmp16 == uip_listenports[c]) { 1223 1224 goto found_listen; 1225 } 1224 1226 } 1225 1227 1226 1228 /* No matching connection found, so we send a RST packet. */ 1227 1229 UIP_STAT(++uip_stat.tcp.synrst); 1230 1228 1231 reset: 1229 1230 1232 /* We do not send resets in response to resets. */ 1231 1233 if(BUF->flags & TCP_RST) { … … 1273 1275 1274 1276 /* 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); 1277 1279 1278 1280 /* And send out the RST packet! */ … … 1283 1285 connection and send a SYNACK in return. */ 1284 1286 found_listen: 1285 /* First we check if there are any connections ava liable. Unused1287 /* First we check if there are any connections available. Unused 1286 1288 connections are kept in the same table as used connections, but 1287 1289 unused ones have the tcpstate set to CLOSED. Also, connections in … … 1320 1322 uip_connr->lport = BUF->destport; 1321 1323 uip_connr->rport = BUF->srcport; 1322 uip_ipaddr_copy( uip_connr->ripaddr,BUF->srcipaddr);1324 uip_ipaddr_copy(&uip_connr->ripaddr, &BUF->srcipaddr); 1323 1325 uip_connr->tcpstateflags = UIP_SYN_RCVD; 1324 1326 … … 1406 1408 goto drop; 1407 1409 } 1408 /* Calculate dthe length of the data, if the application has sent1410 /* Calculate the length of the data, if the application has sent 1409 1411 any data to us. */ 1410 1412 c = (BUF->tcpoffset >> 4) << 2; … … 1416 1418 /* First, check if the sequence number of the incoming packet is 1417 1419 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)))) { 1421 1427 if((uip_len > 0 || ((BUF->flags & (TCP_SYN | TCP_FIN)) != 0)) && 1422 1428 (BUF->seqno[0] != uip_connr->rcv_nxt[0] || … … 1444 1450 uip_connr->snd_nxt[2] = uip_acc32[2]; 1445 1451 uip_connr->snd_nxt[3] = uip_acc32[3]; 1446 1447 1452 1448 1453 /* Do RTT estimation, unless we have done retransmissions. */ … … 1495 1500 goto appsend; 1496 1501 } 1502 /* We need to retransmit the SYNACK */ 1503 if((BUF->flags & TCP_CTL) == TCP_SYN) { 1504 goto tcp_send_synack; 1505 } 1497 1506 goto drop; 1498 1507 #if UIP_ACTIVE_OPEN … … 1798 1807 goto drop; 1799 1808 1800 1801 1809 /* We jump here when we are ready to send the packet, and just want 1802 1810 to set the appropriate TCP sequence numbers in the TCP header. */ 1803 1811 tcp_send_ack: 1804 1812 BUF->flags = TCP_ACK; 1813 1805 1814 tcp_send_nodata: 1806 1815 uip_len = UIP_IPTCPH_LEN; 1816 1807 1817 tcp_send_noopts: 1808 1818 BUF->tcpoffset = (UIP_TCPH_LEN / 4) << 4; 1809 tcp_send: 1819 1810 1820 /* We're done with the input processing. We are now ready to send a 1811 1821 reply. Our job is to fill in all the fields of the TCP and IP 1812 1822 headers before calculating the checksum and finally send the 1813 1823 packet. */ 1824 tcp_send: 1814 1825 BUF->ackno[0] = uip_connr->rcv_nxt[0]; 1815 1826 BUF->ackno[1] = uip_connr->rcv_nxt[1]; … … 1827 1838 BUF->destport = uip_connr->rport; 1828 1839 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); 1831 1842 1832 1843 if(uip_connr->tcpstateflags & UIP_STOPPED) { … … 1858 1869 1859 1870 ip_send_nolen: 1860 1861 1871 #if UIP_CONF_IPV6 1862 1872 BUF->vtc = 0x60; … … 1875 1885 DEBUG_PRINTF("uip ip_send_nolen: chkecum 0x%04x\n", uip_ipchksum()); 1876 1886 #endif /* UIP_CONF_IPV6 */ 1877 1878 1887 UIP_STAT(++uip_stat.tcp.sent); 1888 #if UIP_CONF_IPV6 1879 1889 send: 1890 #endif /* UIP_CONF_IPV6 */ 1880 1891 DEBUG_PRINTF("Sending packet with length %d (%d)\n", uip_len, 1881 1892 (BUF->len[0] << 8) | BUF->len[1]); … … 1885 1896 uip_flags = 0; 1886 1897 return; 1898 1887 1899 drop: 1888 1900 uip_len = 0; … … 1892 1904 /*---------------------------------------------------------------------------*/ 1893 1905 uint16_t 1894 htons(uint16_t val)1906 uip_htons(uint16_t val) 1895 1907 { 1896 return HTONS(val);1908 return UIP_HTONS(val); 1897 1909 } 1898 1910 /*---------------------------------------------------------------------------*/ -
uKadecot/trunk/uip/net/ipv4/uip_arp.c
r158 r262 78 78 uint16_t opcode; 79 79 struct uip_eth_addr shwaddr; 80 ui nt16_t sipaddr[2];80 uip_ipaddr_t sipaddr; 81 81 struct uip_eth_addr dhwaddr; 82 ui nt16_t dipaddr[2];82 uip_ipaddr_t dipaddr; 83 83 }; 84 84 … … 94 94 proto; 95 95 uint16_t ipchksum; 96 uint16_t srcipaddr[2], 97 destipaddr[2]; 96 uip_ipaddr_t srcipaddr, destipaddr; 98 97 }; 99 98 … … 110 109 111 110 struct arp_entry { 112 ui nt16_t ipaddr[2];111 uip_ipaddr_t ipaddr; 113 112 struct uip_eth_addr ethaddr; 114 113 uint8_t time; … … 118 117 {{0xff,0xff,0xff,0xff,0xff,0xff}}; 119 118 static 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 };122 119 123 120 static struct arp_entry arp_table[UIP_ARPTAB_SIZE]; 124 static ui nt16_t ipaddr[2];121 static uip_ipaddr_t ipaddr; 125 122 static uint8_t i, c; 126 123 … … 140 137 { 141 138 for(i = 0; i < UIP_ARPTAB_SIZE; ++i) { 142 memset( arp_table[i].ipaddr, 0, 4);139 memset(&arp_table[i].ipaddr, 0, 4); 143 140 } 144 141 } … … 161 158 for(i = 0; i < UIP_ARPTAB_SIZE; ++i) { 162 159 tabptr = &arp_table[i]; 163 if( (tabptr->ipaddr[0] | tabptr->ipaddr[1]) != 0&&160 if(uip_ipaddr_cmp(&tabptr->ipaddr, &uip_all_zeroes_addr) && 164 161 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 170 168 /*-----------------------------------------------------------------------------------*/ 171 169 static void 172 uip_arp_update(uint16_t *ipaddr, struct uip_eth_addr *ethaddr) 173 { 174 register struct arp_entry *tabptr = NULL; 170 uip_arp_update(uip_ipaddr_t *ipaddr, struct uip_eth_addr *ethaddr) 171 { 172 register struct arp_entry *tabptr = arp_table; 173 175 174 /* Walk through the ARP mapping table and try to find an entry to 176 175 update. If none is found, the IP -> MAC address mapping is 177 176 inserted in the ARP table. */ 178 177 for(i = 0; i < UIP_ARPTAB_SIZE; ++i) { 179 180 178 tabptr = &arp_table[i]; 179 181 180 /* 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)) { 184 182 185 183 /* Check if the source IP address of the incoming packet matches 186 184 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)) { 189 186 190 187 /* An old entry found, update this and return. */ … … 203 200 for(i = 0; i < UIP_ARPTAB_SIZE; ++i) { 204 201 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)) { 207 203 break; 208 204 } … … 227 223 /* Now, i is the ARP table entry which we will fill with the new 228 224 information. */ 229 memcpy(tabptr->ipaddr, ipaddr, 4);225 uip_ipaddr_copy(&tabptr->ipaddr, ipaddr); 230 226 memcpy(tabptr->ethaddr.addr, ethaddr->addr, 6); 231 227 tabptr->time = arptime; … … 300 296 301 297 switch(BUF->opcode) { 302 case HTONS(ARP_REQUEST):298 case UIP_HTONS(ARP_REQUEST): 303 299 /* ARP request. If it asked for our address, we send out a 304 300 reply. */ 305 if(uip_ipaddr_cmp( BUF->dipaddr,uip_hostaddr)) {301 if(uip_ipaddr_cmp(&BUF->dipaddr, &uip_hostaddr)) { 306 302 /* First, we register the one who made the request in our ARP 307 303 table, since it is likely that we will do more communication 308 304 with this host in the future. */ 309 uip_arp_update( BUF->sipaddr, &BUF->shwaddr);305 uip_arp_update(&BUF->sipaddr, &BUF->shwaddr); 310 306 311 307 /* The reply opcode is 2. */ 312 BUF->opcode = HTONS(2);308 BUF->opcode = UIP_HTONS(2); 313 309 314 310 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); 317 313 memcpy(BUF->ethhdr.dest.addr, BUF->dhwaddr.addr, 6); 318 314 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); 325 319 uip_len = sizeof(struct arp_hdr); 326 320 } 327 321 break; 328 case HTONS(ARP_REPLY):322 case UIP_HTONS(ARP_REPLY): 329 323 /* ARP reply. We insert or update the ARP table if it was meant 330 324 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); 333 327 } 334 328 break; … … 378 372 379 373 /* 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)) { 381 375 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. */ 384 378 IPBUF->ethhdr.dest.addr[0] = 0x01; 385 379 IPBUF->ethhdr.dest.addr[1] = 0x00; 386 IPBUF->ethhdr.dest.addr[2] = 0x5 E;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]; 390 384 } else { 391 385 /* 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)) { 393 387 /* Destination address was not on the local network, so we need to 394 388 use the default router's IP address instead of the destination 395 389 address when determining the MAC address. */ 396 uip_ipaddr_copy( ipaddr,uip_draddr);390 uip_ipaddr_copy(&ipaddr, &uip_draddr); 397 391 } else { 398 392 /* Else, we use the destination IP address. */ 399 uip_ipaddr_copy(ipaddr, IPBUF->destipaddr); 400 } 401 393 uip_ipaddr_copy(&ipaddr, &IPBUF->destipaddr); 394 } 402 395 for(i = 0; i < UIP_ARPTAB_SIZE; ++i) { 403 396 tabptr = &arp_table[i]; 404 if(uip_ipaddr_cmp( ipaddr,tabptr->ipaddr)) {397 if(uip_ipaddr_cmp(&ipaddr, &tabptr->ipaddr)) { 405 398 break; 406 399 } … … 413 406 memset(BUF->ethhdr.dest.addr, 0xff, 6); 414 407 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); 423 416 BUF->hwlen = 6; 424 417 BUF->protolen = 4; 425 BUF->ethhdr.type = HTONS(UIP_ETHTYPE_ARP);418 BUF->ethhdr.type = UIP_HTONS(UIP_ETHTYPE_ARP); 426 419 427 420 uip_appdata = &uip_buf[UIP_TCPIP_HLEN + UIP_LLH_LEN]; … … 434 427 memcpy(IPBUF->ethhdr.dest.addr, tabptr->ethaddr.addr, 6); 435 428 } 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); 439 432 440 433 uip_len += sizeof(struct uip_eth_hdr); … … 444 437 /** @} */ 445 438 /** @} */ 439 -
uKadecot/trunk/uip/net/ipv4/uip_arp.h
r158 r262 61 61 #endif 62 62 63 extern struct uip_eth_addr uip_ ethaddr;63 extern struct uip_eth_addr uip_lladdr; 64 64 65 65 /** … … 143 143 * \hideinitializer 144 144 */ 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) 151 151 152 152 /** @} */ 153 /** @} */ 153 154 154 155 155 #endif /* __UIP_ARP_H__ */ 156 /** @} */ -
uKadecot/trunk/uip/target/if_rx62n/if_rx62n.c
r158 r262 251 251 rx62n_bus_init(); 252 252 253 memcpy(uip_ ethaddr.addr, mac_addr, sizeof(uip_ethaddr.addr));253 memcpy(uip_lladdr.addr, mac_addr, sizeof(uip_lladdr.addr)); 254 254 } 255 255 -
uKadecot/trunk/uip/task/uip_adpt.c
r158 r262 91 91 92 92 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, ' '); 94 94 *(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, ' '); 96 96 *(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, ' '); 98 98 *(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, ' '); 100 100 *buf = '\0'; 101 101 -
uKadecot/trunk/uip/task/uip_task.c
r158 r262 106 106 IF_ETHER_NIC_INIT(ic); 107 107 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); 111 111 112 112 timer_set(&uiptsk->periodic_timer, CLOCK_SECOND / 2); … … 116 116 #ifdef __DHCPC_H__ 117 117 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)); 119 119 } 120 120 #endif … … 172 172 uip_len = IF_ETHER_NIC_READ(ic, (void **)&uip_buf); 173 173 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)) { 175 175 uip_arp_ipin(); 176 176 uip_input(); … … 190 190 } 191 191 } 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)) { 193 193 uip_arp_arpin(); 194 194 /* If the above function invocation resulted in data that … … 215 215 sil_wrb_mem((uint8_t *)0x0008C02A, sil_reb_mem((uint8_t *)0x0008C02A) | 0x02); 216 216 217 uip_ipaddr_copy( cepid->ripaddr,buf->ripaddr);217 uip_ipaddr_copy(&cepid->ripaddr, &buf->ripaddr); 218 218 cepid->rport = buf->rport; 219 219 uip_buf = buf->data; … … 222 222 uip_udp_conn = cepid; 223 223 uip_process(UIP_UDP_SEND_CONN); 224 uip_ipaddr( cepid->ripaddr, 0, 0, 0, 0);224 uip_ipaddr(&cepid->ripaddr, 0, 0, 0, 0); 225 225 cepid->rport = 0; 226 226 uip_arp_out(); … … 346 346 struct uip_conn *cepid; 347 347 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)); 349 349 if (cepid != NULL) { 350 350 //cepid->appstate.tcp_callback = pk_ccep->callback; … … 361 361 if (buf->len == 0) { 362 362 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); 365 365 memcpy(&buf->data[UIP_IPTCPH_LEN + UIP_LLH_LEN], data, len); 366 366 uip_out_buf[uip_out_wpos].len = len; … … 389 389 rlen = len; 390 390 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); 393 393 memcpy(data, uip_appdata, rlen); 394 394 … … 408 408 struct uip_udp_conn *cepid; 409 409 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)); 411 411 if (cepid != NULL) { 412 412 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)); 414 414 } 415 415 … … 424 424 if (buf->len == 0) { 425 425 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); 428 428 memcpy(&buf->data[UIP_IPUDPH_LEN + UIP_LLH_LEN], data, len); 429 429 uip_out_buf[uip_out_wpos].len = len; … … 452 452 rlen = len; 453 453 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); 456 456 memcpy(data, uip_appdata, rlen); 457 457 … … 476 476 { 477 477 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); 481 481 // resolv_conf(s->dnsaddr); 482 482 DHCP4_CLI_SET_ADDR_CALLBACK();
Note:
See TracChangeset
for help on using the changeset viewer.