home *** CD-ROM | disk | FTP | other *** search
- Xref: sparky comp.unix.questions:14908 comp.lang.perl:7587
- Path: sparky!uunet!ogicse!reed!romulus!merlyn
- From: merlyn@ora.com (Randal L. Schwartz)
- Newsgroups: comp.unix.questions,comp.lang.perl
- Subject: Re: maybe another stupid question: cookie server
- Message-ID: <MERLYN.92Dec22230755@romulus.reed.edu>
- Date: 23 Dec 92 07:07:58 GMT
- Article-I.D.: romulus.MERLYN.92Dec22230755
- References: <1992Dec18.200019.4175@tolten.puc.cl>
- Sender: news@reed.edu (USENET News System)
- Followup-To: comp.unix.questions
- Organization: Stonehenge Consulting Services; Portland, Oregon, USA
- Lines: 45
- In-Reply-To: daniel@isluga.puc.cl's message of 18 Dec 92 20:00:19 GMT
-
- In article <1992Dec18.200019.4175@tolten.puc.cl> daniel@isluga.puc.cl (Daniel Hirschberg) writes:
- Does anybody know where i can get a cookie server daemon for
- sun?
- If there's anyone who can iluminate me in this topic i would
- really apreciate it!
-
-
- Here's one that I wrote in Perl for a class that I taught:
- [WATCH THE FOLLOWUPS: REMOVE COMP.LANG.PERL IF NO MORE PERL.]
-
- #!/usr/bin/perl
- require 'sys/socket.ph';
- $sockaddr = 'S n a4 x8';
- chop($hostname = `hostname`);
- ($name, $aliases, $proto) = getprotobyname('tcp');
- $port = 4242; # some big number
- $thisport = pack($sockaddr, &AF_INET, $port, "\0\0\0\0"); # wildcard addr
-
- socket(S, &PF_INET, &SOCK_STREAM, $proto) || die "cannot create socket: $!";
- bind(S,$thisport) || die "cannot bind socket: $!";
- listen(S,5) || die "cannot listen socket: $!";
- for (;;) {
- accept(NS,S) || die "cannot accept socket: $!";
- print NS &fortune;
- close NS;
- }
-
- sub fortune {
- @fortunes = split(/\n%%\n/, <<'END') unless @fortunes;
- A fool and his money are soon parted.
- %%
- A penny saved is a penny earned.
- %%
- Ask not what your country can do for you;
- ask what you can do for your country.
- %%
- END
- splice(@fortunes,int(rand(@fortunes)),1)."\n";
- }
-
- Just another Perl hacker,
- --
- Randal L. Schwartz / Stonehenge Consulting Services (503)777-0095
- merlyn@ora.com (semi-permanent) merlyn@reed.edu (for newsreading only)
- factoid: "Portland, Oregon, home of the California Raisins and Lone-Star Beer!"
-