Changeset 26269
- Timestamp:
- 07/05/08 18:37:06 (5 months ago)
- Location:
- haiku/trunk
- Files:
-
- 2 modified
-
headers/os/net/NetAddress.h (modified) (1 diff)
-
src/kits/network/libnetapi/NetAddress.cpp (modified) (10 diffs)
Legend:
- Unmodified
- Added
- Removed
-
haiku/trunk/headers/os/net/NetAddress.h
r18680 r26269 53 53 54 54 status_t fInit; 55 int 32fFamily;56 int 32fPort;55 int16 fFamily; 56 int16 fPort; 57 57 int32 fAddress; 58 int32 fPrivateData[ 6];58 int32 fPrivateData[7]; 59 59 }; 60 60 -
haiku/trunk/src/kits/network/libnetapi/NetAddress.cpp
r18680 r26269 1 1 /* 2 * Copyright 2002-2006, Haiku, Inc. All Rights Reserved.2 * Copyright 2002-2006,2008, Haiku, Inc. All Rights Reserved. 3 3 * Distributed under the terms of the MIT License. 4 4 * 5 5 * Authors: 6 6 * Scott T. Mansfield, thephantom@mac.com 7 * Oliver Tappe, zooey@hirschkaefer.de 7 8 */ 8 9 … … 10 11 NetAddress.cpp -- Implementation of the BNetAddress class. 11 12 Remarks: 12 * In all accessors, address and portare converted from network to13 * In all accessors, non-struct output values are converted from network to 13 14 host byte order. 14 * In all mutators, address and portare converted from host to15 * In all mutators, non-struct input values are converted from host to 15 16 network byte order. 16 17 * No trouts were harmed during the development of this class. … … 77 78 BNetAddress::BNetAddress(BMessage* archive) 78 79 { 79 int 8 int8value;80 if (archive->FindInt 8("bnaddr_family", &int8value) != B_OK)80 int16 int16value; 81 if (archive->FindInt16("bnaddr_family", &int16value) != B_OK) 81 82 return; 82 83 83 fFamily = int 8value;84 85 if (archive->FindInt 8("bnaddr_port", &int8value) != B_OK)84 fFamily = int16value; 85 86 if (archive->FindInt16("bnaddr_port", &int16value) != B_OK) 86 87 return; 87 88 88 fPort = int 8value;89 fPort = int16value; 89 90 90 91 if (archive->FindInt32("bnaddr_addr", &fAddress) != B_OK) … … 188 189 } 189 190 190 sa.sin_family = ( uint8 )fFamily;191 sa.sin_port = ( uint8 )fPort;192 sa.sin_addr.s_addr = ( in_addr_t )fAddress;191 sa.sin_family = fFamily; 192 sa.sin_port = fPort; 193 sa.sin_addr.s_addr = fAddress; 193 194 194 195 return B_OK; … … 209 210 * 210 211 * Remarks: 211 * Output p arameters will be in network byte order, so it is not212 * ne cessary to call htons after calling this method.212 * Output port will be in host byte order, but addr will be in the usual 213 * network byte order (ready to be used by other network functions). 213 214 */ 214 215 status_t BNetAddress::GetAddr( in_addr& addr, unsigned short* port ) const 215 216 { 216 217 if ( fInit != B_OK ) 217 {218 218 return B_NO_INIT; 219 }220 219 221 220 addr.s_addr = fAddress; 222 221 223 222 if ( port != NULL ) 224 { 225 *port = fPort; 226 } 223 *port = ntohs(fPort); 227 224 228 225 return B_OK; … … 262 259 { 263 260 if ( fInit != B_OK ) 264 {265 261 return B_NO_INIT; 266 } 267 268 if ( into->AddInt8( "bnaddr_family", fFamily ) != B_OK ) 269 { 262 263 if ( into->AddInt16( "bnaddr_family", fFamily ) != B_OK ) 270 264 return B_ERROR; 271 } 272 273 if ( into->AddInt8( "bnaddr_port", fPort ) != B_OK ) 274 { 265 266 if ( into->AddInt16( "bnaddr_port", fPort ) != B_OK ) 275 267 return B_ERROR; 276 }277 268 278 269 if ( into->AddInt32( "bnaddr_addr", fAddress ) != B_OK ) 279 {280 270 return B_ERROR; 281 }282 271 283 272 return B_OK; … … 355 344 fFamily = AF_INET; 356 345 fPort = htons(port); 357 fAddress = htonl(addr);346 fAddress = addr; 358 347 359 348 return fInit = B_OK; … … 371 360 { 372 361 fFamily = addr.sin_family; 373 fPort = htons(addr.sin_port);374 fAddress = htonl(addr.sin_addr.s_addr);362 fPort = addr.sin_port; 363 fAddress = addr.sin_addr.s_addr; 375 364 376 365 return fInit = B_OK; … … 390 379 { 391 380 fFamily = AF_INET; 392 fPort = htons( port);393 fAddress = htonl(addr.s_addr);381 fPort = htons((short)port); 382 fAddress = addr.s_addr; 394 383 395 384 return fInit = B_OK; … … 409 398 { 410 399 fFamily = AF_INET; 411 fPort = htons( port);412 fAddress = htonl(addr);400 fPort = htons((short)port); 401 fAddress = addr; 413 402 414 403 return fInit = B_OK;
