1. Winsock.ew as a team project...
- Posted by JesusC - Jesus Consuegra <jconsuegra at REDESTB.ES> Jul 07, 1998
- 439 views
Hi Euphorians: Since the coding of Winsock.ew is getting harder,and there are a lot of functions to implement, any help is very welcome. Greg Harris has joined the (now) team. For anyone else wishing to collaborate, please send mail. Currently I'm stuck with a structure accessing problem in the function gethostbyaddr(). This function returns a pointer to a structure defining host information. In C/C++ the structure is as follows: struct hostent{ char FAR * h_name; char FAR * FAR * h_aliases; short h_addrtype; short h_length; char FAR * FAR * h_addr_list; }; Since I'm not good at all in C, I do not really understand how to code the access to this data in Euphoria.... (What does those FAR * FAR * mean?... Pointers to Pointers?... Two pointers?... Array of pointers?...) (Help welcome. Join the winsock revolution!) Homepage: http://www.geocities.com/SiliconValley/Sector/6432/ under construction.
2. Re: Winsock.ew as a team project...
- Posted by Robert Craig <rds at EMAIL.MSN.COM> Jul 07, 1998
- 444 views
Jesus Consuegra writes: > Currently I'm stuck with a structure accessing problem in the > function gethostbyaddr(). > This function returns a pointer to a structure defining > host information. In C/C++ the structure is as follows: > struct hostent{ > char FAR * h_name; > char FAR * FAR * h_aliases; > short h_addrtype; > short h_length; > char FAR * FAR * h_addr_list; > }; > Since I'm not good at all in C, I do not really understand > how to code the access to this data in Euphoria.... > (What does those FAR * FAR * mean?... > Pointers to Pointers?... Two pointers?... Array of pointers?...) 1. Ignore the word "FAR". Just delete it (in your mind). It was necessary back in the bad old days of 16-bit programming where Intel had two types of pointers: near pointers (16-bit offset), and far pointers (segment plus offset). 2. char *h_name; declares h_name as a pointer to a character (very likely a pointer to the first character in a string of characters. A C string is supposed to be terminated by a 0 character.) char **aliases; This declares aliases as: a pointer to (a pointer to a character). So, there is likely an array of pointers to strings somewhere in memory and aliases points to the first pointer in the array, call it p0: aliases --> p0 --> [char 0][char 1][char 2] ... [0] p1 --> p2 --> This "pointer to pointer to pointer ..." stuff is one of the nastiest things to grasp about C. In Euphoria you would simply have a sequence of strings: aliases = { "fred", "george", ... } 3. Things declared as "short" take 2-bytes. char is 1 byte and int is 4-bytes. (This is not totally standardized in the C world, but is safe to assume here.) Regards, Rob Craig Rapid Deployment Software http://members.aol.com/FilesEu/
3. Re: Winsock.ew as a team project...
- Posted by Jacques Deschenes <desja at GLOBETROTTER.QC.CA> Jul 07, 1998
- 428 views
- Last edited Jul 08, 1998
At 06:27 07-07-98 +0300, you wrote: >Hi Euphorians: > >Since the coding of Winsock.ew is getting harder,and there are a lot of >functions to implement, any help is very welcome. Greg Harris has joined the >(now) team. For anyone else wishing to collaborate, please send mail. > >Currently I'm stuck with a structure accessing problem in the function >gethostbyaddr(). >This function returns a pointer to a structure defining host information. In >C/C++ the structure is as follows: > >struct hostent{ > char FAR * h_name; > char FAR * FAR * h_aliases; > short h_addrtype; > short h_length; > char FAR * FAR * h_addr_list; >}; > >Since I'm not good at all in C, I do not really understand how to code the >access to this data in Euphoria.... >(What does those FAR * FAR * mean?... Pointers to Pointers?... Two >pointers?... Array of pointers?...) >(Help welcome. Join the winsock revolution!) A FAR pointer in protected mode is 48 bits has it include the selector (16 bits) and the offset( 32 bits) and a FAR* FAR* is a pointer to a pointer. So you should allocate 3 * 48 + 2 * 16 bytes for this structure. constant --offset to access data in the structure. h_name = 0, -- FAR * is 6 bytes long h_aliases = 6, -- FAR * h_addrtype = 12, -- short is 2 bytes h_length = 14, -- short h_addr_list = 16 -- FAR * I didn't test it, hoping I'm right, Regards, Jacques Deschenes Baie-Comeau, Quebec Canada desja at globetrotter.qc.ca
4. Re: Winsock.ew as a team project...
- Posted by Robert Craig <rds at EMAIL.MSN.COM> Jul 08, 1998
- 413 views
Jacques Deschenes writes: > A FAR pointer in protected mode is 48 bits has it include the > selector (16 bits) and the offset( 32 bits) and a FAR* FAR* > is a pointer to a pointer. > So you should allocate 3 * 48 + 2 * 16 bytes for this structure. > constant --offset to access data in the structure. > h_name = 0, -- FAR * is 6 bytes long > h_aliases = 6, -- FAR * > h_addrtype = 12, -- short is 2 bytes > h_length = 14, -- short > h_addr_list = 16 -- FAR * >I didn't test it, hoping I'm right, According to the WIN32 API help file... "The Application Program Interface (API) for Win32 uses the flat 32-bit addressing mode...One of the major design goals of the 32-bit API was to minimize the impact on existing code, so that 16-bit applications can be adapted as easily as possible. However, some changes were mandated by the larger address space. Pointers are all 32 bits wide and no longer near or far, and your code cannot make assumptions based on segmented memory. Items which have increased to 32 bits include the following: · Pointers · Window handles · Handles to other objects, such as pens, brushes, and menus · Graphics coordinates" Jacques, you are correct that a "far" pointer on the 386 and higher machines is a 16-bit segment and a 32-bit offset. However in the flat memory model all pointers use the same segment and so all C pointers in an application are 32-bits (4 bytes). The segment number is rarely used for any purpose. (It's used to set hardware interrupts I suppose.) I checked the structure (above) that Jesus asked about using WATCOM C, compiling for 32-bit Windows. The total size (sizeof) of the structure is 16 bytes. The constant offsets should be: h_name = 0, -- pointer is 4 bytes long h_aliases = 4, -- pointer is 4 bytes long h_addrtype = 8, -- short is 2 bytes h_length = 10, -- short is 2 bytes h_addr_list = 12 -- pointer is 4 bytes long The FAR keyword is usually #defined in some C .h file as null string. So the pointers aren't really far pointers. Something like: #ifdef WIN32 #define FAR #else #define FAR _far #endif (or something like that). Regards, Rob Craig Rapid Deployment Software http://members.aol.com/FilesEu/