1. inet_ntoa( ) linux

hey all,

i have one question about the C routine, inet_ntoa( ) in a Linux system.
i am attempting to wrap this function nicely and here is what i have so far:

-- include mixedlib.e

global
function inet_ntoa( ulong s_addr )
  pointer in_addr_ptr, char_str
  sequence char_seq
  
  in_addr_ptr = struc( get_in_addr_seq( ), HIGH )
  Sets( in_addr_ptr, "s_addr", s_addr )
  
  char_str = c_func( inet_ntoa_, { in_addr_ptr } )
  char_seq = str2seq( char_str )
  
  frees( in_addr_ptr )
  
  return char_seq
end function

The problem im having is what char_str points to after the call to inet_ntoa. I
always get some randomish IP in dot-notation being returned with the two last
sections always being ?.?.17.8. This seems rather odd to me. i know that the
s_addr im passing is valid because it never changes value on connections made
from the same client. localhost s_addr is always 16777343.

I think this all has to do with the statically allocated char * that inet_ntoa
returns. Does anyone have an idea? ive tried a lot of things and im really
getting lost.

Thanks for any help on this one.

-- 
evil, corruption and bad taste
^[cense]

new topic     » topic index » view message » categorize

2. Re: inet_ntoa( ) linux

On Thu, 23 Nov 2000 21:35:28 -0700, cense <cense at MAIL.RU> wrote:
cense:

 This is the correct code.

-- Define ALL of your STATIC function,variable, or structure at the
beginning
-- of your program outside of your functions.
-- STATIC means that a function,variable, or structure needs to be available
-- through out the scope of your whole program any function or variable
-- defined within a function is will be destroy when you leave the function.

-- include mixedlib.e

  inet_ntoa_ = define_c_func(YOUR_LIB, "inet_ntoa",{C_POINTER}, C_POINTER)

-- internet numeric to ascii function
-- This function takes a 4 byte POINTER to a in_addr and converts
-- the internet HOST numeric address to a STRING in the standard number/dots
-- notation form.
global
function inet_ntoa( pointer sin_addr )
--
  return str2seq( c_func( inet_ntoa_, { sin_addr_ptr } ) )
--
end function


Bernie

new topic     » goto parent     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu