Re: c structures and type casts in euphoria

new topic     » goto parent     » topic index » view thread      » older message » newer message

On Fri, 26 May 2000 09:05:51 +0400, CenSe <cense at MAIL.RU> wrote:

>return_val = accept( sock, (struct sockaddr *)&addr, addrlen );
>
>// to type cast it.
>
   CenSe:

-- This code is just to show you how to solve your cast problem
-- The code is incomplete because I do not know exactly what you are
-- doing so you can only use it as a guide
----------------------------------------------------------------------------
-
       -- sin_family is address family,
       --   Domain address ( AF_INET )
sequence sockaddr_in, sockaddr            -- sin_port is port number
       --           in network order
sockaddr_in = "sin_family:short : 1 "&    -- sin_addr is Internet address
       "sin_port  :ushort: 1 "&    --           in network order
       -- In "C" sin.sin_addr.s_addr
       "sin_addr  :ulong : 1 "& --<<-- S_addr this is a union can be
       "sin_zero  :char  : 8 "      -- defined as 4 bytes or 2 words
       -- or 1 long ( double word )
       -- uchar s_b1, s_b2, s_b3, s_b4
       -- ushort s_w1, s_w2
       -- ulong s_dw1

       -- sin_zero is 8 bytes of zero

sockaddr = "sa_family:uchar: 1 "&         -- sockaddr structure  NOTE*
    "sa_data  :char :14 "          -- If you total up the bytes in
       -- this structure it is the same
       --  size as sockaddr_in
pointer addr, addr_in

int descriptor

addr    = struc(sockaddr,    HIGH)        -- Create the empty structures
addr_in = struc(sockaddr_in, HIGH)        --

descriptor = accept(sock, addr, sizeof(addr)) -- do the except processing
if descriptor then                            -- and the structure will be
           -- filled in by sockets
  -- copy the return addr structure to addr_in structure
  mem_copy(addr_in,addr,sizeof(addr_in))
  -- Now you use addr_in to access data like print the port number
  ? Gets(addr_in, "sin_port")

end if
----------------------------------------------------------------------------

I will respond to your other question after I have read it

Bernie

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu