Changeset 262 for uKadecot/trunk/uip/net/ip/uip.h
- Timestamp:
- Nov 18, 2016, 2:58:30 PM (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
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
Note:
See TracChangeset
for help on using the changeset viewer.