1. c structures and type casts in euphoria
- Posted by CenSe <cense at MAIL.RU> May 26, 2000
- 567 views
hello all, i am working on a project that has the need to simulate several C `struct` s in memory. I am already using Bernie's mixedlib.e and i find it to be quite good for what i need. I have on problem though. I need to type cast the pointer of one of those structures created from Bernie's mixedlib.e to another type of structure also created through that same lib. I am simulating the `sockaddr' and `sockaddr_in' structures from C headers files on a linux machine. As many of you probably know, you can type cast the `sockaddr_in' to a `sockaddr' structure that many of the socket function want as a parameter. Is there anyway in Euphroia to type cast a structure created in memory from Bernie's mixedlib.e to another structures created in the same way? Any help is greatly appreciated. CenSe, a member of the ak-software development team http://ak-software.virtualave.net/
2. Re: c structures and type casts in euphoria
- Posted by Bernie Ryan <xotron at BUFFNET.NET> May 25, 2000
- 534 views
On Fri, 26 May 2000 02:09:23 +0400, CenSe <cense at MAIL.RU> wrote: >hello all, > >i am working on a project that has the need to simulate several C `struct` s >in memory. I am already using Bernie's mixedlib.e and i find it to be quite >good for what i need. I have on problem though. I need to type cast the >pointer of one of those structures created from Bernie's mixedlib.e to another >type of structure also created through that same lib. > >I am simulating the `sockaddr' and `sockaddr_in' structures from C headers >files on a linux machine. As many of you probably know, you can type cast the >`sockaddr_in' to a `sockaddr' structure that many of the socket function want >as a parameter. > >Is there anyway in Euphroia to type cast a structure created in memory >from Bernie's mixedlib.e to another structures created in the same way? >Any help is greatly appreciated. CenSe I do not understand what you mean by casting a structure ? Bernie
3. Re: c structures and type casts in euphoria
- Posted by CenSe <cense at MAIL.RU> May 26, 2000
- 537 views
-----Original Message----- >CenSe > I do not understand what you mean by casting a structure ? > >Bernie > I am sorry, i did not explain myself properly. what i meant was that i need to type cast a *pointer* of the `sockaddr_in' struct to a *pointer* to a struct of type `sockaddr'. Eg: // the `C' function accept prototype: int accept( int s, struct sockaddr *addr, int *addrlen ) ; // can be used as: * CODE BLOCK * sockaddr *addr; int *addrlen; int return_val; // assign values to addr and addrlen return_val = accept( sock, addr, addrlen ); // or can be used with sockaddr_in like this // where: sockaddr_in *addr; return_val = accept( sock, (struct sockaddr *)&addr, addrlen ); // to type cast it. * END CODE BLOCK * I want to be able to do this in Euphoria. Is it possible? I hope this clarifies to you what my problem is. CenSe, a member of the ak-software development team http://ak-software.virtualave.net/
4. Re: c structures and type casts in euphoria
- Posted by Bernie Ryan <xotron at BUFFNET.NET> May 27, 2000
- 503 views
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
5. Re: c structures and type casts in euphoria
- Posted by CenSe <cense at MAIL.RU> May 28, 2000
- 495 views
-----Original 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 >---------------------------------------------------------------------------- > >I will respond to your other question after I have read it > >Bernie > > thanks a bunch. that should help me out alot. i was just very unsure of how `C' type casts were done in memory and that confused me alot. thanks Bernie. CenSe, a member of the ak-software development team http://ak-software.virtualave.net/