Linux-Development-Apps Digest #284, Volume #7 Fri, 16 Mar 01 21:13:09 EST Contents: Re: sizeof returns wrong structure size (Grant Edwards) Re: sizeof returns wrong structure size ("Joseph A. Knapka") Re: GPL (Micah Cowan) Re: GPL (Micah Cowan) Dynamic function availability in Linux ([EMAIL PROTECTED]) Re: sizeof returns wrong structure size (Grant Edwards) Re: Retrieving a web page ([EMAIL PROTECTED]) Re: sizeof returns wrong structure size ([EMAIL PROTECTED]) Re: Retrieving a web page ("Alex Collins") Re: sizeof returns wrong structure size ([EMAIL PROTECTED]) Re: sizeof returns wrong structure size (Floyd Davidson) Re: sizeof returns wrong structure size (Grant Edwards) Re: sizeof returns wrong structure size (Grant Edwards) Re: sizeof returns wrong structure size (Erik Max Francis) ---------------------------------------------------------------------------- From: [EMAIL PROTECTED] (Grant Edwards) Subject: Re: sizeof returns wrong structure size Date: Fri, 16 Mar 2001 23:20:47 GMT On Fri, 16 Mar 2001 21:46:52 -0000, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote: >C structs cannot define the vast diversity of external formats and protocols >that exist. Only working code can do that. There's no technical reason that structs can't be implimented such that the user can control padding (or even byte order). The compiler guys just don't want to (I assume because they don't need to do that kind of stuff in the software they write). Those of us that have to talk to the outside world would kill for a way to specify storage layout of data structures so that we can make them match external specifications. -- Grant Edwards grante Yow! We are now enjoying at total mutual interaction in visi.com an imaginary hot tub... ------------------------------ From: "Joseph A. Knapka" <[EMAIL PROTECTED]> Subject: Re: sizeof returns wrong structure size Date: Fri, 16 Mar 2001 23:42:37 GMT Grant Edwards wrote: > > On Fri, 16 Mar 2001 21:46:52 -0000, [EMAIL PROTECTED] ><[EMAIL PROTECTED]> wrote: > > >C structs cannot define the vast diversity of external formats and protocols > >that exist. Only working code can do that. > > There's no technical reason that structs can't be implimented > such that the user can control padding (or even byte order). It seems to me this would require language extensions. Some of those are already available; most C compilers provide something like "#pragma pack" to force structs to be laid out in memory without padding. In any case, the compiler and the standard library together give you all the facilities you need to do whatever you want (I speak from experience, having spent most of the past 10 years writing code to speak various obscure proprietary protocols). > The compiler guys just don't want to (I assume because they > don't need to do that kind of stuff in the software they > write). Those of us that have to talk to the outside world > would kill for a way to specify storage layout of data > structures so that we can make them match external > specifications. I think what compiler writers want is to write compilers that are generally useful :) There are languages such as, for example, ASN.1, that are specifically designed for building communication protocols. An ASN.1 compiler takes a protocol description and generates all the code (usually in C, sometimes not) to implement it. Of course, while it *is* a standard, it's not a *free* one, and therefore isn't used as much as it ought to be; and tools are expensive. You'd think people would figure out that if you want something to be a "standard", all you really have to do is design it well and give it away for free... -- Joe Knapka "It was just a maddened crocodile hidden in a flower bed. It could have happened to anyone." -- Pratchett // Linux MM Documentation in progress: // http://home.earthlink.net/~jknapka/linux-mm/vmoutline.html * Evolution is an "unproven theory" in the same sense that gravity is. * ------------------------------ Subject: Re: GPL From: Micah Cowan <[EMAIL PROTECTED]> Date: 16 Mar 2001 16:14:22 -0800 John Hasler <[EMAIL PROTECTED]> writes: > Micah Cowan writes: > > You are not allowed to link non-GPL code with GPL code, even > > dynamically,... > > This is not true. Have you /read/ the GPL? The following is at the end of it: This General Public License does not permit incorporating your program into proprietary programs. If your program is a subroutine library, you may consider it more useful to permit linking proprietary applications with the library. If this is what you want to do, use the GNU Library General Public License instead of this License. This has generally been interpreted to include in-memory incorporation, such as linking. Micah ------------------------------ Subject: Re: GPL From: Micah Cowan <[EMAIL PROTECTED]> Date: 16 Mar 2001 16:20:41 -0800 "Joseph A. Knapka" <[EMAIL PROTECTED]> writes: > Micah Cowan wrote: > > This is the sort of selfishness that the GPL was intended to > > eschew. > > If I produce a product and would like to be compensated for that, > within reason, how am I being selfish? *Everyone* is selfish in > that way - we all want *some* kind of compensation for work > accomplished. Some people just prefer it to be more concrete than > others. I did not imply that the desire to be compensated for your hard work is selfishness - even RMS has this strong desire. What the FSF is against (and the GPL) is the practice of /forcing/ people to compensate you by removing their right to use, and in particular to modify and improve the software for which they are paying. Instead of paying for the program, they are instead only granted the right to use the program upon paying for it. That I call selfish. Naturally, there are many who disagree with me on that - and they have every right to. What they don't have the right to do is exploit the goodwill offering of software released for free (as in freedom), by attempting to use it in an act of constriction (the opposite of the end towards which most people employ the GPL). I'm not really thoroughly against other people releasing proprietary software - and I'm not ready to go to RMS's extreme of not ever buying non-free software. But proprietary software should never exploit the hard work of others who have chosen not to take that route. Micah ------------------------------ From: [EMAIL PROTECTED] Subject: Dynamic function availability in Linux Date: 16 Mar 2001 23:53:11 GMT Hi! I post this message because of a recommendation in comp.lang.c (thanks!) I'm developing some kind of server program under Linux. I would have some compiled modules for that server, all them with the same function calls. The problem is that when I compile main server, I don't know how many modules I will have, their names (only the function names)... Is there any mechanism I can use to call these functions one after another from different modules? I need at least some indication of where to learn from (that's no problem), or some program you know that does something like this and I can read its source code. Thanks in advance, Dani ================================== Posted via http://nodevice.com Linux Programmer's Site ------------------------------ From: [EMAIL PROTECTED] (Grant Edwards) Subject: Re: sizeof returns wrong structure size Date: Sat, 17 Mar 2001 00:51:10 GMT On Fri, 16 Mar 2001 23:42:37 GMT, Joseph A. Knapka <[EMAIL PROTECTED]> wrote: >> >C structs cannot define the vast diversity of external formats and protocols >> >that exist. Only working code can do that. >> >> There's no technical reason that structs can't be implimented >> such that the user can control padding (or even byte order). > >It seems to me this would require language extensions. Some of >those are already available; most C compilers provide something >like "#pragma pack" to force structs to be laid out in memory >without padding. In any case, the compiler and the standard library >together give you all the facilities you need to do whatever >you want (I speak from experience, having spent most of the >past 10 years writing code to speak various obscure proprietary >protocols). I know it can be done. I've been doing it for 15 years. It just seems like a waste to do all those memcpy()'s rather than using structure references. Even if memcpy() is inlined and optimized into the same asm as a structure reference, there's no way you can compare readability and maintainability of structure references. >I think what compiler writers want is to write compilers that >are generally useful :) Yes, but people writing OS tools will usually place higher priority on making the tools do what they need to do. -- Grant Edwards grante Yow! Fold, fold, at FOLD!! FOLDING many items!! visi.com ------------------------------ From: [EMAIL PROTECTED] Subject: Re: Retrieving a web page Date: Sat, 17 Mar 2001 00:58:07 -0000 On Fri, 16 Mar 2001 21:11:15 +0100 Emilien Arino <[EMAIL PROTECTED]> wrote: [...snip...] I send you a private reply, but your mail server is broken. -- ================================================================= | Phil Howard - KA9WGN | Dallas | http://linuxhomepage.com/ | | [EMAIL PROTECTED] | Texas, USA | http://phil.ipal.org/ | ================================================================= ------------------------------ From: [EMAIL PROTECTED] Subject: Re: sizeof returns wrong structure size Date: Sat, 17 Mar 2001 01:04:26 -0000 On Fri, 16 Mar 2001 23:20:47 GMT Grant Edwards <[EMAIL PROTECTED]> wrote: | On Fri, 16 Mar 2001 21:46:52 -0000, [EMAIL PROTECTED] |<[EMAIL PROTECTED]> wrote: | | There's no technical reason that structs can't be implimented | such that the user can control padding (or even byte order). struct mystruct { little_endian int mynum; big_endian long myvalue; } mydata; Like that? | The compiler guys just don't want to (I assume because they | don't need to do that kind of stuff in the software they | write). Those of us that have to talk to the outside world | would kill for a way to specify storage layout of data | structures so that we can make them match external | specifications. External layws can get incredible complex. Many of that have things that vary in size. If the middle item is a string which can be from 4 to 8 bytes in length, and the item following it is a 4 byte number in big endian format, and your code has the number before the string, where are you going to store it? You can't just lay out byte offsets and expect that to work in all cases. Sure, there are many formats for which this is trivial. But there are many which are incredibly complex. Where do you draw the line and say this can be implemented in the compiler with structs and that cannot? -- ================================================================= | Phil Howard - KA9WGN | Dallas | http://linuxhomepage.com/ | | [EMAIL PROTECTED] | Texas, USA | http://phil.ipal.org/ | ================================================================= ------------------------------ From: "Alex Collins" <[EMAIL PROTECTED]> Subject: Re: Retrieving a web page Date: Sat, 17 Mar 2001 01:07:27 -0000 did you try hitting it from a browser at the same time, to see if it is just a server error or if it is your program? it could be just that the server / page etc is having some maitainance done on it - the seti people had some probs a while back with their fibre lines being cut - maybe they are just updating stuff! "Emilien Arino" <[EMAIL PROTECTED]> wrote in message news:98ts08$efj$[EMAIL PROTECTED]... > Hi, > I wrote a little program to retrieve a web page and store it into an array > (code at the bottom of this mail) .The code is still ugly. I'll clean it up > as soon as it works as expected. > > The program works with almost every web page.But I have a problem with this > one : > http://setiathome.ssl.berkeley.edu/cgi-bin/cgi?email=arino.canton%40wanadoo. > fr&cmd=user_stats_new > > > This is what I send to the server > > > GET /cgi-bin/cgi?email=arino.canton%40wanadoo.fr&cmd=user_stats_new HTTP/1.0 > Accept: text/html > User-Agent: HttpClientTest > Host: setiathome.ssl.berkeley.edu > Proxy-Connection: Keep-Alive > > This is what he returns: > > > HTTP/1.1 500 Internal Server Error > Date: Fri, 16 Mar 2001 18:47:06 GMT > Server: Apache/1.3.14 (Unix) mod_fastcgi/2.2.10 > Last-Modified: Thu, 02 Mar 2000 07:29:40 GMT > ETag: "173d8-192-38be1864" > Accept-Ranges: bytes > Content-Length: 402 > Connection: close > Content-Type: text/html > > <head> > <title>Error</title> > </head> > <body BGCOLOR="#000000" TEXT="#FFFFFF" LINK="#00FFA0" VLINK="#00F080"> > <img src="http://setiathome.ssl.berkeley.edu/images/better_banner.jpg"> <br> > <br> > <h2>Web Server Error</h2> > <p> > The page you selected is temporarily down or disabled. > Sorry for the inconvenience. > Please try again later. > <p> > <a href="http://setiathome.ssl.berkeley.edu">Back to the home page</a> > > > > > This is the code I wrote: > > > > #include <stdio.h> > #include <stdlib.h> > #include <netinet/in.h> > #include <netdb.h> > #include <sys/types.h> > #include <sys/socket.h> > > #define LG_BUF 1024 > #define PORT 80 > > > int main(int argc, char *argv[]) { > > int desc; > int nb; > unsigned int i=0; > char host[100]; > char page[200]; > char buffer[LG_BUF]; > char gros_buffer[50000]; > struct sockaddr_in adresse; > struct hostent *hostent; > char http_cmd[200]; > > if (argc != 3) { > printf("usage : adresse page\n"); > exit(1); > } > > strcpy(host, argv[1]); > strcpy(page, argv[2]); > > if ((hostent = gethostbyname(host)) == NULL) { > perror("probleme avec l'adresse"); > } > > if ((desc = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP)) < 0) { > perror("erreur creation de la socket"); > exit(1); > } > > memset(&adresse, 0, sizeof(struct sockaddr_in)); > adresse.sin_family = AF_INET; > adresse.sin_port = htons(PORT); > adresse.sin_addr.s_addr = ((struct in_addr *) (hostent -> h_addr)) -> > s_addr; > > > if (connect(desc, &adresse, sizeof(struct sockaddr_in)) < 0) { > perror("probleme de connexion"); > exit(1); > } > > printf("connecte au serveur : %s\n", host); > > sprintf(http_cmd,"GET %s HTTP/1.0\nAccept: text/html\nUser-Agent: > HttpClientTest\nHost: %s\nProxy-Connection: Keep-Alive\n\n", page, host); > write(desc, http_cmd, strlen(http_cmd)); > printf("requete HTTP :\n%s\n", http_cmd); > > while (1) { > if ((nb = read(desc, buffer, LG_BUF)) == 0) > break; > strncpy(gros_buffer+i, buffer, nb); > i += nb; > printf("."); > } > > printf("\n"); > printf("%d octets recus.\n", i); > > *(gros_buffer+i+1) = '\0'; > printf("reponse du serveur :\n%s", gros_buffer); > > return(0); > > } > > > > > > Any help appreciated. > Thanks in advance, > Emilien Arino > > ------------------------------ From: [EMAIL PROTECTED] Subject: Re: sizeof returns wrong structure size Date: Sat, 17 Mar 2001 01:14:43 -0000 On Fri, 16 Mar 2001 23:42:37 GMT Joseph A. Knapka <[EMAIL PROTECTED]> wrote: |> There's no technical reason that structs can't be implimented |> such that the user can control padding (or even byte order). | | It seems to me this would require language extensions. Some of | those are already available; most C compilers provide something | like "#pragma pack" to force structs to be laid out in memory | without padding. In any case, the compiler and the standard library | together give you all the facilities you need to do whatever | you want (I speak from experience, having spent most of the | past 10 years writing code to speak various obscure proprietary | protocols). I think more of the problem is too many people want to be able to describe their "problem" in a declarative way and expect it all to just happen right. Unfortunately, this isn't easy for everything. While one could design a system which allows a declarative layout to be transmitted to an unlike machine and show up again in the same declarative layout, the intermediate form is not what will be specified. Being able to do declarative _and_ specifying the external format at the same time is what is hard because it is so open ended. |> The compiler guys just don't want to (I assume because they |> don't need to do that kind of stuff in the software they |> write). Those of us that have to talk to the outside world |> would kill for a way to specify storage layout of data |> structures so that we can make them match external |> specifications. | | I think what compiler writers want is to write compilers that | are generally useful :) Or at least spend more of their time on making the parts more people use work better. | There are languages such as, for example, ASN.1, that are | specifically designed for building communication protocols. | An ASN.1 compiler takes a protocol description and generates | all the code (usually in C, sometimes not) to implement it. | Of course, while it *is* a standard, it's not a *free* one, | and therefore isn't used as much as it ought to be; and | tools are expensive. You'd think people would figure out | that if you want something to be a "standard", all you really | have to do is design it well and give it away for free... What needs to be free is the standard. Unfortunately ASN.1 is not that. That why I don't use it. I have been considering writing something like it, but different, and see if it can be suitable for standardizing. Anyway, if there is a free standard and a good one, then implementations, both free and commercial, will happen. -- ================================================================= | Phil Howard - KA9WGN | Dallas | http://linuxhomepage.com/ | | [EMAIL PROTECTED] | Texas, USA | http://phil.ipal.org/ | ================================================================= ------------------------------ From: Floyd Davidson <[EMAIL PROTECTED]> Subject: Re: sizeof returns wrong structure size Date: 16 Mar 2001 15:39:16 -0900 [EMAIL PROTECTED] (Grant Edwards) wrote: >[EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote: > >>C structs cannot define the vast diversity of external formats >>and protocols that exist. Only working code can do that. > >There's no technical reason that structs can't be implimented >such that the user can control padding (or even byte order). Except that then it would not be a programming language data structure, but instead would be a packet networking datagram. Which do you really want integral to a language like C? >The compiler guys just don't want to (I assume because they >don't need to do that kind of stuff in the software they >write). Those of us that have to talk to the outside world >would kill for a way to specify storage layout of data >structures so that we can make them match external >specifications. You would bloat a *programming language* with that??? -- Floyd L. Davidson <http://www.ptialaska.net/~floyd> Ukpeagvik (Barrow, Alaska) [EMAIL PROTECTED] ------------------------------ From: [EMAIL PROTECTED] (Grant Edwards) Subject: Re: sizeof returns wrong structure size Date: Sat, 17 Mar 2001 01:41:30 GMT On Sat, 17 Mar 2001 01:04:26 -0000, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote: >struct mystruct { > little_endian int mynum; > big_endian long myvalue; >} mydata; > >Like that? Sure. >| would kill for a way to specify storage layout of data >| structures so that we can make them match external >| specifications. > >External layws can get incredible complex. Many of that have things >that vary in size. I've spent 90% of my time dealing with frame formats that don't have any variable fields and would be quite happy if C structs could be used for that. Variable size fields is a whole different problem. >[...] Where do you draw the line and say this can be >implemented in the compiler with structs and that cannot? I don't think that static frame structures would require much effort. I'd even give up the byte-ordering without much complaint. It would just nice to just get the bytes in the right place without so much fuss. -- Grant Edwards grante Yow! Used staples are good at with SOY SAUCE! visi.com ------------------------------ From: [EMAIL PROTECTED] (Grant Edwards) Subject: Re: sizeof returns wrong structure size Date: Sat, 17 Mar 2001 01:49:40 GMT On 16 Mar 2001 15:39:16 -0900, Floyd Davidson <[EMAIL PROTECTED]> wrote: >>>C structs cannot define the vast diversity of external formats >>>and protocols that exist. Only working code can do that. >> >>There's no technical reason that structs can't be implimented >>such that the user can control padding (or even byte order). > >Except that then it would not be a programming language data >structure, Nonsense. There's no law that says you aren't allowed to specify the representation of data in a programming language. >but instead would be a packet networking datagram. Specifying representation is also useful in accessing memory-mapped hardware. >Which do you really want integral to a language like C? I think explicit control of storage layout is _especially_ important in a language like C that is intended for low-level systems programming. Even Python (a much higher level language than C) has a method to specify exact byte layout (and byte ordering) for a fields in a structure. It's a damned useful thing to be able to do. >>The compiler guys just don't want to (I assume because they >>don't need to do that kind of stuff in the software they >>write). Those of us that have to talk to the outside world >>would kill for a way to specify storage layout of data >>structures so that we can make them match external >>specifications. > >You would bloat a *programming language* with that??? Yes, I think it's important for a systems language. I guess if you don't think networking or accessing hardware is a useful thing, then it would be "bloat" to have features to allows data to be layed out explicitly. Plenty of other systems (and applications) languages allow it. -- Grant Edwards grante Yow! FIRST, I'm covering at you with OLIVE OIL and visi.com PRUNE WHIP!! ------------------------------ From: Erik Max Francis <[EMAIL PROTECTED]> Subject: Re: sizeof returns wrong structure size Date: Fri, 16 Mar 2001 17:53:00 -0800 Grant Edwards wrote: > There's no technical reason that structs can't be implimented > such that the user can control padding (or even byte order). Not if you want bus errors on some architectures. There's a reason why the Standards don't specify endianness and allow arbitrary struct padding. It's because it's necessary. -- Erik Max Francis / [EMAIL PROTECTED] / http://www.alcyone.com/max/ __ San Jose, CA, US / 37 20 N 121 53 W / ICQ16063900 / &tSftDotIotE / \ Humor is emotional chaos remembered in tranquility. \__/ James Thurber Alcyone Systems' Daily Planet / http://www.alcyone.com/planet.html A new, virtual planet, every day. ------------------------------ ** FOR YOUR REFERENCE ** The service address, to which questions about the list itself and requests to be added to or deleted from it should be directed, is: Internet: [EMAIL PROTECTED] You can send mail to the entire list by posting to the comp.os.linux.development.apps newsgroup. Linux may be obtained via one of these FTP sites: ftp.funet.fi pub/Linux tsx-11.mit.edu pub/linux sunsite.unc.edu pub/Linux End of Linux-Development-Apps Digest ******************************