Changeset 748:daf48a9534be in mediastreamer2
- Timestamp:
- Oct 27, 2009 12:56:52 PM (4 years ago)
- Branch:
- default
- Location:
- linphone/oRTP
- Files:
-
- 2 edited
-
include/ortp/stun.h (modified) (12 diffs)
-
src/stun.c (modified) (26 diffs)
Legend:
- Unmodified
- Added
- Removed
-
linphone/oRTP/include/ortp/stun.h
r747 r748 77 77 #include <ortp/stun_udp.h> 78 78 79 #ifdef __APPLE__ 80 #include "TargetConditionals.h" 81 #endif 79 82 80 83 #ifdef __cplusplus … … 93 96 94 97 /* define some basic types */ 95 typedef unsigned char UInt8; 96 typedef unsigned short UInt16; 97 #if __LP64__ 98 typedef unsigned int UInt32; 98 #if 0 99 typedef unsigned char uint8_t; 100 typedef unsigned short uint16_t; 101 typedef unsigned int uint32_t; 102 103 #if defined(WIN32) || defined(_WIN32_WCE) 104 typedef unsigned __int64 uint64_t; 99 105 #else 100 typedef unsigned long UInt32;106 typedef unsigned long long uint64_t; 101 107 #endif 102 #if defined(WIN32) || defined(_WIN32_WCE)103 typedef unsigned __int64 UInt64;104 #else105 typedef unsigned long long UInt64;106 108 #endif 107 109 typedef struct { unsigned char octet[12]; } UInt96; … … 185 187 typedef struct 186 188 { 187 UInt16msgType;188 UInt16msgLength;189 UInt32magic_cookie;189 uint16_t msgType; 190 uint16_t msgLength; 191 uint32_t magic_cookie; 190 192 UInt96 tr_id; 191 193 } StunMsgHdr; … … 194 196 typedef struct 195 197 { 196 UInt16type;197 UInt16length;198 uint16_t type; 199 uint16_t length; 198 200 } StunAtrHdr; 199 201 200 202 typedef struct 201 203 { 202 UInt16port;203 UInt32addr;204 uint16_t port; 205 uint32_t addr; 204 206 } StunAddress4; 205 207 206 208 typedef struct 207 209 { 208 UInt8pad;209 UInt8family;210 uint8_t pad; 211 uint8_t family; 210 212 StunAddress4 ipv4; 211 213 } StunAtrAddress4; … … 213 215 typedef struct 214 216 { 215 UInt32value;217 uint32_t value; 216 218 } StunAtrChangeRequest; 217 219 218 220 typedef struct 219 221 { 220 UInt16pad; /* all 0 */221 UInt8errorClass;222 UInt8number;222 uint16_t pad; /* all 0 */ 223 uint8_t errorClass; 224 uint8_t number; 223 225 char reason[STUN_MAX_STRING]; 224 UInt16sizeReason;226 uint16_t sizeReason; 225 227 } StunAtrError; 226 228 227 229 typedef struct 228 230 { 229 UInt16attrType[STUN_MAX_UNKNOWN_ATTRIBUTES];230 UInt16numAttributes;231 uint16_t attrType[STUN_MAX_UNKNOWN_ATTRIBUTES]; 232 uint16_t numAttributes; 231 233 } StunAtrUnknown; 232 234 233 235 typedef struct 234 236 { 235 UInt16channelNumber;236 UInt16rffu; /* Reserved For Future Use */237 uint16_t channelNumber; 238 uint16_t rffu; /* Reserved For Future Use */ 237 239 } TurnAtrChannelNumber; 238 240 239 241 typedef struct 240 242 { 241 UInt32lifetime;243 uint32_t lifetime; 242 244 } TurnAtrLifetime; 243 245 … … 245 247 { 246 248 char value[1500]; 247 UInt16sizeValue;249 uint16_t sizeValue; 248 250 } TurnAtrData; 249 251 250 252 typedef struct 251 253 { 252 UInt8proto;253 UInt8pad1;254 UInt8pad2;255 UInt8pad3;254 uint8_t proto; 255 uint8_t pad1; 256 uint8_t pad2; 257 uint8_t pad3; 256 258 } TurnAtrRequestedTransport; 257 259 258 260 typedef struct 259 261 { 260 UInt64value;262 uint64_t value; 261 263 } TurnAtrReservationToken; 262 264 263 265 typedef struct 264 266 { 265 UInt32fingerprint;267 uint32_t fingerprint; 266 268 } StunAtrFingerprint; 267 269 … … 270 272 { 271 273 char value[STUN_MAX_STRING]; 272 UInt16sizeValue;274 uint16_t sizeValue; 273 275 } StunAtrString; 274 276 275 277 typedef struct 276 278 { 277 UInt32priority;279 uint32_t priority; 278 280 } IceAtrPriority; 279 281 280 282 typedef struct 281 283 { 282 UInt64value;284 uint64_t value; 283 285 } IceAtrIceControll; 284 286 … … 300 302 typedef struct 301 303 { 302 UInt16attrType[STUN_MAX_UNKNOWN_ATTRIBUTES];303 UInt16numAttributes;304 uint16_t attrType[STUN_MAX_UNKNOWN_ATTRIBUTES]; 305 uint16_t numAttributes; 304 306 } TurnAtrUnknown; 305 307 … … 437 439 void 438 440 stunCalculateIntegrity_shortterm(char* hmac, const char* input, int length, const char* key); 439 UInt32 441 uint32_t 440 442 stunCalculateFingerprint(const char* input, int length); 441 443 … … 470 472 stunRand(void); 471 473 472 UInt64 474 uint64_t 473 475 stunGetSystemTimeSecs(void); 474 476 … … 479 481 bool_t 480 482 stunParseHostName( const char* peerName, 481 UInt32*ip,482 UInt16*portVal,483 UInt16defaultPort );483 uint32_t *ip, 484 uint16_t *portVal, 485 uint16_t defaultPort ); 484 486 485 487 /* return true if all is OK … … 496 498 /* returns number of address found - take array or addres */ 497 499 int 498 stunFindLocalInterfaces( UInt32* addresses, int maxSize );500 stunFindLocalInterfaces(uint32_t* addresses, int maxSize ); 499 501 500 502 int -
linphone/oRTP/src/stun.c
r723 r748 136 136 if (result->family == IPv4Family) 137 137 { 138 UInt16nport;139 UInt32naddr;138 uint16_t nport; 139 uint32_t naddr; 140 140 memcpy(&nport, body, 2); body+=2; 141 141 result->ipv4.port = ntohs(nport); … … 325 325 #define ntohq(n) n 326 326 #else /* little endian */ 327 static inline UInt64328 htonq ( UInt64v)329 { 330 return htonl (( UInt32) (v >> 32))331 | ( UInt64) htonl ((UInt32) v) << 32;332 } 333 static inline UInt64334 ntohq ( UInt64v)335 { 336 return ntohl (( UInt32) (v >> 32))337 | ( UInt64) ntohl ((UInt32) v) << 32;327 static inline uint64_t 328 htonq (uint64_t v) 329 { 330 return htonl ((uint32_t) (v >> 32)) 331 | (uint64_t) htonl ((uint32_t) v) << 32; 332 } 333 static inline uint64_t 334 ntohq (uint64_t v) 335 { 336 return ntohl ((uint32_t) (v >> 32)) 337 | (uint64_t) ntohl ((uint32_t) v) << 32; 338 338 } 339 339 #endif /* little endian */ … … 789 789 790 790 static char* 791 encode16(char* buf, UInt16data)792 { 793 UInt16ndata = htons(data);794 memcpy(buf, &ndata, sizeof( UInt16));795 return buf + sizeof( UInt16);791 encode16(char* buf, uint16_t data) 792 { 793 uint16_t ndata = htons(data); 794 memcpy(buf, &ndata, sizeof(uint16_t)); 795 return buf + sizeof(uint16_t); 796 796 } 797 797 798 798 static char* 799 encode32(char* buf, UInt32data)800 { 801 UInt32ndata = htonl(data);802 memcpy(buf, &ndata, sizeof( UInt32));803 return buf + sizeof( UInt32);799 encode32(char* buf, uint32_t data) 800 { 801 uint32_t ndata = htonl(data); 802 memcpy(buf, &ndata, sizeof(uint32_t)); 803 return buf + sizeof(uint32_t); 804 804 } 805 805 806 806 static char* 807 encode64(char* buf, UInt64data)808 { 809 UInt64ndata = htonq(data);810 memcpy(buf, &ndata, sizeof( UInt64));811 return buf + sizeof( UInt64);807 encode64(char* buf, uint64_t data) 808 { 809 uint64_t ndata = htonq(data); 810 memcpy(buf, &ndata, sizeof(uint64_t)); 811 return buf + sizeof(uint64_t); 812 812 } 813 813 … … 821 821 822 822 static char* 823 encodeAtrAddress4(char* ptr, UInt16type, const StunAtrAddress4 *atr)823 encodeAtrAddress4(char* ptr, uint16_t type, const StunAtrAddress4 *atr) 824 824 { 825 825 ptr = encode16(ptr, type); … … 881 881 882 882 static char* 883 encodeAtrString(char* ptr, UInt16type, const StunAtrString *atr)883 encodeAtrString(char* ptr, uint16_t type, const StunAtrString *atr) 884 884 { 885 885 int padding; … … 914 914 encodeAtrFingerprint(char* ptr, const StunAtrFingerprint *atr) 915 915 { 916 UInt32val;916 uint32_t val; 917 917 ptr = encode16(ptr, SA_FINGERPRINT); 918 918 ptr = encode16(ptr, 4); … … 971 971 972 972 static char* 973 encodeAtrIceControll(char* ptr, UInt16type, const IceAtrIceControll *atr)973 encodeAtrIceControll(char* ptr, uint16_t type, const IceAtrIceControll *atr) 974 974 { 975 975 ptr = encode16(ptr, type); … … 1116 1116 //ortp_debug("stun: HMAC with password: %s\n", password->value ); 1117 1117 1118 encode16(lengthp, ( UInt16)(ptr - buf - sizeof(StunMsgHdr)+24));1118 encode16(lengthp, (uint16_t)(ptr - buf - sizeof(StunMsgHdr)+24)); 1119 1119 stunCalculateIntegrity_longterm(integrity.hash, buf, (int)(ptr-buf) , 1120 1120 msg->username.value, msg->realmName.value, password->value); … … 1128 1128 //ortp_debug("stun: HMAC with password: %s\n", password->value ); 1129 1129 1130 encode16(lengthp, ( UInt16)(ptr - buf - sizeof(StunMsgHdr)+24));1130 encode16(lengthp, (uint16_t)(ptr - buf - sizeof(StunMsgHdr)+24)); 1131 1131 stunCalculateIntegrity_shortterm(integrity.hash, buf, (int)(ptr-buf) , 1132 1132 password->value); … … 1139 1139 //ortp_debug("stun: HMAC with password: %s\n", password->value ); 1140 1140 1141 encode16(lengthp, ( UInt16)(ptr - buf - sizeof(StunMsgHdr)+8));1141 encode16(lengthp, (uint16_t)(ptr - buf - sizeof(StunMsgHdr)+8)); 1142 1142 fingerprint.fingerprint = stunCalculateFingerprint(buf, (int)(ptr-buf)); 1143 1143 ptr = encodeAtrFingerprint(ptr, &fingerprint); 1144 1144 } 1145 encode16(lengthp, ( UInt16)(ptr - buf - sizeof(StunMsgHdr)));1145 encode16(lengthp, (uint16_t)(ptr - buf - sizeof(StunMsgHdr))); 1146 1146 return (int)(ptr - buf); 1147 1147 } … … 1155 1155 if ( !init ) 1156 1156 { 1157 UInt64tick;1157 uint64_t tick; 1158 1158 int seed; 1159 1159 init = TRUE; … … 1304 1304 #endif 1305 1305 1306 UInt32 1306 uint32_t 1307 1307 stunCalculateFingerprint(const char* input, int length) 1308 1308 { … … 1311 1311 3 * code or tables extracted from it, as desired without restriction. 1312 1312 4 */ 1313 static UInt32crc32_tab[] = {1313 static uint32_t crc32_tab[] = { 1314 1314 0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, 0x076dc419, 0x706af48f, 1315 1315 0xe963a535, 0x9e6495a3, 0x0edb8832, 0x79dcb8a4, 0xe0d5e91e, 0x97d2d988, … … 1365 1365 } 1366 1366 1367 UInt64 1367 uint64_t 1368 1368 stunGetSystemTimeSecs(void) 1369 1369 { 1370 UInt64time=0;1370 uint64_t time=0; 1371 1371 #if defined(_WIN32) || defined(_WIN32_WCE) 1372 1372 SYSTEMTIME t; … … 1387 1387 bool_t 1388 1388 stunParseHostName( const char* peerName, 1389 UInt32* ip,1390 UInt16* portVal,1391 UInt16defaultPort )1389 uint32_t* ip, 1390 uint16_t* portVal, 1391 uint16_t defaultPort ) 1392 1392 { 1393 1393 struct in_addr sin_addr; … … 1563 1563 StunAddress4 mapped; 1564 1564 StunAddress4 respondTo; 1565 UInt32flags;1565 uint32_t flags; 1566 1566 bool_t ok; 1567 1567 /* set up information for default response */ … … 1692 1692 if (1) /* do xorMapped address or not */ 1693 1693 { 1694 UInt32cookie = 0x2112A442;1694 uint32_t cookie = 0x2112A442; 1695 1695 resp->hasXorMappedAddress = TRUE; 1696 1696 resp->xorMappedAddress.ipv4.port = mapped.port^(cookie>>16); … … 1739 1739 if (req.hasUsername && (req.username.sizeValue > 64 ) ) 1740 1740 { 1741 UInt32source;1742 /* assert( sizeof(int) == sizeof( UInt32) ); */1741 uint32_t source; 1742 /* assert( sizeof(int) == sizeof(uint32_t) ); */ 1743 1743 1744 1744 sscanf(req.username.value, "%x", &source); … … 1867 1867 1868 1868 int 1869 stunFindLocalInterfaces( UInt32* addresses,int maxRet)1869 stunFindLocalInterfaces(uint32_t* addresses,int maxRet) 1870 1870 { 1871 1871 #if defined(WIN32) || defined(_WIN32_WCE) || defined(__sparc__) … … 1897 1897 struct sockaddr_in* addr; 1898 1898 1899 UInt32ai;1899 uint32_t ai; 1900 1900 int si = sizeof(ifr->ifr_name) + sizeof(struct sockaddr); 1901 1901 tl -= si; … … 2063 2063 2064 2064 int port = randomPort(); 2065 UInt32interfaceIp=0;2065 uint32_t interfaceIp=0; 2066 2066 Socket myFd; 2067 2067 StunAtrString username; … … 2148 2148 /* assert( dest.addr != 0 ); */ 2149 2149 /* assert( dest.port != 0 ); */ 2150 UInt32interfaceIp=0;2150 uint32_t interfaceIp=0; 2151 2151 Socket myFd1; 2152 2152 Socket myFd2; … … 2167 2167 StunAtrString password; 2168 2168 int count=0; 2169 UInt64second_started;2170 UInt64second_elapsed;2169 uint64_t second_started; 2170 uint64_t second_elapsed; 2171 2171 Socket s; 2172 2172 … … 2538 2538 if (resp.hasXorMappedAddress==TRUE) 2539 2539 { 2540 UInt32cookie = 0x2112A442;2541 UInt16cookie16 = 0x2112A442 >> 16;2540 uint32_t cookie = 0x2112A442; 2541 uint16_t cookie16 = 0x2112A442 >> 16; 2542 2542 mappedAddr.port = resp.xorMappedAddress.ipv4.port^cookie16; 2543 2543 mappedAddr.addr = resp.xorMappedAddress.ipv4.addr^cookie; … … 2648 2648 if (resp.hasXorMappedAddress==TRUE) 2649 2649 { 2650 UInt32cookie = 0x2112A442;2651 UInt16cookie16 = 0x2112A442 >> 16;2650 uint32_t cookie = 0x2112A442; 2651 uint16_t cookie16 = 0x2112A442 >> 16; 2652 2652 mappedAddr[i].port = resp.xorMappedAddress.ipv4.port^cookie16; 2653 2653 mappedAddr[i].addr = resp.xorMappedAddress.ipv4.addr^cookie; … … 2840 2840 if (resp.hasXorRelayedAddress==TRUE) 2841 2841 { 2842 UInt32cookie = 0x2112A442;2843 UInt16cookie16 = 0x2112A442 >> 16;2842 uint32_t cookie = 0x2112A442; 2843 uint16_t cookie16 = 0x2112A442 >> 16; 2844 2844 mappedAddr[i].port = resp.xorRelayedAddress.ipv4.port^cookie16; 2845 2845 mappedAddr[i].addr = resp.xorRelayedAddress.ipv4.addr^cookie;
Note: See TracChangeset
for help on using the changeset viewer.
