On behalf of Scott Mansfield, here come 3/4 of libnetapi.so rewritten,

and now building for your pleasure ;-)


git-svn-id: file:///srv/svn/repos/haiku/trunk/current@1813 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Philippe Houdoin
2002-11-01 03:07:42 +00:00
parent b612edb0d7
commit ae0638a6be
4 changed files with 956 additions and 164 deletions
+2 -2
View File
@@ -3,12 +3,12 @@ SubDir OBOS_TOP src kits net libnetapi ;
UsePrivateHeaders net ;
SharedLibrary netapi :
NetEndpoint.cpp
# NetEndpoint.cpp
NetAddress.cpp
NetBuffer.cpp
NetDebug.cpp
;
LinkSharedOSLibs libnetapi.so :
root net
root be libnet.so
;
+11 -14
View File
@@ -8,7 +8,7 @@
* host byte order.
* * In all mutators, address and port are converted from host to
* network byte order.
* * Michael, no trouts were harmed during the creation of this class.
* * No trouts were harmed during the development of this class.
*=--------------------------------------------------------------------------=*
* Copyright (c) 2002, The OpenBeOS project.
*
@@ -35,8 +35,11 @@
#include <string.h>
#include <netdb.h>
#include <arpa/inet.h> // STM: #include <ByteOrder.h>???
#include <arpa/inet.h>
#include <netinet/in.h>
#include <Message.h>
#include <ByteOrder.h>
#include <NetAddress.h>
/*
@@ -197,7 +200,7 @@ BNetAddress::~BNetAddress( void )
* Hostname and/or port can be NULL; although having them both NULL would
* be a pointless waste of CPU cycles. ;-)
*
* The hostname output parameter can be a variety of things, but it this
* The hostname output parameter can be a variety of things, but in this
* method we convert the IP address to a string. See the relevant
* documentation about inet_ntoa() for details.
*
@@ -249,8 +252,9 @@ status_t BNetAddress::GetAddr( char* hostname, unsigned short* port ) const
*
* Remarks:
* This method fills in the sin_addr, sin_family, and sin_port fields of
* the output parameter, all other fields are untouched. All numeric
* values are in network byte order.
* the output parameter, all other fields are untouched so we can work
* with both POSIX and non-POSIX versions of said struct. The port and
* address values added to the output parameter are in network byte order.
*/
status_t BNetAddress::GetAddr( struct sockaddr_in& sa ) const
{
@@ -309,7 +313,7 @@ status_t BNetAddress::GetAddr( in_addr& addr, unsigned short* port ) const
* Returns:
* B_OK if this instance is initialized, B_ERROR if not.
*/
status_t BNetAddress::InitCheck( void ) const
status_t BNetAddress::InitCheck( void )
{
return ( fInitialized == B_OK ) ? B_OK : B_ERROR;
}
@@ -337,10 +341,6 @@ status_t BNetAddress::Archive( BMessage* into, bool deep ) const
return B_NO_INIT;
}
//STM: When storing, should we store some kind of class name too...
//STM: Is there any way to deal with a complete failure here? (into
// not completely filled).
if ( into->AddInt8( "bnaddr_family", fFamily ) != B_OK )
{
return B_ERROR;
@@ -433,7 +433,6 @@ status_t BNetAddress::SetTo( const char* hostname, unsigned short port )
}
else
{
//STM: Print and/or log an error message?
return B_ERROR;
}
}
@@ -546,10 +545,9 @@ status_t BNetAddress::SetTo( const char* hostname, const char* protocol,
ServiceEntry = getservbyname( service, protocol );
if ( ServiceEntry == NULL )
{
//STM: Print and/or log an error message?
return B_ERROR;
}
endservent( );
// endservent( );
return SetTo( hostname, ServiceEntry->s_port );
}
@@ -581,4 +579,3 @@ status_t BNetAddress::clone( const BNetAddress& RefParam )
}
/*=------------------------------------------------------------------- End -=*/
File diff suppressed because it is too large Load Diff
+178 -6
View File
@@ -1,15 +1,187 @@
#include <size_t.h>
/*=--------------------------------------------------------------------------=*
* NetDebug.cpp -- Implementation of the BNetDebug class.
*
* Written by S.T. Mansfield ([email protected])
*
* Remarks:
* * Although this would more properly be implemented as a namespace...
* * Do not burn the candle at both ends as it leads to the life of a
* hairdresser.
*=--------------------------------------------------------------------------=*
* Copyright (c) 2002, The OpenBeOS project.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*=--------------------------------------------------------------------------=*
*/
#include <ctype.h>
#include <stdio.h>
#include <string.h>
#include <NetDebug.h>
void BNetDebug::Enable(bool) {
// Off by default cuz the BeBook sez so.
static bool g_IsEnabled = false;
/* Enable
*=--------------------------------------------------------------------------=*
* Purpose:
* Enable/disable debug message capability for your app.
*
* Input parameter:
* Enable : True/False to enable/disable debug message output.
*
* Remarks:
* This flag/setting is a per application basis, and not a per-instance
* occurrence as one would expect when instantiating an instance of
* this class. This is by design as /everything/ is static. Caveat
* Emptor. Needs to be dealt with in G.E.
*/
void BNetDebug::Enable( bool Enable )
{
g_IsEnabled = Enable;
}
bool BNetDebug::IsEnabled() {
return false;
/* IsEnabled
*=--------------------------------------------------------------------------=*
* Purpose:
* Quiz the enable/disable status.
*
* Returns:
* True/false if enabled/disabled.
*/
bool BNetDebug::IsEnabled( void )
{
return g_IsEnabled;
}
void BNetDebug::Print(const char *msg) {
/* Print
*=--------------------------------------------------------------------------=*
* Purpose:
* If enabled, spew forth a debug message.
*
* Input parameter:
* msg : The message to print.
*
* Remarks:
* * Basically a no-op if not enabled.
* * We're inheriting R5 (and Nettle's) behavior, so...
* * The output is always "debug: msg\n" Yes, kids, you read it right;
* you get a newline whether you want it or not!
* * If msg is empty, you get "debug: \n"
* * Message is always printed on stderr. Redirect accordingly.
*/
void BNetDebug::Print( const char* msg )
{
if ( g_IsEnabled )
{
if ( msg == NULL )
{
msg = "";
}
fprintf( stderr, "debug: %s\n", msg );
}
}
void BNetDebug::Dump(const char *data, size_t size, const char *title) {
/* Dump
*=--------------------------------------------------------------------------=*
* Purpose:
* If enabled, spew forth a combination hex/ASCII dump of raw data.
*
* Input parameters:
* data : Data to dump.
* size : How many bytes of data to dump.
* title : Title to display in message header.
*
* Remarks:
* * Basically a no-op if not enabled.
* * We're inheriting R5 (and Nettle's) behavior, so...
* * The output is always "debug: msg\n" Yes, kids, you read it right;
* you get a newline whether you want it or not!
* * If msg is empty, you get "debug: \n"
* * Behavior is undefined if data or title is NULL. This is a
* possible design flaw in Nettle/R5.
* * Do not expect an output like this:
* 00 11 22 33 44 55 66 77 88 99 AA BB CC DD EE FF | abcdefghijklmnop
* 00 11 22 33 44 55 66 77 88 99 AA BB CC DD EE FF | abcdefghijklmnop
* 00 11 22 33 44 55 66 77 88 99 AA BB CC DD EE FF | abcdefghijklmnop
* 00 11 22 33 44 55 66 77 88 99 AA BB CC DD EE FF | abcdefghijklmnop
* because you ain't gettin' it. You will get a complete hex dump,
* /followed/ by an ASCII dump. More Glass Elevator stuff.
* * Nettle dumps to stdOUT, the BeBook says all output goes to stdERR, so
* the author chose to...
* * always print to stdERR. Redirect accordingly.
* * stderr is flushed after the dump is complete to keep things
* reasonably cohesive in appearance. This might be an expensive
* operation so use judiciously.
*/
void BNetDebug::Dump( const char* data, size_t size, const char* title )
{
int i;
char line[17];
if ( g_IsEnabled == false )
{
return;
}
fprintf( stderr, "----------\n%s\n(dumping %d bytes)\n", title, size );
memset( line, 0, sizeof( line ) );
while ( i < size )
{
fprintf( stderr, "%02x ", ( unsigned char )data[i] );
line[i % 16] = ( isprint( data[i] ) ) ? data[i] : '.';
if ( ( i + 1 ) % 16 == 0 )
{
fprintf( stderr, " | %s\n", line );
memset( line, 0, sizeof( line ) );
}
i++;
}
if ( ( i + 1 ) % 16 != 0 )
{
while ( i % 16 != 0 )
{
printf( " " );
i++;
}
fprintf( stderr, " | %s", line );
}
fprintf( stderr, "\n----------\n" );
fflush( stderr );
}
/*=------------------------------------------------------------------- End -=*/