home *** CD-ROM | disk | FTP | other *** search
MacBinary | 1994-10-06 | 16.6 KB | [TEXT/MPS ] |
open in:
MacOS 8.1
|
Win98
|
DOS
browse contents |
view JSON data
|
view as text
This file was processed as: MacBinary
(archive/macBinary).
Confidence | Program | Detection | Match Type | Support
|
---|
66%
| dexvert
| Compact Compressed (Unix) (archive/compact)
| ext
| Supported |
10%
| dexvert
| MacBinary (archive/macBinary)
| fallback
| Supported |
1%
| dexvert
| Text File (text/txt)
| fallback
| Supported |
100%
| file
| MacBinary II, inited, Thu Oct 6 14:13:54 1994, modified Thu Oct 6 14:13:54 1994, creator 'MPS ', type ASCII, 16331 bytes "ATDemo.c" , at 0x404b 428 bytes resource
| default (weak)
| |
99%
| file
| data
| default
| |
74%
| TrID
| Macintosh plain text (MacBinary)
| default
| |
25%
| TrID
| MacBinary 2
| default (weak)
| |
100%
| siegfried
| fmt/1762 MacBinary (II)
| default
| |
100%
| lsar
| MacBinary
| default
|
|
id metadata |
---|
key | value |
---|
macFileType | [TEXT] |
macFileCreator | [MPS ] |
hex view+--------+-------------------------+-------------------------+--------+--------+
|00000000| 00 08 41 54 44 65 6d 6f | 2e 63 00 00 00 00 00 00 |..ATDemo|.c......|
|00000010| 00 00 00 00 00 00 00 00 | 00 00 00 00 00 00 00 00 |........|........|
|00000020| 00 00 00 00 00 00 00 00 | 00 00 00 00 00 00 00 00 |........|........|
|00000030| 00 00 00 00 00 00 00 00 | 00 00 00 00 00 00 00 00 |........|........|
|00000040| 00 54 45 58 54 4d 50 53 | 20 01 00 00 00 00 00 00 |.TEXTMPS| .......|
|00000050| 00 00 00 00 00 3f cb 00 | 00 01 ac aa b9 ee e2 aa |.....?..|........|
|00000060| b9 ee e2 00 00 00 00 00 | 00 00 00 00 00 00 00 00 |........|........|
|00000070| 00 00 00 00 00 00 00 00 | 00 00 81 81 d7 f2 00 00 |........|........|
|00000080| 2f 2a 0d 20 2a 20 20 54 | 68 69 73 20 73 61 6d 70 |/*. * T|his samp|
|00000090| 6c 65 20 70 72 6f 67 72 | 61 6d 20 61 77 61 69 74 |le progr|am await|
|000000a0| 73 20 61 6e 20 41 54 50 | 20 63 6f 6e 6e 65 63 74 |s an ATP| connect|
|000000b0| 69 6f 6e 20 66 72 6f 6d | 20 61 20 63 6c 69 65 6e |ion from| a clien|
|000000c0| 74 2e 20 20 57 68 65 6e | 20 69 74 20 67 65 74 73 |t. When| it gets|
|000000d0| 20 6f 6e 65 0d 20 2a 20 | 20 20 69 74 20 73 70 69 | one. * | it spi|
|000000e0| 6e 73 20 6f 66 66 20 61 | 20 6e 65 77 20 74 68 72 |ns off a| new thr|
|000000f0| 65 61 64 20 74 6f 20 68 | 61 6e 64 6c 65 20 74 68 |ead to h|andle th|
|00000100| 65 20 63 6f 6e 76 65 72 | 73 61 74 69 6f 6e 20 77 |e conver|sation w|
|00000110| 69 74 68 20 74 68 65 20 | 63 6c 69 65 6e 74 2c 20 |ith the |client, |
|00000120| 77 68 69 63 68 0d 20 2a | 20 20 20 63 61 6e 20 69 |which. *| can i|
|00000130| 6e 63 6c 75 64 65 20 61 | 6e 20 61 72 62 69 74 72 |nclude a|n arbitr|
|00000140| 61 72 79 20 6e 75 6d 62 | 65 72 20 6f 66 20 71 75 |ary numb|er of qu|
|00000150| 65 72 69 65 73 20 72 65 | 67 61 72 64 69 6e 67 20 |eries re|garding |
|00000160| 63 65 72 74 61 69 6e 20 | 73 65 72 76 65 72 20 69 |certain |server i|
|00000170| 6e 66 6f 72 6d 61 74 69 | 6f 6e 2e 0d 20 2a 20 20 |nformati|on.. * |
|00000180| 20 54 68 65 20 73 65 72 | 76 65 72 20 63 61 6e 20 | The ser|ver can |
|00000190| 68 61 6e 64 6c 65 20 75 | 70 20 74 6f 20 31 32 38 |handle u|p to 128|
|000001a0| 20 73 69 6d 75 6c 74 61 | 6e 65 6f 75 73 20 63 6c | simulta|neous cl|
|000001b0| 69 65 6e 74 73 2e 0d 20 | 2a 0d 20 2a 20 20 54 68 |ients.. |*. * Th|
|000001c0| 69 73 20 63 6f 64 65 20 | 69 73 20 62 61 73 65 64 |is code |is based|
|000001d0| 20 6f 6e 20 74 68 65 20 | 41 54 50 53 45 52 56 20 | on the |ATPSERV |
|000001e0| 63 6f 64 65 20 70 72 6f | 76 69 64 65 64 20 69 6e |code pro|vided in|
|000001f0| 20 74 68 65 20 4e 6f 76 | 65 6c 6c 20 4e 4c 4d 20 | the Nov|ell NLM |
|00000200| 53 44 4b 0d 20 2a 0d 20 | 2a 20 20 57 72 69 74 74 |SDK. *. |* Writt|
|00000210| 65 6e 20 62 79 3a 20 4a | 61 6d 69 65 20 4f 73 62 |en by: J|amie Osb|
|00000220| 6f 72 6e 65 20 20 20 39 | 2f 39 34 0d 20 2a 0d 20 |orne 9|/94. *. |
|00000230| 2a 20 20 59 6f 75 20 6d | 61 79 20 63 6f 70 79 20 |* You m|ay copy |
|00000240| 61 6e 64 20 6d 6f 64 69 | 66 79 20 74 68 69 73 20 |and modi|fy this |
|00000250| 63 6f 64 65 20 61 74 20 | 77 69 6c 6c 2e 0d 20 2a |code at |will.. *|
|00000260| 0d 20 2a 20 20 50 6c 65 | 61 73 65 20 6e 6f 74 65 |. * Ple|ase note|
|00000270| 20 74 68 61 74 20 74 68 | 69 73 20 4e 4c 4d 20 69 | that th|is NLM i|
|00000280| 73 20 69 6e 74 65 6e 64 | 65 64 20 61 74 20 61 20 |s intend|ed at a |
|00000290| 64 65 6d 6f 6e 73 74 72 | 61 74 69 6f 6e 20 70 72 |demonstr|ation pr|
|000002a0| 6f 67 72 61 6d 2e 20 20 | 41 74 20 74 68 65 20 74 |ogram. |At the t|
|000002b0| 69 6d 65 0d 20 2a 20 20 | 6f 66 20 69 74 73 20 63 |ime. * |of its c|
|000002c0| 72 65 61 74 69 6f 6e 2c | 20 4e 65 74 57 61 72 65 |reation,| NetWare|
|000002d0| 20 66 6f 72 20 50 6f 77 | 65 72 50 43 20 77 61 73 | for Pow|erPC was|
|000002e0| 20 69 6e 20 61 6c 70 68 | 61 2e 20 20 41 73 20 73 | in alph|a. As s|
|000002f0| 75 63 68 2c 20 74 68 69 | 73 20 70 72 6f 67 72 61 |uch, thi|s progra|
|00000300| 6d 0d 20 2a 20 20 6d 61 | 79 20 6e 6f 74 20 63 6f |m. * ma|y not co|
|00000310| 6d 70 69 6c 65 20 61 6e | 64 20 72 75 6e 20 77 69 |mpile an|d run wi|
|00000320| 74 68 6f 75 74 20 63 68 | 61 6e 67 65 73 20 69 6e |thout ch|anges in|
|00000330| 20 74 68 65 20 66 69 6e | 61 6c 20 70 72 6f 64 75 | the fin|al produ|
|00000340| 63 74 2e 0d 20 2a 0d 20 | 2a 20 41 70 70 6c 65 20 |ct.. *. |* Apple |
|00000350| 43 6f 6d 70 75 74 65 72 | 2c 20 49 6e 63 2e 20 6d |Computer|, Inc. m|
|00000360| 61 6b 65 73 20 6e 6f 20 | 77 61 72 72 61 6e 74 69 |akes no |warranti|
|00000370| 65 73 20 61 62 6f 75 74 | 20 74 68 65 20 74 68 65 |es about| the the|
|00000380| 20 66 69 74 6e 65 73 73 | 20 6f 66 20 74 68 69 73 | fitness| of this|
|00000390| 20 63 6f 64 65 0d 20 2a | 20 66 6f 72 20 61 6e 79 | code. *| for any|
|000003a0| 20 70 75 72 70 6f 73 65 | 20 61 6e 64 20 77 69 6c | purpose| and wil|
|000003b0| 6c 20 6e 6f 74 20 62 65 | 20 68 65 6c 64 20 6c 69 |l not be| held li|
|000003c0| 61 62 6c 65 20 66 6f 72 | 20 61 6e 79 20 64 61 6d |able for| any dam|
|000003d0| 61 67 65 73 20 79 6f 75 | 20 6d 61 79 20 73 75 66 |ages you| may suf|
|000003e0| 66 65 72 0d 20 2a 20 66 | 72 6f 6d 20 75 73 69 6e |fer. * f|rom usin|
|000003f0| 67 20 74 68 69 73 20 63 | 6f 64 65 2e 20 20 46 75 |g this c|ode. Fu|
|00000400| 72 74 68 65 72 6d 6f 72 | 65 2c 20 41 70 70 6c 65 |rthermor|e, Apple|
|00000410| 20 43 6f 6d 70 75 74 65 | 72 2c 20 49 6e 63 2e 20 | Compute|r, Inc. |
|00000420| 77 69 6c 6c 20 6e 6f 74 | 20 62 65 20 68 65 6c 64 |will not| be held|
|00000430| 0d 20 2a 20 6c 69 61 62 | 6c 65 20 66 6f 72 20 74 |. * liab|le for t|
|00000440| 68 65 20 64 65 61 74 68 | 20 6f 66 20 45 6c 76 69 |he death| of Elvi|
|00000450| 73 20 6f 72 20 61 6e 79 | 20 6f 74 68 65 72 20 73 |s or any| other s|
|00000460| 70 61 63 65 20 61 6c 69 | 65 6e 2e 0d 20 2a 0d 20 |pace ali|en.. *. |
|00000470| 2a 20 59 6f 75 72 20 6d | 69 6c 65 61 67 65 20 6d |* Your m|ileage m|
|00000480| 61 79 20 76 61 72 79 2e | 0d 20 2a 2f 0d 0d 2f 2f |ay vary.|. */..//|
|00000490| 20 53 6f 6d 65 20 73 74 | 61 6e 64 61 72 64 20 69 | Some st|andard i|
|000004a0| 6e 63 6c 75 64 65 73 0d | 23 69 6e 63 6c 75 64 65 |ncludes.|#include|
|000004b0| 20 3c 73 74 64 69 6f 2e | 68 3e 0d 23 69 6e 63 6c | <stdio.|h>.#incl|
|000004c0| 75 64 65 20 3c 73 74 64 | 6c 69 62 2e 68 3e 0d 23 |ude <std|lib.h>.#|
|000004d0| 69 6e 63 6c 75 64 65 20 | 3c 65 72 72 6e 6f 2e 68 |include |<errno.h|
|000004e0| 3e 0d 23 69 6e 63 6c 75 | 64 65 20 3c 73 74 72 69 |>.#inclu|de <stri|
|000004f0| 6e 67 2e 68 3e 0d 23 69 | 6e 63 6c 75 64 65 20 3c |ng.h>.#i|nclude <|
|00000500| 6e 77 65 6e 76 72 6e 2e | 68 3e 20 0d 23 69 6e 63 |nwenvrn.|h> .#inc|
|00000510| 6c 75 64 65 20 3c 73 69 | 67 6e 61 6c 2e 68 3e 0d |lude <si|gnal.h>.|
|00000520| 0d 2f 2a 20 59 6f 75 20 | 63 61 6e 20 63 6f 6d 70 |./* You |can comp|
|00000530| 69 6c 65 20 74 68 69 73 | 20 66 69 6c 65 20 77 69 |ile this| file wi|
|00000540| 74 68 20 74 68 65 20 57 | 61 74 63 6f 6d 20 43 33 |th the W|atcom C3|
|00000550| 32 20 63 6f 6d 70 69 6c | 65 72 20 74 6f 20 62 75 |2 compil|er to bu|
|00000560| 69 6c 64 0d 09 69 74 20 | 66 6f 72 20 4e 65 74 57 |ild..it |for NetW|
|00000570| 61 72 65 20 72 75 6e 6e | 69 6e 67 20 6f 6e 20 61 |are runn|ing on a|
|00000580| 6e 20 49 6e 74 65 6c 2d | 74 79 70 65 20 6d 61 63 |n Intel-|type mac|
|00000590| 68 69 6e 65 2e 20 20 48 | 6f 77 65 76 65 72 2c 0d |hine. H|owever,.|
|000005a0| 09 61 74 20 74 68 65 20 | 74 69 6d 65 20 74 68 69 |.at the |time thi|
|000005b0| 73 20 70 72 6f 67 72 61 | 6d 20 77 61 73 20 77 72 |s progra|m was wr|
|000005c0| 69 74 74 65 6e 2c 20 74 | 68 65 20 4e 65 74 57 61 |itten, t|he NetWa|
|000005d0| 72 65 20 69 6e 74 65 72 | 66 61 63 65 73 0d 09 66 |re inter|faces..f|
|000005e0| 6f 72 20 49 6e 74 65 6c | 20 68 61 64 20 6e 6f 74 |or Intel| had not|
|000005f0| 20 62 65 65 6e 20 75 70 | 64 61 74 65 64 20 74 6f | been up|dated to|
|00000600| 20 34 2e 31 2e 0d 2a 2f | 0d 0d 23 69 66 64 65 66 | 4.1..*/|..#ifdef|
|00000610| 20 4f 4c 44 5f 49 4e 54 | 45 52 46 41 43 45 53 0d | OLD_INT|ERFACES.|
|00000620| 23 69 6e 63 6c 75 64 65 | 20 3c 70 72 6f 63 65 73 |#include| <proces|
|00000630| 73 2e 68 3e 0d 23 69 6e | 63 6c 75 64 65 20 3c 63 |s.h>.#in|clude <c|
|00000640| 6f 6e 69 6f 2e 68 3e 0d | 23 65 6c 73 65 0d 23 69 |onio.h>.|#else.#i|
|00000650| 6e 63 6c 75 64 65 20 3c | 6e 77 74 68 72 65 61 64 |nclude <|nwthread|
|00000660| 2e 68 3e 0d 23 69 6e 63 | 6c 75 64 65 20 3c 6e 77 |.h>.#inc|lude <nw|
|00000670| 65 72 72 6e 6f 2e 68 3e | 20 0d 23 65 6e 64 69 66 |errno.h>| .#endif|
|00000680| 0d 0d 2f 2f 20 54 68 65 | 73 65 20 69 6e 63 6c 75 |..// The|se inclu|
|00000690| 64 65 73 20 61 72 65 20 | 61 6c 6c 20 6e 65 63 65 |des are |all nece|
|000006a0| 73 73 61 72 79 20 66 6f | 72 20 75 73 69 6e 67 20 |ssary fo|r using |
|000006b0| 41 70 70 6c 65 20 54 72 | 61 6e 73 61 63 74 69 6f |Apple Tr|ansactio|
|000006c0| 6e 20 50 72 6f 74 6f 63 | 6f 6c 0d 23 69 6e 63 6c |n Protoc|ol.#incl|
|000006d0| 75 64 65 20 3c 61 70 70 | 6c 65 74 6c 6b 2e 68 3e |ude <app|letlk.h>|
|000006e0| 0d 23 69 6e 63 6c 75 64 | 65 20 3c 61 74 70 2e 68 |.#includ|e <atp.h|
|000006f0| 3e 0d 23 69 6e 63 6c 75 | 64 65 20 3c 6e 62 70 2e |>.#inclu|de <nbp.|
|00000700| 68 3e 0d 23 69 6e 63 6c | 75 64 65 20 3c 64 64 70 |h>.#incl|ude <ddp|
|00000710| 2e 68 3e 0d 23 69 6e 63 | 6c 75 64 65 20 3c 7a 69 |.h>.#inc|lude <zi|
|00000720| 70 2e 68 3e 0d 0d 2f 2a | 20 47 6c 6f 62 61 6c 73 |p.h>../*| Globals|
|00000730| 20 20 20 2a 2f 0d 41 54 | 45 6e 74 69 74 79 5f 74 | */.AT|Entity_t|
|00000740| 20 74 68 69 73 45 6e 74 | 69 74 79 3b 20 20 20 20 | thisEnt|ity; |
|00000750| 20 20 20 20 20 20 09 09 | 2f 2f 20 54 68 65 20 73 | ..|// The s|
|00000760| 65 72 76 65 72 27 73 20 | 4e 42 50 20 65 6e 74 69 |erver's |NBP enti|
|00000770| 74 79 0d 69 6e 74 20 20 | 20 20 20 74 68 72 65 61 |ty.int | threa|
|00000780| 64 43 6f 75 6e 74 20 3d | 20 30 3b 20 20 20 20 20 |dCount =| 0; |
|00000790| 20 20 20 20 20 20 20 20 | 20 20 20 2f 2f 20 41 20 | | // A |
|000007a0| 63 6f 75 6e 74 20 6f 66 | 20 74 68 65 20 6e 75 6d |count of| the num|
|000007b0| 62 65 72 20 6f 66 20 73 | 70 61 77 6e 65 64 20 74 |ber of s|pawned t|
|000007c0| 68 72 65 61 64 73 0d 69 | 6e 74 20 20 20 20 20 65 |hreads.i|nt e|
|000007d0| 78 69 74 69 6e 67 4e 4c | 4d 20 3d 20 46 41 4c 53 |xitingNL|M = FALS|
|000007e0| 45 3b 20 20 20 20 20 20 | 20 20 20 20 20 20 20 2f |E; | /|
|000007f0| 2f 20 46 6c 61 67 20 73 | 65 74 20 77 68 65 6e 20 |/ Flag s|et when |
|00000800| 74 68 65 20 75 73 65 72 | 20 75 6e 6c 6f 61 64 73 |the user| unloads|
|00000810| 20 74 68 65 20 4e 4c 4d | 0d 69 6e 74 20 20 20 20 | the NLM|.int |
|00000820| 20 2a 6d 79 5f 66 64 3b | 20 20 20 20 20 20 20 20 | *my_fd;| |
|00000830| 20 20 20 20 20 20 20 20 | 20 20 20 20 20 20 20 20 | | |
|00000840| 20 2f 2f 20 54 68 65 20 | 6d 61 69 6e 20 66 64 20 | // The |main fd |
|00000850| 75 73 65 64 20 66 6f 72 | 20 6c 69 73 74 65 6e 69 |used for| listeni|
|00000860| 6e 67 20 66 6f 72 20 6e | 65 77 20 63 6f 6e 6e 65 |ng for n|ew conne|
|00000870| 63 74 69 6f 6e 73 0d 0d | 2f 2f 20 57 65 20 6a 75 |ctions..|// We ju|
|00000880| 73 74 20 70 72 6f 74 6f | 74 79 70 65 20 61 20 66 |st proto|type a f|
|00000890| 65 77 20 66 75 6e 63 74 | 69 6f 6e 73 20 68 65 72 |ew funct|ions her|
|000008a0| 65 20 69 6e 73 74 65 61 | 64 20 6f 66 20 6d 61 6b |e instea|d of mak|
|000008b0| 69 6e 67 20 61 20 2e 68 | 20 66 69 6c 65 0d 65 78 |ing a .h| file.ex|
|000008c0| 74 65 72 6e 20 69 6e 74 | 20 61 64 76 65 72 74 69 |tern int| adverti|
|000008d0| 73 65 28 69 6e 74 20 66 | 64 2c 63 68 61 72 20 2a |se(int f|d,char *|
|000008e0| 6e 62 70 5f 6e 61 6d 65 | 29 3b 20 20 20 20 20 20 |nbp_name|); |
|000008f0| 20 20 20 20 20 20 20 20 | 20 20 20 20 20 20 20 20 | | |
|00000900| 20 20 20 20 20 20 2f 2f | 20 41 64 76 65 72 74 69 | //| Adverti|
|00000910| 73 65 73 20 6f 75 72 20 | 73 65 72 76 65 72 20 77 |ses our |server w|
|00000920| 69 74 68 20 4e 42 50 0d | 76 6f 69 64 20 43 6c 65 |ith NBP.|void Cle|
|00000930| 61 6e 55 70 46 75 6e 63 | 28 20 69 6e 74 20 29 3b |anUpFunc|( int );|
|00000940| 20 20 20 20 20 20 20 20 | 20 20 20 20 20 20 20 20 | | |
|00000950| 20 20 20 20 20 20 20 20 | 20 20 20 20 20 20 20 20 | | |
|00000960| 20 20 20 20 20 20 20 20 | 20 20 20 20 20 20 20 20 | | |
|00000970| 2f 2f 20 43 61 6c 6c 65 | 64 20 6f 6e 20 61 20 53 |// Calle|d on a S|
|00000980| 69 67 6e 61 6c 0d 76 6f | 69 64 20 48 61 6e 64 6c |ignal.vo|id Handl|
|00000990| 65 43 6c 69 65 6e 74 53 | 65 73 73 69 6f 6e 28 69 |eClientS|ession(i|
|000009a0| 6e 74 20 2a 63 6c 69 65 | 6e 74 5f 66 64 29 3b 20 |nt *clie|nt_fd); |
|000009b0| 20 20 20 20 20 20 20 20 | 20 20 20 20 20 20 20 20 | | |
|000009c0| 20 20 20 20 20 20 20 20 | 20 20 20 20 20 20 2f 2f | | //|
|000009d0| 20 48 61 6e 64 6c 65 73 | 20 71 75 65 72 79 2f 72 | Handles| query/r|
|000009e0| 65 73 70 6f 6e 73 65 20 | 77 69 74 68 20 61 20 63 |esponse |with a c|
|000009f0| 6c 69 65 6e 74 0d 69 6e | 74 20 53 70 69 6e 4e 65 |lient.in|t SpinNe|
|00000a00| 77 53 65 73 73 69 6f 6e | 28 41 54 41 74 70 50 61 |wSession|(ATAtpPa|
|00000a10| 73 73 5f 74 20 2a 72 65 | 71 5f 70 61 73 73 29 3b |ss_t *re|q_pass);|
|00000a20| 20 20 20 20 20 20 20 20 | 20 20 20 20 20 20 20 20 | | |
|00000a30| 20 20 20 20 20 20 20 20 | 20 20 20 20 20 20 2f 2f | | //|
|00000a40| 20 43 72 65 61 74 65 73 | 20 61 20 6e 65 77 20 74 | Creates| a new t|
|00000a50| 68 72 65 61 64 20 66 6f | 72 20 61 20 63 6c 69 65 |hread fo|r a clie|
|00000a60| 6e 74 20 63 6f 6e 6e 65 | 63 74 69 6f 6e 0d 69 6e |nt conne|ction.in|
|00000a70| 74 20 48 61 6e 64 6c 65 | 52 65 71 75 65 73 74 28 |t Handle|Request(|
|00000a80| 63 68 61 72 20 2a 69 6e | 70 75 74 2c 20 63 68 61 |char *in|put, cha|
|00000a90| 72 20 2a 6f 75 74 70 75 | 74 2c 20 69 6e 74 20 72 |r *outpu|t, int r|
|00000aa0| 65 71 4e 75 6d 29 3b 20 | 20 20 20 20 20 20 09 09 |eqNum); | ..|
|00000ab0| 2f 2f 20 49 6e 74 65 72 | 70 72 65 74 73 20 63 6c |// Inter|prets cl|
|00000ac0| 69 65 6e 74 20 72 65 71 | 75 65 73 74 73 0d 0d 23 |ient req|uests..#|
|00000ad0| 64 65 66 69 6e 65 20 6b | 53 65 72 76 65 72 54 79 |define k|ServerTy|
|00000ae0| 70 65 20 20 20 20 20 22 | 3a 41 54 44 45 4d 4f 5f |pe "|:ATDEMO_|
|00000af0| 53 65 72 76 65 72 2e 4e | 41 54 49 56 45 40 22 0d |Server.N|ATIVE@".|
|00000b00| 65 6e 75 6d 20 7b 53 54 | 52 45 41 4d 5f 45 52 52 |enum {ST|REAM_ERR|
|00000b10| 4f 52 20 3d 20 2d 31 7d | 3b 0d 65 6e 75 6d 20 7b |OR = -1}|;.enum {|
|00000b20| 6b 52 65 71 75 65 73 74 | 65 64 4e 61 6d 65 20 3d |kRequest|edName =|
|00000b30| 20 32 2c 20 6b 52 65 71 | 75 65 73 74 65 64 43 6f | 2, kReq|uestedCo|
|00000b40| 6e 6e 65 63 74 69 6f 6e | 73 49 6e 55 73 65 2c 20 |nnection|sInUse, |
|00000b50| 6b 52 65 71 75 65 73 74 | 65 64 50 65 61 6b 43 6f |kRequest|edPeakCo|
|00000b60| 6e 6e 65 63 74 69 6f 6e | 73 2c 20 6b 52 65 71 75 |nnection|s, kRequ|
|00000b70| 65 73 74 65 64 51 75 69 | 74 7d 3b 0d 0d 0d 76 6f |estedQui|t};...vo|
|00000b80| 69 64 20 6d 61 69 6e 28 | 29 0d 7b 0d 09 41 54 53 |id main(|).{..ATS|
|00000b90| 6f 63 6b 65 74 20 20 20 | 20 20 20 20 20 73 6f 63 |ocket | soc|
|00000ba0| 6b 20 3d 20 30 3b 20 20 | 20 20 20 20 20 20 20 20 |k = 0; | |
|00000bb0| 20 20 20 20 20 20 20 20 | 20 20 20 20 20 20 20 20 | | |
|00000bc0| 20 20 20 20 20 2f 2f 20 | 54 68 65 20 73 65 72 76 | // |The serv|
|00000bd0| 65 72 27 73 20 41 70 70 | 6c 65 54 61 6c 6b 20 73 |er's App|leTalk s|
|00000be0| 6f 63 6b 65 74 2e 20 0d | 09 69 6e 74 20 20 20 20 |ocket. .|.int |
|00000bf0| 20 20 20 20 20 20 20 20 | 20 65 72 72 20 3d 20 30 | | err = 0|
|00000c00| 3b 20 20 20 0d 09 69 6e | 74 20 20 20 20 20 20 20 |; ..in|t |
|00000c10| 20 20 20 20 20 20 66 6c | 61 67 73 20 3d 20 30 3b | fl|ags = 0;|
|00000c20| 0d 09 63 68 61 72 20 20 | 20 20 20 20 20 20 20 20 |..char | |
|00000c30| 20 20 6d 79 54 79 70 65 | 5b 35 32 5d 20 3d 20 6b | myType|[52] = k|
|00000c40| 53 65 72 76 65 72 54 79 | 70 65 3b 20 20 20 20 20 |ServerTy|pe; |
|00000c50| 20 20 09 09 2f 2f 20 4e | 42 50 20 74 79 70 65 0d | ..// N|BP type.|
|00000c60| 09 63 68 61 72 20 20 20 | 20 20 20 20 20 20 20 20 |.char | |
|00000c70| 20 6d 79 53 65 72 76 65 | 72 5b 31 32 38 5d 3b 20 | myServe|r[128]; |
|00000c80| 20 20 20 20 20 20 20 20 | 20 20 20 20 20 20 20 20 | | |
|00000c90| 20 20 20 20 20 20 20 20 | 20 2f 2f 20 53 65 72 76 | | // Serv|
|00000ca0| 65 72 20 6e 61 6d 65 2e | 0d 09 69 6e 74 20 20 20 |er name.|..int |
|00000cb0| 20 20 20 20 20 20 20 20 | 20 20 63 6f 6d 70 6c 65 | | comple|
|00000cc0| 74 69 6f 6e 43 6f 64 65 | 3b 0d 09 41 54 41 74 70 |tionCode|;..ATAtp|
|00000cd0| 50 61 73 73 5f 74 20 72 | 63 76 5f 70 61 73 73 3b |Pass_t r|cv_pass;|
|00000ce0| 20 20 20 20 20 20 20 20 | 20 20 20 20 20 20 20 20 | | |
|00000cf0| 20 20 20 20 20 20 20 20 | 20 20 20 20 20 20 20 20 | | |
|00000d00| 20 20 20 2f 2f 20 55 73 | 65 64 20 66 6f 72 20 69 | // Us|ed for i|
|00000d10| 6e 63 6f 6d 69 6e 67 20 | 72 65 71 75 65 73 74 73 |ncoming |requests|
|00000d20| 0d 09 41 54 49 6e 65 74 | 5f 74 20 20 20 20 20 20 |..ATInet|_t |
|00000d30| 20 20 69 6e 66 6f 3b 20 | 20 20 20 20 20 20 20 20 | info; | |
|00000d40| 20 20 20 20 20 20 20 20 | 20 20 20 20 20 20 20 20 | | |
|00000d50| 20 20 20 20 20 20 20 20 | 20 20 2f 2f 20 54 68 65 | | // The|
|00000d60| 20 73 65 72 76 65 72 27 | 73 20 41 70 70 6c 65 54 | server'|s AppleT|
|00000d70| 61 6c 6b 20 69 6e 74 65 | 72 6e 65 74 20 61 64 64 |alk inte|rnet add|
|00000d80| 72 65 73 73 2e 0d 09 41 | 54 4e 76 65 73 74 72 5f |ress...A|TNvestr_|
|00000d90| 74 20 20 20 20 20 20 6d | 79 5a 6f 6e 65 3b 20 20 |t m|yZone; |
|00000da0| 20 20 20 20 20 20 20 20 | 20 20 20 20 20 20 20 20 | | |
|00000db0| 20 20 20 20 20 20 20 20 | 20 20 20 20 20 20 20 2f | | /|
|00000dc0| 2f 20 54 68 65 20 73 65 | 72 76 65 72 27 73 20 7a |/ The se|rver's z|
|00000dd0| 6f 6e 65 2e 0d 09 41 54 | 49 6e 65 74 5f 74 20 20 |one...AT|Inet_t |
|00000de0| 20 20 20 20 20 20 72 6f | 75 74 65 72 5f 69 6e 66 | ro|uter_inf|
|00000df0| 6f 3b 20 20 20 20 20 20 | 20 20 20 20 20 20 20 20 |o; | |
|00000e00| 20 20 20 20 20 20 20 20 | 20 20 20 20 20 20 2f 2f | | //|
|00000e10| 20 54 68 65 20 72 6f 75 | 74 65 72 27 73 20 41 70 | The rou|ter's Ap|
|00000e20| 70 6c 65 54 61 6c 6b 20 | 69 6e 74 65 72 6e 65 74 |pleTalk |internet|
|00000e30| 20 61 64 64 72 65 73 73 | 20 28 69 66 20 74 68 65 | address| (if the|
|00000e40| 72 65 20 69 66 20 61 20 | 72 6f 75 74 65 72 29 2e |re if a |router).|
|00000e50| 0d 0d 2f 2f 20 20 70 72 | 69 6e 74 66 20 77 69 6c |..// pr|intf wil|
|00000e60| 6c 20 70 72 69 6e 74 20 | 74 6f 20 74 68 65 20 73 |l print |to the s|
|00000e70| 63 72 65 65 6e 20 61 75 | 74 6f 6d 61 74 69 63 61 |creen au|tomatica|
|00000e80| 6c 6c 79 20 63 72 65 61 | 74 65 64 20 66 6f 72 20 |lly crea|ted for |
|00000e90| 74 68 65 20 4e 4c 4d 20 | 77 68 65 6e 20 69 74 20 |the NLM |when it |
|00000ea0| 69 73 20 6c 6f 61 64 65 | 64 0d 09 70 72 69 6e 74 |is loade|d..print|
|00000eb0| 66 28 20 20 22 41 70 70 | 6c 65 54 61 6c 6b 20 44 |f( "App|leTalk D|
|00000ec0| 65 6d 6f 20 53 65 72 76 | 65 72 5c 6e 22 29 3b 0d |emo Serv|er\n");.|
|00000ed0| 0d 2f 2f 20 20 52 65 67 | 69 73 74 65 72 20 68 61 |.// Reg|ister ha|
|00000ee0| 6e 64 6c 65 72 73 20 66 | 6f 72 20 74 68 65 73 65 |ndlers f|or these|
|00000ef0| 20 76 61 72 69 6f 75 73 | 20 73 69 67 6e 61 6c 73 | various| signals|
|00000f00| 20 20 20 20 20 0d 09 73 | 69 67 6e 61 6c 20 28 53 | ..s|ignal (S|
|00000f10| 49 47 49 4e 54 2c 43 6c | 65 61 6e 55 70 46 75 6e |IGINT,Cl|eanUpFun|
|00000f20| 63 29 3b 0d 09 73 69 67 | 6e 61 6c 20 28 53 49 47 |c);..sig|nal (SIG|
|00000f30| 41 42 52 54 2c 43 6c 65 | 61 6e 55 70 46 75 6e 63 |ABRT,Cle|anUpFunc|
|00000f40| 29 3b 0d 09 73 69 67 6e | 61 6c 20 28 53 49 47 54 |);..sign|al (SIGT|
|00000f50| 45 52 4d 2c 43 6c 65 61 | 6e 55 70 46 75 6e 63 29 |ERM,Clea|nUpFunc)|
|00000f60| 3b 0d 0d 2f 2f 20 20 41 | 6c 6c 6f 63 61 74 65 20 |;..// A|llocate |
|00000f70| 74 68 65 20 66 69 6c 65 | 20 64 65 73 63 72 69 70 |the file| descrip|
|00000f80| 74 6f 72 20 75 73 65 64 | 20 66 6f 72 20 69 6e 63 |tor used| for inc|
|00000f90| 6f 6d 69 6e 67 20 63 6f | 6e 6e 65 63 74 69 6f 6e |oming co|nnection|
|00000fa0| 73 0d 09 6d 79 5f 66 64 | 20 3d 20 28 69 6e 74 20 |s..my_fd| = (int |
|00000fb0| 2a 29 6d 61 6c 6c 6f 63 | 28 73 69 7a 65 6f 66 28 |*)malloc|(sizeof(|
|00000fc0| 69 6e 74 29 29 3b 0d 0d | 2f 2f 20 20 4f 70 65 6e |int));..|// Open|
|00000fd0| 20 61 20 73 6f 63 6b 65 | 74 20 64 79 6e 61 6d 69 | a socke|t dynami|
|00000fe0| 63 61 6c 6c 79 0d 09 69 | 66 28 20 65 72 72 20 3d |cally..i|f( err =|
|00000ff0| 20 41 54 41 74 70 4f 70 | 65 6e 28 6d 79 5f 66 64 | ATAtpOp|en(my_fd|
|00001000| 2c 26 73 6f 63 6b 29 20 | 29 0d 09 7b 0d 09 09 20 |,&sock) |)..{... |
|00001010| 70 72 69 6e 74 66 28 22 | 41 54 41 74 70 4f 70 65 |printf("|ATAtpOpe|
|00001020| 6e 20 66 61 69 6c 65 64 | 3a 20 65 72 72 20 3d 20 |n failed|: err = |
|00001030| 25 78 5c 6e 22 2c 65 72 | 72 29 3b 0d 09 09 20 65 |%x\n",er|r);... e|
|00001040| 78 69 74 28 5f 5f 4c 49 | 4e 45 5f 5f 29 3b 20 20 |xit(__LI|NE__); |
|00001050| 20 20 20 20 20 20 20 20 | 20 20 20 20 20 20 2f 2f | | //|
|00001060| 20 41 62 6f 72 74 0d 09 | 7d 0d 09 0d 0d 2f 2f 20 | Abort..|}....// |
|00001070| 20 47 65 74 20 6f 75 72 | 20 61 64 64 72 65 73 73 | Get our| address|
|00001080| 20 66 72 6f 6d 20 74 68 | 65 20 72 6f 75 74 65 72 | from th|e router|
|00001090| 0d 09 69 66 28 65 72 72 | 20 3d 20 41 54 44 64 70 |..if(err| = ATDdp|
|000010a0| 4e 65 74 69 6e 66 6f 28 | 2a 6d 79 5f 66 64 2c 26 |Netinfo(|*my_fd,&|
|000010b0| 69 6e 66 6f 2c 26 72 6f | 75 74 65 72 5f 69 6e 66 |info,&ro|uter_inf|
|000010c0| 6f 2c 26 66 6c 61 67 73 | 29 20 29 0d 09 7b 0d 09 |o,&flags|) )..{..|
|000010d0| 09 70 72 69 6e 74 66 28 | 22 41 54 44 64 70 4e 65 |.printf(|"ATDdpNe|
|000010e0| 74 69 6e 66 6f 20 66 61 | 69 6c 65 64 3a 20 65 72 |tinfo fa|iled: er|
|000010f0| 72 20 3d 20 25 78 5c 6e | 22 2c 20 65 72 72 29 3b |r = %x\n|", err);|
|00001100| 0d 09 09 41 54 41 74 70 | 43 6c 6f 73 65 28 2a 6d |...ATAtp|Close(*m|
|00001110| 79 5f 66 64 29 3b 0d 09 | 09 66 72 65 65 28 6d 79 |y_fd);..|.free(my|
|00001120| 5f 66 64 29 3b 0d 09 09 | 65 78 69 74 28 5f 5f 4c |_fd);...|exit(__L|
|00001130| 49 4e 45 5f 5f 29 3b 0d | 09 7d 0d 09 0d 2f 2f 20 |INE__);.|.}...// |
|00001140| 41 64 64 20 22 2a 22 20 | 61 73 20 74 68 65 20 7a |Add "*" |as the z|
|00001150| 6f 6e 65 20 6e 61 6d 65 | 2e 0d 20 20 20 73 74 72 |one name|.. str|
|00001160| 6e 63 61 74 28 6d 79 54 | 79 70 65 2c 22 2a 22 2c |ncat(myT|ype,"*",|
|00001170| 31 29 3b 0d 0d 0d 2f 2f | 20 20 52 65 67 69 73 74 |1);...//| Regist|
|00001180| 65 72 20 74 68 65 20 73 | 65 72 76 65 72 27 73 20 |er the s|erver's |
|00001190| 6e 61 6d 65 20 61 6e 64 | 20 61 64 76 65 72 74 69 |name and| adverti|
|000011a0| 73 65 20 69 74 20 6f 6e | 20 74 68 65 20 69 6e 74 |se it on| the int|
|000011b0| 65 72 6e 65 74 2e 0d 09 | 47 65 74 46 69 6c 65 53 |ernet...|GetFileS|
|000011c0| 65 72 76 65 72 4e 61 6d | 65 28 30 2c 20 6d 79 53 |erverNam|e(0, myS|
|000011d0| 65 72 76 65 72 29 3b 0d | 09 73 74 72 63 61 74 28 |erver);.|.strcat(|
|000011e0| 20 6d 79 53 65 72 76 65 | 72 2c 20 6d 79 54 79 70 | myServe|r, myTyp|
|000011f0| 65 20 29 3b 20 20 20 20 | 20 20 20 20 20 20 20 20 |e ); | |
|00001200| 20 2f 2f 20 43 6f 6e 63 | 61 74 65 6e 61 74 65 20 | // Conc|atenate |
|00001210| 6f 75 72 20 4e 42 50 20 | 74 79 70 65 20 6f 6e 74 |our NBP |type ont|
|00001220| 6f 20 74 68 65 20 6e 61 | 6d 65 0d 09 0d 09 69 66 |o the na|me....if|
|00001230| 20 28 61 64 76 65 72 74 | 69 73 65 28 20 2a 6d 79 | (advert|ise( *my|
|00001240| 5f 66 64 2c 20 6d 79 53 | 65 72 76 65 72 20 29 20 |_fd, myS|erver ) |
|00001250| 3d 3d 20 53 54 52 45 41 | 4d 5f 45 52 52 4f 52 29 |== STREA|M_ERROR)|
|00001260| 0d 09 7b 0d 09 09 70 72 | 69 6e 74 66 28 22 41 64 |..{...pr|intf("Ad|
|00001270| 76 65 72 74 69 73 65 20 | 66 75 6e 63 74 69 6f 6e |vertise |function|
|00001280| 20 72 65 74 75 72 6e 65 | 64 20 53 74 72 65 61 6d | returne|d Stream|
|00001290| 20 45 72 72 6f 72 22 29 | 3b 0d 09 09 41 54 41 74 | Error")|;...ATAt|
|000012a0| 70 43 6c 6f 73 65 28 2a | 6d 79 5f 66 64 29 3b 0d |pClose(*|my_fd);.|
|000012b0| 09 09 66 72 65 65 28 6d | 79 5f 66 64 29 3b 0d 09 |..free(m|y_fd);..|
|000012c0| 09 65 78 69 74 28 5f 5f | 4c 49 4e 45 5f 5f 29 3b |.exit(__|LINE__);|
|000012d0| 0d 09 7d 0d 0d 2f 2f 20 | 20 50 72 69 6e 74 20 6f |..}..// | Print o|
|000012e0| 75 72 20 41 70 70 6c 65 | 54 61 6c 6b 20 61 64 64 |ur Apple|Talk add|
|000012f0| 72 65 73 73 20 74 6f 20 | 74 68 65 20 73 63 72 65 |ress to |the scre|
|00001300| 65 6e 0d 09 70 72 69 6e | 74 66 28 22 25 73 27 73 |en..prin|tf("%s's|
|00001310| 20 41 70 70 6c 65 54 61 | 6c 6b 20 61 64 64 72 65 | AppleTa|lk addre|
|00001320| 73 73 20 69 73 3a 20 28 | 25 64 2e 25 64 2e 25 64 |ss is: (|%d.%d.%d|
|00001330| 29 5c 6e 22 2c 20 6d 79 | 53 65 72 76 65 72 2c 69 |)\n", my|Server,i|
|00001340| 6e 66 6f 2e 6e 65 74 2c | 69 6e 66 6f 2e 6e 6f 64 |nfo.net,|info.nod|
|00001350| 65 2c 69 6e 66 6f 2e 73 | 6f 63 6b 65 74 29 3b 0d |e,info.s|ocket);.|
|00001360| 0d 2f 2f 20 20 47 65 74 | 20 74 68 65 20 41 70 70 |.// Get| the App|
|00001370| 6c 65 54 61 6c 6b 20 7a | 6f 6e 65 20 74 68 65 20 |leTalk z|one the |
|00001380| 73 65 72 76 65 72 20 6c | 69 76 65 73 20 69 6e 0d |server l|ives in.|
|00001390| 09 69 66 28 65 72 72 20 | 3d 20 41 54 5a 69 70 47 |.if(err |= ATZipG|
|000013a0| 65 74 4d 79 5a 6f 6e 65 | 28 26 6d 79 5a 6f 6e 65 |etMyZone|(&myZone|
|000013b0| 29 20 29 0d 09 7b 0d 09 | 09 70 72 69 6e 74 66 28 |) )..{..|.printf(|
|000013c0| 22 41 54 5a 69 70 47 65 | 74 4d 79 5a 6f 6e 65 20 |"ATZipGe|tMyZone |
|000013d0| 66 61 69 6c 65 64 3a 20 | 65 72 72 20 3d 20 25 78 |failed: |err = %x|
|000013e0| 5c 6e 22 2c 65 72 72 29 | 3b 0d 09 09 41 54 41 74 |\n",err)|;...ATAt|
|000013f0| 70 43 6c 6f 73 65 28 2a | 6d 79 5f 66 64 29 3b 0d |pClose(*|my_fd);.|
|00001400| 09 09 66 72 65 65 28 6d | 79 5f 66 64 29 3b 0d 09 |..free(m|y_fd);..|
|00001410| 09 65 78 69 74 28 5f 5f | 4c 49 4e 45 5f 5f 29 3b |.exit(__|LINE__);|
|00001420| 0d 09 7d 0d 0d 0d 09 6d | 79 5a 6f 6e 65 2e 73 74 |..}....m|yZone.st|
|00001430| 72 5b 6d 79 5a 6f 6e 65 | 2e 6c 65 6e 5d 20 3d 20 |r[myZone|.len] = |
|00001440| 30 3b 20 2f 2f 20 4e 55 | 4c 4c 20 74 65 72 6d 69 |0; // NU|LL termi|
|00001450| 6e 61 74 65 20 74 68 65 | 20 73 74 72 69 6e 67 2e |nate the| string.|
|00001460| 20 28 41 70 70 6c 65 54 | 61 6c 6b 20 73 69 6c 6c | (AppleT|alk sill|
|00001470| 69 6e 65 73 73 29 0d 09 | 0d 09 70 72 69 6e 74 66 |iness)..|..printf|
|00001480| 28 22 54 68 65 20 73 65 | 72 76 65 72 20 69 73 20 |("The se|rver is |
|00001490| 72 65 67 69 73 74 65 72 | 65 64 20 69 6e 20 74 68 |register|ed in th|
|000014a0| 65 20 7a 6f 6e 65 20 6e | 61 6d 65 3a 20 25 73 5c |e zone n|ame: %s\|
|000014b0| 6e 22 2c 6d 79 5a 6f 6e | 65 2e 73 74 72 29 3b 20 |n",myZon|e.str); |
|000014c0| 20 20 0d 09 70 72 69 6e | 74 66 28 22 57 61 69 74 | ..prin|tf("Wait|
|000014d0| 69 6e 67 20 66 6f 72 20 | 72 65 71 75 65 73 74 2e |ing for |request.|
|000014e0| 2e 2e 5c 6e 5c 6e 22 29 | 3b 0d 0d 2f 2f 20 20 41 |..\n\n")|;..// A|
|000014f0| 6c 6c 63 61 74 65 20 6d | 65 6d 6f 72 79 20 66 6f |llcate m|emory fo|
|00001500| 72 20 74 68 65 20 72 65 | 63 65 69 76 65 20 62 75 |r the re|ceive bu|
|00001510| 66 66 65 72 2e 0d 2f 2f | 20 20 49 66 20 74 68 69 |ffer..//| If thi|
|00001520| 73 20 69 73 20 6e 6f 74 | 20 64 6f 6e 65 2c 20 74 |s is not| done, t|
|00001530| 68 65 20 73 65 72 76 65 | 72 20 77 69 6c 6c 20 63 |he serve|r will c|
|00001540| 72 61 73 68 20 77 68 65 | 6e 20 79 6f 75 20 72 65 |rash whe|n you re|
|00001550| 63 65 69 76 65 20 61 20 | 63 6f 6e 6e 65 63 74 69 |ceive a |connecti|
|00001560| 6f 6e 0d 09 72 63 76 5f | 70 61 73 73 2e 64 61 74 |on..rcv_|pass.dat|
|00001570| 61 20 3d 20 28 76 6f 69 | 64 20 2a 29 6d 61 6c 6c |a = (voi|d *)mall|
|00001580| 6f 63 28 41 54 50 5f 44 | 41 54 41 5f 53 49 5a 45 |oc(ATP_D|ATA_SIZE|
|00001590| 29 3b 0d 09 72 63 76 5f | 70 61 73 73 2e 64 61 74 |);..rcv_|pass.dat|
|000015a0| 61 5f 6c 65 6e 20 3d 20 | 41 54 50 5f 44 41 54 41 |a_len = |ATP_DATA|
|000015b0| 5f 53 49 5a 45 3b 20 20 | 20 20 20 20 0d 0d 2f 2f |_SIZE; | ..//|
|000015c0| 20 20 42 65 67 69 6e 20 | 6f 75 72 20 6c 6f 6f 70 | Begin |our loop|
|000015d0| 20 77 61 69 74 69 6e 67 | 20 66 6f 72 20 69 6e 69 | waiting| for ini|
|000015e0| 74 69 61 6c 20 63 6f 6e | 6e 65 63 74 69 6f 6e 73 |tial con|nections|
|000015f0| 0d 09 64 6f 7b 0d 09 0d | 2f 2a 20 20 20 20 20 20 |..do{...|/* |
|00001600| 54 68 69 73 20 69 73 20 | 74 68 65 20 6d 61 69 6e |This is |the main|
|00001610| 20 70 6f 69 6e 74 20 77 | 68 65 72 65 20 6f 75 72 | point w|here our|
|00001620| 20 70 72 6f 67 72 61 6d | 20 77 69 6c 6c 20 73 70 | program| will sp|
|00001630| 65 6e 64 20 6d 6f 73 74 | 20 6f 66 20 69 74 73 20 |end most| of its |
|00001640| 74 69 6d 65 2e 0d 09 09 | 54 68 65 20 6d 61 69 6e |time....|The main|
|00001650| 20 74 68 72 65 61 64 20 | 66 6f 72 20 74 68 69 73 | thread |for this|
|00001660| 20 4e 4c 4d 20 77 69 6c | 6c 20 62 6c 6f 63 6b 20 | NLM wil|l block |
|00001670| 68 65 72 65 20 75 6e 74 | 69 6c 20 69 74 20 72 65 |here unt|il it re|
|00001680| 63 65 69 76 65 73 20 61 | 6e 0d 09 09 41 54 50 20 |ceives a|n...ATP |
|00001690| 72 65 71 75 65 73 74 20 | 64 69 72 65 63 74 65 64 |request |directed|
|000016a0| 20 61 74 20 6f 75 72 20 | 73 65 72 76 65 72 0d 2a | at our |server.*|
|000016b0| 2f 0d 09 09 69 66 28 65 | 72 72 20 3d 20 41 54 41 |/...if(e|rr = ATA|
|000016c0| 74 70 47 65 74 28 2a 6d | 79 5f 66 64 2c 26 72 63 |tpGet(*m|y_fd,&rc|
|000016d0| 76 5f 70 61 73 73 29 20 | 29 0d 09 09 7b 20 20 20 |v_pass) |)...{ |
|000016e0| 20 20 20 20 20 20 20 20 | 20 20 20 20 20 0d 09 09 | | ...|
|000016f0| 09 70 72 69 6e 74 66 28 | 22 41 54 41 74 70 47 65 |.printf(|"ATAtpGe|
|00001700| 74 20 66 61 69 6c 65 64 | 3a 20 65 72 72 20 3d 20 |t failed|: err = |
|00001710| 25 78 5c 6e 22 2c 65 72 | 72 29 3b 0d 09 09 09 65 |%x\n",er|r);....e|
|00001720| 78 69 74 69 6e 67 4e 4c | 4d 20 3d 20 54 52 55 45 |xitingNL|M = TRUE|
|00001730| 3b 0d 09 09 09 62 72 65 | 61 6b 3b 0d 09 09 7d 0d |;....bre|ak;...}.|
|00001740| 0d 2f 2f 20 20 20 20 20 | 20 43 68 65 63 6b 20 74 |.// | Check t|
|00001750| 68 65 20 72 65 74 75 72 | 6e 20 65 72 72 6f 72 20 |he retur|n error |
|00001760| 66 72 6f 6d 20 74 68 65 | 20 70 61 63 6b 65 74 2e |from the| packet.|
|00001770| 20 20 54 68 69 73 20 69 | 73 20 61 20 70 72 6f 74 | This i|s a prot|
|00001780| 6f 63 6f 6c 20 65 72 72 | 6f 72 0d 09 09 69 66 28 |ocol err|or...if(|
|00001790| 72 63 76 5f 70 61 73 73 | 2e 72 65 74 29 0d 09 09 |rcv_pass|.ret)...|
|000017a0| 09 70 72 69 6e 74 66 28 | 22 72 63 76 5f 70 61 73 |.printf(|"rcv_pas|
|000017b0| 73 2e 72 65 74 20 72 65 | 74 75 72 6e 65 64 20 65 |s.ret re|turned e|
|000017c0| 72 72 6f 72 20 28 25 78 | 29 5c 6e 22 2c 72 63 76 |rror (%x|)\n",rcv|
|000017d0| 5f 70 61 73 73 2e 72 65 | 74 29 3b 0d 0d 2f 2f 20 |_pass.re|t);..// |
|000017e0| 20 20 20 20 20 50 72 69 | 6e 74 20 74 68 65 20 41 | Pri|nt the A|
|000017f0| 70 70 6c 65 54 61 6c 6b | 20 61 64 64 72 65 73 73 |ppleTalk| address|
|00001800| 20 6f 66 20 74 68 65 20 | 73 65 6e 64 65 72 0d 09 | of the |sender..|
|00001810| 09 70 72 69 6e 74 66 28 | 22 52 65 63 65 69 76 65 |.printf(|"Receive|
|00001820| 64 20 6d 65 73 73 61 67 | 65 20 66 72 6f 6d 20 61 |d messag|e from a|
|00001830| 20 63 6c 69 65 6e 74 20 | 61 74 20 25 75 2e 25 75 | client |at %u.%u|
|00001840| 2e 25 75 2e 5c 6e 22 2c | 0d 09 09 09 09 72 63 76 |.%u.\n",|.....rcv|
|00001850| 5f 70 61 73 73 2e 61 74 | 5f 61 64 64 72 2e 6e 65 |_pass.at|_addr.ne|
|00001860| 74 2c 0d 09 09 09 09 72 | 63 76 5f 70 61 73 73 2e |t,.....r|cv_pass.|
|00001870| 61 74 5f 61 64 64 72 2e | 6e 6f 64 65 2c 0d 09 09 |at_addr.|node,...|
|00001880| 09 09 72 63 76 5f 70 61 | 73 73 2e 61 74 5f 61 64 |..rcv_pa|ss.at_ad|
|00001890| 64 72 2e 73 6f 63 6b 65 | 74 29 3b 0d 0d 2f 2f 20 |dr.socke|t);..// |
|000018a0| 20 20 20 20 20 50 72 69 | 6e 74 20 74 68 65 20 6d | Pri|nt the m|
|000018b0| 65 73 73 61 67 65 20 66 | 72 6f 6d 20 74 68 65 20 |essage f|rom the |
|000018c0| 63 6c 69 65 6e 74 0d 09 | 09 70 72 69 6e 74 66 28 |client..|.printf(|
|000018d0| 22 52 65 63 65 69 76 65 | 64 3a 25 73 5c 6e 22 2c |"Receive|d:%s\n",|
|000018e0| 72 63 76 5f 70 61 73 73 | 2e 64 61 74 61 29 3b 0d |rcv_pass|.data);.|
|000018f0| 0d 2f 2f 20 20 20 20 20 | 20 53 70 69 6e 20 6f 66 |.// | Spin of|
|00001900| 66 20 61 20 6e 65 77 20 | 74 68 72 65 61 64 20 74 |f a new |thread t|
|00001910| 6f 20 68 61 6e 64 6c 65 | 20 74 68 69 73 20 73 65 |o handle| this se|
|00001920| 73 73 69 6f 6e 20 20 20 | 20 20 20 20 20 20 20 20 |ssion | |
|00001930| 20 0d 09 09 65 72 72 20 | 3d 20 53 70 69 6e 4e 65 | ...err |= SpinNe|
|00001940| 77 53 65 73 73 69 6f 6e | 28 26 72 63 76 5f 70 61 |wSession|(&rcv_pa|
|00001950| 73 73 29 3b 0d 09 09 69 | 66 20 28 65 72 72 20 3d |ss);...i|f (err =|
|00001960| 3d 20 45 46 41 49 4c 55 | 52 45 29 0d 09 09 7b 0d |= EFAILU|RE)...{.|
|00001970| 09 09 09 70 72 69 6e 74 | 66 28 22 53 70 69 6e 4e |...print|f("SpinN|
|00001980| 65 77 53 65 73 73 69 6f | 6e 20 66 61 69 6c 65 64 |ewSessio|n failed|
|00001990| 3a 20 65 72 72 20 3d 20 | 25 78 5c 6e 22 2c 65 72 |: err = |%x\n",er|
|000019a0| 72 6e 6f 29 3b 0d 09 09 | 09 65 78 69 74 69 6e 67 |rno);...|.exiting|
|000019b0| 4e 4c 4d 20 3d 20 54 52 | 55 45 3b 0d 09 09 7d 0d |NLM = TR|UE;...}.|
|000019c0| 09 20 20 0d 09 7d 77 68 | 69 6c 65 20 28 21 65 78 |. ..}wh|ile (!ex|
|000019d0| 69 74 69 6e 67 4e 4c 4d | 29 3b 0d 0d 09 41 54 41 |itingNLM|);...ATA|
|000019e0| 74 70 43 6c 6f 73 65 28 | 2a 6d 79 5f 66 64 29 3b |tpClose(|*my_fd);|
|000019f0| 0d 09 66 72 65 65 28 6d | 79 5f 66 64 29 3b 0d 09 |..free(m|y_fd);..|
|00001a00| 66 72 65 65 28 72 63 76 | 5f 70 61 73 73 2e 64 61 |free(rcv|_pass.da|
|00001a10| 74 61 29 3b 0d 7d 0d 20 | 0d 20 0d 2f 2a 20 53 70 |ta);.}. |. ./* Sp|
|00001a20| 69 6e 4e 65 77 53 65 73 | 73 69 6f 6e 20 69 73 20 |inNewSes|sion is |
|00001a30| 63 61 6c 6c 65 64 20 62 | 79 20 6d 61 69 6e 28 29 |called b|y main()|
|00001a40| 2e 20 20 49 74 20 6f 70 | 65 6e 73 20 61 20 6e 65 |. It op|ens a ne|
|00001a50| 77 20 73 6f 63 6b 65 74 | 2c 0d 09 63 72 65 61 74 |w socket|,..creat|
|00001a60| 65 73 20 61 20 6e 65 77 | 20 74 68 72 65 61 64 2c |es a new| thread,|
|00001a70| 20 61 6e 64 20 74 65 6c | 6c 73 20 74 68 65 20 63 | and tel|ls the c|
|00001a80| 6c 69 65 6e 74 20 77 68 | 65 72 65 20 28 74 6f 20 |lient wh|ere (to |
|00001a90| 77 68 69 63 68 20 73 6f | 63 6b 65 74 29 0d 09 69 |which so|cket)..i|
|00001aa0| 74 20 73 68 6f 75 6c 64 | 20 73 65 6e 64 20 61 6c |t should| send al|
|00001ab0| 6c 20 6f 66 20 69 74 73 | 20 72 65 71 75 65 73 74 |l of its| request|
|00001ac0| 73 2e 20 20 54 68 65 20 | 6e 65 77 20 74 68 72 65 |s. The |new thre|
|00001ad0| 61 64 20 74 68 65 6e 0d | 09 68 61 6e 64 6c 65 73 |ad then.|.handles|
|00001ae0| 20 74 68 65 20 72 65 71 | 75 65 73 74 73 2c 20 61 | the req|uests, a|
|00001af0| 6c 6c 6f 77 69 6e 67 20 | 74 68 65 20 6d 61 69 6e |llowing |the main|
|00001b00| 20 6c 6f 6f 70 20 74 6f | 20 61 77 61 69 74 20 6e | loop to| await n|
|00001b10| 65 77 20 6f 6e 65 73 2e | 0d 2a 2f 0d 69 6e 74 20 |ew ones.|.*/.int |
|00001b20| 53 70 69 6e 4e 65 77 53 | 65 73 73 69 6f 6e 28 41 |SpinNewS|ession(A|
|00001b30| 54 41 74 70 50 61 73 73 | 5f 74 20 2a 72 63 76 5f |TAtpPass|_t *rcv_|
|00001b40| 70 61 73 73 29 0d 7b 0d | 09 41 54 53 6f 63 6b 65 |pass).{.|.ATSocke|
|00001b50| 74 20 20 20 20 20 20 20 | 20 73 6f 63 6b 20 3d 20 |t | sock = |
|00001b60| 30 3b 20 20 20 20 20 20 | 20 20 20 20 20 20 20 20 |0; | |
|00001b70| 20 20 20 20 20 20 20 20 | 20 2f 2f 20 54 68 65 20 | | // The |
|00001b80| 6e 65 77 20 73 6f 63 6b | 65 74 0d 09 69 6e 74 20 |new sock|et..int |
|00001b90| 20 20 20 20 20 20 20 20 | 20 20 20 20 65 72 72 3b | | err;|
|00001ba0| 0d 09 69 6e 74 20 20 20 | 20 20 20 20 20 20 20 20 |..int | |
|00001bb0| 20 20 2a 6e 65 77 5f 66 | 64 3b 20 20 20 20 20 20 | *new_f|d; |
|00001bc0| 20 20 20 20 20 20 20 20 | 20 20 20 20 20 20 20 20 | | |
|00001bd0| 20 20 2f 2f 20 54 68 65 | 20 6e 65 77 20 66 69 6c | // The| new fil|
|00001be0| 65 20 64 65 73 63 72 69 | 70 74 6f 72 20 66 6f 72 |e descri|ptor for|
|00001bf0| 20 74 68 65 20 73 6f 63 | 6b 65 74 0d 09 69 6e 74 | the soc|ket..int|
|00001c00| 20 20 20 20 20 20 20 20 | 20 20 20 20 20 20 20 20 | | |
|00001c10| 20 20 20 20 20 74 68 72 | 65 61 64 49 44 3b 20 20 | thr|eadID; |
|00001c20| 20 20 20 20 20 20 20 20 | 20 20 20 20 20 20 20 20 | | |
|00001c30| 20 20 20 20 20 2f 2f 20 | 54 68 72 65 61 64 20 49 | // |Thread I|
|00001c40| 44 20 6f 66 20 74 68 65 | 20 6e 65 77 20 74 68 72 |D of the| new thr|
|00001c50| 65 61 64 0d 09 41 54 41 | 74 70 50 61 73 73 5f 74 |ead..ATA|tpPass_t|
|00001c60| 20 72 65 73 70 5f 70 61 | 73 73 3b 20 20 20 20 20 | resp_pa|ss; |
|00001c70| 20 20 20 20 20 20 20 20 | 20 20 20 20 20 2f 2f 20 | | // |
|00001c80| 46 6f 72 20 73 65 6e 64 | 69 6e 67 20 6f 75 72 20 |For send|ing our |
|00001c90| 66 69 72 73 74 20 72 65 | 73 70 6f 6e 73 65 0d 09 |first re|sponse..|
|00001ca0| 63 68 61 72 20 20 20 20 | 20 20 20 20 20 20 20 20 |char | |
|00001cb0| 72 65 73 70 42 75 66 66 | 65 72 5b 32 35 36 5d 3b |respBuff|er[256];|
|00001cc0| 20 20 20 20 20 20 20 20 | 0d 09 69 6e 74 20 20 20 | |..int |
|00001cd0| 20 20 20 20 20 20 20 20 | 20 20 63 6f 6d 70 6c 65 | | comple|
|00001ce0| 74 69 6f 6e 43 6f 64 65 | 3b 0d 09 0d 09 70 72 69 |tionCode|;....pri|
|00001cf0| 6e 74 66 28 22 49 6e 20 | 53 70 69 6e 4e 65 77 53 |ntf("In |SpinNewS|
|00001d00| 65 73 73 69 6f 6e 2e 2e | 2e 5c 6e 22 29 3b 0d 0d |ession..|.\n");..|
|00001d10| 2f 2f 20 20 41 6c 6c 6f | 63 61 74 65 20 72 6f 6f |// Allo|cate roo|
|00001d20| 6d 20 66 6f 72 20 61 20 | 6e 65 77 20 66 69 6c 65 |m for a |new file|
|00001d30| 20 64 65 73 63 72 69 70 | 74 6f 72 0d 09 6e 65 77 | descrip|tor..new|
|00001d40| 5f 66 64 20 3d 20 28 69 | 6e 74 20 2a 29 6d 61 6c |_fd = (i|nt *)mal|
|00001d50| 6c 6f 63 28 73 69 7a 65 | 6f 66 28 69 6e 74 29 29 |loc(size|of(int))|
|00001d60| 3b 0d 0d 2f 2f 20 20 4f | 70 65 6e 20 61 20 6e 65 |;..// O|pen a ne|
|00001d70| 77 20 73 6f 63 6b 65 74 | 20 66 6f 72 20 74 68 69 |w socket| for thi|
|00001d80| 73 20 63 6c 69 65 6e 74 | 20 6f 6e 6c 79 20 20 0d |s client| only .|
|00001d90| 09 69 66 28 20 65 72 72 | 20 3d 20 41 54 41 74 70 |.if( err| = ATAtp|
|00001da0| 4f 70 65 6e 28 6e 65 77 | 5f 66 64 2c 26 73 6f 63 |Open(new|_fd,&soc|
|00001db0| 6b 29 20 29 0d 09 7b 0d | 09 09 20 70 72 69 6e 74 |k) )..{.|.. print|
|00001dc0| 66 28 22 41 54 41 74 70 | 4f 70 65 6e 20 66 61 69 |f("ATAtp|Open fai|
|00001dd0| 6c 65 64 3a 20 65 72 72 | 20 3d 20 25 78 5c 6e 22 |led: err| = %x\n"|
|00001de0| 2c 65 72 72 29 3b 0d 09 | 09 20 66 72 65 65 28 6e |,err);..|. free(n|
|00001df0| 65 77 5f 66 64 29 3b 0d | 09 09 20 72 65 74 75 72 |ew_fd);.|.. retur|
|00001e00| 6e 20 45 46 41 49 4c 55 | 52 45 3b 0d 09 7d 0d 09 |n EFAILU|RE;..}..|
|00001e10| 70 72 69 6e 74 66 28 22 | 4f 70 65 6e 65 64 20 73 |printf("|Opened s|
|00001e20| 6f 63 6b 65 74 3a 20 25 | 64 2c 20 66 64 20 3a 25 |ocket: %|d, fd :%|
|00001e30| 64 5c 6e 22 2c 20 73 6f | 63 6b 2c 20 2a 6e 65 77 |d\n", so|ck, *new|
|00001e40| 5f 66 64 29 3b 0d 09 0d | 2f 2f 20 20 53 65 6e 64 |_fd);...|// Send|
|00001e50| 20 62 61 63 6b 20 61 20 | 72 65 73 70 6f 6e 73 65 | back a |response|
|00001e60| 2c 20 69 6e 63 6c 75 64 | 69 6e 67 20 77 68 69 63 |, includ|ing whic|
|00001e70| 68 20 73 6f 63 6b 65 74 | 20 74 68 65 20 63 6c 69 |h socket| the cli|
|00001e80| 65 6e 74 0d 2f 2f 20 20 | 73 68 6f 75 6c 64 20 73 |ent.// |should s|
|00001e90| 65 6e 64 20 66 75 72 74 | 68 65 72 20 72 65 71 75 |end furt|her requ|
|00001ea0| 65 73 74 73 20 74 6f 0d | 09 74 68 72 65 61 64 49 |ests to.|.threadI|
|00001eb0| 44 20 3d 20 47 65 74 54 | 68 72 65 61 64 49 44 28 |D = GetT|hreadID(|
|00001ec0| 29 3b 0d 09 73 70 72 69 | 6e 74 66 28 72 65 73 70 |);..spri|ntf(resp|
|00001ed0| 42 75 66 66 65 72 2c 20 | 22 59 6f 75 20 61 72 65 |Buffer, |"You are|
|00001ee0| 20 62 65 69 6e 67 20 68 | 61 6e 64 6c 65 64 20 62 | being h|andled b|
|00001ef0| 79 20 73 6f 63 6b 65 74 | 3a 25 64 22 2c 20 73 6f |y socket|:%d", so|
|00001f00| 63 6b 29 3b 0d 0d 09 72 | 65 73 70 5f 70 61 73 73 |ck);...r|esp_pass|
|00001f10| 2e 61 74 5f 61 64 64 72 | 20 3d 20 72 63 76 5f 70 |.at_addr| = rcv_p|
|00001f20| 61 73 73 2d 3e 61 74 5f | 61 64 64 72 3b 20 20 20 |ass->at_|addr; |
|00001f30| 20 20 20 20 20 20 20 2f | 2f 20 54 68 65 20 64 65 | /|/ The de|
|00001f40| 73 74 69 6e 61 74 69 6f | 6e 20 69 73 20 74 68 65 |stinatio|n is the|
|00001f50| 20 72 63 76 20 73 6f 75 | 72 63 65 0d 0d 2f 2f 20 | rcv sou|rce..// |
|00001f60| 20 4a 75 73 74 20 74 6f | 20 6b 65 65 70 20 74 68 | Just to| keep th|
|00001f70| 65 20 63 6f 6e 73 6f 6c | 65 20 69 6e 66 6f 72 6d |e consol|e inform|
|00001f80| 65 64 0d 09 70 72 69 6e | 74 66 28 22 53 65 6e 64 |ed..prin|tf("Send|
|00001f90| 69 6e 67 20 72 65 73 70 | 6f 6e 73 65 20 74 6f 20 |ing resp|onse to |
|00001fa0| 63 6c 69 65 6e 74 20 61 | 74 20 25 75 2e 25 75 2e |client a|t %u.%u.|
|00001fb0| 25 75 2e 5c 6e 22 2c 0d | 09 72 65 73 70 5f 70 61 |%u.\n",.|.resp_pa|
|00001fc0| 73 73 2e 61 74 5f 61 64 | 64 72 2e 6e 65 74 2c 0d |ss.at_ad|dr.net,.|
|00001fd0| 09 72 65 73 70 5f 70 61 | 73 73 2e 61 74 5f 61 64 |.resp_pa|ss.at_ad|
|00001fe0| 64 72 2e 6e 6f 64 65 2c | 0d 09 72 65 73 70 5f 70 |dr.node,|..resp_p|
|00001ff0| 61 73 73 2e 61 74 5f 61 | 64 64 72 2e 73 6f 63 6b |ass.at_a|ddr.sock|
|00002000| 65 74 29 3b 0d 0d 0d 09 | 72 65 73 70 5f 70 61 73 |et);....|resp_pas|
|00002010| 73 2e 62 69 74 6d 61 70 | 20 3d 20 31 3b 20 20 20 |s.bitmap| = 1; |
|00002020| 20 20 20 20 20 20 20 20 | 20 20 20 20 20 20 20 20 | | |
|00002030| 20 20 20 20 20 20 20 20 | 2f 2f 20 57 65 27 72 65 | |// We're|
|00002040| 20 73 65 6e 64 69 6e 67 | 20 31 20 70 61 63 6b 65 | sending| 1 packe|
|00002050| 74 0d 09 72 65 73 70 5f | 70 61 73 73 2e 70 61 63 |t..resp_|pass.pac|
|00002060| 6b 65 74 69 7a 65 20 3d | 20 30 3b 20 20 20 20 20 |ketize =| 0; |
|00002070| 20 20 20 20 20 20 20 20 | 20 20 20 20 20 20 20 20 | | |
|00002080| 20 20 20 2f 2f 20 4e 6f | 20 6e 65 65 64 20 74 6f | // No| need to|
|00002090| 20 70 61 63 6b 65 74 69 | 7a 65 0d 09 72 65 73 70 | packeti|ze..resp|
|000020a0| 5f 70 61 73 73 2e 72 65 | 74 72 79 2e 69 6e 74 65 |_pass.re|try.inte|
|000020b0| 72 76 61 6c 20 3d 20 32 | 30 30 30 3b 20 20 20 20 |rval = 2|000; |
|000020c0| 20 20 20 20 20 20 20 20 | 20 20 20 20 2f 2f 20 32 | | // 2|
|000020d0| 30 30 30 20 74 69 63 6b | 73 20 74 6f 20 72 65 74 |000 tick|s to ret|
|000020e0| 72 79 0d 09 72 65 73 70 | 5f 70 61 73 73 2e 72 65 |ry..resp|_pass.re|
|000020f0| 74 72 79 2e 72 65 74 72 | 69 65 73 20 3d 20 31 30 |try.retr|ies = 10|
|00002100| 3b 0d 09 72 65 73 70 5f | 70 61 73 73 2e 72 65 74 |;..resp_|pass.ret|
|00002110| 72 79 2e 62 61 63 6b 6f | 66 66 20 3d 20 32 3b 0d |ry.backo|ff = 2;.|
|00002120| 09 72 65 73 70 5f 70 61 | 73 73 2e 72 65 74 20 3d |.resp_pa|ss.ret =|
|00002130| 30 3b 0d 09 72 65 73 70 | 5f 70 61 73 73 2e 64 61 |0;..resp|_pass.da|
|00002140| 74 61 20 3d 20 72 65 73 | 70 42 75 66 66 65 72 3b |ta = res|pBuffer;|
|00002150| 20 20 20 20 20 20 20 20 | 20 20 20 20 20 20 20 20 | | |
|00002160| 20 20 20 20 2f 2f 20 4f | 75 72 20 73 74 72 69 6e | // O|ur strin|
|00002170| 67 0d 09 72 65 73 70 5f | 70 61 73 73 2e 64 61 74 |g..resp_|pass.dat|
|00002180| 61 5f 6c 65 6e 20 3d 20 | 73 74 72 6c 65 6e 28 72 |a_len = |strlen(r|
|00002190| 65 73 70 42 75 66 66 65 | 72 29 2b 31 3b 20 20 20 |espBuffe|r)+1; |
|000021a0| 20 20 20 2f 2f 20 54 68 | 65 20 73 74 72 69 6e 67 | // Th|e string|
|000021b0| 27 73 20 6c 65 6e 67 74 | 68 20 70 6c 75 73 20 6f |'s lengt|h plus o|
|000021c0| 6e 20 66 6f 72 20 74 68 | 65 20 4e 55 4c 4c 0d 09 |n for th|e NULL..|
|000021d0| 72 65 73 70 5f 70 61 73 | 73 2e 75 73 65 72 64 61 |resp_pas|s.userda|
|000021e0| 74 61 5b 30 5d 20 3d 20 | 73 6f 63 6b 3b 20 20 20 |ta[0] = |sock; |
|000021f0| 20 20 20 20 20 20 20 20 | 20 20 20 20 20 20 20 20 | | |
|00002200| 2f 2f 20 2a 2a 2a 20 53 | 74 6f 72 65 20 74 68 65 |// *** S|tore the|
|00002210| 20 6e 65 77 20 73 6f 63 | 6b 65 74 20 69 6e 20 74 | new soc|ket in t|
|00002220| 68 65 20 75 73 65 72 20 | 64 61 74 61 2e 20 20 41 |he user |data. A|
|00002230| 20 68 61 6e 64 79 20 70 | 6c 61 63 65 20 66 6f 72 | handy p|lace for|
|00002240| 20 69 6e 74 73 0d 09 72 | 65 73 70 5f 70 61 73 73 | ints..r|esp_pass|
|00002250| 2e 78 6f 20 3d 20 31 3b | 20 20 20 20 20 20 20 20 |.xo = 1;| |
|00002260| 20 20 20 20 20 20 20 20 | 20 20 20 20 20 20 20 20 | | |
|00002270| 20 20 20 20 20 20 20 2f | 2f 20 57 65 20 77 61 6e | /|/ We wan|
|00002280| 74 20 74 68 69 73 20 73 | 65 6e 74 20 65 78 61 63 |t this s|ent exac|
|00002290| 74 6c 79 20 6f 6e 63 65 | 0d 09 72 65 73 70 5f 70 |tly once|..resp_p|
|000022a0| 61 73 73 2e 78 6f 5f 72 | 65 6c 74 20 3d 20 41 54 |ass.xo_r|elt = AT|
|000022b0| 50 5f 58 4f 5f 44 45 46 | 5f 52 45 4c 5f 54 49 4d |P_XO_DEF|_REL_TIM|
|000022c0| 45 3b 0d 09 72 65 73 70 | 5f 70 61 73 73 2e 54 72 |E;..resp|_pass.Tr|
|000022d0| 61 6e 73 49 44 20 3d 20 | 72 63 76 5f 70 61 73 73 |ansID = |rcv_pass|
|000022e0| 2d 3e 54 72 61 6e 73 49 | 44 3b 20 20 20 20 20 20 |->TransI|D; |
|000022f0| 20 20 20 20 2f 2f 20 4d | 61 74 63 68 20 74 68 65 | // M|atch the|
|00002300| 20 54 49 44 20 66 72 6f | 6d 20 74 68 65 20 63 6c | TID fro|m the cl|
|00002310| 69 65 6e 74 0d 09 0d 2f | 2f 20 20 53 65 6e 64 20 |ient.../|/ Send |
|00002320| 62 61 63 6b 20 6f 75 72 | 20 66 69 72 73 74 20 72 |back our| first r|
|00002330| 65 73 70 6f 6e 73 65 20 | 6f 6e 20 74 68 65 20 6f |esponse |on the o|
|00002340| 6c 64 20 66 69 6c 65 20 | 64 65 73 63 72 69 70 74 |ld file |descript|
|00002350| 6f 72 0d 09 70 72 69 6e | 74 66 28 22 53 65 6e 64 |or..prin|tf("Send|
|00002360| 69 6e 67 20 66 69 72 73 | 74 20 74 68 72 65 61 64 |ing firs|t thread|
|00002370| 20 72 65 73 70 6f 6e 73 | 65 20 6f 6e 20 6f 6c 64 | respons|e on old|
|00002380| 20 66 64 20 25 64 2e 5c | 6e 22 2c 20 2a 6d 79 5f | fd %d.\|n", *my_|
|00002390| 66 64 29 3b 0d 09 69 66 | 28 20 65 72 72 20 3d 20 |fd);..if|( err = |
|000023a0| 41 54 41 74 70 53 65 6e | 64 52 73 70 28 2a 6d 79 |ATAtpSen|dRsp(*my|
|000023b0| 5f 66 64 2c 26 72 65 73 | 70 5f 70 61 73 73 29 29 |_fd,&res|p_pass))|
|000023c0| 0d 09 7b 0d 09 09 20 70 | 72 69 6e 74 66 28 22 41 |..{... p|rintf("A|
|000023d0| 54 41 74 70 52 73 70 20 | 66 61 69 6c 65 64 3a 20 |TAtpRsp |failed: |
|000023e0| 65 72 72 20 3d 20 25 78 | 5c 6e 22 2c 65 72 72 29 |err = %x|\n",err)|
|000023f0| 3b 0d 09 09 20 66 72 65 | 65 28 6e 65 77 5f 66 64 |;... fre|e(new_fd|
|00002400| 29 3b 0d 09 09 20 72 65 | 74 75 72 6e 20 45 46 41 |);... re|turn EFA|
|00002410| 49 4c 55 52 45 3b 0d 09 | 7d 0d 0d 2f 2f 20 20 42 |ILURE;..|}..// B|
|00002420| 65 67 69 6e 20 61 20 6e | 65 77 20 74 68 72 65 61 |egin a n|ew threa|
|00002430| 64 2c 20 61 6c 6c 6f 77 | 69 6e 67 20 69 74 20 74 |d, allow|ing it t|
|00002440| 6f 20 63 72 65 61 74 65 | 20 69 74 73 20 6f 77 6e |o create| its own|
|00002450| 20 73 74 61 63 6b 2e 20 | 20 20 20 20 20 20 20 0d | stack. | .|
|00002460| 09 63 6f 6d 70 6c 65 74 | 69 6f 6e 43 6f 64 65 20 |.complet|ionCode |
|00002470| 3d 20 42 65 67 69 6e 54 | 68 72 65 61 64 28 48 61 |= BeginT|hread(Ha|
|00002480| 6e 64 6c 65 43 6c 69 65 | 6e 74 53 65 73 73 69 6f |ndleClie|ntSessio|
|00002490| 6e 2c 20 4e 55 4c 4c 2c | 20 30 2c 20 6e 65 77 5f |n, NULL,| 0, new_|
|000024a0| 66 64 29 3b 0d 09 69 66 | 20 28 63 6f 6d 70 6c 65 |fd);..if| (comple|
|000024b0| 74 69 6f 6e 43 6f 64 65 | 20 21 3d 20 45 4e 4f 4d |tionCode| != ENOM|
|000024c0| 45 4d 20 26 26 20 63 6f | 6d 70 6c 65 74 69 6f 6e |EM && co|mpletion|
|000024d0| 43 6f 64 65 20 21 3d 20 | 45 49 4e 56 41 4c 29 0d |Code != |EINVAL).|
|000024e0| 09 09 74 68 72 65 61 64 | 43 6f 75 6e 74 2b 2b 3b |..thread|Count++;|
|000024f0| 20 20 20 20 20 20 20 20 | 20 20 2f 2f 20 49 6e 63 | | // Inc|
|00002500| 72 65 6d 65 6e 74 20 6f | 75 72 20 67 6c 6f 62 61 |rement o|ur globa|
|00002510| 6c 20 74 68 72 65 61 64 | 20 63 6f 75 6e 74 65 72 |l thread| counter|
|00002520| 0d 0d 09 72 65 74 75 72 | 6e 20 63 6f 6d 70 6c 65 |...retur|n comple|
|00002530| 74 69 6f 6e 43 6f 64 65 | 3b 20 20 20 20 20 20 20 |tionCode|; |
|00002540| 20 20 20 0d 7d 0d 0d 0d | 2f 2a 20 20 48 61 6e 64 | .}...|/* Hand|
|00002550| 6c 65 43 6c 69 65 6e 74 | 53 65 73 73 69 6f 6e 20 |leClient|Session |
|00002560| 69 73 20 63 61 6c 6c 65 | 64 20 62 79 20 74 68 65 |is calle|d by the|
|00002570| 20 74 68 72 65 61 64 20 | 74 68 61 74 20 69 73 20 | thread |that is |
|00002580| 63 72 65 61 74 65 64 20 | 62 79 0d 09 53 70 69 6e |created |by..Spin|
|00002590| 4e 65 77 53 65 73 73 69 | 6f 6e 2e 20 20 49 74 20 |NewSessi|on. It |
|000025a0| 69 73 20 73 69 6d 69 6c | 61 72 20 74 6f 20 6f 75 |is simil|ar to ou|
|000025b0| 72 20 6d 61 69 6e 20 6c | 6f 6f 70 2c 20 62 75 74 |r main l|oop, but|
|000025c0| 20 69 74 20 68 61 6e 64 | 6c 65 73 0d 09 69 6e 74 | it hand|les..int|
|000025d0| 65 72 61 63 74 69 6f 6e | 20 77 69 74 68 20 61 20 |eraction| with a |
|000025e0| 73 69 6e 67 6c 65 20 63 | 6c 69 65 6e 74 2e 20 20 |single c|lient. |
|000025f0| 57 68 65 6e 20 74 68 65 | 20 63 6c 69 65 6e 74 20 |When the| client |
|00002600| 74 65 6c 6c 73 20 75 73 | 20 69 74 73 0d 09 66 69 |tells us| its..fi|
|00002610| 6e 69 73 68 65 64 2c 20 | 6f 72 20 74 68 65 20 73 |nished, |or the s|
|00002620| 6f 6d 65 20 61 62 6e 6f | 72 6d 61 6c 20 63 6f 6e |ome abno|rmal con|
|00002630| 64 69 74 69 6f 6e 20 68 | 61 70 70 65 6e 73 2c 20 |dition h|appens, |
|00002640| 77 65 20 74 65 72 6d 69 | 6e 61 74 65 0d 09 74 68 |we termi|nate..th|
|00002650| 65 20 74 68 72 65 61 64 | 2e 20 20 4e 6f 74 65 20 |e thread|. Note |
|00002660| 74 68 61 74 20 69 66 20 | 74 68 65 20 66 75 6e 63 |that if |the func|
|00002670| 74 69 6f 6e 20 72 65 74 | 75 72 6e 73 2c 20 74 68 |tion ret|urns, th|
|00002680| 65 20 74 68 72 65 61 64 | 20 69 73 0d 09 74 65 72 |e thread| is..ter|
|00002690| 6d 69 6e 61 74 65 64 20 | 62 79 20 74 68 65 20 73 |minated |by the s|
|000026a0| 79 73 74 65 6d 0d 2a 2f | 0d 76 6f 69 64 20 48 61 |ystem.*/|.void Ha|
|000026b0| 6e 64 6c 65 43 6c 69 65 | 6e 74 53 65 73 73 69 6f |ndleClie|ntSessio|
|000026c0| 6e 28 69 6e 74 20 2a 63 | 6c 69 65 6e 74 5f 66 64 |n(int *c|lient_fd|
|000026d0| 29 0d 7b 0d 09 41 54 41 | 74 70 50 61 73 73 5f 74 |).{..ATA|tpPass_t|
|000026e0| 20 20 20 20 20 72 63 76 | 5f 70 61 73 73 2c 20 72 | rcv|_pass, r|
|000026f0| 65 73 70 5f 70 61 73 73 | 3b 20 20 09 09 09 2f 2f |esp_pass|; ...//|
|00002700| 20 46 6f 72 20 72 65 63 | 65 69 76 69 6e 67 20 61 | For rec|eiving a|
|00002710| 6e 64 20 72 65 73 70 6f | 6e 64 69 6e 67 0d 09 69 |nd respo|nding..i|
|00002720| 6e 74 20 20 20 20 20 20 | 20 20 20 20 20 20 20 20 |nt | |
|00002730| 20 20 20 20 20 20 20 65 | 72 72 2c 20 71 75 69 74 | e|rr, quit|
|00002740| 52 65 71 75 65 73 74 3b | 20 20 20 20 20 20 20 2f |Request;| /|
|00002750| 2f 20 71 75 69 74 52 65 | 71 75 65 73 74 20 69 73 |/ quitRe|quest is|
|00002760| 20 75 73 65 64 20 74 6f | 20 64 65 74 65 72 6d 69 | used to| determi|
|00002770| 6e 65 20 69 66 20 74 68 | 65 20 63 6c 69 65 6e 74 |ne if th|e client|
|00002780| 20 69 73 20 64 6f 6e 65 | 0d 09 63 68 61 72 20 20 | is done|..char |
|00002790| 20 20 20 20 20 20 20 20 | 20 20 20 20 20 20 20 20 | | |
|000027a0| 20 20 72 65 73 70 42 75 | 66 66 65 72 5b 31 32 38 | respBu|ffer[128|
|000027b0| 5d 3b 20 20 20 20 20 20 | 20 20 2f 2f 20 42 75 66 |]; | // Buf|
|000027c0| 66 65 72 20 66 6f 72 20 | 6f 75 72 20 72 65 73 70 |fer for |our resp|
|000027d0| 6f 6e 73 65 20 73 74 72 | 69 6e 67 73 0d 09 0d 2f |onse str|ings.../|
|000027e0| 2f 20 20 41 6c 6c 6f 63 | 61 74 65 20 72 6f 6f 6d |/ Alloc|ate room|
|000027f0| 20 66 6f 72 20 6f 75 72 | 20 72 65 63 65 69 76 65 | for our| receive|
|00002800| 20 62 75 66 66 65 72 0d | 09 72 63 76 5f 70 61 73 | buffer.|.rcv_pas|
|00002810| 73 2e 64 61 74 61 20 3d | 20 28 76 6f 69 64 20 2a |s.data =| (void *|
|00002820| 29 6d 61 6c 6c 6f 63 28 | 41 54 50 5f 44 41 54 41 |)malloc(|ATP_DATA|
|00002830| 5f 53 49 5a 45 29 3b 0d | 09 72 63 76 5f 70 61 73 |_SIZE);.|.rcv_pas|
|00002840| 73 2e 64 61 74 61 5f 6c | 65 6e 20 3d 20 41 54 50 |s.data_l|en = ATP|
|00002850| 5f 44 41 54 41 5f 53 49 | 5a 45 3b 0d 0d 09 64 6f |_DATA_SI|ZE;...do|
|00002860| 0d 09 7b 0d 2f 2f 20 20 | 20 20 20 20 54 68 69 73 |..{.// | This|
|00002870| 20 47 65 74 20 77 69 6c | 6c 20 62 6c 6f 63 6b 20 | Get wil|l block |
|00002880| 75 6e 74 69 6c 20 6f 75 | 72 20 63 6c 69 65 6e 74 |until ou|r client|
|00002890| 20 73 65 6e 64 73 20 61 | 20 72 65 71 75 65 73 74 | sends a| request|
|000028a0| 20 66 6f 72 20 69 6e 66 | 6f 72 6d 61 74 69 6f 6e | for inf|ormation|
|000028b0| 2e 0d 2f 2f 20 20 20 20 | 20 20 49 66 20 77 65 20 |..// | If we |
|000028c0| 6e 65 76 65 72 20 67 65 | 74 20 61 20 72 65 71 75 |never ge|t a requ|
|000028d0| 65 73 74 2c 20 74 68 69 | 73 20 63 61 6c 6c 20 6e |est, thi|s call n|
|000028e0| 65 76 65 72 20 72 65 74 | 75 72 6e 73 0d 09 09 70 |ever ret|urns...p|
|000028f0| 72 69 6e 74 66 28 22 49 | 6e 20 63 6c 69 65 6e 74 |rintf("I|n client|
|00002900| 20 68 61 6e 64 6c 69 6e | 67 20 74 68 72 65 61 64 | handlin|g thread|
|00002910| 3a 20 43 61 6c 6c 69 6e | 67 20 41 54 41 74 70 47 |: Callin|g ATAtpG|
|00002920| 65 74 20 66 64 3a 25 64 | 2e 5c 6e 22 2c 20 2a 63 |et fd:%d|.\n", *c|
|00002930| 6c 69 65 6e 74 5f 66 64 | 29 3b 0d 09 09 69 66 28 |lient_fd|);...if(|
|00002940| 65 72 72 20 3d 20 41 54 | 41 74 70 47 65 74 28 2a |err = AT|AtpGet(*|
|00002950| 63 6c 69 65 6e 74 5f 66 | 64 2c 26 72 63 76 5f 70 |client_f|d,&rcv_p|
|00002960| 61 73 73 29 20 29 0d 09 | 09 7b 0d 09 09 20 0d 09 |ass) )..|.{... ..|
|00002970| 09 09 20 70 72 69 6e 74 | 66 28 22 41 54 41 74 70 |.. print|f("ATAtp|
|00002980| 47 65 74 20 66 61 69 6c | 65 64 3a 20 65 72 72 20 |Get fail|ed: err |
|00002990| 3d 20 25 78 5c 6e 22 2c | 65 72 72 29 3b 0d 09 09 |= %x\n",|err);...|
|000029a0| 09 20 41 54 41 74 70 43 | 6c 6f 73 65 28 2a 63 6c |. ATAtpC|lose(*cl|
|000029b0| 69 65 6e 74 5f 66 64 29 | 3b 20 20 20 20 20 20 20 |ient_fd)|; |
|000029c0| 20 20 20 20 20 20 20 20 | 20 2f 2f 20 57 65 20 6f | | // We o|
|000029d0| 77 6e 20 74 68 65 20 66 | 64 20 77 68 65 6e 20 77 |wn the f|d when w|
|000029e0| 65 27 72 65 20 63 61 6c | 6c 65 64 0d 09 09 09 20 |e're cal|led.... |
|000029f0| 66 72 65 65 28 72 63 76 | 5f 70 61 73 73 2e 64 61 |free(rcv|_pass.da|
|00002a00| 74 61 29 3b 0d 09 09 09 | 20 66 72 65 65 28 63 6c |ta);....| free(cl|
|00002a10| 69 65 6e 74 5f 66 64 29 | 3b 0d 09 09 09 20 74 68 |ient_fd)|;.... th|
|00002a20| 72 65 61 64 43 6f 75 6e | 74 2d 2d 3b 0d 09 09 09 |readCoun|t--;....|
|00002a30| 20 72 65 74 75 72 6e 3b | 09 09 09 09 09 09 09 09 | return;|........|
|00002a40| 2f 2f 20 54 68 69 73 20 | 77 69 6c 6c 20 6b 69 6c |// This |will kil|
|00002a50| 6c 20 74 68 65 20 74 68 | 72 65 61 64 0d 09 09 7d |l the th|read...}|
|00002a60| 0d 0d 2f 2f 20 20 20 20 | 20 20 54 68 65 20 67 65 |..// | The ge|
|00002a70| 74 20 77 61 73 20 73 75 | 63 63 65 73 73 66 75 6c |t was su|ccessful|
|00002a80| 2c 20 62 75 74 20 74 68 | 65 72 65 20 77 61 73 20 |, but th|ere was |
|00002a90| 61 20 70 72 6f 74 6f 63 | 6f 6c 20 65 72 72 6f 72 |a protoc|ol error|
|00002aa0| 2e 0d 09 09 69 66 28 72 | 63 76 5f 70 61 73 73 2e |....if(r|cv_pass.|
|00002ab0| 72 65 74 29 0d 09 09 09 | 20 70 72 69 6e 74 66 28 |ret)....| printf(|
|00002ac0| 22 72 63 76 5f 70 61 73 | 73 2e 72 65 74 20 72 65 |"rcv_pas|s.ret re|
|00002ad0| 74 75 72 6e 65 64 20 65 | 72 72 6f 72 20 28 25 78 |turned e|rror (%x|
|00002ae0| 29 5c 6e 22 2c 72 63 76 | 5f 70 61 73 73 2e 72 65 |)\n",rcv|_pass.re|
|00002af0| 74 29 3b 0d 0d 2f 2f 20 | 20 20 20 20 20 53 68 6f |t);..// | Sho|
|00002b00| 77 20 77 68 6f 20 74 68 | 65 20 6d 65 73 73 61 67 |w who th|e messag|
|00002b10| 65 20 77 61 73 20 66 72 | 6f 6d 0d 09 09 70 72 69 |e was fr|om...pri|
|00002b20| 6e 74 66 28 22 52 65 63 | 65 69 76 65 64 20 6d 65 |ntf("Rec|eived me|
|00002b30| 73 73 61 67 65 20 66 72 | 6f 6d 20 61 20 63 6c 69 |ssage fr|om a cli|
|00002b40| 65 6e 74 20 61 74 20 25 | 64 2e 25 64 2e 25 64 2e |ent at %|d.%d.%d.|
|00002b50| 5c 6e 22 2c 0d 09 09 72 | 63 76 5f 70 61 73 73 2e |\n",...r|cv_pass.|
|00002b60| 61 74 5f 61 64 64 72 2e | 6e 65 74 2c 0d 09 09 72 |at_addr.|net,...r|
|00002b70| 63 76 5f 70 61 73 73 2e | 61 74 5f 61 64 64 72 2e |cv_pass.|at_addr.|
|00002b80| 6e 6f 64 65 2c 0d 09 09 | 72 63 76 5f 70 61 73 73 |node,...|rcv_pass|
|00002b90| 2e 61 74 5f 61 64 64 72 | 2e 73 6f 63 6b 65 74 29 |.at_addr|.socket)|
|00002ba0| 3b 0d 09 09 0d 2f 2f 20 | 20 20 20 20 20 50 72 69 |;....// | Pri|
|00002bb0| 6e 74 20 77 68 61 74 20 | 77 65 20 67 6f 74 0d 09 |nt what |we got..|
|00002bc0| 09 70 72 69 6e 74 66 28 | 22 52 65 63 65 69 76 65 |.printf(|"Receive|
|00002bd0| 64 3a 25 73 5c 6e 22 2c | 72 63 76 5f 70 61 73 73 |d:%s\n",|rcv_pass|
|00002be0| 2e 64 61 74 61 29 3b 0d | 09 09 70 72 69 6e 74 66 |.data);.|..printf|
|00002bf0| 28 22 55 73 65 72 64 61 | 74 61 3a 20 25 64 5c 6e |("Userda|ta: %d\n|
|00002c00| 22 2c 20 72 63 76 5f 70 | 61 73 73 2e 75 73 65 72 |", rcv_p|ass.user|
|00002c10| 64 61 74 61 5b 30 5d 29 | 3b 20 20 20 0d 0d 2f 2f |data[0])|; ..//|
|00002c20| 20 20 20 20 20 20 49 6e | 74 65 72 70 72 65 74 20 | In|terpret |
|00002c30| 74 68 65 20 72 65 71 75 | 65 73 74 20 61 6e 64 20 |the requ|est and |
|00002c40| 67 65 74 20 74 68 65 20 | 61 70 70 72 6f 70 72 69 |get the |appropri|
|00002c50| 61 74 65 20 72 65 73 70 | 6f 6e 73 65 20 69 6e 20 |ate resp|onse in |
|00002c60| 74 68 65 20 72 65 73 70 | 6f 6e 73 65 20 62 75 66 |the resp|onse buf|
|00002c70| 66 65 72 0d 2f 2f 20 20 | 20 20 20 20 52 65 71 75 |fer.// | Requ|
|00002c80| 65 73 74 73 20 61 72 65 | 20 73 65 6e 74 20 61 73 |ests are| sent as|
|00002c90| 20 69 6e 74 65 67 65 72 | 73 20 69 6e 20 74 68 65 | integer|s in the|
|00002ca0| 20 75 73 65 72 64 61 74 | 61 20 66 69 65 6c 64 0d | userdat|a field.|
|00002cb0| 09 09 71 75 69 74 52 65 | 71 75 65 73 74 20 3d 20 |..quitRe|quest = |
|00002cc0| 48 61 6e 64 6c 65 52 65 | 71 75 65 73 74 28 28 63 |HandleRe|quest((c|
|00002cd0| 68 61 72 20 2a 29 72 63 | 76 5f 70 61 73 73 2e 64 |har *)rc|v_pass.d|
|00002ce0| 61 74 61 2c 20 26 72 65 | 73 70 42 75 66 66 65 72 |ata, &re|spBuffer|
|00002cf0| 2c 20 72 63 76 5f 70 61 | 73 73 2e 75 73 65 72 64 |, rcv_pa|ss.userd|
|00002d00| 61 74 61 5b 30 5d 29 3b | 0d 09 09 0d 2f 2f 20 20 |ata[0]);|....// |
|00002d10| 20 20 20 20 53 65 6e 64 | 20 62 61 63 6b 20 61 20 | Send| back a |
|00002d20| 72 65 73 70 6f 6e 73 65 | 0d 09 09 72 65 73 70 5f |response|...resp_|
|00002d30| 70 61 73 73 2e 61 74 5f | 61 64 64 72 20 3d 20 72 |pass.at_|addr = r|
|00002d40| 63 76 5f 70 61 73 73 2e | 61 74 5f 61 64 64 72 3b |cv_pass.|at_addr;|
|00002d50| 0d 09 09 72 65 73 70 5f | 70 61 73 73 2e 62 69 74 |...resp_|pass.bit|
|00002d60| 6d 61 70 20 3d 20 31 3b | 2f 2a 20 53 65 6e 64 69 |map = 1;|/* Sendi|
|00002d70| 6e 67 20 31 20 70 61 63 | 6b 65 74 2e 20 2a 2f 0d |ng 1 pac|ket. */.|
|00002d80| 09 09 72 65 73 70 5f 70 | 61 73 73 2e 70 61 63 6b |..resp_p|ass.pack|
|00002d90| 65 74 69 7a 65 20 3d 20 | 30 3b 0d 09 09 72 65 73 |etize = |0;...res|
|00002da0| 70 5f 70 61 73 73 2e 72 | 65 74 72 79 2e 69 6e 74 |p_pass.r|etry.int|
|00002db0| 65 72 76 61 6c 20 3d 20 | 32 30 30 30 3b 0d 09 09 |erval = |2000;...|
|00002dc0| 72 65 73 70 5f 70 61 73 | 73 2e 72 65 74 72 79 2e |resp_pas|s.retry.|
|00002dd0| 72 65 74 72 69 65 73 20 | 3d 20 32 3b 0d 09 09 72 |retries |= 2;...r|
|00002de0| 65 73 70 5f 70 61 73 73 | 2e 72 65 74 72 79 2e 62 |esp_pass|.retry.b|
|00002df0| 61 63 6b 6f 66 66 20 3d | 20 32 3b 0d 09 09 72 65 |ackoff =| 2;...re|
|00002e00| 73 70 5f 70 61 73 73 2e | 72 65 74 20 3d 30 3b 0d |sp_pass.|ret =0;.|
|00002e10| 09 09 72 65 73 70 5f 70 | 61 73 73 2e 64 61 74 61 |..resp_p|ass.data|
|00002e20| 20 3d 20 72 65 73 70 42 | 75 66 66 65 72 3b 20 0d | = respB|uffer; .|
|00002e30| 09 09 72 65 73 70 5f 70 | 61 73 73 2e 64 61 74 61 |..resp_p|ass.data|
|00002e40| 5f 6c 65 6e 20 3d 20 73 | 74 72 6c 65 6e 28 72 65 |_len = s|trlen(re|
|00002e50| 73 70 42 75 66 66 65 72 | 29 2b 31 3b 0d 09 09 72 |spBuffer|)+1;...r|
|00002e60| 65 73 70 5f 70 61 73 73 | 2e 75 73 65 72 64 61 74 |esp_pass|.userdat|
|00002e70| 61 5b 30 5d 20 3d 20 30 | 3b 0d 09 09 72 65 73 70 |a[0] = 0|;...resp|
|00002e80| 5f 70 61 73 73 2e 78 6f | 20 3d 20 31 3b 0d 09 09 |_pass.xo| = 1;...|
|00002e90| 72 65 73 70 5f 70 61 73 | 73 2e 78 6f 5f 72 65 6c |resp_pas|s.xo_rel|
|00002ea0| 74 20 3d 20 41 54 50 5f | 58 4f 5f 44 45 46 5f 52 |t = ATP_|XO_DEF_R|
|00002eb0| 45 4c 5f 54 49 4d 45 3b | 0d 09 09 72 65 73 70 5f |EL_TIME;|...resp_|
|00002ec0| 70 61 73 73 2e 54 72 61 | 6e 73 49 44 20 3d 20 72 |pass.Tra|nsID = r|
|00002ed0| 63 76 5f 70 61 73 73 2e | 54 72 61 6e 73 49 44 3b |cv_pass.|TransID;|
|00002ee0| 0d 0d 09 0d 09 09 70 72 | 69 6e 74 66 28 22 53 65 |......pr|intf("Se|
|00002ef0| 6e 64 69 6e 67 20 74 68 | 72 65 61 64 20 72 65 73 |nding th|read res|
|00002f00| 70 6f 6e 73 65 20 6f 6e | 20 66 64 20 25 64 2e 5c |ponse on| fd %d.\|
|00002f10| 6e 22 2c 20 2a 63 6c 69 | 65 6e 74 5f 66 64 29 3b |n", *cli|ent_fd);|
|00002f20| 0d 09 09 69 66 28 20 65 | 72 72 20 3d 20 41 54 41 |...if( e|rr = ATA|
|00002f30| 74 70 53 65 6e 64 52 73 | 70 28 2a 63 6c 69 65 6e |tpSendRs|p(*clien|
|00002f40| 74 5f 66 64 2c 26 72 65 | 73 70 5f 70 61 73 73 29 |t_fd,&re|sp_pass)|
|00002f50| 29 0d 09 09 7b 0d 09 09 | 09 20 70 72 69 6e 74 66 |)...{...|. printf|
|00002f60| 28 22 41 54 41 74 70 52 | 73 70 20 66 61 69 6c 65 |("ATAtpR|sp faile|
|00002f70| 64 3a 20 65 72 72 20 3d | 20 25 78 5c 6e 22 2c 65 |d: err =| %x\n",e|
|00002f80| 72 72 29 3b 0d 09 09 09 | 20 41 54 41 74 70 43 6c |rr);....| ATAtpCl|
|00002f90| 6f 73 65 28 2a 63 6c 69 | 65 6e 74 5f 66 64 29 3b |ose(*cli|ent_fd);|
|00002fa0| 0d 09 09 09 20 66 72 65 | 65 28 72 63 76 5f 70 61 |.... fre|e(rcv_pa|
|00002fb0| 73 73 2e 64 61 74 61 29 | 3b 0d 09 09 09 20 66 72 |ss.data)|;.... fr|
|00002fc0| 65 65 28 63 6c 69 65 6e | 74 5f 66 64 29 3b 0d 09 |ee(clien|t_fd);..|
|00002fd0| 09 09 20 74 68 72 65 61 | 64 43 6f 75 6e 74 2d 2d |.. threa|dCount--|
|00002fe0| 3b 0d 09 09 09 20 72 65 | 74 75 72 6e 3b 0d 09 09 |;.... re|turn;...|
|00002ff0| 7d 0d 0d 09 09 69 66 20 | 28 71 75 69 74 52 65 71 |}....if |(quitReq|
|00003000| 75 65 73 74 29 0d 09 09 | 7b 0d 09 09 09 70 72 69 |uest)...|{....pri|
|00003010| 6e 74 66 28 22 43 6c 69 | 65 6e 74 20 72 65 71 75 |ntf("Cli|ent requ|
|00003020| 65 73 74 65 64 20 71 75 | 69 74 5c 6e 22 29 3b 0d |ested qu|it\n");.|
|00003030| 09 09 09 41 54 41 74 70 | 43 6c 6f 73 65 28 2a 63 |...ATAtp|Close(*c|
|00003040| 6c 69 65 6e 74 5f 66 64 | 29 3b 0d 09 09 09 66 72 |lient_fd|);....fr|
|00003050| 65 65 28 72 63 76 5f 70 | 61 73 73 2e 64 61 74 61 |ee(rcv_p|ass.data|
|00003060| 29 3b 0d 09 09 09 66 72 | 65 65 28 63 6c 69 65 6e |);....fr|ee(clien|
|00003070| 74 5f 66 64 29 3b 0d 09 | 09 09 74 68 72 65 61 64 |t_fd);..|..thread|
|00003080| 43 6f 75 6e 74 2d 2d 3b | 0d 09 09 09 72 65 74 75 |Count--;|....retu|
|00003090| 72 6e 3b 0d 09 09 7d 20 | 20 20 20 20 20 20 0d 09 |rn;...} | ..|
|000030a0| 7d 77 68 69 6c 65 20 28 | 20 21 65 78 69 74 69 6e |}while (| !exitin|
|000030b0| 67 4e 4c 4d 20 29 3b 0d | 0d 0d 2f 2f 20 20 57 65 |gNLM );.|..// We|
|000030c0| 20 77 69 6c 6c 20 6f 6e | 6c 79 20 72 65 61 63 68 | will on|ly reach|
|000030d0| 20 74 68 69 73 20 70 6f | 69 6e 74 20 69 66 20 65 | this po|int if e|
|000030e0| 78 69 74 69 6e 67 4e 4c | 4d 20 69 73 20 74 72 75 |xitingNL|M is tru|
|000030f0| 65 2e 20 20 54 68 61 74 | 20 6d 65 61 6e 73 20 73 |e. That| means s|
|00003100| 6f 6d 65 6f 6e 65 20 75 | 6e 6c 6f 61 64 65 64 20 |omeone u|nloaded |
|00003110| 75 73 0d 2f 2f 20 20 61 | 74 20 74 68 65 20 63 6f |us.// a|t the co|
|00003120| 6e 73 6f 6c 65 0d 0d 2f | 2f 20 20 43 6c 6f 73 65 |nsole../|/ Close|
|00003130| 20 74 68 65 20 41 54 50 | 20 73 6f 63 6b 65 74 20 | the ATP| socket |
|00003140| 67 72 61 63 65 66 75 6c | 6c 79 2e 0d 09 69 66 28 |graceful|ly...if(|
|00003150| 65 72 72 20 3d 20 41 54 | 41 74 70 43 6c 6f 73 65 |err = AT|AtpClose|
|00003160| 28 2a 63 6c 69 65 6e 74 | 5f 66 64 29 29 0d 09 7b |(*client|_fd))..{|
|00003170| 0d 09 09 20 70 72 69 6e | 74 66 28 22 41 54 41 74 |... prin|tf("ATAt|
|00003180| 70 43 6c 6f 73 65 20 66 | 61 69 6c 65 64 3a 20 65 |pClose f|ailed: e|
|00003190| 72 72 20 3d 20 25 78 5c | 6e 22 2c 20 65 72 72 29 |rr = %x\|n", err)|
|000031a0| 3b 0d 09 7d 20 20 20 20 | 20 20 20 0d 09 0d 09 66 |;..} | ....f|
|000031b0| 72 65 65 28 72 63 76 5f | 70 61 73 73 2e 64 61 74 |ree(rcv_|pass.dat|
|000031c0| 61 29 3b 0d 09 66 72 65 | 65 28 63 6c 69 65 6e 74 |a);..fre|e(client|
|000031d0| 5f 66 64 29 3b 20 20 20 | 20 20 20 20 20 20 20 20 |_fd); | |
|000031e0| 20 20 20 20 0d 09 74 68 | 72 65 61 64 43 6f 75 6e | ..th|readCoun|
|000031f0| 74 2d 2d 3b 0d 7d 0d 0d | 2f 2a 20 48 61 6e 64 6c |t--;.}..|/* Handl|
|00003200| 65 52 65 71 75 65 73 74 | 20 69 6e 74 65 72 70 72 |eRequest| interpr|
|00003210| 65 74 73 20 74 68 65 20 | 74 68 65 20 72 65 71 75 |ets the |the requ|
|00003220| 65 73 74 20 6e 75 6d 62 | 65 72 20 73 75 70 70 6c |est numb|er suppl|
|00003230| 69 65 64 20 61 6e 64 20 | 67 65 74 73 20 74 68 65 |ied and |gets the|
|00003240| 20 0d 09 61 70 70 72 6f | 70 72 69 61 74 65 20 61 | ..appro|priate a|
|00003250| 6e 73 77 65 72 2e 20 20 | 49 66 20 74 68 65 20 63 |nswer. |If the c|
|00003260| 6c 69 65 6e 74 20 72 65 | 71 75 65 73 74 73 20 74 |lient re|quests t|
|00003270| 6f 20 71 75 69 74 2c 20 | 74 68 65 20 66 75 6e 63 |o quit, |the func|
|00003280| 74 69 6f 6e 20 72 65 74 | 75 72 6e 73 20 31 2c 0d |tion ret|urns 1,.|
|00003290| 09 6f 74 68 65 72 77 69 | 73 65 20 69 74 20 72 65 |.otherwi|se it re|
|000032a0| 74 75 72 6e 73 20 30 2e | 0d 2a 2f 0d 69 6e 74 20 |turns 0.|.*/.int |
|000032b0| 48 61 6e 64 6c 65 52 65 | 71 75 65 73 74 28 63 68 |HandleRe|quest(ch|
|000032c0| 61 72 20 2a 69 6e 70 75 | 74 2c 20 63 68 61 72 20 |ar *inpu|t, char |
|000032d0| 2a 6f 75 74 70 75 74 2c | 20 69 6e 74 20 72 65 71 |*output,| int req|
|000032e0| 4e 75 6d 29 0d 7b 0d 09 | 69 6e 74 20 20 20 20 20 |Num).{..|int |
|000032f0| 20 20 20 20 20 20 20 20 | 20 20 20 20 20 20 20 20 | | |
|00003300| 63 63 6f 64 65 2c 20 73 | 74 72 75 63 74 73 69 7a |ccode, s|tructsiz|
|00003310| 65 20 3d 20 31 32 38 3b | 20 20 20 20 20 20 20 20 |e = 128;| |
|00003320| 2f 2f 20 46 6f 72 20 63 | 61 6c 6c 73 20 74 6f 20 |// For c|alls to |
|00003330| 67 65 74 20 73 65 72 76 | 65 72 20 69 6e 66 6f 0d |get serv|er info.|
|00003340| 09 46 49 4c 45 5f 53 45 | 52 56 5f 49 4e 46 4f 20 |.FILE_SE|RV_INFO |
|00003350| 20 73 62 75 66 3b 20 20 | 20 20 20 20 20 20 20 20 | sbuf; | |
|00003360| 20 20 20 20 20 20 20 20 | 20 20 20 20 20 20 20 20 | | |
|00003370| 20 20 20 20 20 20 20 20 | 20 20 20 20 20 20 20 20 | | |
|00003380| 20 2f 2f 20 53 65 72 76 | 65 72 20 69 6e 66 6f 20 | // Serv|er info |
|00003390| 64 61 74 61 20 73 74 72 | 75 63 74 75 72 65 0d 09 |data str|ucture..|
|000033a0| 69 6e 74 20 20 20 20 20 | 20 20 20 20 20 20 20 20 |int | |
|000033b0| 20 20 20 20 20 20 20 20 | 20 20 20 20 20 20 20 20 | | |
|000033c0| 72 65 71 75 65 73 74 65 | 64 51 75 69 74 20 3d 20 |requeste|dQuit = |
|000033d0| 30 3b 0d 09 0d 2f 2f 20 | 20 47 65 74 20 73 6f 6d |0;...// | Get som|
|000033e0| 65 20 67 65 6e 65 72 69 | 63 20 69 6e 66 6f 72 6d |e generi|c inform|
|000033f0| 61 74 69 6f 6e 20 61 62 | 6f 75 74 20 74 68 65 20 |ation ab|out the |
|00003400| 63 75 72 72 65 6e 74 20 | 73 65 72 76 65 72 20 73 |current |server s|
|00003410| 74 61 74 75 73 2e 0d 09 | 63 63 6f 64 65 20 3d 20 |tatus...|ccode = |
|00003420| 47 65 74 53 65 72 76 65 | 72 49 6e 66 6f 72 6d 61 |GetServe|rInforma|
|00003430| 74 69 6f 6e 28 73 74 72 | 75 63 74 73 69 7a 65 2c |tion(str|uctsize,|
|00003440| 20 26 73 62 75 66 29 3b | 0d 09 69 66 20 28 63 63 | &sbuf);|..if (cc|
|00003450| 6f 64 65 20 21 3d 20 30 | 29 0d 09 7b 0d 09 09 70 |ode != 0|)..{...p|
|00003460| 72 69 6e 74 66 28 22 47 | 65 74 53 65 72 76 65 72 |rintf("G|etServer|
|00003470| 49 6e 66 6f 72 6d 61 74 | 69 6f 6e 20 72 65 74 75 |Informat|ion retu|
|00003480| 72 6e 65 64 20 61 6e 20 | 65 72 72 6f 72 21 20 25 |rned an |error! %|
|00003490| 64 2e 5c 6e 22 2c 20 63 | 63 6f 64 65 29 3b 0d 09 |d.\n", c|code);..|
|000034a0| 09 72 65 74 75 72 6e 20 | 31 3b 20 20 20 20 20 20 |.return |1; |
|000034b0| 20 2f 2f 20 74 68 69 73 | 20 69 73 20 4f 4b 20 65 | // this| is OK e|
|000034c0| 76 65 6e 20 69 66 20 63 | 63 6f 64 65 20 69 73 20 |ven if c|code is |
|000034d0| 31 2e 20 20 57 65 20 6a | 75 73 74 20 77 61 6e 74 |1. We j|ust want|
|000034e0| 20 74 6f 20 6b 69 6c 6c | 20 74 68 69 73 20 74 68 | to kill| this th|
|000034f0| 72 65 61 64 0d 09 7d 0d | 09 0d 2f 2f 20 20 50 72 |read..}.|..// Pr|
|00003500| 69 6e 74 20 74 68 65 20 | 72 65 71 75 65 73 74 20 |int the |request |
|00003510| 6e 75 6d 62 65 72 0d 09 | 70 72 69 6e 74 66 28 22 |number..|printf("|
|00003520| 52 65 71 4e 75 6d 3a 20 | 25 64 5c 6e 22 2c 20 72 |ReqNum: |%d\n", r|
|00003530| 65 71 4e 75 6d 29 3b 0d | 0d 2f 2f 20 20 49 6e 74 |eqNum);.|.// Int|
|00003540| 65 72 70 72 65 74 20 69 | 74 0d 09 73 77 69 74 63 |erpret i|t..switc|
|00003550| 68 28 72 65 71 4e 75 6d | 29 0d 09 7b 0d 09 09 63 |h(reqNum|)..{...c|
|00003560| 61 73 65 20 6b 52 65 71 | 75 65 73 74 65 64 4e 61 |ase kReq|uestedNa|
|00003570| 6d 65 3a 0d 09 09 09 73 | 74 72 63 70 79 28 6f 75 |me:....s|trcpy(ou|
|00003580| 74 70 75 74 2c 20 73 62 | 75 66 2e 73 65 72 76 65 |tput, sb|uf.serve|
|00003590| 72 4e 61 6d 65 29 3b 20 | 20 20 20 20 20 20 20 20 |rName); | |
|000035a0| 20 20 20 20 20 20 20 0d | 09 09 62 72 65 61 6b 3b | .|..break;|
|000035b0| 0d 09 09 63 61 73 65 20 | 6b 52 65 71 75 65 73 74 |...case |kRequest|
|000035c0| 65 64 43 6f 6e 6e 65 63 | 74 69 6f 6e 73 49 6e 55 |edConnec|tionsInU|
|000035d0| 73 65 3a 0d 09 09 09 73 | 70 72 69 6e 74 66 28 6f |se:....s|printf(o|
|000035e0| 75 74 70 75 74 2c 22 25 | 64 22 2c 20 73 62 75 66 |utput,"%|d", sbuf|
|000035f0| 2e 63 6f 6e 6e 65 63 74 | 69 6f 6e 73 49 6e 55 73 |.connect|ionsInUs|
|00003600| 65 29 3b 0d 09 09 62 72 | 65 61 6b 3b 0d 09 09 63 |e);...br|eak;...c|
|00003610| 61 73 65 20 6b 52 65 71 | 75 65 73 74 65 64 50 65 |ase kReq|uestedPe|
|00003620| 61 6b 43 6f 6e 6e 65 63 | 74 69 6f 6e 73 3a 0d 09 |akConnec|tions:..|
|00003630| 09 09 73 70 72 69 6e 74 | 66 28 6f 75 74 70 75 74 |..sprint|f(output|
|00003640| 2c 22 25 64 22 2c 20 73 | 62 75 66 2e 70 65 61 6b |,"%d", s|buf.peak|
|00003650| 43 6f 6e 6e 65 63 74 69 | 6f 6e 73 55 73 65 64 29 |Connecti|onsUsed)|
|00003660| 3b 0d 09 09 62 72 65 61 | 6b 3b 0d 09 09 63 61 73 |;...brea|k;...cas|
|00003670| 65 20 6b 52 65 71 75 65 | 73 74 65 64 51 75 69 74 |e kReque|stedQuit|
|00003680| 3a 0d 09 09 09 09 73 74 | 72 63 70 79 28 6f 75 74 |:.....st|rcpy(out|
|00003690| 70 75 74 2c 20 22 42 79 | 65 20 62 79 65 20 63 6c |put, "By|e bye cl|
|000036a0| 69 65 6e 74 2e 22 29 3b | 0d 09 09 09 09 72 65 71 |ient.");|.....req|
|000036b0| 75 65 73 74 65 64 51 75 | 69 74 20 3d 20 31 3b 20 |uestedQu|it = 1; |
|000036c0| 0d 09 09 62 72 65 61 6b | 3b 0d 09 09 64 65 66 61 |...break|;...defa|
|000036d0| 75 6c 74 3a 0d 09 09 09 | 73 74 72 63 70 79 28 6f |ult:....|strcpy(o|
|000036e0| 75 74 70 75 74 2c 20 22 | 55 6e 6b 6e 6f 77 6e 20 |utput, "|Unknown |
|000036f0| 72 65 71 75 65 73 74 2e | 22 29 3b 20 20 20 20 20 |request.|"); |
|00003700| 20 20 20 20 20 20 20 20 | 0d 09 09 62 72 65 61 6b | |...break|
|00003710| 3b 0d 09 7d 0d 09 0d 09 | 70 72 69 6e 74 66 28 22 |;..}....|printf("|
|00003720| 49 6e 20 48 61 6e 64 6c | 65 52 65 71 75 65 73 74 |In Handl|eRequest|
|00003730| 3a 20 69 6e 70 75 74 3a | 20 25 73 20 6f 75 74 70 |: input:| %s outp|
|00003740| 75 74 3a 20 25 73 5c 6e | 22 2c 20 69 6e 70 75 74 |ut: %s\n|", input|
|00003750| 2c 20 6f 75 74 70 75 74 | 29 3b 0d 0d 09 72 65 74 |, output|);...ret|
|00003760| 75 72 6e 20 72 65 71 75 | 65 73 74 65 64 51 75 69 |urn requ|estedQui|
|00003770| 74 3b 0d 7d 0d 0d 0d 0d | 0d 2f 2a 20 20 54 68 65 |t;.}....|./* The|
|00003780| 20 61 64 76 65 72 74 69 | 73 65 28 29 20 66 75 6e | adverti|se() fun|
|00003790| 63 74 69 6f 6e 20 61 64 | 76 65 72 74 69 73 65 73 |ction ad|vertises|
|000037a0| 20 74 68 65 20 73 65 72 | 76 65 72 27 73 20 6e 61 | the ser|ver's na|
|000037b0| 6d 65 20 6f 6e 20 74 68 | 65 20 6e 65 74 77 6f 72 |me on th|e networ|
|000037c0| 6b 2e 20 54 68 65 0d 66 | 75 6e 63 74 69 6f 6e 20 |k. The.f|unction |
|000037d0| 70 61 72 73 65 73 20 74 | 68 65 20 6e 61 6d 65 20 |parses t|he name |
|000037e0| 73 74 72 69 6e 67 20 53 | 65 72 76 65 72 4e 61 6d |string S|erverNam|
|000037f0| 65 3a 41 54 50 5f 53 65 | 72 76 65 72 2e 4e 41 54 |e:ATP_Se|rver.NAT|
|00003800| 49 56 45 40 7a 6f 6e 65 | 6e 61 6d 65 0d 69 6e 74 |IVE@zone|name.int|
|00003810| 6f 20 61 6e 20 6e 62 70 | 20 6e 61 6d 65 20 77 69 |o an nbp| name wi|
|00003820| 74 68 20 61 20 74 79 70 | 65 2c 20 6f 62 6a 65 63 |th a typ|e, objec|
|00003830| 74 2c 20 61 6e 64 20 7a | 6f 6e 65 2e 20 20 54 68 |t, and z|one. Th|
|00003840| 65 6e 2c 20 69 74 0d 72 | 65 67 69 73 74 65 72 73 |en, it.r|egisters|
|00003850| 20 74 68 65 20 6e 61 6d | 65 20 77 69 74 68 20 74 | the nam|e with t|
|00003860| 68 65 20 69 6e 74 65 72 | 6e 65 74 2e 20 20 2a 2f |he inter|net. */|
|00003870| 0d 69 6e 74 20 61 64 76 | 65 72 74 69 73 65 28 20 |.int adv|ertise( |
|00003880| 69 6e 74 20 66 64 2c 20 | 63 68 61 72 20 2a 20 6e |int fd, |char * n|
|00003890| 62 70 5f 6e 61 6d 65 29 | 0d 7b 0d 09 69 6e 74 20 |bp_name)|.{..int |
|000038a0| 65 72 72 3b 0d 09 41 54 | 52 65 74 72 79 5f 74 20 |err;..AT|Retry_t |
|000038b0| 72 65 74 72 79 3b 0d 09 | 0d 09 2f 2a 0d 09 2a 20 |retry;..|../*..* |
|000038c0| 53 65 74 20 75 70 20 74 | 68 65 20 73 74 72 75 63 |Set up t|he struc|
|000038d0| 74 75 72 65 20 74 68 61 | 74 20 68 6f 6c 64 73 20 |ture tha|t holds |
|000038e0| 74 68 65 20 74 69 6d 65 | 6f 75 74 20 61 6e 64 20 |the time|out and |
|000038f0| 72 65 74 72 69 65 73 2e | 0d 09 2a 2f 0d 09 0d 09 |retries.|..*/....|
|00003900| 72 65 74 72 79 2e 69 6e | 74 65 72 76 61 6c 20 3d |retry.in|terval =|
|00003910| 20 31 30 30 30 3b 20 2f | 2a 20 54 69 6d 65 6f 75 | 1000; /|* Timeou|
|00003920| 74 20 56 61 6c 75 65 2e | 20 2a 2f 0d 09 72 65 74 |t Value.| */..ret|
|00003930| 72 79 2e 72 65 74 72 69 | 65 73 20 20 3d 20 38 3b |ry.retri|es = 8;|
|00003940| 20 2f 2a 20 4e 75 6d 62 | 65 72 20 6f 66 20 72 65 | /* Numb|er of re|
|00003950| 74 72 69 65 73 2e 2a 2f | 0d 09 72 65 74 72 79 2e |tries.*/|..retry.|
|00003960| 62 61 63 6b 6f 66 66 20 | 3d 20 32 3b 20 20 2f 2a |backoff |= 2; /*|
|00003970| 20 47 72 61 64 75 61 6c | 6c 79 20 69 6e 63 72 65 | Gradual|ly incre|
|00003980| 61 73 65 73 20 69 6e 20 | 74 69 6d 65 20 62 65 74 |ases in |time bet|
|00003990| 77 65 65 6e 20 72 65 74 | 72 69 65 73 2e 20 2a 2f |ween ret|ries. */|
|000039a0| 0d 09 0d 09 69 66 20 28 | 65 72 72 20 3d 20 41 54 |....if (|err = AT|
|000039b0| 4e 62 70 50 61 72 73 65 | 45 6e 74 69 74 79 28 26 |NbpParse|Entity(&|
|000039c0| 74 68 69 73 45 6e 74 69 | 74 79 2c 20 6e 62 70 5f |thisEnti|ty, nbp_|
|000039d0| 6e 61 6d 65 29 29 0d 09 | 7b 0d 09 09 20 70 72 69 |name))..|{... pri|
|000039e0| 6e 74 66 28 22 41 54 4e | 62 70 50 61 72 73 65 45 |ntf("ATN|bpParseE|
|000039f0| 6e 74 69 74 79 20 66 61 | 69 6c 65 64 3a 20 65 72 |ntity fa|iled: er|
|00003a00| 72 20 3d 20 25 78 5c 6e | 22 2c 65 72 72 29 3b 0d |r = %x\n|",err);.|
|00003a10| 09 09 20 72 65 74 75 72 | 6e 20 53 54 52 45 41 4d |.. retur|n STREAM|
|00003a20| 5f 45 52 52 4f 52 3b 20 | 20 20 2f 2a 20 43 6c 65 |_ERROR; | /* Cle|
|00003a30| 61 6e 20 75 70 20 61 6e | 64 20 65 78 69 74 20 69 |an up an|d exit i|
|00003a40| 73 20 64 6f 6e 65 20 69 | 6e 20 6d 61 69 6e 2e 20 |s done i|n main. |
|00003a50| 2a 2f 0d 09 7d 0d 09 69 | 66 20 28 65 72 72 20 3d |*/..}..i|f (err =|
|00003a60| 20 41 54 4e 62 70 52 65 | 67 69 73 74 65 72 28 20 | ATNbpRe|gister( |
|00003a70| 26 74 68 69 73 45 6e 74 | 69 74 79 2c 20 66 64 2c |&thisEnt|ity, fd,|
|00003a80| 20 28 41 54 52 65 74 72 | 79 5f 74 20 2a 29 26 72 | (ATRetr|y_t *)&r|
|00003a90| 65 74 72 79 29 29 0d 09 | 7b 0d 09 09 20 70 72 69 |etry))..|{... pri|
|00003aa0| 6e 74 66 28 22 41 54 4e | 62 70 52 65 67 69 73 74 |ntf("ATN|bpRegist|
|00003ab0| 65 72 20 66 61 69 6c 65 | 64 3a 20 65 72 72 20 3d |er faile|d: err =|
|00003ac0| 20 25 78 5c 6e 22 2c 65 | 72 72 29 3b 0d 09 09 20 | %x\n",e|rr);... |
|00003ad0| 72 65 74 75 72 6e 20 53 | 54 52 45 41 4d 5f 45 52 |return S|TREAM_ER|
|00003ae0| 52 4f 52 3b 20 20 20 2f | 2a 20 43 6c 65 61 6e 20 |ROR; /|* Clean |
|00003af0| 75 70 20 61 6e 64 20 65 | 78 69 74 20 69 73 20 64 |up and e|xit is d|
|00003b00| 6f 6e 65 20 69 6e 20 6d | 61 69 6e 2e 20 2a 2f 0d |one in m|ain. */.|
|00003b10| 09 7d 0d 09 0d 09 72 65 | 74 75 72 6e 20 30 3b 0d |.}....re|turn 0;.|
|00003b20| 7d 0d 0d 2f 2a 0d 09 43 | 6c 65 61 6e 55 70 46 75 |}../*..C|leanUpFu|
|00003b30| 6e 63 20 69 73 20 72 65 | 67 69 73 74 65 72 65 64 |nc is re|gistered|
|00003b40| 20 61 74 20 74 68 65 20 | 62 65 67 69 6e 6e 69 6e | at the |beginnin|
|00003b50| 67 20 6f 66 20 6f 75 72 | 20 70 72 6f 67 72 61 6d |g of our| program|
|00003b60| 2e 20 20 49 66 0d 09 61 | 6e 79 20 6f 66 20 74 68 |. If..a|ny of th|
|00003b70| 65 73 65 20 73 69 67 6e | 61 6c 20 63 6f 6e 64 69 |ese sign|al condi|
|00003b80| 74 69 6f 6e 73 20 68 61 | 70 70 65 6e 2c 20 74 68 |tions ha|ppen, th|
|00003b90| 65 20 61 70 70 72 6f 70 | 72 69 61 74 65 20 63 6f |e approp|riate co|
|00003ba0| 64 65 20 77 69 6c 6c 0d | 09 62 65 20 65 78 65 63 |de will.|.be exec|
|00003bb0| 75 74 65 64 2e 20 20 49 | 66 20 74 68 65 20 4e 4c |uted. I|f the NL|
|00003bc0| 4d 20 69 73 20 75 6e 6c | 6f 61 64 65 64 20 61 74 |M is unl|oaded at|
|00003bd0| 20 74 68 65 20 63 6f 6e | 73 6f 6c 65 2c 20 53 49 | the con|sole, SI|
|00003be0| 47 54 45 52 4d 20 69 73 | 0d 09 72 61 69 73 65 64 |GTERM is|..raised|
|00003bf0| 2e 0d 2a 2f 0d 76 6f 69 | 64 20 43 6c 65 61 6e 55 |..*/.voi|d CleanU|
|00003c00| 70 46 75 6e 63 28 69 6e | 74 20 73 69 67 6e 61 6c |pFunc(in|t signal|
|00003c10| 43 6f 6e 64 69 74 69 6f | 6e 29 0d 7b 0d 09 69 6e |Conditio|n).{..in|
|00003c20| 74 20 65 72 72 3b 0d 09 | 69 6e 74 20 69 20 3d 20 |t err;..|int i = |
|00003c30| 30 3b 0d 09 0d 20 20 20 | 20 73 77 69 74 63 68 28 |0;... | switch(|
|00003c40| 73 69 67 6e 61 6c 43 6f | 6e 64 69 74 69 6f 6e 29 |signalCo|ndition)|
|00003c50| 0d 20 20 20 20 7b 0d 20 | 20 20 20 20 20 20 63 61 |. {. | ca|
|00003c60| 73 65 20 28 53 49 47 54 | 45 52 4d 29 20 3a 0d 09 |se (SIGT|ERM) :..|
|00003c70| 20 20 20 20 43 6f 6e 73 | 6f 6c 65 50 72 69 6e 74 | Cons|olePrint|
|00003c80| 66 28 22 55 6e 6c 6f 61 | 64 20 44 65 74 65 63 74 |f("Unloa|d Detect|
|00003c90| 65 64 20 69 6e 20 43 6c | 65 61 6e 55 70 20 46 75 |ed in Cl|eanUp Fu|
|00003ca0| 6e 63 74 69 6f 6e 21 5c | 6e 5c 72 22 29 20 3b 0d |nction!\|n\r") ;.|
|00003cb0| 09 20 20 20 20 65 78 69 | 74 69 6e 67 4e 4c 4d 20 |. exi|tingNLM |
|00003cc0| 3d 20 54 52 55 45 3b 0d | 09 20 20 20 20 0d 09 09 |= TRUE;.|. ...|
|00003cd0| 09 43 6f 6e 73 6f 6c 65 | 50 72 69 6e 74 66 28 22 |.Console|Printf("|
|00003ce0| 43 61 6c 6c 69 6e 67 20 | 41 54 4e 62 70 52 65 6d |Calling |ATNbpRem|
|00003cf0| 6f 76 65 2e 2e 2e 5c 6e | 22 29 3b 0d 09 09 09 69 |ove...\n|");....i|
|00003d00| 66 28 65 72 72 20 3d 20 | 41 54 4e 62 70 52 65 6d |f(err = |ATNbpRem|
|00003d10| 6f 76 65 28 26 74 68 69 | 73 45 6e 74 69 74 79 2c |ove(&thi|sEntity,|
|00003d20| 2a 6d 79 5f 66 64 29 29 | 0d 09 09 09 7b 0d 09 09 |*my_fd))|....{...|
|00003d30| 09 09 20 70 72 69 6e 74 | 66 28 22 41 54 4e 62 70 |.. print|f("ATNbp|
|00003d40| 52 65 6d 6f 76 65 20 66 | 61 69 6c 65 64 3a 20 65 |Remove f|ailed: e|
|00003d50| 72 72 20 3d 20 25 78 5c | 6e 22 2c 65 72 72 29 3b |rr = %x\|n",err);|
|00003d60| 0d 09 09 09 09 20 65 78 | 69 74 28 5f 5f 4c 49 4e |..... ex|it(__LIN|
|00003d70| 45 5f 5f 29 3b 0d 09 09 | 09 7d 0d 0d 0d 2f 2f 20 |E__);...|.}...// |
|00003d80| 20 20 20 20 20 20 20 20 | 20 43 6c 6f 73 65 20 74 | | Close t|
|00003d90| 68 65 20 41 54 50 20 73 | 6f 63 6b 65 74 20 67 72 |he ATP s|ocket gr|
|00003da0| 61 63 65 66 75 6c 6c 79 | 2e 20 20 20 20 20 20 20 |acefully|. |
|00003db0| 20 20 20 20 20 20 20 20 | 20 0d 09 09 09 43 6f 6e | | ....Con|
|00003dc0| 73 6f 6c 65 50 72 69 6e | 74 66 28 22 43 61 6c 6c |solePrin|tf("Call|
|00003dd0| 69 6e 67 20 41 54 41 74 | 70 43 6c 6f 73 65 20 6f |ing ATAt|pClose o|
|00003de0| 6e 20 25 64 5c 6e 22 2c | 20 2a 6d 79 5f 66 64 29 |n %d\n",| *my_fd)|
|00003df0| 3b 0d 09 09 09 69 66 28 | 65 72 72 20 3d 20 41 54 |;....if(|err = AT|
|00003e00| 41 74 70 43 6c 6f 73 65 | 28 2a 6d 79 5f 66 64 29 |AtpClose|(*my_fd)|
|00003e10| 29 0d 09 09 09 7b 0d 09 | 09 09 09 20 70 72 69 6e |)....{..|... prin|
|00003e20| 74 66 28 22 41 54 41 74 | 70 43 6c 6f 73 65 20 66 |tf("ATAt|pClose f|
|00003e30| 61 69 6c 65 64 3a 20 65 | 72 72 20 3d 20 25 78 5c |ailed: e|rr = %x\|
|00003e40| 6e 22 2c 20 65 72 72 29 | 3b 0d 09 09 09 09 20 65 |n", err)|;..... e|
|00003e50| 78 69 74 28 5f 5f 4c 49 | 4e 45 5f 5f 29 3b 0d 09 |xit(__LI|NE__);..|
|00003e60| 09 09 7d 20 20 20 20 20 | 20 20 0d 0d 2f 2f 20 20 |..} | ..// |
|00003e70| 20 20 20 20 47 69 76 65 | 20 74 68 65 20 76 61 72 | Give| the var|
|00003e80| 69 6f 75 73 20 74 68 72 | 65 61 64 73 20 61 20 63 |ious thr|eads a c|
|00003e90| 68 61 6e 63 65 20 74 6f | 20 63 6c 65 61 6e 20 75 |hance to| clean u|
|00003ea0| 70 0d 2f 2f 20 20 20 20 | 20 20 49 66 20 69 74 20 |p.// | If it |
|00003eb0| 68 61 73 6e 27 74 20 68 | 61 70 70 65 6e 65 64 20 |hasn't h|appened |
|00003ec0| 69 6e 20 33 30 30 20 74 | 68 72 65 61 64 20 73 77 |in 300 t|hread sw|
|00003ed0| 69 74 63 68 65 73 2c 20 | 67 69 76 65 20 75 70 2e |itches, |give up.|
|00003ee0| 0d 09 20 20 20 20 77 68 | 69 6c 65 28 74 68 72 65 |.. wh|ile(thre|
|00003ef0| 61 64 43 6f 75 6e 74 20 | 3e 20 30 20 26 20 69 2b |adCount |> 0 & i+|
|00003f00| 2b 20 3c 20 33 30 30 29 | 0d 09 20 20 20 20 7b 0d |+ < 300)|.. {.|
|00003f10| 09 09 20 20 20 20 43 6f | 6e 73 6f 6c 65 50 72 69 |.. Co|nsolePri|
|00003f20| 6e 74 66 28 22 54 68 72 | 65 61 64 43 6f 75 6e 74 |ntf("Thr|eadCount|
|00003f30| 3a 20 25 64 5c 6e 22 2c | 20 74 68 72 65 61 64 43 |: %d\n",| threadC|
|00003f40| 6f 75 6e 74 29 3b 0d 09 | 09 09 09 54 68 72 65 61 |ount);..|...Threa|
|00003f50| 64 53 77 69 74 63 68 57 | 69 74 68 44 65 6c 61 79 |dSwitchW|ithDelay|
|00003f60| 28 29 20 3b 0d 09 09 7d | 0d 20 20 0d 2f 2f 20 20 |() ;...}|. .// |
|00003f70| 20 20 20 20 47 69 6d 65 | 20 6d 61 69 6e 28 29 20 | Gime| main() |
|00003f80| 6f 6e 65 20 6c 61 73 74 | 20 63 68 61 6e 63 65 20 |one last| chance |
|00003f90| 74 6f 20 63 6c 65 61 6e | 20 75 70 0d 09 20 20 20 |to clean| up.. |
|00003fa0| 20 54 68 72 65 61 64 53 | 77 69 74 63 68 57 69 74 | ThreadS|witchWit|
|00003fb0| 68 44 65 6c 61 79 28 29 | 20 3b 0d 09 62 72 65 61 |hDelay()| ;..brea|
|00003fc0| 6b 20 3b 0d 09 63 61 73 | 65 20 28 53 49 47 41 42 |k ;..cas|e (SIGAB|
|00003fd0| 52 54 29 20 3a 0d 09 63 | 61 73 65 20 28 53 49 47 |RT) :..c|ase (SIG|
|00003fe0| 49 4e 54 29 20 3a 0d 09 | 09 09 65 78 69 74 28 5f |INT) :..|..exit(_|
|00003ff0| 5f 4c 49 4e 45 5f 5f 29 | 3b 0d 09 62 72 65 61 6b |_LINE__)|;..break|
|00004000| 20 3b 0d 09 64 65 66 61 | 75 6c 74 20 3a 0d 09 20 | ;..defa|ult :.. |
|00004010| 20 20 20 43 6f 6e 73 6f | 6c 65 50 72 69 6e 74 66 | Conso|lePrintf|
|00004020| 28 22 55 6e 6b 6e 6f 77 | 6e 20 53 69 67 6e 61 6c |("Unknow|n Signal|
|00004030| 20 43 6f 6e 64 69 74 69 | 6f 6e 5c 6e 5c 72 22 29 | Conditi|on\n\r")|
|00004040| 20 3b 0d 20 20 20 20 7d | 0d 7d 0d 00 00 00 00 00 | ;. }|.}......|
|00004050| 00 00 00 00 00 00 00 00 | 00 00 00 00 00 00 00 00 |........|........|
|00004060| 00 00 00 00 00 00 00 00 | 00 00 00 00 00 00 00 00 |........|........|
|00004070| 00 00 00 00 00 00 00 00 | 00 00 00 00 00 00 00 00 |........|........|
|00004080| 00 00 01 00 00 00 01 6e | 00 00 00 6e 00 00 00 3e |.......n|...n...>|
|00004090| 6c 65 20 70 72 6f 67 72 | 61 6d 20 61 77 61 69 74 |le progr|am await|
|000040a0| 73 20 61 6e 20 41 54 50 | 20 63 6f 6e 6e 65 63 74 |s an ATP| connect|
|000040b0| 08 41 54 44 65 6d 6f 2e | 63 00 02 00 00 00 54 45 |.ATDemo.|c.....TE|
|000040c0| 58 54 4d 50 53 20 01 00 | 00 00 00 00 00 00 00 00 |XTMPS ..|........|
|000040d0| 00 00 54 45 58 54 4d 50 | 53 20 01 00 00 00 00 00 |..TEXTMP|S ......|
|000040e0| 00 00 00 00 00 00 00 00 | 00 00 00 00 00 00 00 00 |........|........|
|000040f0| 00 00 aa b9 b2 c0 00 00 | 3f cb 00 00 01 ac 74 68 |........|?.....th|
|00004100| 65 20 63 6f 6e 76 65 72 | 73 61 74 69 6f 6e 20 77 |e conver|sation w|
|00004110| 69 74 68 20 74 68 65 20 | 63 6c 69 65 6e 74 2c 20 |ith the |client, |
|00004120| 77 68 69 63 68 0d 20 2a | 20 20 20 63 61 6e 20 69 |which. *| can i|
|00004130| 6e 63 6c 75 64 65 20 61 | 6e 20 61 72 62 69 74 72 |nclude a|n arbitr|
|00004140| 61 72 79 20 6e 75 6d 62 | 65 72 20 6f 66 20 71 75 |ary numb|er of qu|
|00004150| 65 72 69 65 73 20 72 65 | 67 61 72 64 69 6e 67 20 |eries re|garding |
|00004160| 63 65 72 74 61 69 6e 20 | 73 65 72 76 65 72 20 69 |certain |server i|
|00004170| 6e 66 6f 72 6d 61 74 69 | 6f 6e 2e 0d 20 2a 20 20 |nformati|on.. * |
|00004180| 00 00 00 48 00 09 4d 6f | 6e 61 63 6f 00 61 20 63 |...H..Mo|naco.a c|
|00004190| 6c 69 65 6e 74 2e 20 20 | 57 68 65 6e 20 69 74 20 |lient. |When it |
|000041a0| 67 65 74 73 20 6f 00 06 | 00 04 00 6e 01 59 02 d9 |gets o..|...n.Y..|
|000041b0| 03 b7 00 50 00 20 02 bb | 02 7e aa b9 b6 a2 00 00 |...P. ..|.~......|
|000041c0| 06 d8 00 00 06 d8 00 00 | 23 9a 01 00 00 00 00 1e |........|#.......|
|000041d0| 00 6e 01 59 02 d9 03 b7 | 00 50 00 20 02 bb 02 7e |.n.Y....|.P. ...~|
|000041e0| 00 00 23 9a 00 00 00 00 | 00 00 00 00 00 00 00 00 |..#.....|........|
|000041f0| 01 00 00 00 01 6e 00 00 | 00 6e 00 00 00 3e 01 5a |.....n..|.n...>.Z|
|00004200| 44 88 1a d0 00 00 00 1c | 00 3e 00 00 4d 50 53 52 |D.......|.>..MPSR|
|00004210| 00 01 00 0a 03 ed ff ff | 00 00 00 00 00 00 00 00 |........|........|
|00004220| 03 f0 ff ff 00 00 00 4c | 01 5c 9c a0 00 00 00 00 |.......L|.\......|
|00004230| 00 00 00 00 00 00 00 00 | 00 00 00 00 00 00 00 00 |........|........|
|00004240| 00 00 00 00 00 00 00 00 | 00 00 00 00 00 00 00 00 |........|........|
|00004250| 00 00 00 00 00 00 00 00 | 00 00 00 00 00 00 00 00 |........|........|
|00004260| 00 00 00 00 00 00 00 00 | 00 00 00 00 00 00 00 00 |........|........|
|00004270| 00 00 00 00 00 00 00 00 | 00 00 00 00 00 00 00 00 |........|........|
+--------+-------------------------+-------------------------+--------+--------+