home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #31 / NN_1992_31.iso / spool / comp / unix / question / 14908 < prev    next >
Encoding:
Text File  |  1992-12-23  |  2.0 KB  |  61 lines

  1. Xref: sparky comp.unix.questions:14908 comp.lang.perl:7587
  2. Path: sparky!uunet!ogicse!reed!romulus!merlyn
  3. From: merlyn@ora.com (Randal L. Schwartz)
  4. Newsgroups: comp.unix.questions,comp.lang.perl
  5. Subject: Re: maybe another stupid question: cookie server
  6. Message-ID: <MERLYN.92Dec22230755@romulus.reed.edu>
  7. Date: 23 Dec 92 07:07:58 GMT
  8. Article-I.D.: romulus.MERLYN.92Dec22230755
  9. References: <1992Dec18.200019.4175@tolten.puc.cl>
  10. Sender: news@reed.edu (USENET News System)
  11. Followup-To: comp.unix.questions
  12. Organization: Stonehenge Consulting Services; Portland, Oregon, USA
  13. Lines: 45
  14. In-Reply-To: daniel@isluga.puc.cl's message of 18 Dec 92 20:00:19 GMT
  15.  
  16. In article <1992Dec18.200019.4175@tolten.puc.cl> daniel@isluga.puc.cl (Daniel Hirschberg) writes:
  17.        Does anybody know where i can get a cookie server daemon for
  18.    sun?
  19.        If there's anyone who can iluminate me in this topic i would
  20.    really apreciate it!
  21.  
  22.  
  23. Here's one that I wrote in Perl for a class that I taught:
  24. [WATCH THE FOLLOWUPS: REMOVE COMP.LANG.PERL IF NO MORE PERL.]
  25.  
  26. #!/usr/bin/perl
  27. require 'sys/socket.ph';
  28. $sockaddr = 'S n a4 x8';
  29. chop($hostname = `hostname`);
  30. ($name, $aliases, $proto) = getprotobyname('tcp');
  31. $port = 4242; # some big number
  32. $thisport = pack($sockaddr, &AF_INET, $port, "\0\0\0\0"); # wildcard addr
  33.  
  34. socket(S, &PF_INET, &SOCK_STREAM, $proto) || die "cannot create socket: $!";
  35. bind(S,$thisport) || die "cannot bind socket: $!";
  36. listen(S,5) || die "cannot listen socket: $!";
  37. for (;;) {
  38.   accept(NS,S) || die "cannot accept socket: $!";
  39.   print NS &fortune;
  40.   close NS;
  41. }
  42.  
  43. sub fortune {
  44.   @fortunes = split(/\n%%\n/, <<'END') unless @fortunes;
  45. A fool and his money are soon parted.
  46. %%
  47. A penny saved is a penny earned.
  48. %%
  49. Ask not what your country can do for you;
  50. ask what you can do for your country.
  51. %%
  52. END
  53.   splice(@fortunes,int(rand(@fortunes)),1)."\n";
  54. }
  55.  
  56. Just another Perl hacker,
  57. --
  58. Randal L. Schwartz / Stonehenge Consulting Services (503)777-0095
  59. merlyn@ora.com (semi-permanent) merlyn@reed.edu (for newsreading only)
  60. factoid: "Portland, Oregon, home of the California Raisins and Lone-Star Beer!"
  61.