ucspi-tcp-0.88-ipv6.patch 128 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977
  1. diff -uNr ucspi-tcp-0.88.orig/FILES ucspi-tcp-0.88/FILES
  2. --- ucspi-tcp-0.88.orig/FILES 2009-08-04 15:19:16.000000000 -0500
  3. +++ ucspi-tcp-0.88/FILES 2009-08-04 17:45:59.000000000 -0500
  4. @@ -216,3 +216,40 @@
  5. warn-auto.sh
  6. warn-shsgr
  7. x86cpuid.c
  8. +dns_ip6.c
  9. +dns_ipq6.c
  10. +dns_nd6.c
  11. +dns_sortip6.c
  12. +fmt_xlong.c
  13. +ip6_fmt.c
  14. +ip6_scan.c
  15. +scan_0x.c
  16. +socket_accept6.c
  17. +socket_bind6.c
  18. +socket_conn6.c
  19. +socket_local6.c
  20. +socket_recv6.c
  21. +socket_remote6.c
  22. +socket_send6.c
  23. +socket_tcp6.c
  24. +timeoutconn6.c
  25. +tryip6.c
  26. +haveip6.h2
  27. +haveip6.h1
  28. +remoteinfo6.c
  29. +addcr.1
  30. +argv0.1
  31. +date@.1
  32. +delcr.1
  33. +finger@.1
  34. +fixcr.1
  35. +http@.1
  36. +mconnect.1
  37. +recordio.1
  38. +tcp-environ.5
  39. +tcpcat.1
  40. +tcpclient.1
  41. +tcprules.1
  42. +tcprulescheck.1
  43. +tcpserver.1
  44. +who@.1
  45. diff -uNr ucspi-tcp-0.88.orig/Makefile ucspi-tcp-0.88/Makefile
  46. --- ucspi-tcp-0.88.orig/Makefile 2009-08-04 15:19:16.000000000 -0500
  47. +++ ucspi-tcp-0.88/Makefile 2009-08-04 17:45:59.000000000 -0500
  48. @@ -76,12 +76,14 @@
  49. makelib byte_chr.o byte_copy.o byte_cr.o byte_diff.o byte_rchr.o \
  50. byte_zero.o case_diffb.o case_diffs.o fmt_ulong.o ip4_fmt.o \
  51. ip4_scan.o scan_ulong.o str_chr.o str_diff.o str_len.o str_start.o \
  52. -uint16_pack.o uint16_unpack.o uint32_pack.o uint32_unpack.o
  53. +uint16_pack.o uint16_unpack.o uint32_pack.o uint32_unpack.o \
  54. +ip6_fmt.o scan_ip6.o scan_xlong.o fmt_xlong.o
  55. ./makelib byte.a byte_chr.o byte_copy.o byte_cr.o \
  56. byte_diff.o byte_rchr.o byte_zero.o case_diffb.o \
  57. case_diffs.o fmt_ulong.o ip4_fmt.o ip4_scan.o scan_ulong.o \
  58. str_chr.o str_diff.o str_len.o str_start.o uint16_pack.o \
  59. - uint16_unpack.o uint32_pack.o uint32_unpack.o
  60. + uint16_unpack.o uint32_pack.o uint32_unpack.o ip6_fmt.o \
  61. + scan_ip6.o scan_xlong.o fmt_xlong.o
  62. byte_chr.o: \
  63. compile byte_chr.c byte.h
  64. @@ -181,11 +183,13 @@
  65. dns.a: \
  66. makelib dns_dfd.o dns_domain.o dns_dtda.o dns_ip.o dns_ipq.o \
  67. dns_name.o dns_nd.o dns_packet.o dns_random.o dns_rcip.o dns_rcrw.o \
  68. -dns_resolve.o dns_sortip.o dns_transmit.o dns_txt.o
  69. +dns_resolve.o dns_sortip.o dns_transmit.o dns_txt.o dns_ip6.o \
  70. +dns_sortip6.o dns_nd6.o dns_ipq6.o
  71. ./makelib dns.a dns_dfd.o dns_domain.o dns_dtda.o dns_ip.o \
  72. dns_ipq.o dns_name.o dns_nd.o dns_packet.o dns_random.o \
  73. dns_rcip.o dns_rcrw.o dns_resolve.o dns_sortip.o \
  74. - dns_transmit.o dns_txt.o
  75. + dns_transmit.o dns_txt.o dns_ip6.o dns_sortip6.o dns_nd6.o \
  76. + dns_ipq6.o
  77. dns_dfd.o: \
  78. compile dns_dfd.c error.h alloc.h byte.h dns.h stralloc.h gen_alloc.h \
  79. @@ -257,7 +261,7 @@
  80. dns_transmit.o: \
  81. compile dns_transmit.c socket.h uint16.h alloc.h error.h byte.h \
  82. readwrite.h uint16.h dns.h stralloc.h gen_alloc.h iopause.h taia.h \
  83. -tai.h uint64.h taia.h
  84. +tai.h uint64.h taia.h uint32.h
  85. ./compile dns_transmit.c
  86. dns_txt.o: \
  87. @@ -498,9 +502,15 @@
  88. remoteinfo.o: \
  89. compile remoteinfo.c fmt.h buffer.h socket.h uint16.h error.h \
  90. iopause.h taia.h tai.h uint64.h timeoutconn.h uint16.h remoteinfo.h \
  91. -stralloc.h gen_alloc.h uint16.h
  92. +stralloc.h gen_alloc.h uint16.h uint32.h
  93. ./compile remoteinfo.c
  94. +remoteinfo6.o: \
  95. +compile remoteinfo6.c fmt.h buffer.h socket.h uint16.h error.h \
  96. +iopause.h taia.h tai.h uint64.h timeoutconn.h uint16.h remoteinfo.h \
  97. +stralloc.h gen_alloc.h uint16.h uint32.h
  98. + ./compile remoteinfo6.c
  99. +
  100. rts: \
  101. warn-auto.sh rts.sh conf-home
  102. cat warn-auto.sh rts.sh \
  103. @@ -557,43 +567,43 @@
  104. rm -f trylsock.o trylsock
  105. socket_accept.o: \
  106. -compile socket_accept.c byte.h socket.h uint16.h
  107. +compile socket_accept.c byte.h socket.h uint16.h uint32.h
  108. ./compile socket_accept.c
  109. socket_bind.o: \
  110. -compile socket_bind.c byte.h socket.h uint16.h
  111. +compile socket_bind.c byte.h socket.h uint16.h uint32.h
  112. ./compile socket_bind.c
  113. socket_conn.o: \
  114. -compile socket_conn.c readwrite.h byte.h socket.h uint16.h
  115. +compile socket_conn.c readwrite.h byte.h socket.h uint16.h uint32.h
  116. ./compile socket_conn.c
  117. socket_delay.o: \
  118. -compile socket_delay.c socket.h uint16.h
  119. +compile socket_delay.c socket.h uint16.h uint32.h
  120. ./compile socket_delay.c
  121. socket_listen.o: \
  122. -compile socket_listen.c socket.h uint16.h
  123. +compile socket_listen.c socket.h uint16.h uint32.h
  124. ./compile socket_listen.c
  125. socket_local.o: \
  126. -compile socket_local.c byte.h socket.h uint16.h
  127. +compile socket_local.c byte.h socket.h uint16.h uint32.h
  128. ./compile socket_local.c
  129. socket_opts.o: \
  130. -compile socket_opts.c socket.h uint16.h
  131. +compile socket_opts.c socket.h uint16.h uint32.h
  132. ./compile socket_opts.c
  133. socket_remote.o: \
  134. -compile socket_remote.c byte.h socket.h uint16.h
  135. +compile socket_remote.c byte.h socket.h uint16.h uint32.h
  136. ./compile socket_remote.c
  137. socket_tcp.o: \
  138. -compile socket_tcp.c ndelay.h socket.h uint16.h
  139. +compile socket_tcp.c ndelay.h socket.h uint16.h uint32.h
  140. ./compile socket_tcp.c
  141. socket_udp.o: \
  142. -compile socket_udp.c ndelay.h socket.h uint16.h
  143. +compile socket_udp.c ndelay.h socket.h uint16.h uint32.h
  144. ./compile socket_udp.c
  145. str_chr.o: \
  146. @@ -710,9 +720,9 @@
  147. chmod 755 tcpcat
  148. tcpclient: \
  149. -load tcpclient.o remoteinfo.o timeoutconn.o dns.a time.a unix.a \
  150. -byte.a socket.lib
  151. - ./load tcpclient remoteinfo.o timeoutconn.o dns.a time.a \
  152. +load tcpclient.o remoteinfo6.o dns.a time.a unix.a \
  153. +byte.a socket.lib byte.h timeoutconn6.o
  154. + ./load tcpclient remoteinfo6.o timeoutconn6.o dns.a time.a \
  155. unix.a byte.a `cat socket.lib`
  156. tcpclient.o: \
  157. @@ -720,7 +730,7 @@
  158. scan.h str.h ip4.h uint16.h socket.h uint16.h fd.h stralloc.h \
  159. gen_alloc.h buffer.h error.h strerr.h pathexec.h timeoutconn.h \
  160. uint16.h remoteinfo.h stralloc.h uint16.h dns.h stralloc.h iopause.h \
  161. -taia.h tai.h uint64.h taia.h
  162. +taia.h tai.h uint64.h taia.h uint32.h
  163. ./compile tcpclient.c
  164. tcprules: \
  165. @@ -742,9 +752,9 @@
  166. ./compile tcprulescheck.c
  167. tcpserver: \
  168. -load tcpserver.o rules.o remoteinfo.o timeoutconn.o cdb.a dns.a \
  169. +load tcpserver.o rules.o remoteinfo6.o timeoutconn6.o cdb.a dns.a \
  170. time.a unix.a byte.a socket.lib
  171. - ./load tcpserver rules.o remoteinfo.o timeoutconn.o cdb.a \
  172. + ./load tcpserver rules.o remoteinfo6.o timeoutconn6.o cdb.a \
  173. dns.a time.a unix.a byte.a `cat socket.lib`
  174. tcpserver.o: \
  175. @@ -753,7 +763,7 @@
  176. alloc.h buffer.h error.h strerr.h sgetopt.h subgetopt.h pathexec.h \
  177. socket.h uint16.h ndelay.h remoteinfo.h stralloc.h uint16.h rules.h \
  178. stralloc.h sig.h dns.h stralloc.h iopause.h taia.h tai.h uint64.h \
  179. -taia.h
  180. +taia.h uint32.h
  181. ./compile tcpserver.c
  182. time.a: \
  183. @@ -765,9 +775,14 @@
  184. timeoutconn.o: \
  185. compile timeoutconn.c ndelay.h socket.h uint16.h iopause.h taia.h \
  186. -tai.h uint64.h error.h timeoutconn.h uint16.h
  187. +tai.h uint64.h error.h timeoutconn.h uint16.h uint32.h
  188. ./compile timeoutconn.c
  189. +timeoutconn6.o: \
  190. +compile timeoutconn6.c ndelay.h socket.h uint16.h iopause.h taia.h \
  191. +tai.h uint64.h error.h timeoutconn.h uint16.h uint32.h
  192. + ./compile timeoutconn6.c
  193. +
  194. uint16_pack.o: \
  195. compile uint16_pack.c uint16.h
  196. ./compile uint16_pack.c
  197. @@ -806,7 +821,12 @@
  198. socket_opts.o socket_remote.o socket_tcp.o socket_udp.o \
  199. stralloc_cat.o stralloc_catb.o stralloc_cats.o stralloc_copy.o \
  200. stralloc_eady.o stralloc_opyb.o stralloc_opys.o stralloc_pend.o \
  201. -strerr_die.o strerr_sys.o subgetopt.o wait_nohang.o wait_pid.o
  202. +strerr_die.o strerr_sys.o subgetopt.o wait_nohang.o wait_pid.o \
  203. +socket_conn6.o socket_bind6.o socket_accept6.o socket_recv6.o \
  204. +socket_send6.o socket_local6.o socket_remote6.o socket_tcp6.o \
  205. +socket_getifname.o socket_getifidx.o socket_v4mappedprefix.o \
  206. +socket_ip4loopback.o socket_v6any.o socket_v6loopback.o \
  207. +socket_udp6.o
  208. ./makelib unix.a alloc.o alloc_re.o buffer.o buffer_0.o \
  209. buffer_1.o buffer_2.o buffer_copy.o buffer_get.o \
  210. buffer_put.o env.o error.o error_str.o fd_copy.o fd_move.o \
  211. @@ -819,7 +839,12 @@
  212. socket_udp.o stralloc_cat.o stralloc_catb.o stralloc_cats.o \
  213. stralloc_copy.o stralloc_eady.o stralloc_opyb.o \
  214. stralloc_opys.o stralloc_pend.o strerr_die.o strerr_sys.o \
  215. - subgetopt.o wait_nohang.o wait_pid.o
  216. + subgetopt.o wait_nohang.o wait_pid.o socket_conn6.o \
  217. + socket_bind6.o socket_accept6.o socket_recv6.o socket_send6.o \
  218. + socket_local6.o socket_remote6.o socket_tcp6.o \
  219. + socket_getifname.o socket_getifidx.o socket_v4mappedprefix.o \
  220. + socket_ip4loopback.o socket_v6any.o socket_v6loopback.o \
  221. + socket_udp6.o
  222. wait_nohang.o: \
  223. compile wait_nohang.c haswaitp.h
  224. @@ -835,3 +860,110 @@
  225. | sed s}HOME}"`head -1 conf-home`"}g \
  226. > who@
  227. chmod 755 who@
  228. +
  229. +socket_conn6.o: \
  230. +compile socket_conn6.c socket.h uint16.h haveip6.h error.h ip6.h \
  231. +uint32.h
  232. + ./compile socket_conn6.c
  233. +
  234. +socket_bind6.o: \
  235. +compile socket_bind6.c socket.h uint16.h haveip6.h error.h ip6.h \
  236. +uint32.h
  237. + ./compile socket_bind6.c
  238. +
  239. +socket_accept6.o: \
  240. +compile socket_accept6.c socket.h uint16.h haveip6.h error.h ip6.h \
  241. +uint32.h
  242. + ./compile socket_accept6.c
  243. +
  244. +socket_recv6.o: \
  245. +compile socket_recv6.c socket.h uint16.h haveip6.h error.h ip6.h \
  246. +uint32.h
  247. + ./compile socket_recv6.c
  248. +
  249. +socket_send6.o: \
  250. +compile socket_send6.c socket.h uint16.h haveip6.h error.h uint32.h
  251. + ./compile socket_send6.c
  252. +
  253. +socket_local6.o: \
  254. +compile socket_local6.c socket.h uint16.h haveip6.h error.h uint32.h
  255. + ./compile socket_local6.c
  256. +
  257. +socket_remote6.o: \
  258. +compile socket_remote6.c socket.h uint16.h haveip6.h error.h uint32.h
  259. + ./compile socket_remote6.c
  260. +
  261. +dns_sortip6.o: \
  262. +compile dns_sortip6.c byte.h dns.h stralloc.h gen_alloc.h iopause.h \
  263. +taia.h tai.h uint64.h taia.h
  264. + ./compile dns_sortip6.c
  265. +
  266. +dns_nd6.o: \
  267. +compile dns_nd6.c byte.h fmt.h dns.h stralloc.h gen_alloc.h iopause.h \
  268. +taia.h tai.h uint64.h taia.h
  269. + ./compile dns_nd6.c
  270. +
  271. +dns_ipq6.o: \
  272. +compile dns_ipq6.c stralloc.h gen_alloc.h case.h byte.h str.h dns.h \
  273. +stralloc.h iopause.h taia.h tai.h uint64.h taia.h ip6.h
  274. + ./compile dns_ipq6.c
  275. +
  276. +dns_ip6.o: \
  277. +compile dns_ip6.c stralloc.h gen_alloc.h uint16.h byte.h dns.h \
  278. +stralloc.h iopause.h taia.h tai.h uint64.h taia.h
  279. + ./compile dns_ip6.c
  280. +
  281. +fmt_xlong.o: \
  282. +compile fmt_xlong.c scan.h
  283. + ./compile fmt_xlong.c
  284. +
  285. +scan_xlong.o: \
  286. +compile scan_xlong.c scan.h
  287. + ./compile scan_xlong.c
  288. +
  289. +ip6_fmt.o: \
  290. +compile ip6_fmt.c fmt.h ip6.h
  291. + ./compile ip6_fmt.c
  292. +
  293. +scan_ip6.o: \
  294. +compile scan_ip6.c scan.h ip6.h
  295. + ./compile scan_ip6.c
  296. +
  297. +socket_tcp6.o: \
  298. +compile socket_tcp6.c ndelay.h socket.h uint16.h haveip6.h uint32.h
  299. + ./compile socket_tcp6.c
  300. +
  301. +socket_udp6.o: \
  302. +compile socket_udp6.c ndelay.h socket.h uint16.h haveip6.h uint32.h
  303. + ./compile socket_udp6.c
  304. +
  305. +haveip6.h: \
  306. +tryip6.c choose compile haveip6.h1 haveip6.h2
  307. + ./choose c tryip6 haveip6.h1 haveip6.h2 > haveip6.h
  308. +
  309. +socket_getifname.o: \
  310. +compile socket_getifname.c socket.h uint16.h uint32.h
  311. + ./compile socket_getifname.c
  312. +
  313. +socket_getifidx.o: \
  314. +compile socket_getifidx.c socket.h uint16.h uint32.h
  315. + ./compile socket_getifidx.c
  316. +
  317. +socket_ip4loopback.o: \
  318. +compile socket_ip4loopback.c
  319. + ./compile socket_ip4loopback.c
  320. +
  321. +socket_v4mappedprefix.o: \
  322. +compile socket_v4mappedprefix.c
  323. + ./compile socket_v4mappedprefix.c
  324. +
  325. +socket_v6any.o: \
  326. +compile socket_v6any.c
  327. + ./compile socket_v6any.c
  328. +
  329. +socket_v6loopback.o: \
  330. +compile socket_v6loopback.c
  331. + ./compile socket_v6loopback.c
  332. +
  333. +clean:
  334. + rm -f `cat TARGETS`
  335. diff -uNr ucspi-tcp-0.88.orig/TARGETS ucspi-tcp-0.88/TARGETS
  336. --- ucspi-tcp-0.88.orig/TARGETS 2009-08-04 15:19:16.000000000 -0500
  337. +++ ucspi-tcp-0.88/TARGETS 2009-08-04 17:45:59.000000000 -0500
  338. @@ -169,3 +169,31 @@
  339. it
  340. setup
  341. check
  342. +dns_ip6.o
  343. +dns_ipq6.o
  344. +dns_nd6.o
  345. +dns_sortip6.o
  346. +fmt_xlong.o
  347. +ip6_fmt.o
  348. +ip6_scan.o
  349. +scan_0x.o
  350. +socket_accept6.o
  351. +socket_bind6.o
  352. +socket_conn6.o
  353. +socket_local6.o
  354. +socket_recv6.o
  355. +socket_remote6.o
  356. +socket_send6.o
  357. +socket_tcp6.o
  358. +timeoutconn6.o
  359. +haveip6.h
  360. +remoteinfo6.o
  361. +socket_getifidx.o
  362. +socket_getifname.o
  363. +scan_ip6.o
  364. +scan_xlong.o
  365. +socket_ip4loopback.o
  366. +socket_udp6.o
  367. +socket_v4mappedprefix.o
  368. +socket_v6any.o
  369. +socket_v6loopback.o
  370. diff -uNr ucspi-tcp-0.88.orig/addcr.1 ucspi-tcp-0.88/addcr.1
  371. --- ucspi-tcp-0.88.orig/addcr.1 1969-12-31 18:00:00.000000000 -0600
  372. +++ ucspi-tcp-0.88/addcr.1 2009-08-04 17:45:59.000000000 -0500
  373. @@ -0,0 +1,22 @@
  374. +.TH addcr 1
  375. +.SH NAME
  376. +addcr \- add a CR before each LF
  377. +.SH SYNOPSIS
  378. +.B addcr
  379. +.SH DESCRIPTION
  380. +.B addcr
  381. +inserts CR at the end of each line of input.
  382. +It does not insert CR at the end of a partial final line.
  383. +.SH COMPATIBILITY
  384. +Some vendors ship
  385. +.B unix2dos
  386. +or
  387. +.B bsd2dos
  388. +tools similar to
  389. +.BR addcr .
  390. +Those tools often blow up on long lines and nulls.
  391. +.B addcr
  392. +has no trouble with long lines and nulls.
  393. +.SH "SEE ALSO"
  394. +delcr(1),
  395. +fixcr(1)
  396. diff -uNr ucspi-tcp-0.88.orig/argv0.1 ucspi-tcp-0.88/argv0.1
  397. --- ucspi-tcp-0.88.orig/argv0.1 1969-12-31 18:00:00.000000000 -0600
  398. +++ ucspi-tcp-0.88/argv0.1 2009-08-04 17:45:59.000000000 -0500
  399. @@ -0,0 +1,47 @@
  400. +.TH argv0 1
  401. +.SH NAME
  402. +argv0 \- run a program with a specified 0th argument
  403. +.SH SYNOPSIS
  404. +.B argv0
  405. +.I realname
  406. +.I zero
  407. +[
  408. +.I arg ...
  409. +]
  410. +.SH DESCRIPTION
  411. +.B argv0
  412. +runs
  413. +the program stored as
  414. +.I realname
  415. +on disk,
  416. +with the given
  417. +arguments.
  418. +It sets the 0th argument of
  419. +the program to
  420. +.IR zero .
  421. +
  422. +For example,
  423. +
  424. +.EX
  425. + argv0 /bin/csh -bin/csh
  426. +.EE
  427. +
  428. +runs
  429. +.B /bin/csh
  430. +with a 0th argument of
  431. +.BR -bin/csh .
  432. +.B csh
  433. +will think it is a login shell
  434. +and behave accordingly.
  435. +
  436. +.B argv0
  437. +can be used to run some
  438. +.B inetd
  439. +wrappers under
  440. +.BR tcpserver .
  441. +.SH "SEE ALSO"
  442. +csh(1),
  443. +tcpserver(1),
  444. +execve(2),
  445. +execvp(3),
  446. +inetd(8)
  447. diff -uNr ucspi-tcp-0.88.orig/date@.1 ucspi-tcp-0.88/date@.1
  448. --- ucspi-tcp-0.88.orig/date@.1 1969-12-31 18:00:00.000000000 -0600
  449. +++ ucspi-tcp-0.88/date@.1 2009-08-04 17:45:59.000000000 -0500
  450. @@ -0,0 +1,32 @@
  451. +.TH date@ 1
  452. +.SH NAME
  453. +date@ \- print the date on a host
  454. +.SH SYNTAX
  455. +.B date@
  456. +[
  457. +.I host
  458. +]
  459. +.SH DESCRIPTION
  460. +.B date@
  461. +connects to TCP port 13 (Daytime) on
  462. +.I host
  463. +and prints any data it receives.
  464. +It removes CR and converts unprintable characters to a visible format.
  465. +
  466. +If
  467. +.I host
  468. +is not supplied,
  469. +.B date@
  470. +connects to the local host.
  471. +
  472. +Some computers respond to port 13 with a human-readable date.
  473. +For example, they may be running
  474. +
  475. +.EX
  476. + tcpserver 0 13 date &
  477. +.EE
  478. +.SH "SEE ALSO"
  479. +cat(1),
  480. +delcr(1),
  481. +tcpclient(1),
  482. +tcpserver(1)
  483. diff -uNr ucspi-tcp-0.88.orig/delcr.1 ucspi-tcp-0.88/delcr.1
  484. --- ucspi-tcp-0.88.orig/delcr.1 1969-12-31 18:00:00.000000000 -0600
  485. +++ ucspi-tcp-0.88/delcr.1 2009-08-04 17:45:59.000000000 -0500
  486. @@ -0,0 +1,30 @@
  487. +.TH delcr 1
  488. +.SH NAME
  489. +delcr \- remove a CR before each LF
  490. +.SH SYNOPSIS
  491. +.B delcr
  492. +.SH DESCRIPTION
  493. +.B delcr
  494. +removes a CR at the end of each line of input,
  495. +if a CR is present.
  496. +It also removes a CR at the end of a partial final line.
  497. +
  498. +The pipeline
  499. +
  500. +.EX
  501. + addcr | delcr
  502. +.EE
  503. +
  504. +prints an exact copy of its input.
  505. +.SH COMPATIBILITY
  506. +Some vendors ship
  507. +.B dos2unix
  508. +or
  509. +.B dos2bsd
  510. +tools similar to
  511. +.BR delcr .
  512. +Those tools often blow up on long lines and nulls.
  513. +.B delcr
  514. +has no trouble with long lines and nulls.
  515. +.SH "SEE ALSO"
  516. +addcr(1)
  517. diff -uNr ucspi-tcp-0.88.orig/dns.h ucspi-tcp-0.88/dns.h
  518. --- ucspi-tcp-0.88.orig/dns.h 2009-08-04 15:19:16.000000000 -0500
  519. +++ ucspi-tcp-0.88/dns.h 2009-08-04 17:45:59.000000000 -0500
  520. @@ -34,51 +34,60 @@
  521. unsigned int curserver;
  522. struct taia deadline;
  523. unsigned int pos;
  524. - char *servers;
  525. - char localip[4];
  526. + const char *servers;
  527. + char localip[16];
  528. + unsigned int scope_id;
  529. char qtype[2];
  530. } ;
  531. -extern void dns_random_init(char *);
  532. +extern void dns_random_init(const char *);
  533. extern unsigned int dns_random(unsigned int);
  534. extern void dns_sortip(char *,unsigned int);
  535. +extern void dns_sortip6(char *,unsigned int);
  536. extern void dns_domain_free(char **);
  537. -extern int dns_domain_copy(char **,char *);
  538. -extern unsigned int dns_domain_length(char *);
  539. -extern int dns_domain_equal(char *,char *);
  540. -extern char *dns_domain_suffix(char *,char *);
  541. -extern int dns_domain_fromdot(char **,char *,unsigned int);
  542. -extern int dns_domain_todot_cat(stralloc *,char *);
  543. -
  544. -extern unsigned int dns_packet_copy(char *,unsigned int,unsigned int,char *,unsigned int);
  545. -extern unsigned int dns_packet_getname(char *,unsigned int,unsigned int,char **);
  546. -extern unsigned int dns_packet_skipname(char *,unsigned int,unsigned int);
  547. -extern int dns_packet_nameequal(char *,unsigned int,unsigned int,char *,unsigned int,unsigned int);
  548. +extern int dns_domain_copy(char **,const char *);
  549. +extern unsigned int dns_domain_length(const char *);
  550. +extern int dns_domain_equal(const char *,const char *);
  551. +extern int dns_domain_suffix(const char *,const char *);
  552. +extern unsigned int dns_domain_suffixpos(const char *,const char *);
  553. +extern int dns_domain_fromdot(char **,const char *,unsigned int);
  554. +extern int dns_domain_todot_cat(stralloc *,const char *);
  555. +
  556. +extern unsigned int dns_packet_copy(const char *,unsigned int,unsigned int,char *,unsigned int);
  557. +extern unsigned int dns_packet_getname(const char *,unsigned int,unsigned int,char **);
  558. +extern unsigned int dns_packet_skipname(const char *,unsigned int,unsigned int);
  559. -extern int dns_transmit_start(struct dns_transmit *,char *,int,char *,char *,char *);
  560. +extern int dns_transmit_start(struct dns_transmit *,const char *,int,const char *,const char *,const char *);
  561. extern void dns_transmit_free(struct dns_transmit *);
  562. extern void dns_transmit_io(struct dns_transmit *,iopause_fd *,struct taia *);
  563. -extern int dns_transmit_get(struct dns_transmit *,iopause_fd *,struct taia *);
  564. +extern int dns_transmit_get(struct dns_transmit *,const iopause_fd *,const struct taia *);
  565. extern int dns_resolvconfip(char *);
  566. -extern int dns_resolve(char *,char *);
  567. +extern int dns_resolve(const char *,const char *);
  568. extern struct dns_transmit dns_resolve_tx;
  569. -extern int dns_ip4_packet(stralloc *,char *,unsigned int);
  570. -extern int dns_ip4(stralloc *,stralloc *);
  571. -extern int dns_name_packet(stralloc *,char *,unsigned int);
  572. -extern void dns_name4_domain(char *,char *);
  573. +extern int dns_ip4_packet(stralloc *,const char *,unsigned int);
  574. +extern int dns_ip4(stralloc *,const stralloc *);
  575. +extern int dns_ip6_packet(stralloc *,const char *,unsigned int);
  576. +extern int dns_ip6(stralloc *,stralloc *);
  577. +extern int dns_name_packet(stralloc *,const char *,unsigned int);
  578. +extern void dns_name4_domain(char *,const char *);
  579. #define DNS_NAME4_DOMAIN 31
  580. -extern int dns_name4(stralloc *,char *);
  581. -extern int dns_txt_packet(stralloc *,char *,unsigned int);
  582. -extern int dns_txt(stralloc *,stralloc *);
  583. -extern int dns_mx_packet(stralloc *,char *,unsigned int);
  584. -extern int dns_mx(stralloc *,stralloc *);
  585. +extern int dns_name4(stralloc *,const char *);
  586. +extern int dns_txt_packet(stralloc *,const char *,unsigned int);
  587. +extern int dns_txt(stralloc *,const stralloc *);
  588. +extern int dns_mx_packet(stralloc *,const char *,unsigned int);
  589. +extern int dns_mx(stralloc *,const stralloc *);
  590. extern int dns_resolvconfrewrite(stralloc *);
  591. -extern int dns_ip4_qualify_rules(stralloc *,stralloc *,stralloc *,stralloc *);
  592. -extern int dns_ip4_qualify(stralloc *,stralloc *,stralloc *);
  593. +extern int dns_ip4_qualify_rules(stralloc *,stralloc *,const stralloc *,const stralloc *);
  594. +extern int dns_ip4_qualify(stralloc *,stralloc *,const stralloc *);
  595. +extern int dns_ip6_qualify_rules(stralloc *,stralloc *,const stralloc *,const stralloc *);
  596. +extern int dns_ip6_qualify(stralloc *,stralloc *,const stralloc *);
  597. +
  598. +extern int dns_name6_domain(char *,char *);
  599. +#define DNS_NAME6_DOMAIN (4*16+11)
  600. #endif
  601. diff -uNr ucspi-tcp-0.88.orig/dns_dfd.c ucspi-tcp-0.88/dns_dfd.c
  602. --- ucspi-tcp-0.88.orig/dns_dfd.c 2009-08-04 15:19:16.000000000 -0500
  603. +++ ucspi-tcp-0.88/dns_dfd.c 2009-08-04 17:45:59.000000000 -0500
  604. @@ -1,9 +1,10 @@
  605. -#include "error.h"
  606. -#include "alloc.h"
  607. +#include <stdlib.h>
  608. +#include <errno.h>
  609. #include "byte.h"
  610. #include "dns.h"
  611. +#include "error.h"
  612. -int dns_domain_fromdot(char **out,char *buf,unsigned int n)
  613. +int dns_domain_fromdot(char **out,const char *buf,unsigned int n)
  614. {
  615. char label[63];
  616. unsigned int labellen = 0; /* <= sizeof label */
  617. @@ -59,11 +60,11 @@
  618. if (namelen + 1 > sizeof name) return 0;
  619. name[namelen++] = 0;
  620. - x = alloc(namelen);
  621. + x = malloc(namelen);
  622. if (!x) return 0;
  623. byte_copy(x,namelen,name);
  624. - if (*out) alloc_free(*out);
  625. + if (*out) free(*out);
  626. *out = x;
  627. return 1;
  628. }
  629. diff -uNr ucspi-tcp-0.88.orig/dns_domain.c ucspi-tcp-0.88/dns_domain.c
  630. --- ucspi-tcp-0.88.orig/dns_domain.c 2009-08-04 15:19:16.000000000 -0500
  631. +++ ucspi-tcp-0.88/dns_domain.c 2009-08-04 17:45:59.000000000 -0500
  632. @@ -1,16 +1,15 @@
  633. -#include "error.h"
  634. -#include "alloc.h"
  635. +#include <stdlib.h>
  636. #include "case.h"
  637. #include "byte.h"
  638. #include "dns.h"
  639. -unsigned int dns_domain_length(char *dn)
  640. +unsigned int dns_domain_length(const char *dn)
  641. {
  642. - char *x;
  643. + const char *x;
  644. unsigned char c;
  645. x = dn;
  646. - while (c = *x++)
  647. + while ((c = *x++))
  648. x += (unsigned int) c;
  649. return x - dn;
  650. }
  651. @@ -18,26 +17,26 @@
  652. void dns_domain_free(char **out)
  653. {
  654. if (*out) {
  655. - alloc_free(*out);
  656. + free(*out);
  657. *out = 0;
  658. }
  659. }
  660. -int dns_domain_copy(char **out,char *in)
  661. +int dns_domain_copy(char **out,const char *in)
  662. {
  663. unsigned int len;
  664. char *x;
  665. len = dns_domain_length(in);
  666. - x = alloc(len);
  667. + x = malloc(len);
  668. if (!x) return 0;
  669. byte_copy(x,len,in);
  670. - if (*out) alloc_free(*out);
  671. + if (*out) free(*out);
  672. *out = x;
  673. return 1;
  674. }
  675. -int dns_domain_equal(char *dn1,char *dn2)
  676. +int dns_domain_equal(const char *dn1,const char *dn2)
  677. {
  678. unsigned int len;
  679. @@ -48,12 +47,25 @@
  680. return 1;
  681. }
  682. -char *dns_domain_suffix(char *big,char *little)
  683. +int dns_domain_suffix(const char *big,const char *little)
  684. +{
  685. + unsigned char c;
  686. +
  687. + for (;;) {
  688. + if (dns_domain_equal(big,little)) return 1;
  689. + c = *big++;
  690. + if (!c) return 0;
  691. + big += c;
  692. + }
  693. +}
  694. +
  695. +unsigned int dns_domain_suffixpos(const char *big,const char *little)
  696. {
  697. + const char *orig = big;
  698. unsigned char c;
  699. for (;;) {
  700. - if (dns_domain_equal(big,little)) return big;
  701. + if (dns_domain_equal(big,little)) return big - orig;
  702. c = *big++;
  703. if (!c) return 0;
  704. big += c;
  705. diff -uNr ucspi-tcp-0.88.orig/dns_dtda.c ucspi-tcp-0.88/dns_dtda.c
  706. --- ucspi-tcp-0.88.orig/dns_dtda.c 2009-08-04 15:19:16.000000000 -0500
  707. +++ ucspi-tcp-0.88/dns_dtda.c 2009-08-04 17:45:59.000000000 -0500
  708. @@ -1,7 +1,7 @@
  709. #include "stralloc.h"
  710. #include "dns.h"
  711. -int dns_domain_todot_cat(stralloc *out,char *d)
  712. +int dns_domain_todot_cat(stralloc *out,const char *d)
  713. {
  714. char ch;
  715. char ch2;
  716. diff -uNr ucspi-tcp-0.88.orig/dns_ip.c ucspi-tcp-0.88/dns_ip.c
  717. --- ucspi-tcp-0.88.orig/dns_ip.c 2009-08-04 15:19:16.000000000 -0500
  718. +++ ucspi-tcp-0.88/dns_ip.c 2009-08-04 17:45:59.000000000 -0500
  719. @@ -3,7 +3,7 @@
  720. #include "byte.h"
  721. #include "dns.h"
  722. -int dns_ip4_packet(stralloc *out,char *buf,unsigned int len)
  723. +int dns_ip4_packet(stralloc *out,const char *buf,unsigned int len)
  724. {
  725. unsigned int pos;
  726. char header[12];
  727. @@ -36,7 +36,7 @@
  728. static char *q = 0;
  729. -int dns_ip4(stralloc *out,stralloc *fqdn)
  730. +int dns_ip4(stralloc *out,const stralloc *fqdn)
  731. {
  732. unsigned int i;
  733. char code;
  734. diff -uNr ucspi-tcp-0.88.orig/dns_ip6.c ucspi-tcp-0.88/dns_ip6.c
  735. --- ucspi-tcp-0.88.orig/dns_ip6.c 1969-12-31 18:00:00.000000000 -0600
  736. +++ ucspi-tcp-0.88/dns_ip6.c 2009-08-04 17:45:59.000000000 -0500
  737. @@ -0,0 +1,103 @@
  738. +#include "stralloc.h"
  739. +#include "uint16.h"
  740. +#include "byte.h"
  741. +#include "dns.h"
  742. +#include "ip4.h"
  743. +#include "ip6.h"
  744. +
  745. +static int dns_ip6_packet_add(stralloc *out,const char *buf,unsigned int len)
  746. +{
  747. + unsigned int pos;
  748. + char header[16];
  749. + uint16 numanswers;
  750. + uint16 datalen;
  751. +
  752. + pos = dns_packet_copy(buf,len,0,header,12); if (!pos) return -1;
  753. + uint16_unpack_big(header + 6,&numanswers);
  754. + pos = dns_packet_skipname(buf,len,pos); if (!pos) return -1;
  755. + pos += 4;
  756. +
  757. + while (numanswers--) {
  758. + pos = dns_packet_skipname(buf,len,pos); if (!pos) return -1;
  759. + pos = dns_packet_copy(buf,len,pos,header,10); if (!pos) return -1;
  760. + uint16_unpack_big(header + 8,&datalen);
  761. + if (byte_equal(header,2,DNS_T_AAAA)) {
  762. + if (byte_equal(header + 2,2,DNS_C_IN))
  763. + if (datalen == 16) {
  764. + if (!dns_packet_copy(buf,len,pos,header,16)) return -1;
  765. + if (!stralloc_catb(out,header,16)) return -1;
  766. + }
  767. + } else if (byte_equal(header,2,DNS_T_A))
  768. + if (byte_equal(header + 2,2,DNS_C_IN))
  769. + if (datalen == 4) {
  770. + byte_copy(header,12,V4mappedprefix);
  771. + if (!dns_packet_copy(buf,len,pos,header+12,4)) return -1;
  772. + if (!stralloc_catb(out,header,16)) return -1;
  773. + }
  774. + pos += datalen;
  775. + }
  776. +
  777. + dns_sortip6(out->s,out->len);
  778. + return 0;
  779. +}
  780. +
  781. +int dns_ip6_packet(stralloc *out,const char *buf,unsigned int len) {
  782. + if (!stralloc_copys(out,"")) return -1;
  783. + return dns_ip6_packet_add(out,buf,len);
  784. +}
  785. +
  786. +static char *q = 0;
  787. +
  788. +int dns_ip6(stralloc *out,stralloc *fqdn)
  789. +{
  790. + unsigned int i;
  791. + char code;
  792. + char ch;
  793. + char ip[16];
  794. +
  795. + if (!stralloc_copys(out,"")) return -1;
  796. + if (!stralloc_readyplus(fqdn,1)) return -1;
  797. + fqdn->s[fqdn->len]=0;
  798. + if ((i=scan_ip6(fqdn->s,ip))) {
  799. + if (fqdn->s[i]) return -1;
  800. + stralloc_copyb(out,ip,16);
  801. + return 0;
  802. + }
  803. + code = 0;
  804. + for (i = 0;i <= fqdn->len;++i) {
  805. + if (i < fqdn->len)
  806. + ch = fqdn->s[i];
  807. + else
  808. + ch = '.';
  809. +
  810. + if ((ch == '[') || (ch == ']')) continue;
  811. + if (ch == '.') {
  812. + if (!stralloc_append(out,&code)) return -1;
  813. + code = 0;
  814. + continue;
  815. + }
  816. + if ((ch >= '0') && (ch <= '9')) {
  817. + code *= 10;
  818. + code += ch - '0';
  819. + continue;
  820. + }
  821. +
  822. + if (!dns_domain_fromdot(&q,fqdn->s,fqdn->len)) return -1;
  823. + if (!stralloc_copys(out,"")) return -1;
  824. + if (dns_resolve(q,DNS_T_AAAA) != -1)
  825. + if (dns_ip6_packet_add(out,dns_resolve_tx.packet,dns_resolve_tx.packetlen) != -1) {
  826. + dns_transmit_free(&dns_resolve_tx);
  827. + dns_domain_free(&q);
  828. + }
  829. + if (!dns_domain_fromdot(&q,fqdn->s,fqdn->len)) return -1;
  830. + if (dns_resolve(q,DNS_T_A) != -1)
  831. + if (dns_ip6_packet_add(out,dns_resolve_tx.packet,dns_resolve_tx.packetlen) != -1) {
  832. + dns_transmit_free(&dns_resolve_tx);
  833. + dns_domain_free(&q);
  834. + }
  835. + return out->a>0?0:-1;
  836. + }
  837. +
  838. + out->len &= ~3;
  839. + return 0;
  840. +}
  841. diff -uNr ucspi-tcp-0.88.orig/dns_ipq.c ucspi-tcp-0.88/dns_ipq.c
  842. --- ucspi-tcp-0.88.orig/dns_ipq.c 2009-08-04 15:19:16.000000000 -0500
  843. +++ ucspi-tcp-0.88/dns_ipq.c 2009-08-04 17:45:59.000000000 -0500
  844. @@ -4,7 +4,7 @@
  845. #include "str.h"
  846. #include "dns.h"
  847. -static int doit(stralloc *work,char *rule)
  848. +static int doit(stralloc *work,const char *rule)
  849. {
  850. char ch;
  851. unsigned int colon;
  852. @@ -30,7 +30,7 @@
  853. return stralloc_cats(work,rule + colon + 1);
  854. }
  855. -int dns_ip4_qualify_rules(stralloc *out,stralloc *fqdn,stralloc *in,stralloc *rules)
  856. +int dns_ip4_qualify_rules(stralloc *out,stralloc *fqdn,const stralloc *in,const stralloc *rules)
  857. {
  858. unsigned int i;
  859. unsigned int j;
  860. @@ -63,7 +63,7 @@
  861. }
  862. }
  863. -int dns_ip4_qualify(stralloc *out,stralloc *fqdn,stralloc *in)
  864. +int dns_ip4_qualify(stralloc *out,stralloc *fqdn,const stralloc *in)
  865. {
  866. static stralloc rules;
  867. if (dns_resolvconfrewrite(&rules) == -1) return -1;
  868. diff -uNr ucspi-tcp-0.88.orig/dns_ipq6.c ucspi-tcp-0.88/dns_ipq6.c
  869. --- ucspi-tcp-0.88.orig/dns_ipq6.c 1969-12-31 18:00:00.000000000 -0600
  870. +++ ucspi-tcp-0.88/dns_ipq6.c 2009-08-04 17:45:59.000000000 -0500
  871. @@ -0,0 +1,72 @@
  872. +#include "stralloc.h"
  873. +#include "case.h"
  874. +#include "byte.h"
  875. +#include "str.h"
  876. +#include "dns.h"
  877. +
  878. +static int doit(stralloc *work,const char *rule)
  879. +{
  880. + char ch;
  881. + unsigned int colon;
  882. + unsigned int prefixlen;
  883. +
  884. + ch = *rule++;
  885. + if ((ch != '?') && (ch != '=') && (ch != '*') && (ch != '-')) return 1;
  886. + colon = str_chr(rule,':');
  887. + if (!rule[colon]) return 1;
  888. +
  889. + if (work->len < colon) return 1;
  890. + prefixlen = work->len - colon;
  891. + if ((ch == '=') && prefixlen) return 1;
  892. + if (case_diffb(rule,colon,work->s + prefixlen)) return 1;
  893. + if (ch == '?') {
  894. + if (byte_chr(work->s,prefixlen,'.') < prefixlen) return 1;
  895. + if (byte_chr(work->s,prefixlen,':') < prefixlen) return 1;
  896. + if (byte_chr(work->s,prefixlen,'[') < prefixlen) return 1;
  897. + if (byte_chr(work->s,prefixlen,']') < prefixlen) return 1;
  898. + }
  899. +
  900. + work->len = prefixlen;
  901. + if (ch == '-') work->len = 0;
  902. + return stralloc_cats(work,rule + colon + 1);
  903. +}
  904. +
  905. +int dns_ip6_qualify_rules(stralloc *out,stralloc *fqdn,const stralloc *in,const stralloc *rules)
  906. +{
  907. + unsigned int i;
  908. + unsigned int j;
  909. + unsigned int plus;
  910. + unsigned int fqdnlen;
  911. +
  912. + if (!stralloc_copy(fqdn,in)) return -1;
  913. +
  914. + for (j = i = 0;j < rules->len;++j)
  915. + if (!rules->s[j]) {
  916. + if (!doit(fqdn,rules->s + i)) return -1;
  917. + i = j + 1;
  918. + }
  919. +
  920. + fqdnlen = fqdn->len;
  921. + plus = byte_chr(fqdn->s,fqdnlen,'+');
  922. + if (plus >= fqdnlen)
  923. + return dns_ip6(out,fqdn);
  924. +
  925. + i = plus + 1;
  926. + for (;;) {
  927. + j = byte_chr(fqdn->s + i,fqdnlen - i,'+');
  928. + byte_copy(fqdn->s + plus,j,fqdn->s + i);
  929. + fqdn->len = plus + j;
  930. + if (dns_ip6(out,fqdn) == -1) return -1;
  931. + if (out->len) return 0;
  932. + i += j;
  933. + if (i >= fqdnlen) return 0;
  934. + ++i;
  935. + }
  936. +}
  937. +
  938. +int dns_ip6_qualify(stralloc *out,stralloc *fqdn,const stralloc *in)
  939. +{
  940. + static stralloc rules;
  941. + if (dns_resolvconfrewrite(&rules) == -1) return -1;
  942. + return dns_ip6_qualify_rules(out,fqdn,in,&rules);
  943. +}
  944. diff -uNr ucspi-tcp-0.88.orig/dns_name.c ucspi-tcp-0.88/dns_name.c
  945. --- ucspi-tcp-0.88.orig/dns_name.c 2009-08-04 15:19:16.000000000 -0500
  946. +++ ucspi-tcp-0.88/dns_name.c 2009-08-04 17:45:59.000000000 -0500
  947. @@ -2,10 +2,11 @@
  948. #include "uint16.h"
  949. #include "byte.h"
  950. #include "dns.h"
  951. +#include "ip6.h"
  952. static char *q = 0;
  953. -int dns_name_packet(stralloc *out,char *buf,unsigned int len)
  954. +int dns_name_packet(stralloc *out,const char *buf,unsigned int len)
  955. {
  956. unsigned int pos;
  957. char header[12];
  958. @@ -35,7 +36,7 @@
  959. return 0;
  960. }
  961. -int dns_name4(stralloc *out,char ip[4])
  962. +int dns_name4(stralloc *out,const char ip[4])
  963. {
  964. char name[DNS_NAME4_DOMAIN];
  965. @@ -46,3 +47,17 @@
  966. dns_domain_free(&q);
  967. return 0;
  968. }
  969. +
  970. +int dns_name6(stralloc *out,char ip[16])
  971. +{
  972. + char name[DNS_NAME6_DOMAIN];
  973. +
  974. + if (ip6_isv4mapped(ip))
  975. + return dns_name4(out,ip+12);
  976. + dns_name6_domain(name,ip);
  977. + if (dns_resolve(name,DNS_T_PTR) == -1) return -1;
  978. + if (dns_name_packet(out,dns_resolve_tx.packet,dns_resolve_tx.packetlen) == -1) return -1;
  979. + dns_transmit_free(&dns_resolve_tx);
  980. + dns_domain_free(&q);
  981. + return 0;
  982. +}
  983. diff -uNr ucspi-tcp-0.88.orig/dns_nd.c ucspi-tcp-0.88/dns_nd.c
  984. --- ucspi-tcp-0.88.orig/dns_nd.c 2009-08-04 15:19:16.000000000 -0500
  985. +++ ucspi-tcp-0.88/dns_nd.c 2009-08-04 17:45:59.000000000 -0500
  986. @@ -2,7 +2,7 @@
  987. #include "fmt.h"
  988. #include "dns.h"
  989. -void dns_name4_domain(char name[DNS_NAME4_DOMAIN],char ip[4])
  990. +void dns_name4_domain(char name[DNS_NAME4_DOMAIN],const char ip[4])
  991. {
  992. unsigned int namelen;
  993. unsigned int i;
  994. diff -uNr ucspi-tcp-0.88.orig/dns_nd6.c ucspi-tcp-0.88/dns_nd6.c
  995. --- ucspi-tcp-0.88.orig/dns_nd6.c 1969-12-31 18:00:00.000000000 -0600
  996. +++ ucspi-tcp-0.88/dns_nd6.c 2009-08-04 17:45:59.000000000 -0500
  997. @@ -0,0 +1,28 @@
  998. +#include "byte.h"
  999. +#include "fmt.h"
  1000. +#include "dns.h"
  1001. +
  1002. +/* RFC1886:
  1003. + * 4321:0:1:2:3:4:567:89ab
  1004. + * ->
  1005. + * b.a.9.8.7.6.5.0.4.0.0.0.3.0.0.0.2.0.0.0.1.0.0.0.0.0.0.0.1.2.3.4.IP6.INT.
  1006. + */
  1007. +
  1008. +static inline char tohex(char c) {
  1009. + return c>=10?c-10+'a':c+'0';
  1010. +}
  1011. +
  1012. +int dns_name6_domain(char name[DNS_NAME6_DOMAIN],char ip[16])
  1013. +{
  1014. + unsigned int j;
  1015. +
  1016. + for (j=0; j<16; j++) {
  1017. + name[j*4]=1;
  1018. + name[j*4+1]=tohex(ip[15-j] & 15);
  1019. + name[j*4+2]=1;
  1020. + name[j*4+3]=tohex((unsigned char)ip[15-j] >> 4);
  1021. + }
  1022. + byte_copy(name + 4*16,10,"\3ip6\4arpa\0");
  1023. + return 4*16+10;
  1024. +}
  1025. +
  1026. diff -uNr ucspi-tcp-0.88.orig/dns_packet.c ucspi-tcp-0.88/dns_packet.c
  1027. --- ucspi-tcp-0.88.orig/dns_packet.c 2009-08-04 15:19:16.000000000 -0500
  1028. +++ ucspi-tcp-0.88/dns_packet.c 2009-08-04 17:45:59.000000000 -0500
  1029. @@ -2,10 +2,11 @@
  1030. DNS should have used LZ77 instead of its own sophomoric compression algorithm.
  1031. */
  1032. -#include "error.h"
  1033. +#include <errno.h>
  1034. #include "dns.h"
  1035. +#include "error.h"
  1036. -unsigned int dns_packet_copy(char *buf,unsigned int len,unsigned int pos,char *out,unsigned int outlen)
  1037. +unsigned int dns_packet_copy(const char *buf,unsigned int len,unsigned int pos,char *out,unsigned int outlen)
  1038. {
  1039. while (outlen) {
  1040. if (pos >= len) { errno = error_proto; return 0; }
  1041. @@ -15,7 +16,7 @@
  1042. return pos;
  1043. }
  1044. -unsigned int dns_packet_skipname(char *buf,unsigned int len,unsigned int pos)
  1045. +unsigned int dns_packet_skipname(const char *buf,unsigned int len,unsigned int pos)
  1046. {
  1047. unsigned char ch;
  1048. @@ -32,7 +33,7 @@
  1049. return 0;
  1050. }
  1051. -unsigned int dns_packet_getname(char *buf,unsigned int len,unsigned int pos,char **d)
  1052. +unsigned int dns_packet_getname(const char *buf,unsigned int len,unsigned int pos,char **d)
  1053. {
  1054. unsigned int loop = 0;
  1055. unsigned int state = 0;
  1056. diff -uNr ucspi-tcp-0.88.orig/dns_random.c ucspi-tcp-0.88/dns_random.c
  1057. --- ucspi-tcp-0.88.orig/dns_random.c 2009-08-04 15:19:16.000000000 -0500
  1058. +++ ucspi-tcp-0.88/dns_random.c 2009-08-04 17:45:59.000000000 -0500
  1059. @@ -1,3 +1,4 @@
  1060. +#include <unistd.h>
  1061. #include "dns.h"
  1062. #include "taia.h"
  1063. #include "uint32.h"
  1064. @@ -29,7 +30,7 @@
  1065. }
  1066. }
  1067. -void dns_random_init(char data[128])
  1068. +void dns_random_init(const char data[128])
  1069. {
  1070. int i;
  1071. struct taia t;
  1072. diff -uNr ucspi-tcp-0.88.orig/dns_rcip.c ucspi-tcp-0.88/dns_rcip.c
  1073. --- ucspi-tcp-0.88.orig/dns_rcip.c 2009-08-04 15:19:16.000000000 -0500
  1074. +++ ucspi-tcp-0.88/dns_rcip.c 2009-08-04 17:45:59.000000000 -0500
  1075. @@ -2,12 +2,13 @@
  1076. #include "openreadclose.h"
  1077. #include "byte.h"
  1078. #include "ip4.h"
  1079. -#include "env.h"
  1080. +#include "ip6.h"
  1081. #include "dns.h"
  1082. +#include "env.h"
  1083. static stralloc data = {0};
  1084. -static int init(char ip[64])
  1085. +static int init(char ip[256])
  1086. {
  1087. int i;
  1088. int j;
  1089. @@ -16,15 +17,16 @@
  1090. x = env_get("DNSCACHEIP");
  1091. if (x)
  1092. - while (iplen <= 60)
  1093. + while (iplen <= 60) {
  1094. if (*x == '.')
  1095. ++x;
  1096. else {
  1097. - i = ip4_scan(x,ip + iplen);
  1098. + i = scan_ip6(x,ip + iplen);
  1099. if (!i) break;
  1100. x += i;
  1101. - iplen += 4;
  1102. + iplen += 16;
  1103. }
  1104. + }
  1105. if (!iplen) {
  1106. i = openreadclose("/etc/resolv.conf",&data,64);
  1107. @@ -39,8 +41,9 @@
  1108. while ((data.s[i] == ' ') || (data.s[i] == '\t'))
  1109. ++i;
  1110. if (iplen <= 60)
  1111. - if (ip4_scan(data.s + i,ip + iplen))
  1112. - iplen += 4;
  1113. + if (scan_ip6(data.s + i,ip + iplen)) {
  1114. + iplen += 16;
  1115. + }
  1116. }
  1117. i = j + 1;
  1118. }
  1119. @@ -48,19 +51,19 @@
  1120. }
  1121. if (!iplen) {
  1122. - byte_copy(ip,4,"\177\0\0\1");
  1123. - iplen = 4;
  1124. + byte_copy(ip,16,"\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\1");
  1125. + iplen = 16;
  1126. }
  1127. - byte_zero(ip + iplen,64 - iplen);
  1128. + byte_zero(ip + iplen,256 - iplen);
  1129. return 0;
  1130. }
  1131. static int ok = 0;
  1132. static unsigned int uses;
  1133. static struct taia deadline;
  1134. -static char ip[64]; /* defined if ok */
  1135. +static char ip[256]; /* defined if ok */
  1136. -int dns_resolvconfip(char s[64])
  1137. +int dns_resolvconfip(char s[256])
  1138. {
  1139. struct taia now;
  1140. @@ -77,6 +80,6 @@
  1141. }
  1142. --uses;
  1143. - byte_copy(s,64,ip);
  1144. + byte_copy(s,256,ip);
  1145. return 0;
  1146. }
  1147. diff -uNr ucspi-tcp-0.88.orig/dns_rcrw.c ucspi-tcp-0.88/dns_rcrw.c
  1148. --- ucspi-tcp-0.88.orig/dns_rcrw.c 2009-08-04 15:19:16.000000000 -0500
  1149. +++ ucspi-tcp-0.88/dns_rcrw.c 2009-08-04 17:45:59.000000000 -0500
  1150. @@ -1,16 +1,17 @@
  1151. +#include <unistd.h>
  1152. #include "taia.h"
  1153. -#include "env.h"
  1154. #include "byte.h"
  1155. #include "str.h"
  1156. #include "openreadclose.h"
  1157. #include "dns.h"
  1158. +#include "env.h"
  1159. static stralloc data = {0};
  1160. static int init(stralloc *rules)
  1161. {
  1162. char host[256];
  1163. - char *x;
  1164. + const char *x;
  1165. int i;
  1166. int j;
  1167. int k;
  1168. diff -uNr ucspi-tcp-0.88.orig/dns_resolve.c ucspi-tcp-0.88/dns_resolve.c
  1169. --- ucspi-tcp-0.88.orig/dns_resolve.c 2009-08-04 15:19:16.000000000 -0500
  1170. +++ ucspi-tcp-0.88/dns_resolve.c 2009-08-04 17:45:59.000000000 -0500
  1171. @@ -2,19 +2,20 @@
  1172. #include "taia.h"
  1173. #include "byte.h"
  1174. #include "dns.h"
  1175. +#include "ip6.h"
  1176. struct dns_transmit dns_resolve_tx = {0};
  1177. -int dns_resolve(char *q,char qtype[2])
  1178. +int dns_resolve(const char *q,const char qtype[2])
  1179. {
  1180. struct taia stamp;
  1181. struct taia deadline;
  1182. - char servers[64];
  1183. + char servers[256];
  1184. iopause_fd x[1];
  1185. int r;
  1186. if (dns_resolvconfip(servers) == -1) return -1;
  1187. - if (dns_transmit_start(&dns_resolve_tx,servers,1,q,qtype,"\0\0\0\0") == -1) return -1;
  1188. + if (dns_transmit_start(&dns_resolve_tx,servers,1,q,qtype,V6any) == -1) return -1;
  1189. for (;;) {
  1190. taia_now(&stamp);
  1191. diff -uNr ucspi-tcp-0.88.orig/dns_sortip6.c ucspi-tcp-0.88/dns_sortip6.c
  1192. --- ucspi-tcp-0.88.orig/dns_sortip6.c 1969-12-31 18:00:00.000000000 -0600
  1193. +++ ucspi-tcp-0.88/dns_sortip6.c 2009-08-04 17:45:59.000000000 -0500
  1194. @@ -0,0 +1,20 @@
  1195. +#include "byte.h"
  1196. +#include "dns.h"
  1197. +
  1198. +/* XXX: sort servers by configurable notion of closeness? */
  1199. +/* XXX: pay attention to competence of each server? */
  1200. +
  1201. +void dns_sortip6(char *s,unsigned int n)
  1202. +{
  1203. + unsigned int i;
  1204. + char tmp[16];
  1205. +
  1206. + n >>= 4;
  1207. + while (n > 1) {
  1208. + i = dns_random(n);
  1209. + --n;
  1210. + byte_copy(tmp,16,s + (i << 4));
  1211. + byte_copy(s + (i << 4),16,s + (n << 4));
  1212. + byte_copy(s + (n << 4),16,tmp);
  1213. + }
  1214. +}
  1215. diff -uNr ucspi-tcp-0.88.orig/dns_transmit.c ucspi-tcp-0.88/dns_transmit.c
  1216. --- ucspi-tcp-0.88.orig/dns_transmit.c 2009-08-04 15:19:16.000000000 -0500
  1217. +++ ucspi-tcp-0.88/dns_transmit.c 2009-08-04 17:45:59.000000000 -0500
  1218. @@ -1,12 +1,15 @@
  1219. +#include <sys/types.h>
  1220. +#include <sys/socket.h>
  1221. +#include <unistd.h>
  1222. +#include <stdlib.h>
  1223. #include "socket.h"
  1224. -#include "alloc.h"
  1225. -#include "error.h"
  1226. +#include <errno.h>
  1227. #include "byte.h"
  1228. -#include "readwrite.h"
  1229. #include "uint16.h"
  1230. #include "dns.h"
  1231. +#include "ip6.h"
  1232. -static int serverwantstcp(char *buf,unsigned int len)
  1233. +static int serverwantstcp(const char *buf,unsigned int len)
  1234. {
  1235. char out[12];
  1236. @@ -15,7 +18,7 @@
  1237. return 0;
  1238. }
  1239. -static int serverfailed(char *buf,unsigned int len)
  1240. +static int serverfailed(const char *buf,unsigned int len)
  1241. {
  1242. char out[12];
  1243. unsigned int rcode;
  1244. @@ -23,11 +26,11 @@
  1245. if (!dns_packet_copy(buf,len,0,out,12)) return 1;
  1246. rcode = out[3];
  1247. rcode &= 15;
  1248. - if (rcode && (rcode != 3)) { errno = error_again; return 1; }
  1249. + if (rcode && (rcode != 3)) { errno = EAGAIN; return 1; }
  1250. return 0;
  1251. }
  1252. -static int irrelevant(struct dns_transmit *d,char *buf,unsigned int len)
  1253. +static int irrelevant(const struct dns_transmit *d,const char *buf,unsigned int len)
  1254. {
  1255. char out[12];
  1256. char *dn;
  1257. @@ -40,8 +43,8 @@
  1258. dn = 0;
  1259. pos = dns_packet_getname(buf,len,pos,&dn); if (!pos) return 1;
  1260. - if (!dns_domain_equal(dn,d->query + 14)) { alloc_free(dn); return 1; }
  1261. - alloc_free(dn);
  1262. + if (!dns_domain_equal(dn,d->query + 14)) { free(dn); return 1; }
  1263. + free(dn);
  1264. pos = dns_packet_copy(buf,len,pos,out,4); if (!pos) return 1;
  1265. if (byte_diff(out,2,d->qtype)) return 1;
  1266. @@ -53,14 +56,14 @@
  1267. static void packetfree(struct dns_transmit *d)
  1268. {
  1269. if (!d->packet) return;
  1270. - alloc_free(d->packet);
  1271. + free(d->packet);
  1272. d->packet = 0;
  1273. }
  1274. static void queryfree(struct dns_transmit *d)
  1275. {
  1276. if (!d->query) return;
  1277. - alloc_free(d->query);
  1278. + free(d->query);
  1279. d->query = 0;
  1280. }
  1281. @@ -83,9 +86,9 @@
  1282. int j;
  1283. for (j = 0;j < 10;++j)
  1284. - if (socket_bind4(d->s1 - 1,d->localip,1025 + dns_random(64510)) == 0)
  1285. + if (socket_bind6(d->s1 - 1,d->localip,1025 + dns_random(64510),d->scope_id) == 0)
  1286. return 0;
  1287. - if (socket_bind4(d->s1 - 1,d->localip,0) == 0)
  1288. + if (socket_bind6(d->s1 - 1,d->localip,0,d->scope_id) == 0)
  1289. return 0;
  1290. return -1;
  1291. }
  1292. @@ -94,22 +97,22 @@
  1293. static int thisudp(struct dns_transmit *d)
  1294. {
  1295. - char *ip;
  1296. + const char *ip;
  1297. socketfree(d);
  1298. while (d->udploop < 4) {
  1299. for (;d->curserver < 16;++d->curserver) {
  1300. - ip = d->servers + 4 * d->curserver;
  1301. - if (byte_diff(ip,4,"\0\0\0\0")) {
  1302. + ip = d->servers + 16 * d->curserver;
  1303. + if (byte_diff(ip,16,V6any)) {
  1304. d->query[2] = dns_random(256);
  1305. d->query[3] = dns_random(256);
  1306. - d->s1 = 1 + socket_udp();
  1307. + d->s1 = 1 + socket_udp6();
  1308. if (!d->s1) { dns_transmit_free(d); return -1; }
  1309. if (randombind(d) == -1) { dns_transmit_free(d); return -1; }
  1310. - if (socket_connect4(d->s1 - 1,ip,53) == 0)
  1311. + if (socket_connect6(d->s1 - 1,ip,53,d->scope_id) == 0)
  1312. if (send(d->s1 - 1,d->query + 2,d->querylen - 2,0) == d->querylen - 2) {
  1313. struct taia now;
  1314. taia_now(&now);
  1315. @@ -145,29 +148,29 @@
  1316. static int thistcp(struct dns_transmit *d)
  1317. {
  1318. struct taia now;
  1319. - char *ip;
  1320. + const char *ip;
  1321. socketfree(d);
  1322. packetfree(d);
  1323. for (;d->curserver < 16;++d->curserver) {
  1324. - ip = d->servers + 4 * d->curserver;
  1325. - if (byte_diff(ip,4,"\0\0\0\0")) {
  1326. + ip = d->servers + 16 * d->curserver;
  1327. + if (byte_diff(ip,16,V6any)) {
  1328. d->query[2] = dns_random(256);
  1329. d->query[3] = dns_random(256);
  1330. - d->s1 = 1 + socket_tcp();
  1331. + d->s1 = 1 + socket_tcp6();
  1332. if (!d->s1) { dns_transmit_free(d); return -1; }
  1333. if (randombind(d) == -1) { dns_transmit_free(d); return -1; }
  1334. taia_now(&now);
  1335. taia_uint(&d->deadline,10);
  1336. taia_add(&d->deadline,&d->deadline,&now);
  1337. - if (socket_connect4(d->s1 - 1,ip,53) == 0) {
  1338. + if (socket_connect6(d->s1 - 1,ip,53,d->scope_id) == 0) {
  1339. d->tcpstate = 2;
  1340. return 0;
  1341. }
  1342. - if ((errno == error_inprogress) || (errno == error_wouldblock)) {
  1343. + if ((errno == EINPROGRESS) || (errno == EWOULDBLOCK)) {
  1344. d->tcpstate = 1;
  1345. return 0;
  1346. }
  1347. @@ -191,16 +194,16 @@
  1348. return thistcp(d);
  1349. }
  1350. -int dns_transmit_start(struct dns_transmit *d,char servers[64],int flagrecursive,char *q,char qtype[2],char localip[4])
  1351. +int dns_transmit_start(struct dns_transmit *d,const char servers[256],int flagrecursive,const char *q,const char qtype[2],const char localip[16])
  1352. {
  1353. unsigned int len;
  1354. dns_transmit_free(d);
  1355. - errno = error_io;
  1356. + errno = EIO;
  1357. len = dns_domain_length(q);
  1358. d->querylen = len + 18;
  1359. - d->query = alloc(d->querylen);
  1360. + d->query = malloc(d->querylen);
  1361. if (!d->query) return -1;
  1362. uint16_pack_big(d->query,len + 16);
  1363. @@ -211,7 +214,7 @@
  1364. byte_copy(d->qtype,2,qtype);
  1365. d->servers = servers;
  1366. - byte_copy(d->localip,4,localip);
  1367. + byte_copy(d->localip,16,localip);
  1368. d->udploop = flagrecursive ? 1 : 0;
  1369. @@ -236,19 +239,19 @@
  1370. *deadline = d->deadline;
  1371. }
  1372. -int dns_transmit_get(struct dns_transmit *d,iopause_fd *x,struct taia *when)
  1373. +int dns_transmit_get(struct dns_transmit *d,const iopause_fd *x,const struct taia *when)
  1374. {
  1375. char udpbuf[513];
  1376. unsigned char ch;
  1377. int r;
  1378. int fd;
  1379. - errno = error_io;
  1380. + errno = EIO;
  1381. fd = d->s1 - 1;
  1382. if (!x->revents) {
  1383. if (taia_less(when,&d->deadline)) return 0;
  1384. - errno = error_timeout;
  1385. + errno = ETIMEDOUT;
  1386. if (d->tcpstate == 0) return nextudp(d);
  1387. return nexttcp(d);
  1388. }
  1389. @@ -260,7 +263,7 @@
  1390. */
  1391. r = recv(fd,udpbuf,sizeof udpbuf,0);
  1392. if (r <= 0) {
  1393. - if (d->udploop == 2) return 0;
  1394. + if (errno == ECONNREFUSED) if (d->udploop == 2) return 0;
  1395. return nextudp(d);
  1396. }
  1397. if (r + 1 > sizeof udpbuf) return 0;
  1398. @@ -274,7 +277,7 @@
  1399. socketfree(d);
  1400. d->packetlen = r;
  1401. - d->packet = alloc(d->packetlen);
  1402. + d->packet = malloc(d->packetlen);
  1403. if (!d->packet) { dns_transmit_free(d); return -1; }
  1404. byte_copy(d->packet,d->packetlen,udpbuf);
  1405. queryfree(d);
  1406. @@ -334,7 +337,7 @@
  1407. d->packetlen += ch;
  1408. d->tcpstate = 5;
  1409. d->pos = 0;
  1410. - d->packet = alloc(d->packetlen);
  1411. + d->packet = malloc(d->packetlen);
  1412. if (!d->packet) { dns_transmit_free(d); return -1; }
  1413. return 0;
  1414. }
  1415. diff -uNr ucspi-tcp-0.88.orig/dns_txt.c ucspi-tcp-0.88/dns_txt.c
  1416. --- ucspi-tcp-0.88.orig/dns_txt.c 2009-08-04 15:19:16.000000000 -0500
  1417. +++ ucspi-tcp-0.88/dns_txt.c 2009-08-04 17:45:59.000000000 -0500
  1418. @@ -3,7 +3,7 @@
  1419. #include "byte.h"
  1420. #include "dns.h"
  1421. -int dns_txt_packet(stralloc *out,char *buf,unsigned int len)
  1422. +int dns_txt_packet(stralloc *out,const char *buf,unsigned int len)
  1423. {
  1424. unsigned int pos;
  1425. char header[12];
  1426. @@ -48,7 +48,7 @@
  1427. static char *q = 0;
  1428. -int dns_txt(stralloc *out,stralloc *fqdn)
  1429. +int dns_txt(stralloc *out,const stralloc *fqdn)
  1430. {
  1431. if (!dns_domain_fromdot(&q,fqdn->s,fqdn->len)) return -1;
  1432. if (dns_resolve(q,DNS_T_TXT) == -1) return -1;
  1433. diff -uNr ucspi-tcp-0.88.orig/error.h ucspi-tcp-0.88/error.h
  1434. --- ucspi-tcp-0.88.orig/error.h 2009-08-04 15:19:16.000000000 -0500
  1435. +++ ucspi-tcp-0.88/error.h 2009-08-04 17:45:59.000000000 -0500
  1436. @@ -1,7 +1,7 @@
  1437. #ifndef ERROR_H
  1438. #define ERROR_H
  1439. -extern int errno;
  1440. +#include <errno.h>
  1441. extern int error_intr;
  1442. extern int error_nomem;
  1443. diff -uNr ucspi-tcp-0.88.orig/finger@.1 ucspi-tcp-0.88/finger@.1
  1444. --- ucspi-tcp-0.88.orig/finger@.1 1969-12-31 18:00:00.000000000 -0600
  1445. +++ ucspi-tcp-0.88/finger@.1 2009-08-04 17:45:59.000000000 -0500
  1446. @@ -0,0 +1,45 @@
  1447. +.TH finger@ 1
  1448. +.SH NAME
  1449. +finger@ \- get user information from a host
  1450. +.SH SYNTAX
  1451. +.B finger@
  1452. +[
  1453. +.I host
  1454. +[
  1455. +.I user
  1456. +]
  1457. +]
  1458. +.SH DESCRIPTION
  1459. +.B finger@
  1460. +connects to TCP port 79 (Finger) on
  1461. +.IR host ,
  1462. +sends
  1463. +.I user
  1464. +(with an extra CR)
  1465. +to
  1466. +.IR host ,
  1467. +and prints any data it receives.
  1468. +It removes CR and converts unprintable characters to a visible format.
  1469. +Some computers respond to port 79 with information about
  1470. +.IR user .
  1471. +
  1472. +If
  1473. +.I user
  1474. +is not supplied,
  1475. +.B finger@
  1476. +sends a blank line to
  1477. +.IR host .
  1478. +Some computers respond with information about
  1479. +all the users who are logged in.
  1480. +
  1481. +If
  1482. +.I host
  1483. +is not supplied,
  1484. +.B finger@
  1485. +connects to the local host.
  1486. +.SH "SEE ALSO"
  1487. +addcr(1),
  1488. +cat(1),
  1489. +delcr(1),
  1490. +finger(1),
  1491. +tcpclient(1)
  1492. diff -uNr ucspi-tcp-0.88.orig/fixcr.1 ucspi-tcp-0.88/fixcr.1
  1493. --- ucspi-tcp-0.88.orig/fixcr.1 1969-12-31 18:00:00.000000000 -0600
  1494. +++ ucspi-tcp-0.88/fixcr.1 2009-08-04 17:45:59.000000000 -0500
  1495. @@ -0,0 +1,11 @@
  1496. +.TH fixcr 1
  1497. +.SH NAME
  1498. +fixcr \- make sure that there is a CR before each LF
  1499. +.SH SYNOPSIS
  1500. +.B fixcr
  1501. +.SH DESCRIPTION
  1502. +.B fixcr
  1503. +inserts CR at the end of each line of input where a CR is not already present.
  1504. +It does not insert CR at the end of a partial final line.
  1505. +.SH "SEE ALSO"
  1506. +addcr(1)
  1507. diff -uNr ucspi-tcp-0.88.orig/fmt_xlong.c ucspi-tcp-0.88/fmt_xlong.c
  1508. --- ucspi-tcp-0.88.orig/fmt_xlong.c 1969-12-31 18:00:00.000000000 -0600
  1509. +++ ucspi-tcp-0.88/fmt_xlong.c 2009-08-04 17:45:59.000000000 -0500
  1510. @@ -0,0 +1,22 @@
  1511. +#include "fmt.h"
  1512. +
  1513. +char tohex(char num) {
  1514. + if (num<10)
  1515. + return num+'0';
  1516. + else if (num<16)
  1517. + return num-10+'a';
  1518. + else
  1519. + return -1;
  1520. +}
  1521. +
  1522. +unsigned int fmt_xlong(register char *s,register unsigned long u)
  1523. +{
  1524. + register unsigned int len; register unsigned long q;
  1525. + len = 1; q = u;
  1526. + while (q > 15) { ++len; q /= 16; }
  1527. + if (s) {
  1528. + s += len;
  1529. + do { *--s = tohex(u % 16); u /= 16; } while(u); /* handles u == 0 */
  1530. + }
  1531. + return len;
  1532. +}
  1533. diff -uNr ucspi-tcp-0.88.orig/haveip6.h1 ucspi-tcp-0.88/haveip6.h1
  1534. --- ucspi-tcp-0.88.orig/haveip6.h1 1969-12-31 18:00:00.000000000 -0600
  1535. +++ ucspi-tcp-0.88/haveip6.h1 2009-08-04 17:45:59.000000000 -0500
  1536. @@ -0,0 +1 @@
  1537. +
  1538. diff -uNr ucspi-tcp-0.88.orig/haveip6.h2 ucspi-tcp-0.88/haveip6.h2
  1539. --- ucspi-tcp-0.88.orig/haveip6.h2 1969-12-31 18:00:00.000000000 -0600
  1540. +++ ucspi-tcp-0.88/haveip6.h2 2009-08-04 17:45:59.000000000 -0500
  1541. @@ -0,0 +1 @@
  1542. +#define LIBC_HAS_IP6 1
  1543. diff -uNr ucspi-tcp-0.88.orig/hier.c ucspi-tcp-0.88/hier.c
  1544. --- ucspi-tcp-0.88.orig/hier.c 2009-08-04 15:19:16.000000000 -0500
  1545. +++ ucspi-tcp-0.88/hier.c 2009-08-04 17:45:59.000000000 -0500
  1546. @@ -4,6 +4,9 @@
  1547. {
  1548. h(auto_home,-1,-1,02755);
  1549. d(auto_home,"bin",-1,-1,02755);
  1550. + d(auto_home,"man",-1,-1,02755);
  1551. + d(auto_home,"man/man1",-1,-1,02755);
  1552. + d(auto_home,"man/man5",-1,-1,02755);
  1553. c(auto_home,"bin","tcpserver",-1,-1,0755);
  1554. c(auto_home,"bin","tcprules",-1,-1,0755);
  1555. @@ -22,4 +25,20 @@
  1556. c(auto_home,"bin","delcr",-1,-1,0755);
  1557. c(auto_home,"bin","fixcrio",-1,-1,0755);
  1558. c(auto_home,"bin","rblsmtpd",-1,-1,0755);
  1559. +
  1560. + c(auto_home,"man/man1","tcpclient.1",-1,-1,0644);
  1561. + c(auto_home,"man/man1","tcpserver.1",-1,-1,0644);
  1562. + c(auto_home,"man/man1","tcprules.1",-1,-1,0644);
  1563. + c(auto_home,"man/man1","tcprulescheck.1",-1,-1,0644);
  1564. + c(auto_home,"man/man1","fixcr.1",-1,-1,0644);
  1565. + c(auto_home,"man/man1","addcr.1",-1,-1,0644);
  1566. + c(auto_home,"man/man1","delcr.1",-1,-1,0644);
  1567. + c(auto_home,"man/man1","who@.1",-1,-1,0644);
  1568. + c(auto_home,"man/man1","date@.1",-1,-1,0644);
  1569. + c(auto_home,"man/man1","finger@.1",-1,-1,0644);
  1570. + c(auto_home,"man/man1","http@.1",-1,-1,0644);
  1571. + c(auto_home,"man/man1","mconnect.1",-1,-1,0644);
  1572. + c(auto_home,"man/man1","argv0.1",-1,-1,0644);
  1573. + c(auto_home,"man/man1","recordio.1",-1,-1,0644);
  1574. + c(auto_home,"man/man5","tcp-environ.5",-1,-1,0644);
  1575. }
  1576. diff -uNr ucspi-tcp-0.88.orig/http@.1 ucspi-tcp-0.88/http@.1
  1577. --- ucspi-tcp-0.88.orig/http@.1 1969-12-31 18:00:00.000000000 -0600
  1578. +++ ucspi-tcp-0.88/http@.1 2009-08-04 17:45:59.000000000 -0500
  1579. @@ -0,0 +1,52 @@
  1580. +.TH http@ 1
  1581. +.SH NAME
  1582. +http@ \- get a web page from a host through HTTP
  1583. +.SH SYNTAX
  1584. +.B http@
  1585. +[
  1586. +.I host
  1587. +[
  1588. +.I page
  1589. +[
  1590. +.I port
  1591. +]
  1592. +]
  1593. +]
  1594. +.SH DESCRIPTION
  1595. +.B http@
  1596. +connects to
  1597. +.I port
  1598. +on
  1599. +.IR host ,
  1600. +sends
  1601. +.B GET /\fIpage
  1602. +(with an extra CR)
  1603. +to
  1604. +.IR host ,
  1605. +and prints any data it receives,
  1606. +removing CR from the end of each line.
  1607. +
  1608. +If
  1609. +.I port
  1610. +is not supplied,
  1611. +.B http@
  1612. +uses port 80 (HTTP).
  1613. +
  1614. +If
  1615. +.I page
  1616. +is not supplied,
  1617. +.B http@
  1618. +sends
  1619. +.B GET /
  1620. +to
  1621. +.IR host .
  1622. +
  1623. +If
  1624. +.I host
  1625. +is not supplied,
  1626. +.B http@
  1627. +connects to the local host.
  1628. +.SH "SEE ALSO"
  1629. +addcr(1),
  1630. +delcr(1),
  1631. +tcpclient(1)
  1632. diff -uNr ucspi-tcp-0.88.orig/ip4.h ucspi-tcp-0.88/ip4.h
  1633. --- ucspi-tcp-0.88.orig/ip4.h 2009-08-04 15:19:16.000000000 -0500
  1634. +++ ucspi-tcp-0.88/ip4.h 2009-08-04 17:45:59.000000000 -0500
  1635. @@ -6,4 +6,6 @@
  1636. #define IP4_FMT 20
  1637. +extern const char ip4loopback[4]; /* = {127,0,0,1}; */
  1638. +
  1639. #endif
  1640. diff -uNr ucspi-tcp-0.88.orig/ip6.h ucspi-tcp-0.88/ip6.h
  1641. --- ucspi-tcp-0.88.orig/ip6.h 1969-12-31 18:00:00.000000000 -0600
  1642. +++ ucspi-tcp-0.88/ip6.h 2009-08-04 17:45:59.000000000 -0500
  1643. @@ -0,0 +1,28 @@
  1644. +#ifndef IP6_H
  1645. +#define IP6_H
  1646. +
  1647. +#include "byte.h"
  1648. +
  1649. +extern unsigned int scan_ip6(const char *src,char *ip);
  1650. +extern unsigned int fmt_ip6(char *dest,const char *ip);
  1651. +
  1652. +extern unsigned int scan_ip6_flat(const char *src,char *);
  1653. +extern unsigned int fmt_ip6_flat(char *dest,const char *);
  1654. +
  1655. +/*
  1656. + ip6 address syntax: (h = hex digit), no leading '0' required
  1657. + 1. hhhh:hhhh:hhhh:hhhh:hhhh:hhhh:hhhh:hhhh
  1658. + 2. any number of 0000 may be abbreviated as "::", but only once
  1659. + flat ip6 address syntax:
  1660. + hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh
  1661. + */
  1662. +
  1663. +#define IP6_FMT 40
  1664. +
  1665. +extern const unsigned char V4mappedprefix[12]; /*={0,0,0,0,0,0,0,0,0,0,0xff,0xff}; */
  1666. +extern const unsigned char V6loopback[16]; /*={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1}; */
  1667. +extern const unsigned char V6any[16]; /*={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}; */
  1668. +
  1669. +#define ip6_isv4mapped(ip) (byte_equal(ip,12,V4mappedprefix))
  1670. +
  1671. +#endif
  1672. diff -uNr ucspi-tcp-0.88.orig/ip6_fmt.c ucspi-tcp-0.88/ip6_fmt.c
  1673. --- ucspi-tcp-0.88.orig/ip6_fmt.c 1969-12-31 18:00:00.000000000 -0600
  1674. +++ ucspi-tcp-0.88/ip6_fmt.c 2009-08-04 17:45:59.000000000 -0500
  1675. @@ -0,0 +1,64 @@
  1676. +#include "fmt.h"
  1677. +#include "byte.h"
  1678. +#include "ip4.h"
  1679. +#include "ip6.h"
  1680. +
  1681. +unsigned int ip6_fmt(char *s,char ip[16])
  1682. +{
  1683. + unsigned long len,temp, k, pos0=0,len0=0, pos1=0, compr=0;
  1684. +
  1685. + for (k=0; k<16; k+=2) {
  1686. + if (ip[k]==0 && ip[k+1]==0) {
  1687. + if (!compr) {
  1688. + compr=1;
  1689. + pos1=k;
  1690. + }
  1691. + if (k==14) { k=16; goto last; }
  1692. + } else if (compr) {
  1693. + last:
  1694. + if ((temp=k-pos1) > len0) {
  1695. + len0=temp;
  1696. + pos0=pos1;
  1697. + }
  1698. + compr=0;
  1699. + }
  1700. + }
  1701. +
  1702. + for (len=0,k=0; k<16; k+=2) {
  1703. + if (k==12 && ip6_isv4mapped(ip)) {
  1704. + len += ip4_fmt(s,ip+12);
  1705. + break;
  1706. + }
  1707. + if (pos0==k && len0) {
  1708. + if (k==0) { ++len; if (s) *s++ = ':'; }
  1709. + ++len; if (s) *s++ = ':';
  1710. + k += len0-2;
  1711. + continue;
  1712. + }
  1713. + temp = ((unsigned long) (unsigned char) ip[k] << 8) +
  1714. + (unsigned long) (unsigned char) ip[k+1];
  1715. + temp = fmt_xlong(s,temp); len += temp; if (s) s += temp;
  1716. + if (k<14) { ++len; if (s) *s++ = ':'; }
  1717. + }
  1718. +
  1719. + return len;
  1720. +}
  1721. +
  1722. +static char tohex(char num) {
  1723. + if (num<10)
  1724. + return num+'0';
  1725. + else if (num<16)
  1726. + return num-10+'a';
  1727. + else
  1728. + return -1;
  1729. +}
  1730. +
  1731. +unsigned int ip6_fmt_flat(char *s,char ip[16])
  1732. +{
  1733. + int i;
  1734. + for (i=0; i<16; i++) {
  1735. + *s++=tohex((unsigned char)ip[i] >> 4);
  1736. + *s++=tohex((unsigned char)ip[i] & 15);
  1737. + }
  1738. + return 32;
  1739. +}
  1740. diff -uNr ucspi-tcp-0.88.orig/mconnect.1 ucspi-tcp-0.88/mconnect.1
  1741. --- ucspi-tcp-0.88.orig/mconnect.1 1969-12-31 18:00:00.000000000 -0600
  1742. +++ ucspi-tcp-0.88/mconnect.1 2009-08-04 17:45:59.000000000 -0500
  1743. @@ -0,0 +1,36 @@
  1744. +.TH mconnect 1
  1745. +.SH NAME
  1746. +mconnect \- connect to the SMTP server on a host
  1747. +.SH SYNTAX
  1748. +.B mconnect
  1749. +[
  1750. +.I host
  1751. +[
  1752. +.I port
  1753. +]
  1754. +]
  1755. +.SH DESCRIPTION
  1756. +.B mconnect
  1757. +connects to
  1758. +.I port
  1759. +on
  1760. +.IR host .
  1761. +It sends its input to
  1762. +.IR host ,
  1763. +adding a CR to each line.
  1764. +Meanwhile it prints anything it receives from
  1765. +.IR host .
  1766. +
  1767. +If
  1768. +.I port
  1769. +is not supplied,
  1770. +.B mconnect
  1771. +uses port 25 (SMTP).
  1772. +
  1773. +If
  1774. +.I host
  1775. +is not supplied,
  1776. +.B mconnect
  1777. +connects to the local host.
  1778. +.SH "SEE ALSO"
  1779. +tcpclient(1)
  1780. diff -uNr ucspi-tcp-0.88.orig/old-rules.c ucspi-tcp-0.88/old-rules.c
  1781. --- ucspi-tcp-0.88.orig/old-rules.c 1969-12-31 18:00:00.000000000 -0600
  1782. +++ ucspi-tcp-0.88/old-rules.c 2009-08-04 17:45:59.000000000 -0500
  1783. @@ -0,0 +1,101 @@
  1784. +#include "alloc.h"
  1785. +#include "stralloc.h"
  1786. +#include "open.h"
  1787. +#include "cdb.h"
  1788. +#include "rules.h"
  1789. +
  1790. +stralloc rules_name = {0};
  1791. +
  1792. +static struct cdb c;
  1793. +
  1794. +static int dorule(void (*callback)(char *,unsigned int))
  1795. +{
  1796. + char *data;
  1797. + unsigned int datalen;
  1798. +
  1799. + switch(cdb_find(&c,rules_name.s,rules_name.len)) {
  1800. + case -1: return -1;
  1801. + case 0: return 0;
  1802. + }
  1803. +
  1804. + datalen = cdb_datalen(&c);
  1805. + data = alloc(datalen);
  1806. + if (!data) return -1;
  1807. + if (cdb_read(&c,data,datalen,cdb_datapos(&c)) == -1) {
  1808. + alloc_free(data);
  1809. + return -1;
  1810. + }
  1811. +
  1812. + callback(data,datalen);
  1813. + alloc_free(data);
  1814. + return 1;
  1815. +}
  1816. +
  1817. +static int doit(void (*callback)(char *,unsigned int),char *ip,char *host,char *info)
  1818. +{
  1819. + int r;
  1820. +
  1821. + if (info) {
  1822. + if (!stralloc_copys(&rules_name,info)) return -1;
  1823. + if (!stralloc_cats(&rules_name,"@")) return -1;
  1824. + if (!stralloc_cats(&rules_name,ip)) return -1;
  1825. + r = dorule(callback);
  1826. + if (r) return r;
  1827. +
  1828. + if (host) {
  1829. + if (!stralloc_copys(&rules_name,info)) return -1;
  1830. + if (!stralloc_cats(&rules_name,"@=")) return -1;
  1831. + if (!stralloc_cats(&rules_name,host)) return -1;
  1832. + r = dorule(callback);
  1833. + if (r) return r;
  1834. + }
  1835. + }
  1836. +
  1837. + if (!stralloc_copys(&rules_name,ip)) return -1;
  1838. + r = dorule(callback);
  1839. + if (r) return r;
  1840. +
  1841. + if (host) {
  1842. + if (!stralloc_copys(&rules_name,"=")) return -1;
  1843. + if (!stralloc_cats(&rules_name,host)) return -1;
  1844. + r = dorule(callback);
  1845. + if (r) return r;
  1846. + }
  1847. +
  1848. + if (!stralloc_copys(&rules_name,ip)) return -1;
  1849. + while (rules_name.len > 0) {
  1850. + if (ip[rules_name.len - 1] == '.' ||
  1851. + (ip[rules_name.len-1]==':' && rules_name.len>1)) {
  1852. + r = dorule(callback);
  1853. + if (r) return r;
  1854. + }
  1855. + --rules_name.len;
  1856. + }
  1857. +
  1858. + if (host) {
  1859. + while (*host) {
  1860. + if (*host == '.') {
  1861. + if (!stralloc_copys(&rules_name,"=")) return -1;
  1862. + if (!stralloc_cats(&rules_name,host)) return -1;
  1863. + r = dorule(callback);
  1864. + if (r) return r;
  1865. + }
  1866. + ++host;
  1867. + }
  1868. + if (!stralloc_copys(&rules_name,"=")) return -1;
  1869. + r = dorule(callback);
  1870. + if (r) return r;
  1871. + }
  1872. +
  1873. + rules_name.len = 0;
  1874. + return dorule(callback);
  1875. +}
  1876. +
  1877. +int rules(void (*callback)(char *,unsigned int),int fd,char *ip,char *host,char *info)
  1878. +{
  1879. + int r;
  1880. + cdb_init(&c,fd);
  1881. + r = doit(callback,ip,host,info);
  1882. + cdb_free(&c);
  1883. + return r;
  1884. +}
  1885. diff -uNr ucspi-tcp-0.88.orig/pathexec.h ucspi-tcp-0.88/pathexec.h
  1886. --- ucspi-tcp-0.88.orig/pathexec.h 2009-08-04 15:19:16.000000000 -0500
  1887. +++ ucspi-tcp-0.88/pathexec.h 2009-08-04 17:45:59.000000000 -0500
  1888. @@ -2,7 +2,7 @@
  1889. #define PATHEXEC_H
  1890. extern void pathexec_run(char *,char **,char **);
  1891. -extern int pathexec_env(char *,char *);
  1892. +extern int pathexec_env(const char *,const char *);
  1893. extern void pathexec(char **);
  1894. #endif
  1895. diff -uNr ucspi-tcp-0.88.orig/pathexec_env.c ucspi-tcp-0.88/pathexec_env.c
  1896. --- ucspi-tcp-0.88.orig/pathexec_env.c 2009-08-04 15:19:16.000000000 -0500
  1897. +++ ucspi-tcp-0.88/pathexec_env.c 2009-08-04 17:45:59.000000000 -0500
  1898. @@ -8,7 +8,7 @@
  1899. static stralloc plus;
  1900. static stralloc tmp;
  1901. -int pathexec_env(char *s,char *t)
  1902. +int pathexec_env(const char *s,const char *t)
  1903. {
  1904. if (!s) return 1;
  1905. if (!stralloc_copys(&tmp,s)) return 0;
  1906. @@ -22,7 +22,6 @@
  1907. void pathexec(char **argv)
  1908. {
  1909. - char *path;
  1910. char **e;
  1911. unsigned int elen;
  1912. unsigned int i;
  1913. diff -uNr ucspi-tcp-0.88.orig/rblsmtpd.c ucspi-tcp-0.88/rblsmtpd.c
  1914. --- ucspi-tcp-0.88.orig/rblsmtpd.c 2009-08-04 15:19:16.000000000 -0500
  1915. +++ ucspi-tcp-0.88/rblsmtpd.c 2009-08-04 17:51:17.000000000 -0500
  1916. @@ -25,26 +25,58 @@
  1917. strerr_die1x(100,"rblsmtpd: usage: rblsmtpd [ -b ] [ -R ] [ -t timeout ] [ -r base ] [ -a base ] smtpd [ arg ... ]");
  1918. }
  1919. +char *tcp_proto;
  1920. char *ip_env;
  1921. static stralloc ip_reverse;
  1922. +static inline char tohex(char c) {
  1923. + return c>=10?c-10+'a':c+'0';
  1924. +}
  1925. +
  1926. void ip_init(void)
  1927. {
  1928. unsigned int i;
  1929. unsigned int j;
  1930. + unsigned char remoteip[16];
  1931. + char hexval;
  1932. + tcp_proto = env_get("PROTO");
  1933. + if (!tcp_proto) tcp_proto = "";
  1934. ip_env = env_get("TCPREMOTEIP");
  1935. if (!ip_env) ip_env = "";
  1936. if (!stralloc_copys(&ip_reverse,"")) nomem();
  1937. i = str_len(ip_env);
  1938. - while (i) {
  1939. - for (j = i;j > 0;--j) if (ip_env[j - 1] == '.') break;
  1940. - if (!stralloc_catb(&ip_reverse,ip_env + j,i - j)) nomem();
  1941. - if (!stralloc_cats(&ip_reverse,".")) nomem();
  1942. - if (!j) break;
  1943. - i = j - 1;
  1944. + if (str_diff(tcp_proto, "TCP6") != 0)
  1945. + {
  1946. + // IPv4
  1947. + while (i) {
  1948. + for (j = i;j > 0;--j) if (ip_env[j - 1] == '.') break;
  1949. + if (!stralloc_catb(&ip_reverse,ip_env + j,i - j)) nomem();
  1950. + if (!stralloc_cats(&ip_reverse,".")) nomem();
  1951. + if (!j) break;
  1952. + i = j - 1;
  1953. + }
  1954. + }
  1955. + else
  1956. + {
  1957. + // IPv6
  1958. + if ((i=scan_ip6(ip_env, remoteip))==0)
  1959. + return;
  1960. +
  1961. + for (j=16; j>0; j--)
  1962. + {
  1963. + hexval=tohex(remoteip[j-1] & 15);
  1964. + if(!stralloc_catb(&ip_reverse, &hexval, 1)) nomem();
  1965. + if(!stralloc_cats(&ip_reverse, ".")) nomem();
  1966. +
  1967. + hexval=tohex(remoteip[j-1] >> 4);
  1968. + if(!stralloc_catb(&ip_reverse, &hexval, 1)) nomem();
  1969. + if(!stralloc_cats(&ip_reverse, ".")) nomem();
  1970. + }
  1971. +
  1972. + if(!stralloc_cats(&ip_reverse, "ipv6.")) nomem();
  1973. }
  1974. }
  1975. @@ -190,7 +222,7 @@
  1976. argv += optind;
  1977. if (!*argv) usage();
  1978. - if (flagwantdefaultrbl) rbl("rbl.maps.vix.com");
  1979. + if (flagwantdefaultrbl) rbl("zen.spamhaus.org");
  1980. if (decision >= 2) rblsmtpd();
  1981. pathexec_run(*argv,argv,envp);
  1982. diff -uNr ucspi-tcp-0.88.orig/recordio.1 ucspi-tcp-0.88/recordio.1
  1983. --- ucspi-tcp-0.88.orig/recordio.1 1969-12-31 18:00:00.000000000 -0600
  1984. +++ ucspi-tcp-0.88/recordio.1 2009-08-04 17:45:59.000000000 -0500
  1985. @@ -0,0 +1,75 @@
  1986. +.TH recordio 1
  1987. +.SH NAME
  1988. +recordio \- record the input and output of a program
  1989. +.SH SYNTAX
  1990. +.B recordio
  1991. +.I program
  1992. +[
  1993. +.I arg ...
  1994. +]
  1995. +.SH DESCRIPTION
  1996. +.B recordio
  1997. +runs
  1998. +.I program
  1999. +with the given arguments.
  2000. +It prints lines to stderr
  2001. +showing the input and output of
  2002. +.IR program .
  2003. +
  2004. +At the beginning of each line on stderr,
  2005. +.B recordio
  2006. +inserts the
  2007. +.I program
  2008. +process ID,
  2009. +along with
  2010. +.B <
  2011. +for input or
  2012. +.B >
  2013. +for output.
  2014. +At the end of each line it inserts a space, a plus sign, or [EOF];
  2015. +a space indicates that there was a newline in the input or output,
  2016. +and [EOF] indicates the end of input or output.
  2017. +
  2018. +.B recordio
  2019. +prints every packet of input and output immediately.
  2020. +It does not attempt to combine packets into coherent stderr lines.
  2021. +For example,
  2022. +
  2023. +.EX
  2024. + recordio sh -c 'cat /dev/fd/8 2>&1' > /dev/null
  2025. +.EE
  2026. +
  2027. +could produce
  2028. +
  2029. +.EX
  2030. + 5135 > cat: /dev/fd/8: Bad file descriptor
  2031. +.br
  2032. + 5135 > [EOF]
  2033. +.EE
  2034. +
  2035. +or
  2036. +
  2037. +.EX
  2038. + 5135 > cat: +
  2039. +.br
  2040. + 5135 > /dev/fd/8+
  2041. +.br
  2042. + 5135 > : +
  2043. +.br
  2044. + 5135 > Bad file descriptor
  2045. +.br
  2046. + 5135 > [EOF]
  2047. +.EE
  2048. +
  2049. +.B recordio
  2050. +uses several lines for long packets
  2051. +to guarantee that each line is printed atomically to stderr.
  2052. +
  2053. +.B recordio
  2054. +runs as a child of
  2055. +.IR program .
  2056. +It exits when it sees the end of
  2057. +.IR program 's
  2058. +output.
  2059. +.SH "SEE ALSO"
  2060. +tcpserver(1)
  2061. diff -uNr ucspi-tcp-0.88.orig/remoteinfo.h ucspi-tcp-0.88/remoteinfo.h
  2062. --- ucspi-tcp-0.88.orig/remoteinfo.h 2009-08-04 15:19:16.000000000 -0500
  2063. +++ ucspi-tcp-0.88/remoteinfo.h 2009-08-04 17:45:59.000000000 -0500
  2064. @@ -5,5 +5,6 @@
  2065. #include "uint16.h"
  2066. extern int remoteinfo(stralloc *,char *,uint16,char *,uint16,unsigned int);
  2067. +extern int remoteinfo6(stralloc *,char *,uint16,char *,uint16,unsigned int,uint32);
  2068. #endif
  2069. diff -uNr ucspi-tcp-0.88.orig/remoteinfo6.c ucspi-tcp-0.88/remoteinfo6.c
  2070. --- ucspi-tcp-0.88.orig/remoteinfo6.c 1969-12-31 18:00:00.000000000 -0600
  2071. +++ ucspi-tcp-0.88/remoteinfo6.c 2009-08-04 17:45:59.000000000 -0500
  2072. @@ -0,0 +1,98 @@
  2073. +#include "fmt.h"
  2074. +#include "buffer.h"
  2075. +#include "socket.h"
  2076. +#include "error.h"
  2077. +#include "iopause.h"
  2078. +#include "timeoutconn.h"
  2079. +#include "remoteinfo.h"
  2080. +
  2081. +static struct taia now;
  2082. +static struct taia deadline;
  2083. +
  2084. +static int mywrite(int fd,char *buf,int len)
  2085. +{
  2086. + iopause_fd x;
  2087. +
  2088. + x.fd = fd;
  2089. + x.events = IOPAUSE_WRITE;
  2090. + for (;;) {
  2091. + taia_now(&now);
  2092. + iopause(&x,1,&deadline,&now);
  2093. + if (x.revents) break;
  2094. + if (taia_less(&deadline,&now)) {
  2095. + errno = error_timeout;
  2096. + return -1;
  2097. + }
  2098. + }
  2099. + return write(fd,buf,len);
  2100. +}
  2101. +
  2102. +static int myread(int fd,char *buf,int len)
  2103. +{
  2104. + iopause_fd x;
  2105. +
  2106. + x.fd = fd;
  2107. + x.events = IOPAUSE_READ;
  2108. + for (;;) {
  2109. + taia_now(&now);
  2110. + iopause(&x,1,&deadline,&now);
  2111. + if (x.revents) break;
  2112. + if (taia_less(&deadline,&now)) {
  2113. + errno = error_timeout;
  2114. + return -1;
  2115. + }
  2116. + }
  2117. + return read(fd,buf,len);
  2118. +}
  2119. +
  2120. +static int doit(stralloc *out,int s,char ipremote[16],uint16 portremote,char iplocal[16],uint16 portlocal,unsigned int timeout,uint32 netif)
  2121. +{
  2122. + buffer b;
  2123. + char bspace[128];
  2124. + char strnum[FMT_ULONG];
  2125. + int numcolons;
  2126. + char ch;
  2127. +
  2128. + if (socket_bind6(s,iplocal,0,netif) == -1) return -1;
  2129. + if (timeoutconn6(s,ipremote,113,timeout,netif) == -1) return -1;
  2130. +
  2131. + buffer_init(&b,mywrite,s,bspace,sizeof bspace);
  2132. + buffer_put(&b,strnum,fmt_ulong(strnum,portremote));
  2133. + buffer_put(&b," , ",3);
  2134. + buffer_put(&b,strnum,fmt_ulong(strnum,portlocal));
  2135. + buffer_put(&b,"\r\n",2);
  2136. + if (buffer_flush(&b) == -1) return -1;
  2137. +
  2138. + buffer_init(&b,myread,s,bspace,sizeof bspace);
  2139. + numcolons = 0;
  2140. + for (;;) {
  2141. + if (buffer_get(&b,&ch,1) != 1) return -1;
  2142. + if ((ch == ' ') || (ch == '\t') || (ch == '\r')) continue;
  2143. + if (ch == '\n') return 0;
  2144. + if (numcolons < 3) {
  2145. + if (ch == ':') ++numcolons;
  2146. + }
  2147. + else {
  2148. + if (!stralloc_append(out,&ch)) return -1;
  2149. + if (out->len > 256) return 0;
  2150. + }
  2151. + }
  2152. +}
  2153. +
  2154. +int remoteinfo6(stralloc *out,char ipremote[16],uint16 portremote,char iplocal[16],uint16 portlocal,unsigned int timeout,uint32 netif)
  2155. +{
  2156. + int s;
  2157. + int r;
  2158. +
  2159. + if (!stralloc_copys(out,"")) return -1;
  2160. +
  2161. + taia_now(&now);
  2162. + taia_uint(&deadline,timeout);
  2163. + taia_add(&deadline,&now,&deadline);
  2164. +
  2165. + s = socket_tcp6();
  2166. + if (s == -1) return -1;
  2167. + r = doit(out,s,ipremote,portremote,iplocal,portlocal,timeout,netif);
  2168. + close(s);
  2169. + return r;
  2170. +}
  2171. diff -uNr ucspi-tcp-0.88.orig/rules.c ucspi-tcp-0.88/rules.c
  2172. --- ucspi-tcp-0.88.orig/rules.c 2009-08-04 15:19:16.000000000 -0500
  2173. +++ ucspi-tcp-0.88/rules.c 2009-08-04 17:45:59.000000000 -0500
  2174. @@ -64,7 +64,7 @@
  2175. if (!stralloc_copys(&rules_name,ip)) return -1;
  2176. while (rules_name.len > 0) {
  2177. - if (ip[rules_name.len - 1] == '.') {
  2178. + if (ip[rules_name.len - 1] == '.' || ip[rules_name.len - 1] == ':') {
  2179. r = dorule(callback);
  2180. if (r) return r;
  2181. }
  2182. diff -uNr ucspi-tcp-0.88.orig/scan_ip6.c ucspi-tcp-0.88/scan_ip6.c
  2183. --- ucspi-tcp-0.88.orig/scan_ip6.c 1969-12-31 18:00:00.000000000 -0600
  2184. +++ ucspi-tcp-0.88/scan_ip6.c 2009-08-04 17:45:59.000000000 -0500
  2185. @@ -0,0 +1,87 @@
  2186. +#include "scan.h"
  2187. +#include "ip4.h"
  2188. +#include "ip6.h"
  2189. +
  2190. +/*
  2191. + * IPv6 addresses are really ugly to parse.
  2192. + * Syntax: (h = hex digit)
  2193. + * 1. hhhh:hhhh:hhhh:hhhh:hhhh:hhhh:hhhh:hhhh
  2194. + * 2. any number of 0000 may be abbreviated as "::", but only once
  2195. + * 3. The last two words may be written as IPv4 address
  2196. + */
  2197. +
  2198. +unsigned int scan_ip6(const char *s,char ip[16])
  2199. +{
  2200. + unsigned int i;
  2201. + unsigned int len=0;
  2202. + unsigned long u;
  2203. +
  2204. + char suffix[16];
  2205. + int prefixlen=0;
  2206. + int suffixlen=0;
  2207. +
  2208. + if ((i=ip4_scan((char*)s,ip+12))) {
  2209. + for (len=0; len<12; ++len) ip[len]=V4mappedprefix[len];
  2210. + return i;
  2211. + }
  2212. + for (i=0; i<16; i++) ip[i]=0;
  2213. + for (;;) {
  2214. + if (*s == ':') {
  2215. + len++;
  2216. + if (s[1] == ':') { /* Found "::", skip to part 2 */
  2217. + s+=2;
  2218. + len++;
  2219. + break;
  2220. + }
  2221. + s++;
  2222. + }
  2223. + i = scan_xlong((char*)s,&u);
  2224. + if (!i) return 0;
  2225. + if (prefixlen==12 && s[i]=='.') {
  2226. + /* the last 4 bytes may be written as IPv4 address */
  2227. + i=ip4_scan((char*)s,ip+12);
  2228. + if (i)
  2229. + return i+len;
  2230. + else
  2231. + return 0;
  2232. + }
  2233. + ip[prefixlen++] = (u >> 8);
  2234. + ip[prefixlen++] = (u & 255);
  2235. + s += i; len += i;
  2236. + if (prefixlen==16)
  2237. + return len;
  2238. + }
  2239. +
  2240. +/* part 2, after "::" */
  2241. + for (;;) {
  2242. + if (*s == ':') {
  2243. + if (suffixlen==0)
  2244. + break;
  2245. + s++;
  2246. + len++;
  2247. + } else if (suffixlen!=0)
  2248. + break;
  2249. + i = scan_xlong((char*)s,&u);
  2250. + if (!i) {
  2251. + len--;
  2252. + break;
  2253. + }
  2254. + if (suffixlen+prefixlen<=12 && s[i]=='.') {
  2255. + int j=ip4_scan((char*)s,suffix+suffixlen);
  2256. + if (j) {
  2257. + suffixlen+=4;
  2258. + len+=j;
  2259. + break;
  2260. + } else
  2261. + prefixlen=12-suffixlen; /* make end-of-loop test true */
  2262. + }
  2263. + suffix[suffixlen++] = (u >> 8);
  2264. + suffix[suffixlen++] = (u & 255);
  2265. + s += i; len += i;
  2266. + if (prefixlen+suffixlen==16)
  2267. + break;
  2268. + }
  2269. + for (i=0; i<suffixlen; i++)
  2270. + ip[16-suffixlen+i] = suffix[i];
  2271. + return len;
  2272. +}
  2273. diff -uNr ucspi-tcp-0.88.orig/scan_xlong.c ucspi-tcp-0.88/scan_xlong.c
  2274. --- ucspi-tcp-0.88.orig/scan_xlong.c 1969-12-31 18:00:00.000000000 -0600
  2275. +++ ucspi-tcp-0.88/scan_xlong.c 2009-08-04 17:45:59.000000000 -0500
  2276. @@ -0,0 +1,23 @@
  2277. +#include "scan.h"
  2278. +
  2279. +static int fromhex(unsigned char c) {
  2280. + if (c>='0' && c<='9')
  2281. + return c-'0';
  2282. + else if (c>='A' && c<='F')
  2283. + return c-'A'+10;
  2284. + else if (c>='a' && c<='f')
  2285. + return c-'a'+10;
  2286. + return -1;
  2287. +}
  2288. +
  2289. +unsigned int scan_xlong(char *src,unsigned long *dest) {
  2290. + register const char *tmp=src;
  2291. + register int l=0;
  2292. + register unsigned char c;
  2293. + while ((c=fromhex(*tmp))<16) {
  2294. + l=(l<<4)+c;
  2295. + ++tmp;
  2296. + }
  2297. + *dest=l;
  2298. + return tmp-src;
  2299. +}
  2300. diff -uNr ucspi-tcp-0.88.orig/socket.h ucspi-tcp-0.88/socket.h
  2301. --- ucspi-tcp-0.88.orig/socket.h 2009-08-04 15:19:16.000000000 -0500
  2302. +++ ucspi-tcp-0.88/socket.h 2009-08-04 17:45:59.000000000 -0500
  2303. @@ -2,21 +2,52 @@
  2304. #define SOCKET_H
  2305. #include "uint16.h"
  2306. +#include "uint32.h"
  2307. extern int socket_tcp(void);
  2308. extern int socket_udp(void);
  2309. +extern int socket_tcp6(void);
  2310. +extern int socket_udp6(void);
  2311. -extern int socket_connect4(int,char *,uint16);
  2312. +extern int socket_connect4(int,const char *,uint16);
  2313. +extern int socket_connect6(int s,const char *ip,uint16 port,uint32 scope_id);
  2314. extern int socket_connected(int);
  2315. -extern int socket_bind4(int,char *,uint16);
  2316. -extern int socket_bind4_reuse(int,char *,uint16);
  2317. +extern int socket_bind4(int,const char *,uint16);
  2318. +extern int socket_bind4_reuse(int,const char *,uint16);
  2319. +extern int socket_bind6(int s,const char *ip,uint16 port,uint32 scope_id);
  2320. +extern int socket_bind6_reuse(int s,const char *ip,uint16 port,uint32 scope_id);
  2321. extern int socket_listen(int,int);
  2322. extern int socket_accept4(int,char *,uint16 *);
  2323. +extern int socket_accept6(int s,char *ip,uint16 *port,uint32 *scope_id);
  2324. extern int socket_recv4(int,char *,int,char *,uint16 *);
  2325. -extern int socket_send4(int,char *,int,char *,uint16);
  2326. +extern int socket_send4(int,const char *,int,const char *,uint16);
  2327. +extern int socket_recv6(int s,char *buf,unsigned int len,char *ip,uint16 *port,uint32 *scope_id);
  2328. +extern int socket_send6(int s,const char *buf,unsigned int len,const char *ip,uint16 port,uint32 scope_id);
  2329. extern int socket_local4(int,char *,uint16 *);
  2330. extern int socket_remote4(int,char *,uint16 *);
  2331. +extern int socket_local6(int s,char *ip,uint16 *port,uint32 *scope_id);
  2332. +extern int socket_remote6(int s,char *ip,uint16 *port,uint32 *scope_id);
  2333. +
  2334. +/* enable sending udp packets to the broadcast address */
  2335. +extern int socket_broadcast(int);
  2336. +/* join a multicast group on the given interface */
  2337. +extern int socket_mcjoin4(int,char *,char *);
  2338. +extern int socket_mcjoin6(int,char *,int);
  2339. +/* leave a multicast group on the given interface */
  2340. +extern int socket_mcleave4(int,char *);
  2341. +extern int socket_mcleave6(int,char *);
  2342. +/* set multicast TTL/hop count for outgoing packets */
  2343. +extern int socket_mcttl4(int,char);
  2344. +extern int socket_mcttl6(int,char);
  2345. +/* enable multicast loopback */
  2346. +extern int socket_mcloop4(int,char);
  2347. +extern int socket_mcloop6(int,char);
  2348. +
  2349. +extern const char* socket_getifname(uint32 interface);
  2350. +extern uint32 socket_getifidx(const char *ifname);
  2351. extern void socket_tryreservein(int,int);
  2352. +extern int noipv6;
  2353. +
  2354. #endif
  2355. diff -uNr ucspi-tcp-0.88.orig/socket_accept6.c ucspi-tcp-0.88/socket_accept6.c
  2356. --- ucspi-tcp-0.88.orig/socket_accept6.c 1969-12-31 18:00:00.000000000 -0600
  2357. +++ ucspi-tcp-0.88/socket_accept6.c 2009-08-04 17:45:59.000000000 -0500
  2358. @@ -0,0 +1,44 @@
  2359. +#include <sys/types.h>
  2360. +#include <sys/param.h>
  2361. +#include <sys/socket.h>
  2362. +#include <netinet/in.h>
  2363. +#include "byte.h"
  2364. +#include "socket.h"
  2365. +#include "ip6.h"
  2366. +#include "haveip6.h"
  2367. +#include "error.h"
  2368. +
  2369. +int socket_accept6(int s,char ip[16],uint16 *port,uint32 *scope_id)
  2370. +{
  2371. +#ifdef LIBC_HAS_IP6
  2372. + struct sockaddr_in6 sa;
  2373. +#else
  2374. + struct sockaddr_in sa;
  2375. +#endif
  2376. + unsigned int dummy = sizeof sa;
  2377. + int fd;
  2378. +
  2379. + fd = accept(s,(struct sockaddr *) &sa,&dummy);
  2380. + if (fd == -1) return -1;
  2381. +
  2382. +#ifdef LIBC_HAS_IP6
  2383. + if (sa.sin6_family==AF_INET) {
  2384. + struct sockaddr_in *sa4=(struct sockaddr_in*)&sa;
  2385. + byte_copy(ip,12,V4mappedprefix);
  2386. + byte_copy(ip+12,4,(char *) &sa4->sin_addr);
  2387. + uint16_unpack_big((char *) &sa4->sin_port,port);
  2388. + return fd;
  2389. + }
  2390. + byte_copy(ip,16,(char *) &sa.sin6_addr);
  2391. + uint16_unpack_big((char *) &sa.sin6_port,port);
  2392. + if (scope_id) *scope_id=sa.sin6_scope_id;
  2393. +
  2394. + return fd;
  2395. +#else
  2396. + byte_copy(ip,12,V4mappedprefix);
  2397. + byte_copy(ip+12,4,(char *) &sa.sin_addr);
  2398. + uint16_unpack_big((char *) &sa.sin_port,port);
  2399. + if (scope_id) *scope_id=0;
  2400. + return fd;
  2401. +#endif
  2402. +}
  2403. diff -uNr ucspi-tcp-0.88.orig/socket_bind.c ucspi-tcp-0.88/socket_bind.c
  2404. --- ucspi-tcp-0.88.orig/socket_bind.c 2009-08-04 15:19:16.000000000 -0500
  2405. +++ ucspi-tcp-0.88/socket_bind.c 2009-08-04 17:45:59.000000000 -0500
  2406. @@ -5,7 +5,7 @@
  2407. #include "byte.h"
  2408. #include "socket.h"
  2409. -int socket_bind4(int s,char ip[4],uint16 port)
  2410. +int socket_bind4(int s,const char ip[4],uint16 port)
  2411. {
  2412. struct sockaddr_in sa;
  2413. @@ -17,7 +17,7 @@
  2414. return bind(s,(struct sockaddr *) &sa,sizeof sa);
  2415. }
  2416. -int socket_bind4_reuse(int s,char ip[4],uint16 port)
  2417. +int socket_bind4_reuse(int s,const char ip[4],uint16 port)
  2418. {
  2419. int opt = 1;
  2420. setsockopt(s,SOL_SOCKET,SO_REUSEADDR,&opt,sizeof opt);
  2421. diff -uNr ucspi-tcp-0.88.orig/socket_bind6.c ucspi-tcp-0.88/socket_bind6.c
  2422. --- ucspi-tcp-0.88.orig/socket_bind6.c 1969-12-31 18:00:00.000000000 -0600
  2423. +++ ucspi-tcp-0.88/socket_bind6.c 2009-08-04 17:45:59.000000000 -0500
  2424. @@ -0,0 +1,45 @@
  2425. +#include <sys/types.h>
  2426. +#include <sys/param.h>
  2427. +#include <sys/socket.h>
  2428. +#include <netinet/in.h>
  2429. +#include "byte.h"
  2430. +#include "socket.h"
  2431. +#include "ip6.h"
  2432. +#include "haveip6.h"
  2433. +#include "error.h"
  2434. +
  2435. +int socket_bind6(int s,const char ip[16],uint16 port,uint32 scope_id)
  2436. +{
  2437. +#ifdef LIBC_HAS_IP6
  2438. + struct sockaddr_in6 sa;
  2439. +
  2440. + if (noipv6) {
  2441. +#endif
  2442. + int i;
  2443. + for (i=0; i<16; i++)
  2444. + if (ip[i]!=0) break;
  2445. + if (i==16 || ip6_isv4mapped(ip))
  2446. + return socket_bind4(s,ip+12,port);
  2447. +#ifdef LIBC_HAS_IP6
  2448. + }
  2449. + byte_zero(&sa,sizeof sa);
  2450. + sa.sin6_family = AF_INET6;
  2451. + uint16_pack_big((char *) &sa.sin6_port,port);
  2452. +/* implicit: sa.sin6_flowinfo = 0; */
  2453. + byte_copy((char *) &sa.sin6_addr,16,ip);
  2454. + sa.sin6_scope_id=scope_id;
  2455. +
  2456. + return bind(s,(struct sockaddr *) &sa,sizeof sa);
  2457. +#else
  2458. + errno=error_proto;
  2459. + return -1;
  2460. +#endif
  2461. +}
  2462. +
  2463. +int socket_bind6_reuse(int s,const char ip[16],uint16 port,uint32 scope_id)
  2464. +{
  2465. + int opt = 1;
  2466. + setsockopt(s,SOL_SOCKET,SO_REUSEADDR,&opt,sizeof opt);
  2467. + return socket_bind6(s,ip,port,scope_id);
  2468. +}
  2469. +
  2470. diff -uNr ucspi-tcp-0.88.orig/socket_conn.c ucspi-tcp-0.88/socket_conn.c
  2471. --- ucspi-tcp-0.88.orig/socket_conn.c 2009-08-04 15:19:16.000000000 -0500
  2472. +++ ucspi-tcp-0.88/socket_conn.c 2009-08-04 17:45:59.000000000 -0500
  2473. @@ -6,7 +6,7 @@
  2474. #include "byte.h"
  2475. #include "socket.h"
  2476. -int socket_connect4(int s,char ip[4],uint16 port)
  2477. +int socket_connect4(int s,const char ip[4],uint16 port)
  2478. {
  2479. struct sockaddr_in sa;
  2480. diff -uNr ucspi-tcp-0.88.orig/socket_conn6.c ucspi-tcp-0.88/socket_conn6.c
  2481. --- ucspi-tcp-0.88.orig/socket_conn6.c 1969-12-31 18:00:00.000000000 -0600
  2482. +++ ucspi-tcp-0.88/socket_conn6.c 2009-08-04 17:45:59.000000000 -0500
  2483. @@ -0,0 +1,38 @@
  2484. +#include <sys/param.h>
  2485. +#include <sys/types.h>
  2486. +#include <sys/socket.h>
  2487. +#include <netinet/in.h>
  2488. +#include <errno.h>
  2489. +#include "byte.h"
  2490. +#include "socket.h"
  2491. +#include "ip6.h"
  2492. +#include "haveip6.h"
  2493. +#include "uint32.h"
  2494. +#include "ip4.h"
  2495. +
  2496. +int socket_connect6(int s,const char ip[16],uint16 port,uint32 scope_id)
  2497. +{
  2498. +#ifdef LIBC_HAS_IP6
  2499. + struct sockaddr_in6 sa;
  2500. +
  2501. + if (noipv6) {
  2502. +#endif
  2503. + if (ip6_isv4mapped(ip))
  2504. + return socket_connect4(s,ip+12,port);
  2505. + if (byte_equal(ip,16,V6loopback))
  2506. + return socket_connect4(s,ip4loopback,port);
  2507. +#ifdef LIBC_HAS_IP6
  2508. + }
  2509. + byte_zero(&sa,sizeof sa);
  2510. + sa.sin6_family = PF_INET6;
  2511. + uint16_pack_big((char *) &sa.sin6_port,port);
  2512. + sa.sin6_flowinfo = 0;
  2513. + sa.sin6_scope_id = scope_id;
  2514. + byte_copy((char *) &sa.sin6_addr,16,ip);
  2515. +
  2516. + return connect(s,(struct sockaddr *) &sa,sizeof sa);
  2517. +#else
  2518. + errno=EPROTONOSUPPORT;
  2519. + return -1;
  2520. +#endif
  2521. +}
  2522. diff -uNr ucspi-tcp-0.88.orig/socket_getifidx.c ucspi-tcp-0.88/socket_getifidx.c
  2523. --- ucspi-tcp-0.88.orig/socket_getifidx.c 1969-12-31 18:00:00.000000000 -0600
  2524. +++ ucspi-tcp-0.88/socket_getifidx.c 2009-08-04 17:45:59.000000000 -0500
  2525. @@ -0,0 +1,8 @@
  2526. +#include <sys/types.h>
  2527. +#include <sys/socket.h>
  2528. +#include <net/if.h>
  2529. +#include "socket.h"
  2530. +
  2531. +uint32 socket_getifidx(const char* ifname) {
  2532. + return if_nametoindex(ifname);
  2533. +}
  2534. diff -uNr ucspi-tcp-0.88.orig/socket_getifname.c ucspi-tcp-0.88/socket_getifname.c
  2535. --- ucspi-tcp-0.88.orig/socket_getifname.c 1969-12-31 18:00:00.000000000 -0600
  2536. +++ ucspi-tcp-0.88/socket_getifname.c 2009-08-04 17:45:59.000000000 -0500
  2537. @@ -0,0 +1,14 @@
  2538. +#include <sys/types.h>
  2539. +#include <sys/socket.h>
  2540. +#include <net/if.h>
  2541. +#include "socket.h"
  2542. +
  2543. +static char ifname[IFNAMSIZ];
  2544. +
  2545. +const char* socket_getifname(uint32 interface) {
  2546. + char *tmp=if_indextoname(interface,ifname);
  2547. + if (tmp)
  2548. + return tmp;
  2549. + else
  2550. + return "[unknown]";
  2551. +}
  2552. diff -uNr ucspi-tcp-0.88.orig/socket_ip4loopback.c ucspi-tcp-0.88/socket_ip4loopback.c
  2553. --- ucspi-tcp-0.88.orig/socket_ip4loopback.c 1969-12-31 18:00:00.000000000 -0600
  2554. +++ ucspi-tcp-0.88/socket_ip4loopback.c 2009-08-04 17:45:59.000000000 -0500
  2555. @@ -0,0 +1,2 @@
  2556. +
  2557. +const char ip4loopback[4] = {127,0,0,1};
  2558. diff -uNr ucspi-tcp-0.88.orig/socket_local6.c ucspi-tcp-0.88/socket_local6.c
  2559. --- ucspi-tcp-0.88.orig/socket_local6.c 1969-12-31 18:00:00.000000000 -0600
  2560. +++ ucspi-tcp-0.88/socket_local6.c 2009-08-04 17:45:59.000000000 -0500
  2561. @@ -0,0 +1,39 @@
  2562. +#include <sys/types.h>
  2563. +#include <sys/param.h>
  2564. +#include <sys/socket.h>
  2565. +#include <netinet/in.h>
  2566. +#include "byte.h"
  2567. +#include "socket.h"
  2568. +#include "ip6.h"
  2569. +#include "haveip6.h"
  2570. +#include "error.h"
  2571. +
  2572. +int socket_local6(int s,char ip[16],uint16 *port,uint32 *scope_id)
  2573. +{
  2574. +#ifdef LIBC_HAS_IP6
  2575. + struct sockaddr_in6 sa;
  2576. +#else
  2577. + struct sockaddr_in sa;
  2578. +#endif
  2579. + unsigned int dummy = sizeof sa;
  2580. +
  2581. + if (getsockname(s,(struct sockaddr *) &sa,&dummy) == -1) return -1;
  2582. +#ifdef LIBC_HAS_IP6
  2583. + if (sa.sin6_family==AF_INET) {
  2584. + struct sockaddr_in *sa4=(struct sockaddr_in*)&sa;
  2585. + byte_copy(ip,12,V4mappedprefix);
  2586. + byte_copy(ip+12,4,(char *) &sa4->sin_addr);
  2587. + uint16_unpack_big((char *) &sa4->sin_port,port);
  2588. + return 0;
  2589. + }
  2590. + byte_copy(ip,16,(char *) &sa.sin6_addr);
  2591. + uint16_unpack_big((char *) &sa.sin6_port,port);
  2592. + if (scope_id) *scope_id=sa.sin6_scope_id;
  2593. +#else
  2594. + byte_copy(ip,12,V4mappedprefix);
  2595. + byte_copy(ip+12,4,(char *) &sa.sin_addr);
  2596. + uint16_unpack_big((char *) &sa.sin_port,port);
  2597. + if (scope_id) *scope_id=0;
  2598. +#endif
  2599. + return 0;
  2600. +}
  2601. diff -uNr ucspi-tcp-0.88.orig/socket_recv6.c ucspi-tcp-0.88/socket_recv6.c
  2602. --- ucspi-tcp-0.88.orig/socket_recv6.c 1969-12-31 18:00:00.000000000 -0600
  2603. +++ ucspi-tcp-0.88/socket_recv6.c 2009-08-04 17:45:59.000000000 -0500
  2604. @@ -0,0 +1,44 @@
  2605. +#include <sys/types.h>
  2606. +#include <sys/param.h>
  2607. +#include <sys/socket.h>
  2608. +#include <netinet/in.h>
  2609. +#include "byte.h"
  2610. +#include "socket.h"
  2611. +#include "ip6.h"
  2612. +#include "haveip6.h"
  2613. +#include "error.h"
  2614. +
  2615. +int socket_recv6(int s,char *buf,unsigned int len,char ip[16],uint16 *port,uint32 *scope_id)
  2616. +{
  2617. +#ifdef LIBC_HAS_IP6
  2618. + struct sockaddr_in6 sa;
  2619. +#else
  2620. + struct sockaddr_in sa;
  2621. +#endif
  2622. + unsigned int dummy = sizeof sa;
  2623. + int r;
  2624. +
  2625. + byte_zero(&sa,dummy);
  2626. + r = recvfrom(s,buf,len,0,(struct sockaddr *) &sa,&dummy);
  2627. + if (r == -1) return -1;
  2628. +
  2629. +#ifdef LIBC_HAS_IP6
  2630. + if (noipv6) {
  2631. + struct sockaddr_in *sa4=(struct sockaddr_in *)&sa;
  2632. + byte_copy(ip,12,V4mappedprefix);
  2633. + byte_copy(ip+12,4,(char *) &sa4->sin_addr);
  2634. + uint16_unpack_big((char *) &sa4->sin_port,port);
  2635. + return r;
  2636. + }
  2637. + byte_copy(ip,16,(char *) &sa.sin6_addr);
  2638. + uint16_unpack_big((char *) &sa.sin6_port,port);
  2639. + if (scope_id) *scope_id=sa.sin6_scope_id;
  2640. +#else
  2641. + byte_copy(ip,12,(char *)V4mappedprefix);
  2642. + byte_copy(ip+12,4,(char *) &sa.sin_addr);
  2643. + uint16_unpack_big((char *) &sa.sin_port,port);
  2644. + if (scope_id) *scope_id=0;
  2645. +#endif
  2646. +
  2647. + return r;
  2648. +}
  2649. diff -uNr ucspi-tcp-0.88.orig/socket_remote6.c ucspi-tcp-0.88/socket_remote6.c
  2650. --- ucspi-tcp-0.88.orig/socket_remote6.c 1969-12-31 18:00:00.000000000 -0600
  2651. +++ ucspi-tcp-0.88/socket_remote6.c 2009-08-04 17:45:59.000000000 -0500
  2652. @@ -0,0 +1,39 @@
  2653. +#include <sys/types.h>
  2654. +#include <sys/param.h>
  2655. +#include <sys/socket.h>
  2656. +#include <netinet/in.h>
  2657. +#include "byte.h"
  2658. +#include "socket.h"
  2659. +#include "ip6.h"
  2660. +#include "haveip6.h"
  2661. +#include "error.h"
  2662. +
  2663. +int socket_remote6(int s,char ip[16],uint16 *port,uint32 *scope_id)
  2664. +{
  2665. +#ifdef LIBC_HAS_IP6
  2666. + struct sockaddr_in6 sa;
  2667. +#else
  2668. + struct sockaddr_in sa;
  2669. +#endif
  2670. + unsigned int dummy = sizeof sa;
  2671. +
  2672. + if (getpeername(s,(struct sockaddr *) &sa,&dummy) == -1) return -1;
  2673. +#ifdef LIBC_HAS_IP6
  2674. + if (sa.sin6_family==AF_INET) {
  2675. + struct sockaddr_in *sa4=(struct sockaddr_in*)&sa;
  2676. + byte_copy(ip,12,V4mappedprefix);
  2677. + byte_copy(ip+12,4,(char *) &sa4->sin_addr);
  2678. + uint16_unpack_big((char *) &sa4->sin_port,port);
  2679. + return 0;
  2680. + }
  2681. + byte_copy(ip,16,(char *) &sa.sin6_addr);
  2682. + uint16_unpack_big((char *) &sa.sin6_port,port);
  2683. + if (scope_id) *scope_id=sa.sin6_scope_id;
  2684. +#else
  2685. + byte_copy(ip,12,V4mappedprefix);
  2686. + byte_copy(ip+12,4,(char *) &sa.sin_addr);
  2687. + uint16_unpack_big((char *) &sa.sin_port,port);
  2688. + if (scope_id) *scope_id=0;
  2689. +#endif
  2690. + return 0;
  2691. +}
  2692. diff -uNr ucspi-tcp-0.88.orig/socket_send6.c ucspi-tcp-0.88/socket_send6.c
  2693. --- ucspi-tcp-0.88.orig/socket_send6.c 1969-12-31 18:00:00.000000000 -0600
  2694. +++ ucspi-tcp-0.88/socket_send6.c 2009-08-04 17:45:59.000000000 -0500
  2695. @@ -0,0 +1,40 @@
  2696. +#include <sys/types.h>
  2697. +#include <sys/param.h>
  2698. +#include <sys/socket.h>
  2699. +#include <netinet/in.h>
  2700. +#include "byte.h"
  2701. +#include "socket.h"
  2702. +#include "ip4.h"
  2703. +#include "ip6.h"
  2704. +#include "haveip6.h"
  2705. +#include "error.h"
  2706. +
  2707. +int socket_send6(int s,const char *buf,unsigned int len,const char ip[16],uint16 port,uint32 scope_id)
  2708. +{
  2709. +#ifdef LIBC_HAS_IP6
  2710. + struct sockaddr_in6 sa;
  2711. +#else
  2712. + struct sockaddr_in sa;
  2713. +#endif
  2714. +
  2715. + byte_zero(&sa,sizeof sa);
  2716. +#ifdef LIBC_HAS_IP6
  2717. + if (noipv6) {
  2718. +#endif
  2719. + if (ip6_isv4mapped(ip))
  2720. + return socket_send4(s,buf,len,ip+12,port);
  2721. + if (byte_equal(ip,16,V6loopback))
  2722. + return socket_send4(s,buf,len,ip4loopback,port);
  2723. +#ifdef LIBC_HAS_IP6
  2724. + errno=error_proto;
  2725. + return -1;
  2726. + }
  2727. + sa.sin6_family = AF_INET6;
  2728. + uint16_pack_big((char *) &sa.sin6_port,port);
  2729. + byte_copy((char *) &sa.sin6_addr,16,ip);
  2730. + return sendto(s,buf,len,0,(struct sockaddr *) &sa,sizeof sa);
  2731. +#else
  2732. + errno=error_proto;
  2733. + return -1;
  2734. +#endif
  2735. +}
  2736. diff -uNr ucspi-tcp-0.88.orig/socket_tcp6.c ucspi-tcp-0.88/socket_tcp6.c
  2737. --- ucspi-tcp-0.88.orig/socket_tcp6.c 1969-12-31 18:00:00.000000000 -0600
  2738. +++ ucspi-tcp-0.88/socket_tcp6.c 2009-08-04 17:45:59.000000000 -0500
  2739. @@ -0,0 +1,44 @@
  2740. +#include <sys/types.h>
  2741. +#include <sys/param.h>
  2742. +#include <sys/socket.h>
  2743. +#include <netinet/in.h>
  2744. +#include <errno.h>
  2745. +#include "ndelay.h"
  2746. +#include "socket.h"
  2747. +#include "haveip6.h"
  2748. +#include "error.h"
  2749. +
  2750. +#ifdef LIBC_HAS_IP6
  2751. +int noipv6=0;
  2752. +#else
  2753. +int noipv6=1;
  2754. +#endif
  2755. +
  2756. +int socket_tcp6(void)
  2757. +{
  2758. +#ifdef LIBC_HAS_IP6
  2759. + int s;
  2760. +
  2761. + if (noipv6) goto compat;
  2762. + s = socket(PF_INET6,SOCK_STREAM,0);
  2763. + if (s == -1) {
  2764. + if (errno == EINVAL || errno == EAFNOSUPPORT) {
  2765. +compat:
  2766. + s=socket(AF_INET,SOCK_STREAM,0);
  2767. + noipv6=1;
  2768. + if (s==-1) return -1;
  2769. + } else
  2770. + return -1;
  2771. + }
  2772. + if (ndelay_on(s) == -1) { close(s); return -1; }
  2773. +#ifdef IPV6_V6ONLY
  2774. + {
  2775. + int zero=0;
  2776. + setsockopt(s,IPPROTO_IPV6,IPV6_V6ONLY,(void*)&zero,sizeof(zero));
  2777. + }
  2778. +#endif
  2779. + return s;
  2780. +#else
  2781. + return socket_tcp();
  2782. +#endif
  2783. +}
  2784. diff -uNr ucspi-tcp-0.88.orig/socket_udp6.c ucspi-tcp-0.88/socket_udp6.c
  2785. --- ucspi-tcp-0.88.orig/socket_udp6.c 1969-12-31 18:00:00.000000000 -0600
  2786. +++ ucspi-tcp-0.88/socket_udp6.c 2009-08-04 17:45:59.000000000 -0500
  2787. @@ -0,0 +1,38 @@
  2788. +#include <sys/types.h>
  2789. +#include <sys/socket.h>
  2790. +#include <netinet/in.h>
  2791. +#include <errno.h>
  2792. +#include "haveip6.h"
  2793. +#include "socket.h"
  2794. +
  2795. +#ifndef EAFNOSUPPORT
  2796. +#define EAFNOSUPPORT EINVAL
  2797. +#endif
  2798. +
  2799. +int socket_udp6(void)
  2800. +{
  2801. +#ifdef LIBC_HAS_IP6
  2802. + int s;
  2803. +
  2804. + if (noipv6) goto compat;
  2805. + s = socket(PF_INET6,SOCK_DGRAM,0);
  2806. + if (s == -1) {
  2807. + if (errno == EINVAL || errno == EAFNOSUPPORT) {
  2808. +compat:
  2809. + s=socket(AF_INET,SOCK_DGRAM,0);
  2810. + noipv6=1;
  2811. + if (s==-1) return -1;
  2812. + } else
  2813. + return -1;
  2814. + }
  2815. +#ifdef IPV6_V6ONLY
  2816. + {
  2817. + int zero=0;
  2818. + setsockopt(s,IPPROTO_IPV6,IPV6_V6ONLY,(void*)&zero,sizeof(zero));
  2819. + }
  2820. +#endif
  2821. + return s;
  2822. +#else
  2823. + return socket_udp();
  2824. +#endif
  2825. +}
  2826. diff -uNr ucspi-tcp-0.88.orig/socket_v4mappedprefix.c ucspi-tcp-0.88/socket_v4mappedprefix.c
  2827. --- ucspi-tcp-0.88.orig/socket_v4mappedprefix.c 1969-12-31 18:00:00.000000000 -0600
  2828. +++ ucspi-tcp-0.88/socket_v4mappedprefix.c 2009-08-04 17:45:59.000000000 -0500
  2829. @@ -0,0 +1,2 @@
  2830. +
  2831. +const unsigned char V4mappedprefix[12]={0,0,0,0,0,0,0,0,0,0,0xff,0xff};
  2832. diff -uNr ucspi-tcp-0.88.orig/socket_v6any.c ucspi-tcp-0.88/socket_v6any.c
  2833. --- ucspi-tcp-0.88.orig/socket_v6any.c 1969-12-31 18:00:00.000000000 -0600
  2834. +++ ucspi-tcp-0.88/socket_v6any.c 2009-08-04 17:45:59.000000000 -0500
  2835. @@ -0,0 +1,2 @@
  2836. +
  2837. +const unsigned char V6any[16]={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
  2838. diff -uNr ucspi-tcp-0.88.orig/socket_v6loopback.c ucspi-tcp-0.88/socket_v6loopback.c
  2839. --- ucspi-tcp-0.88.orig/socket_v6loopback.c 1969-12-31 18:00:00.000000000 -0600
  2840. +++ ucspi-tcp-0.88/socket_v6loopback.c 2009-08-04 17:45:59.000000000 -0500
  2841. @@ -0,0 +1,2 @@
  2842. +
  2843. +const unsigned char V6loopback[16]={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1};
  2844. diff -uNr ucspi-tcp-0.88.orig/str.h ucspi-tcp-0.88/str.h
  2845. --- ucspi-tcp-0.88.orig/str.h 2009-08-04 15:19:16.000000000 -0500
  2846. +++ ucspi-tcp-0.88/str.h 2009-08-04 17:45:59.000000000 -0500
  2847. @@ -1,13 +1,13 @@
  2848. #ifndef STR_H
  2849. #define STR_H
  2850. -extern unsigned int str_copy(char *,char *);
  2851. -extern int str_diff(char *,char *);
  2852. -extern int str_diffn(char *,char *,unsigned int);
  2853. -extern unsigned int str_len(char *);
  2854. -extern unsigned int str_chr(char *,int);
  2855. -extern unsigned int str_rchr(char *,int);
  2856. -extern int str_start(char *,char *);
  2857. +extern unsigned int str_copy(char *,const char *);
  2858. +extern int str_diff(const char *,const char *);
  2859. +extern int str_diffn(const char *,const char *,unsigned int);
  2860. +extern unsigned int str_len(const char *);
  2861. +extern unsigned int str_chr(const char *,int);
  2862. +extern unsigned int str_rchr(const char *,int);
  2863. +extern int str_start(const char *,const char *);
  2864. #define str_equal(s,t) (!str_diff((s),(t)))
  2865. diff -uNr ucspi-tcp-0.88.orig/str_chr.c ucspi-tcp-0.88/str_chr.c
  2866. --- ucspi-tcp-0.88.orig/str_chr.c 2009-08-04 15:19:16.000000000 -0500
  2867. +++ ucspi-tcp-0.88/str_chr.c 2009-08-04 17:45:59.000000000 -0500
  2868. @@ -1,9 +1,9 @@
  2869. #include "str.h"
  2870. -unsigned int str_chr(register char *s,int c)
  2871. +unsigned int str_chr(register const char *s,int c)
  2872. {
  2873. register char ch;
  2874. - register char *t;
  2875. + register const char *t;
  2876. ch = c;
  2877. t = s;
  2878. diff -uNr ucspi-tcp-0.88.orig/str_diff.c ucspi-tcp-0.88/str_diff.c
  2879. --- ucspi-tcp-0.88.orig/str_diff.c 2009-08-04 15:19:16.000000000 -0500
  2880. +++ ucspi-tcp-0.88/str_diff.c 2009-08-04 17:45:59.000000000 -0500
  2881. @@ -1,6 +1,6 @@
  2882. #include "str.h"
  2883. -int str_diff(register char *s,register char *t)
  2884. +int str_diff(register const char *s,register const char *t)
  2885. {
  2886. register char x;
  2887. diff -uNr ucspi-tcp-0.88.orig/str_len.c ucspi-tcp-0.88/str_len.c
  2888. --- ucspi-tcp-0.88.orig/str_len.c 2009-08-04 15:19:16.000000000 -0500
  2889. +++ ucspi-tcp-0.88/str_len.c 2009-08-04 17:45:59.000000000 -0500
  2890. @@ -1,8 +1,8 @@
  2891. #include "str.h"
  2892. -unsigned int str_len(char *s)
  2893. +unsigned int str_len(const char *s)
  2894. {
  2895. - register char *t;
  2896. + register const char *t;
  2897. t = s;
  2898. for (;;) {
  2899. diff -uNr ucspi-tcp-0.88.orig/str_start.c ucspi-tcp-0.88/str_start.c
  2900. --- ucspi-tcp-0.88.orig/str_start.c 2009-08-04 15:19:16.000000000 -0500
  2901. +++ ucspi-tcp-0.88/str_start.c 2009-08-04 17:45:59.000000000 -0500
  2902. @@ -1,6 +1,6 @@
  2903. #include "str.h"
  2904. -int str_start(register char *s,register char *t)
  2905. +int str_start(register const char *s,register const char *t)
  2906. {
  2907. register char x;
  2908. diff -uNr ucspi-tcp-0.88.orig/stralloc.h ucspi-tcp-0.88/stralloc.h
  2909. --- ucspi-tcp-0.88.orig/stralloc.h 2009-08-04 15:19:16.000000000 -0500
  2910. +++ ucspi-tcp-0.88/stralloc.h 2009-08-04 17:45:59.000000000 -0500
  2911. @@ -9,18 +9,20 @@
  2912. extern int stralloc_readyplus(stralloc *,unsigned int);
  2913. extern int stralloc_copy(stralloc *,stralloc *);
  2914. extern int stralloc_cat(stralloc *,stralloc *);
  2915. -extern int stralloc_copys(stralloc *,char *);
  2916. -extern int stralloc_cats(stralloc *,char *);
  2917. -extern int stralloc_copyb(stralloc *,char *,unsigned int);
  2918. -extern int stralloc_catb(stralloc *,char *,unsigned int);
  2919. +extern int stralloc_copys(stralloc *,const char *);
  2920. +extern int stralloc_cats(stralloc *,const char *);
  2921. +extern int stralloc_copyb(stralloc *,const char *,unsigned int);
  2922. +extern int stralloc_catb(stralloc *,const char *,unsigned int);
  2923. extern int stralloc_append(stralloc *,char *); /* beware: this takes a pointer to 1 char */
  2924. -extern int stralloc_starts(stralloc *,char *);
  2925. +extern int stralloc_starts(stralloc *,const char *);
  2926. #define stralloc_0(sa) stralloc_append(sa,"")
  2927. extern int stralloc_catulong0(stralloc *,unsigned long,unsigned int);
  2928. extern int stralloc_catlong0(stralloc *,long,unsigned int);
  2929. +extern void stralloc_free(stralloc *);
  2930. +
  2931. #define stralloc_catlong(sa,l) (stralloc_catlong0((sa),(l),0))
  2932. #define stralloc_catuint0(sa,i,n) (stralloc_catulong0((sa),(i),(n)))
  2933. #define stralloc_catint0(sa,i,n) (stralloc_catlong0((sa),(i),(n)))
  2934. diff -uNr ucspi-tcp-0.88.orig/stralloc_catb.c ucspi-tcp-0.88/stralloc_catb.c
  2935. --- ucspi-tcp-0.88.orig/stralloc_catb.c 2009-08-04 15:19:16.000000000 -0500
  2936. +++ ucspi-tcp-0.88/stralloc_catb.c 2009-08-04 17:45:59.000000000 -0500
  2937. @@ -1,7 +1,7 @@
  2938. #include "stralloc.h"
  2939. #include "byte.h"
  2940. -int stralloc_catb(stralloc *sa,char *s,unsigned int n)
  2941. +int stralloc_catb(stralloc *sa,const char *s,unsigned int n)
  2942. {
  2943. if (!sa->s) return stralloc_copyb(sa,s,n);
  2944. if (!stralloc_readyplus(sa,n + 1)) return 0;
  2945. diff -uNr ucspi-tcp-0.88.orig/stralloc_cats.c ucspi-tcp-0.88/stralloc_cats.c
  2946. --- ucspi-tcp-0.88.orig/stralloc_cats.c 2009-08-04 15:19:16.000000000 -0500
  2947. +++ ucspi-tcp-0.88/stralloc_cats.c 2009-08-04 17:45:59.000000000 -0500
  2948. @@ -2,7 +2,7 @@
  2949. #include "str.h"
  2950. #include "stralloc.h"
  2951. -int stralloc_cats(stralloc *sa,char *s)
  2952. +int stralloc_cats(stralloc *sa,const char *s)
  2953. {
  2954. return stralloc_catb(sa,s,str_len(s));
  2955. }
  2956. diff -uNr ucspi-tcp-0.88.orig/stralloc_opyb.c ucspi-tcp-0.88/stralloc_opyb.c
  2957. --- ucspi-tcp-0.88.orig/stralloc_opyb.c 2009-08-04 15:19:16.000000000 -0500
  2958. +++ ucspi-tcp-0.88/stralloc_opyb.c 2009-08-04 17:45:59.000000000 -0500
  2959. @@ -1,7 +1,7 @@
  2960. #include "stralloc.h"
  2961. #include "byte.h"
  2962. -int stralloc_copyb(stralloc *sa,char *s,unsigned int n)
  2963. +int stralloc_copyb(stralloc *sa,const char *s,unsigned int n)
  2964. {
  2965. if (!stralloc_ready(sa,n + 1)) return 0;
  2966. byte_copy(sa->s,n,s);
  2967. diff -uNr ucspi-tcp-0.88.orig/stralloc_opys.c ucspi-tcp-0.88/stralloc_opys.c
  2968. --- ucspi-tcp-0.88.orig/stralloc_opys.c 2009-08-04 15:19:16.000000000 -0500
  2969. +++ ucspi-tcp-0.88/stralloc_opys.c 2009-08-04 17:45:59.000000000 -0500
  2970. @@ -2,7 +2,7 @@
  2971. #include "str.h"
  2972. #include "stralloc.h"
  2973. -int stralloc_copys(stralloc *sa,char *s)
  2974. +int stralloc_copys(stralloc *sa,const char *s)
  2975. {
  2976. return stralloc_copyb(sa,s,str_len(s));
  2977. }
  2978. diff -uNr ucspi-tcp-0.88.orig/tcp-environ.5 ucspi-tcp-0.88/tcp-environ.5
  2979. --- ucspi-tcp-0.88.orig/tcp-environ.5 1969-12-31 18:00:00.000000000 -0600
  2980. +++ ucspi-tcp-0.88/tcp-environ.5 2009-08-04 17:45:59.000000000 -0500
  2981. @@ -0,0 +1,66 @@
  2982. +.TH tcp-environ 5
  2983. +.SH NAME
  2984. +tcp-environ \- TCP-related environment variables
  2985. +.SH DESCRIPTION
  2986. +The following environment variables
  2987. +describe a TCP connection.
  2988. +They are set up by
  2989. +.BR tcp-env ,
  2990. +.BR tcpclient ,
  2991. +and
  2992. +.BR tcpserver .
  2993. +Note that
  2994. +.BR TCPLOCALHOST ,
  2995. +.BR TCPREMOTEHOST ,
  2996. +and
  2997. +.B TCPREMOTEINFO
  2998. +can contain arbitrary characters.
  2999. +.TP 5
  3000. +PROTO
  3001. +The string
  3002. +.BR TCP .
  3003. +.TP 5
  3004. +TCPLOCALHOST
  3005. +The domain name of the local host,
  3006. +with uppercase letters converted to lowercase.
  3007. +If there is no currently available domain name
  3008. +for the local IP address,
  3009. +.B TCPLOCALHOST
  3010. +is not set.
  3011. +.TP 5
  3012. +TCPLOCALIP
  3013. +The IP address of the local host, in dotted-decimal form.
  3014. +.TP 5
  3015. +TCPLOCALPORT
  3016. +The local TCP port number, in decimal.
  3017. +.TP 5
  3018. +TCPREMOTEHOST
  3019. +The domain name of the remote host,
  3020. +with uppercase letters converted to lowercase.
  3021. +If there is no currently available domain name
  3022. +for the remote IP address,
  3023. +.B TCPREMOTEHOST
  3024. +is not set.
  3025. +.TP 5
  3026. +TCPREMOTEINFO
  3027. +A connection-specific string, perhaps a username,
  3028. +supplied by the remote host
  3029. +via 931/1413/IDENT/TAP.
  3030. +If the remote host did not supply connection information,
  3031. +.B TCPREMOTEINFO
  3032. +is not set.
  3033. +.TP 5
  3034. +TCPREMOTEIP
  3035. +The IP address of the remote host.
  3036. +.TP 5
  3037. +TCPREMOTEPORT
  3038. +The remote TCP port number.
  3039. +.TP 5
  3040. +TCPINTERFACE
  3041. +The interface name ("eth0") for IPv6 connections using link-local
  3042. +addresses.
  3043. +.SH "SEE ALSO"
  3044. +tcpclient(1),
  3045. +tcpserver(1),
  3046. +tcp-env(1),
  3047. +tcp(4)
  3048. diff -uNr ucspi-tcp-0.88.orig/tcpcat.1 ucspi-tcp-0.88/tcpcat.1
  3049. --- ucspi-tcp-0.88.orig/tcpcat.1 1969-12-31 18:00:00.000000000 -0600
  3050. +++ ucspi-tcp-0.88/tcpcat.1 2009-08-04 17:45:59.000000000 -0500
  3051. @@ -0,0 +1,20 @@
  3052. +.TH tcpcat 1
  3053. +.SH NAME
  3054. +tcpcat \- print data from a TCP port
  3055. +.SH SYNTAX
  3056. +.B tcpcat
  3057. +.I host
  3058. +.I port
  3059. +.SH DESCRIPTION
  3060. +.B tcpcat
  3061. +connects to
  3062. +.I port
  3063. +on
  3064. +.I host
  3065. +and prints any data it receives.
  3066. +
  3067. +.B tcpcat
  3068. +can be used to transfer binary data.
  3069. +It does no conversions.
  3070. +.SH "SEE ALSO"
  3071. +tcpclient(1)
  3072. diff -uNr ucspi-tcp-0.88.orig/tcpclient.1 ucspi-tcp-0.88/tcpclient.1
  3073. --- ucspi-tcp-0.88.orig/tcpclient.1 1969-12-31 18:00:00.000000000 -0600
  3074. +++ ucspi-tcp-0.88/tcpclient.1 2009-08-04 17:45:59.000000000 -0500
  3075. @@ -0,0 +1,173 @@
  3076. +.TH tcpclient 1
  3077. +.SH NAME
  3078. +tcpclient \- create an outgoing TCP connection
  3079. +.SH SYNOPSIS
  3080. +.B tcpclient
  3081. +[
  3082. +.B \-46hHrRdDqQv
  3083. +]
  3084. +[
  3085. +.B \-i\fIlocalip
  3086. +]
  3087. +[
  3088. +.B \-p\fIlocalport
  3089. +]
  3090. +[
  3091. +.B \-T\fItimeoutconn
  3092. +]
  3093. +[
  3094. +.B \-l\fIlocalname
  3095. +]
  3096. +[
  3097. +.B \-t\fItimeoutinfo
  3098. +]
  3099. +[
  3100. +.B \-I\fIinterface
  3101. +]
  3102. +.I host
  3103. +.I port
  3104. +.I program
  3105. +[
  3106. +.I arg ...
  3107. +]
  3108. +.SH DESCRIPTION
  3109. +.B tcpclient
  3110. +attempts to connect to a TCP server.
  3111. +If it is successful, it runs
  3112. +.I program
  3113. +with the given arguments,
  3114. +with descriptor 6 reading from the network
  3115. +and descriptor 7 writing to the network.
  3116. +
  3117. +The server's address is given by
  3118. +.I host
  3119. +and
  3120. +.IR port .
  3121. +.I host
  3122. +may be 0, referring to the local machine,
  3123. +or a dotted-decimal IP address,
  3124. +or a host name;
  3125. +if a host has several IP addresses,
  3126. +.B tcpclient
  3127. +tries each in turn.
  3128. +.I port
  3129. +may be a numeric port number
  3130. +or a port name.
  3131. +
  3132. +.B tcpclient
  3133. +sets up several environment variables,
  3134. +as described in
  3135. +.B tcp-environ(5).
  3136. +.SH OPTIONS
  3137. +.TP
  3138. +.B \-i\fIlocalip
  3139. +Use
  3140. +.I localip
  3141. +as the IP address for the local side of the connection;
  3142. +quit if
  3143. +.I localip
  3144. +is not available.
  3145. +.TP
  3146. +.B \-p\fIlocalport
  3147. +Use
  3148. +.I localport
  3149. +as the port number for the local side of the connection;
  3150. +quit if
  3151. +.I localport
  3152. +is not available.
  3153. +.TP
  3154. +.B \-I\fIinterface
  3155. +Use
  3156. +.I interface
  3157. +as the local network interface. This is only defined for IPv6 sockets
  3158. +and needed if you use link-local IPv6 addresses.
  3159. +.TP
  3160. +.B \-T\fItimeoutconn
  3161. +Give up on the
  3162. +connection attempt
  3163. +after
  3164. +.I timeoutconn
  3165. +seconds. Default: 60.
  3166. +This timeout applies to each IP address tried.
  3167. +.TP
  3168. +.B \-d
  3169. +(Default.)
  3170. +Delay sending data for a fraction of a second whenever the
  3171. +remote host is responding slowly,
  3172. +to make better use of the network.
  3173. +.TP
  3174. +.B \-D
  3175. +Never delay sending data;
  3176. +enable TCP_NODELAY.
  3177. +This is appropriate for interactive connections.
  3178. +.TP
  3179. +.B \-q
  3180. +Quiet.
  3181. +Do not print any messages.
  3182. +.TP
  3183. +.B \-Q
  3184. +(Default.)
  3185. +Print error messages.
  3186. +.TP
  3187. +.B \-v
  3188. +Verbose.
  3189. +Print all available messages.
  3190. +.SH "DATA-GATHERING OPTIONS"
  3191. +.TP
  3192. +.B \-h
  3193. +(Default.)
  3194. +Look up the remote host name for
  3195. +.BR TCPREMOTEHOST .
  3196. +.TP
  3197. +.B \-H
  3198. +Do not look up the remote host name;
  3199. +unset
  3200. +.BR TCPREMOTEHOST .
  3201. +.TP
  3202. +.B \-l\fIlocalname
  3203. +Do not look up the local host name;
  3204. +use
  3205. +.I localname
  3206. +for
  3207. +.BR TCPLOCALHOST .
  3208. +.TP
  3209. +.B \-r
  3210. +(Default.)
  3211. +Attempt to obtain
  3212. +.B TCPREMOTEINFO
  3213. +from the remote host.
  3214. +.TP
  3215. +.B \-R
  3216. +Do not attempt to obtain
  3217. +.B TCPREMOTEINFO
  3218. +from the remote host.
  3219. +.TP
  3220. +.B \-t\fItimeoutinfo
  3221. +Give up on the
  3222. +.B TCPREMOTEINFO
  3223. +connection attempt
  3224. +after
  3225. +.I timeoutinfo
  3226. +seconds. Default: 26.
  3227. +.TP
  3228. +.B \-4
  3229. +Fall back to IPv4 sockets. This is necessary for terminally broken
  3230. +systems like OpenBSD which will not let IPv6 sockets connect to
  3231. +V4-mapped IPv6 addresses. Please note that this also applies to DNS
  3232. +lookups, so you will have to use an DNS resolver with an IPv6 address to
  3233. +connect to IPv6 systems. Use \fBDNSCACHEIP\fR to set the DNS resolver
  3234. +IP dynamically.
  3235. +.TP
  3236. +.B \-6
  3237. +Force IPv6 mode in UCSPI environment variables, even for
  3238. +IPv4 connections. This will set \fB$PROTO\fR to \fBTCP6\fR and put
  3239. +IPv4-mapped IPv6 addresses in \fBTCPLOCALIP\fR and \fBTCPREMOTEIP\fR.
  3240. +.SH "SEE ALSO"
  3241. +date@(1),
  3242. +finger@(1),
  3243. +http@(1),
  3244. +mconnect(1),
  3245. +tcpcat(1),
  3246. +tcpserver(1),
  3247. +who@(1),
  3248. +tcp-environ(5)
  3249. diff -uNr ucspi-tcp-0.88.orig/tcpclient.c ucspi-tcp-0.88/tcpclient.c
  3250. --- ucspi-tcp-0.88.orig/tcpclient.c 2009-08-04 15:19:16.000000000 -0500
  3251. +++ ucspi-tcp-0.88/tcpclient.c 2009-08-04 17:45:59.000000000 -0500
  3252. @@ -9,6 +9,7 @@
  3253. #include "scan.h"
  3254. #include "str.h"
  3255. #include "ip4.h"
  3256. +#include "ip6.h"
  3257. #include "uint16.h"
  3258. #include "socket.h"
  3259. #include "fd.h"
  3260. @@ -20,6 +21,7 @@
  3261. #include "timeoutconn.h"
  3262. #include "remoteinfo.h"
  3263. #include "dns.h"
  3264. +#include "byte.h"
  3265. #define FATAL "tcpclient: fatal: "
  3266. #define CONNECT "tcpclient: unable to connect to "
  3267. @@ -31,27 +33,30 @@
  3268. void usage(void)
  3269. {
  3270. strerr_die1x(100,"tcpclient: usage: tcpclient \
  3271. -[ -hHrRdDqQv ] \
  3272. +[ -46hHrRdDqQv ] \
  3273. [ -i localip ] \
  3274. [ -p localport ] \
  3275. [ -T timeoutconn ] \
  3276. [ -l localname ] \
  3277. [ -t timeoutinfo ] \
  3278. +[ -I interface ] \
  3279. host port program");
  3280. }
  3281. +int forcev6 = 0;
  3282. int verbosity = 1;
  3283. int flagdelay = 1;
  3284. int flagremoteinfo = 1;
  3285. int flagremotehost = 1;
  3286. unsigned long itimeout = 26;
  3287. unsigned long ctimeout[2] = { 2, 58 };
  3288. +uint32 netif = 0;
  3289. -char iplocal[4] = { 0,0,0,0 };
  3290. +char iplocal[16] = { 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0 };
  3291. uint16 portlocal = 0;
  3292. char *forcelocal = 0;
  3293. -char ipremote[4];
  3294. +char ipremote[16];
  3295. uint16 portremote;
  3296. char *hostname;
  3297. @@ -61,12 +66,13 @@
  3298. static stralloc tmp;
  3299. static stralloc fqdn;
  3300. char strnum[FMT_ULONG];
  3301. -char ipstr[IP4_FMT];
  3302. +char ipstr[IP6_FMT];
  3303. char seed[128];
  3304. main(int argc,char **argv)
  3305. {
  3306. + int fakev4=0;
  3307. unsigned long u;
  3308. int opt;
  3309. char *x;
  3310. @@ -80,8 +86,10 @@
  3311. close(7);
  3312. sig_ignore(sig_pipe);
  3313. - while ((opt = getopt(argc,argv,"dDvqQhHrRi:p:t:T:l:")) != opteof)
  3314. + while ((opt = getopt(argc,argv,"46dDvqQhHrRi:p:t:T:l:I:")) != opteof)
  3315. switch(opt) {
  3316. + case '4': noipv6 = 1; break;
  3317. + case '6': forcev6 = 1; break;
  3318. case 'd': flagdelay = 1; break;
  3319. case 'D': flagdelay = 0; break;
  3320. case 'v': verbosity = 2; break;
  3321. @@ -97,7 +105,8 @@
  3322. if (optarg[j] == '+') ++j;
  3323. scan_ulong(optarg + j,&ctimeout[1]);
  3324. break;
  3325. - case 'i': if (!ip4_scan(optarg,iplocal)) usage(); break;
  3326. + case 'i': if (!scan_ip6(optarg,iplocal)) usage(); break;
  3327. + case 'I': netif=socket_getifidx(optarg); break;
  3328. case 'p': scan_ulong(optarg,&u); portlocal = u; break;
  3329. default: usage();
  3330. }
  3331. @@ -108,8 +117,8 @@
  3332. hostname = *argv;
  3333. if (!hostname) usage();
  3334. - if (str_equal(hostname,"")) hostname = "127.0.0.1";
  3335. - if (str_equal(hostname,"0")) hostname = "127.0.0.1";
  3336. + if (!hostname[0] || str_equal(hostname,"0"))
  3337. + hostname = (noipv6?"127.0.0.1":"::1");
  3338. x = *++argv;
  3339. if (!x) usage();
  3340. @@ -127,33 +136,36 @@
  3341. if (!*++argv) usage();
  3342. if (!stralloc_copys(&tmp,hostname)) nomem();
  3343. - if (dns_ip4_qualify(&addresses,&fqdn,&tmp) == -1)
  3344. + if (dns_ip6_qualify(&addresses,&fqdn,&tmp) == -1)
  3345. strerr_die4sys(111,FATAL,"temporarily unable to figure out IP address for ",hostname,": ");
  3346. - if (addresses.len < 4)
  3347. + if (addresses.len < 16)
  3348. strerr_die3x(111,FATAL,"no IP address for ",hostname);
  3349. - if (addresses.len == 4) {
  3350. + if (addresses.len == 16) {
  3351. ctimeout[0] += ctimeout[1];
  3352. ctimeout[1] = 0;
  3353. }
  3354. for (cloop = 0;cloop < 2;++cloop) {
  3355. if (!stralloc_copys(&moreaddresses,"")) nomem();
  3356. - for (j = 0;j + 4 <= addresses.len;j += 4) {
  3357. - s = socket_tcp();
  3358. + for (j = 0;j + 16 <= addresses.len;j += 4) {
  3359. + s = socket_tcp6();
  3360. if (s == -1)
  3361. strerr_die2sys(111,FATAL,"unable to create socket: ");
  3362. - if (socket_bind4(s,iplocal,portlocal) == -1)
  3363. + if (socket_bind6(s,iplocal,portlocal,netif) == -1)
  3364. strerr_die2sys(111,FATAL,"unable to bind socket: ");
  3365. - if (timeoutconn(s,addresses.s + j,portremote,ctimeout[cloop]) == 0)
  3366. + if (timeoutconn6(s,addresses.s + j,portremote,ctimeout[cloop],netif) == 0)
  3367. goto CONNECTED;
  3368. close(s);
  3369. if (!cloop && ctimeout[1] && (errno == error_timeout)) {
  3370. - if (!stralloc_catb(&moreaddresses,addresses.s + j,4)) nomem();
  3371. + if (!stralloc_catb(&moreaddresses,addresses.s + j,16)) nomem();
  3372. }
  3373. else {
  3374. strnum[fmt_ulong(strnum,portremote)] = 0;
  3375. - ipstr[ip4_fmt(ipstr,addresses.s + j)] = 0;
  3376. + if (ip6_isv4mapped(addresses.s+j))
  3377. + ipstr[ip4_fmt(ipstr,addresses.s + j + 12)] = 0;
  3378. + else
  3379. + ipstr[ip6_fmt(ipstr,addresses.s + j)] = 0;
  3380. strerr_warn5(CONNECT,ipstr," port ",strnum,": ",&strerr_sys);
  3381. }
  3382. }
  3383. @@ -169,37 +181,46 @@
  3384. if (!flagdelay)
  3385. socket_tcpnodelay(s); /* if it fails, bummer */
  3386. - if (!pathexec_env("PROTO","TCP")) nomem();
  3387. -
  3388. - if (socket_local4(s,iplocal,&portlocal) == -1)
  3389. + if (socket_local6(s,iplocal,&portlocal,&netif) == -1)
  3390. strerr_die2sys(111,FATAL,"unable to get local address: ");
  3391. + if (!forcev6 && (ip6_isv4mapped(iplocal) || byte_equal(iplocal,16,V6any)))
  3392. + fakev4=1;
  3393. +
  3394. + if (!pathexec_env("PROTO",fakev4?"TCP":"TCP6")) nomem();
  3395. +
  3396. strnum[fmt_ulong(strnum,portlocal)] = 0;
  3397. if (!pathexec_env("TCPLOCALPORT",strnum)) nomem();
  3398. - ipstr[ip4_fmt(ipstr,iplocal)] = 0;
  3399. + if (fakev4)
  3400. + ipstr[ip4_fmt(ipstr,iplocal+12)] = 0;
  3401. + else
  3402. + ipstr[ip6_fmt(ipstr,iplocal)] = 0;
  3403. if (!pathexec_env("TCPLOCALIP",ipstr)) nomem();
  3404. x = forcelocal;
  3405. if (!x)
  3406. - if (dns_name4(&tmp,iplocal) == 0) {
  3407. + if (dns_name6(&tmp,iplocal) == 0) {
  3408. if (!stralloc_0(&tmp)) nomem();
  3409. x = tmp.s;
  3410. }
  3411. if (!pathexec_env("TCPLOCALHOST",x)) nomem();
  3412. - if (socket_remote4(s,ipremote,&portremote) == -1)
  3413. + if (socket_remote6(s,ipremote,&portremote,&netif) == -1)
  3414. strerr_die2sys(111,FATAL,"unable to get remote address: ");
  3415. strnum[fmt_ulong(strnum,portremote)] = 0;
  3416. if (!pathexec_env("TCPREMOTEPORT",strnum)) nomem();
  3417. - ipstr[ip4_fmt(ipstr,ipremote)] = 0;
  3418. + if (fakev4)
  3419. + ipstr[ip4_fmt(ipstr,ipremote+12)] = 0;
  3420. + else
  3421. + ipstr[ip6_fmt(ipstr,ipremote)] = 0;
  3422. if (!pathexec_env("TCPREMOTEIP",ipstr)) nomem();
  3423. if (verbosity >= 2)
  3424. strerr_warn4("tcpclient: connected to ",ipstr," port ",strnum,0);
  3425. x = 0;
  3426. if (flagremotehost)
  3427. - if (dns_name4(&tmp,ipremote) == 0) {
  3428. + if (dns_name6(&tmp,ipremote) == 0) {
  3429. if (!stralloc_0(&tmp)) nomem();
  3430. x = tmp.s;
  3431. }
  3432. @@ -207,7 +228,7 @@
  3433. x = 0;
  3434. if (flagremoteinfo)
  3435. - if (remoteinfo(&tmp,ipremote,portremote,iplocal,portlocal,itimeout) == 0) {
  3436. + if (remoteinfo6(&tmp,ipremote,portremote,iplocal,portlocal,itimeout,netif) == 0) {
  3437. if (!stralloc_0(&tmp)) nomem();
  3438. x = tmp.s;
  3439. }
  3440. diff -uNr ucspi-tcp-0.88.orig/tcprules.1 ucspi-tcp-0.88/tcprules.1
  3441. --- ucspi-tcp-0.88.orig/tcprules.1 1969-12-31 18:00:00.000000000 -0600
  3442. +++ ucspi-tcp-0.88/tcprules.1 2009-08-04 17:45:59.000000000 -0500
  3443. @@ -0,0 +1,221 @@
  3444. +.TH tcprules 1
  3445. +.SH NAME
  3446. +tcprules \- compile rules for tcpserver
  3447. +.SH SYNOPSIS
  3448. +.B tcprules
  3449. +.I rules.cdb
  3450. +.I rules.tmp
  3451. +.SH OVERVIEW
  3452. +.B tcpserver
  3453. +optionally follows rules to decide whether a TCP connection is acceptable.
  3454. +For example, a rule of
  3455. +
  3456. +.EX
  3457. + 18.23.0.32:deny
  3458. +.EE
  3459. +
  3460. +prohibits connections from IP address 18.23.0.32.
  3461. +
  3462. +.B tcprules
  3463. +reads rules from its standard input
  3464. +and writes them into
  3465. +.I rules.cdb
  3466. +in a binary format suited
  3467. +for quick access by
  3468. +.BR tcpserver .
  3469. +
  3470. +.B tcprules
  3471. +can be used while
  3472. +.B tcpserver
  3473. +is running:
  3474. +it ensures that
  3475. +.I rules.cdb
  3476. +is updated atomically.
  3477. +It does this by first writing the rules to
  3478. +.I rules.tmp
  3479. +and then moving
  3480. +.I rules.tmp
  3481. +on top of
  3482. +.IR rules.cdb .
  3483. +If
  3484. +.I rules.tmp
  3485. +already exists, it is destroyed.
  3486. +The directories containing
  3487. +.I rules.cdb
  3488. +and
  3489. +.I rules.tmp
  3490. +must be writable to
  3491. +.BR tcprules ;
  3492. +they must also be on the same filesystem.
  3493. +
  3494. +If there is a problem with the input,
  3495. +.B tcprules
  3496. +complains and leaves
  3497. +.I rules.cdb
  3498. +alone.
  3499. +
  3500. +The binary
  3501. +.I rules.cdb
  3502. +format is portable across machines.
  3503. +.SH "RULE FORMAT"
  3504. +A rule takes up one line.
  3505. +A file containing rules
  3506. +may also contain comments: lines beginning with # are ignored.
  3507. +
  3508. +Each rule contains an
  3509. +.BR address ,
  3510. +a colon,
  3511. +and a list of
  3512. +.BR instructions ,
  3513. +with no extra spaces.
  3514. +When
  3515. +.B tcpserver
  3516. +receives a connection from that address,
  3517. +it follows the instructions.
  3518. +.SH "ADDRESSES"
  3519. +.B tcpserver
  3520. +starts by looking for a rule with address
  3521. +.IR TCPREMOTEINFO\fB@\fITCPREMOTEIP .
  3522. +If it doesn't find one, or if
  3523. +.I TCPREMOTEINFO
  3524. +is not set, it tries the address
  3525. +.IR TCPREMOTEIP .
  3526. +If that doesn't work, it tries shorter and shorter prefixes of
  3527. +.I TCPREMOTEIP
  3528. +ending with a dot.
  3529. +If none of them work, it tries the empty string.
  3530. +
  3531. +For example, here are some rules:
  3532. +
  3533. +.EX
  3534. + joe@127.0.0.1:first
  3535. +.br
  3536. + 18.23.0.32:second
  3537. +.br
  3538. + 127.:third
  3539. +.br
  3540. + :fourth
  3541. +.br
  3542. + ::1:fifth
  3543. +.EE
  3544. +
  3545. +If
  3546. +.I TCPREMOTEIP
  3547. +is
  3548. +.BR 10.119.75.38 ,
  3549. +.B tcpserver
  3550. +will follow the
  3551. +.B fourth
  3552. +instructions.
  3553. +
  3554. +If
  3555. +.I TCPREMOTEIP
  3556. +is
  3557. +.BR ::1 ,
  3558. +.B tcpserver
  3559. +will follow the
  3560. +.B fifth
  3561. +instructions. Note that you cannot detect IPv4 mapped addresses by
  3562. +matching "::ffff", as those addresses will be converted to IPv4 before
  3563. +looking at the rules.
  3564. +
  3565. +If
  3566. +.I TCPREMOTEIP
  3567. +is
  3568. +.BR 18.23.0.32 ,
  3569. +.B tcpserver
  3570. +will follow the
  3571. +.B second
  3572. +instructions.
  3573. +
  3574. +If
  3575. +.I TCPREMOTEINFO
  3576. +is
  3577. +.B bill
  3578. +and
  3579. +.I TCPREMOTEIP
  3580. +is
  3581. +.BR 127.0.0.1 ,
  3582. +.B tcpserver
  3583. +will follow the
  3584. +.B third
  3585. +instructions.
  3586. +
  3587. +If
  3588. +.I TCPREMOTEINFO
  3589. +is
  3590. +.B joe
  3591. +and
  3592. +.I TCPREMOTEIP
  3593. +is
  3594. +.BR 127.0.0.1 ,
  3595. +.B tcpserver
  3596. +will follow the
  3597. +.B first
  3598. +instructions.
  3599. +.SH "ADDRESS RANGES"
  3600. +.B tcprules
  3601. +treats
  3602. +.B 1.2.3.37-53:ins
  3603. +as an abbreviation
  3604. +for the rules
  3605. +.BR 1.2.3.37:ins ,
  3606. +.BR 1.2.3.38:ins ,
  3607. +and so on up through
  3608. +.BR 1.2.3.53:ins .
  3609. +Similarly,
  3610. +.BR 10.2-3.:ins
  3611. +is an abbreviation for
  3612. +.B 10.2.:ins
  3613. +and
  3614. +.BR 10.3.:ins .
  3615. +.SH "INSTRUCTIONS"
  3616. +The instructions in a rule must begin with either
  3617. +.B allow
  3618. +or
  3619. +.BR deny .
  3620. +.B deny
  3621. +tells
  3622. +.B tcpserver
  3623. +to drop the connection without running anything.
  3624. +For example, the rule
  3625. +
  3626. +.EX
  3627. + :deny
  3628. +.EE
  3629. +
  3630. +tells
  3631. +.B tcpserver
  3632. +to drop all connections that aren't handled by more specific rules.
  3633. +
  3634. +The instructions may continue with some environment variables,
  3635. +in the format
  3636. +.IR ,VAR="VALUE" .
  3637. +.B tcpserver
  3638. +adds
  3639. +.I VAR=VALUE
  3640. +to the current environment.
  3641. +For example,
  3642. +
  3643. +.EX
  3644. + 10.0.:allow,RELAYCLIENT="@fix.me"
  3645. +.EE
  3646. +
  3647. +adds
  3648. +.B RELAYCLIENT=@fix.me
  3649. +to the environment.
  3650. +The quotes here may be replaced by any repeated character:
  3651. +
  3652. +.EX
  3653. + 10.0.:allow,RELAYCLIENT=/@fix.me/
  3654. +.EE
  3655. +
  3656. +Any number of variables may be listed:
  3657. +
  3658. +.EX
  3659. + 127.0.0.1:allow,RELAYCLIENT="",TCPLOCALHOST="movie.edu"
  3660. +.EE
  3661. +.SH "SEE ALSO"
  3662. +tcprulescheck(1),
  3663. +tcpserver(1),
  3664. +tcp-environ(5)
  3665. diff -uNr ucspi-tcp-0.88.orig/tcprules.c ucspi-tcp-0.88/tcprules.c
  3666. --- ucspi-tcp-0.88.orig/tcprules.c 2009-08-04 15:19:16.000000000 -0500
  3667. +++ ucspi-tcp-0.88/tcprules.c 2009-08-04 17:45:59.000000000 -0500
  3668. @@ -123,8 +123,15 @@
  3669. }
  3670. line.len = len; /* for die_bad() */
  3671. - colon = byte_chr(x,len,':');
  3672. - if (colon == len) continue;
  3673. + colon = 0;
  3674. + for (;;) {
  3675. + int tmp;
  3676. + tmp = byte_chr(x + colon,len - colon,':');
  3677. + colon += tmp;
  3678. + if (colon == len) continue;
  3679. + if (byte_equal(x+colon+1,4,"deny") || byte_equal(x+colon+1,5,"allow")) break;
  3680. + ++colon;
  3681. + }
  3682. if (!stralloc_copyb(&address,x,colon)) nomem();
  3683. if (!stralloc_copys(&data,"")) nomem();
  3684. diff -uNr ucspi-tcp-0.88.orig/tcprulescheck.1 ucspi-tcp-0.88/tcprulescheck.1
  3685. --- ucspi-tcp-0.88.orig/tcprulescheck.1 1969-12-31 18:00:00.000000000 -0600
  3686. +++ ucspi-tcp-0.88/tcprulescheck.1 2009-08-04 17:45:59.000000000 -0500
  3687. @@ -0,0 +1,25 @@
  3688. +.TH tcprulescheck 1
  3689. +.SH NAME
  3690. +tcprulescheck \- try out rules for tcpserver
  3691. +.SH SYNTAX
  3692. +.B tcprulescheck
  3693. +.I rules.cdb
  3694. +.I tcpremoteip
  3695. +[
  3696. +.I tcpremoteinfo
  3697. +]
  3698. +.SH DESCRIPTION
  3699. +.B tcprulescheck
  3700. +says what
  3701. +.B tcpserver
  3702. +will do with a connection from
  3703. +IP address
  3704. +.IR tcpremoteip ,
  3705. +following the rules compiled into
  3706. +.I rules.cdb
  3707. +by
  3708. +.BR tcprules .
  3709. +.SH "SEE ALSO"
  3710. +tcprules(1),
  3711. +tcpserver(1),
  3712. +tcp-environ(5)
  3713. diff -uNr ucspi-tcp-0.88.orig/tcpserver.1 ucspi-tcp-0.88/tcpserver.1
  3714. --- ucspi-tcp-0.88.orig/tcpserver.1 1969-12-31 18:00:00.000000000 -0600
  3715. +++ ucspi-tcp-0.88/tcpserver.1 2009-08-04 17:45:59.000000000 -0500
  3716. @@ -0,0 +1,266 @@
  3717. +.TH tcpserver 1
  3718. +.SH NAME
  3719. +tcpserver \- accept incoming TCP connections
  3720. +.SH SYNOPSIS
  3721. +.B tcpserver
  3722. +[
  3723. +.B \-146jpPhHrRoOdDqQv
  3724. +]
  3725. +[
  3726. +.B \-c\fIlimit
  3727. +]
  3728. +[
  3729. +.B \-x\fIrules.cdb
  3730. +]
  3731. +[
  3732. +.B \-B\fIbanner
  3733. +]
  3734. +[
  3735. +.B \-g\fIgid
  3736. +]
  3737. +[
  3738. +.B \-u\fIuid
  3739. +]
  3740. +[
  3741. +.B \-b\fIbacklog
  3742. +]
  3743. +[
  3744. +.B \-l\fIlocalname
  3745. +]
  3746. +[
  3747. +.B \-t\fItimeout
  3748. +]
  3749. +[
  3750. +.B \-I\fIinterface
  3751. +]
  3752. +.I host
  3753. +.I port
  3754. +.I program
  3755. +[
  3756. +.I arg ...
  3757. +]
  3758. +.SH DESCRIPTION
  3759. +.B tcpserver
  3760. +waits for connections from TCP clients.
  3761. +For each connection, it runs
  3762. +.I program
  3763. +with the given arguments,
  3764. +with descriptor 0 reading from the network
  3765. +and descriptor 1 writing to the network.
  3766. +
  3767. +The server's address is given by
  3768. +.I host
  3769. +and
  3770. +.IR port .
  3771. +.I host
  3772. +can be 0, allowing connections from any host;
  3773. +or a particular IP address,
  3774. +allowing connections only to that address;
  3775. +or a host name, allowing connections to the first IP address
  3776. +for that host.
  3777. +.I port
  3778. +may be a numeric port number
  3779. +or a port name.
  3780. +If
  3781. +.I port
  3782. +is 0,
  3783. +.B tcpserver
  3784. +will choose a free port.
  3785. +
  3786. +.B tcpserver
  3787. +sets up several environment variables,
  3788. +as described in
  3789. +.B tcp-environ(5).
  3790. +
  3791. +.B tcpserver
  3792. +exits when it receives SIGTERM.
  3793. +.SH "OPTIONS"
  3794. +.TP
  3795. +.B \-c\fIlimit
  3796. +Do not handle more than
  3797. +.I limit
  3798. +simultaneous connections.
  3799. +If there are
  3800. +.I limit
  3801. +simultaneous copies of
  3802. +.I program
  3803. +running, defer acceptance of a new connection
  3804. +until one copy finishes.
  3805. +.I limit
  3806. +must be a positive integer.
  3807. +Default: 40.
  3808. +.TP
  3809. +.B \-x\fIrules.cdb
  3810. +Follow the rules compiled into
  3811. +.I rules.cdb
  3812. +by
  3813. +.BR tcprules .
  3814. +These rules may specify setting environment variables
  3815. +or rejecting connections from bad sources.
  3816. +
  3817. +.B tcpserver
  3818. +does not read
  3819. +.I rules.cdb
  3820. +into memory;
  3821. +you can rerun
  3822. +.B tcprules
  3823. +to change
  3824. +.BR tcpserver 's
  3825. +behavior on the fly.
  3826. +.TP
  3827. +.B \-B\fIbanner
  3828. +Write
  3829. +.I banner
  3830. +to the network immediately after each connection is made.
  3831. +.B tcpserver
  3832. +writes
  3833. +.I banner
  3834. +before looking up
  3835. +.BR TCPREMOTEHOST ,
  3836. +before looking up
  3837. +.BR TCPREMOTEINFO ,
  3838. +and before checking
  3839. +.IR rules.cdb .
  3840. +
  3841. +This feature can be used to reduce latency in protocols
  3842. +where the client waits for a greeting from the server.
  3843. +.TP
  3844. +.B \-g\fIgid
  3845. +Switch group ID to
  3846. +.I gid
  3847. +after preparing to receive connections.
  3848. +.I gid
  3849. +must be a positive integer.
  3850. +.TP
  3851. +.B \-u\fIuid
  3852. +Switch user ID to
  3853. +.I uid
  3854. +after preparing to receive connections.
  3855. +.I uid
  3856. +must be a positive integer.
  3857. +.TP
  3858. +.B \-1
  3859. +After preparing to receive connections,
  3860. +print the local port number to standard output.
  3861. +.TP
  3862. +.B \-4
  3863. +Fall back to IPv4 sockets. This is necessary for terminally broken
  3864. +systems like OpenBSD which will not let IPv6 sockets connect to
  3865. +V4-mapped IPv6 addresses. Please note that this also applies to DNS
  3866. +lookups, so you will have to use an DNS resolver with an IPv6 address to
  3867. +accept IPv6 connections. Use \fBDNSCACHEIP\fR to set the DNS resolver
  3868. +IP dynamically.
  3869. +.TP
  3870. +.B \-6
  3871. +Force IPv6 mode in UCSPI environment variables, even for
  3872. +IPv4 connections. This will set \fB$PROTO\fR to \fBTCP6\fR and put
  3873. +IPv4-mapped IPv6 addresses in \fBTCPLOCALIP\fR and \fBTCPREMOTEIP\fR.
  3874. +.TP
  3875. +.B \-I\fIinterface
  3876. +Bind to the network interface
  3877. +.I interface
  3878. +("eth0" on Linux, for example). This is only defined and needed for
  3879. +IPv6 link-local addresses.
  3880. +.TP
  3881. +.B \-b\fIbacklog
  3882. +Allow up to
  3883. +.I backlog
  3884. +simultaneous SYN_RECEIVEDs.
  3885. +Default: 20.
  3886. +On some systems,
  3887. +.I backlog
  3888. +is silently limited to 5.
  3889. +See
  3890. +.BR listen (2)
  3891. +for more details.
  3892. +.TP
  3893. +.B \-o
  3894. +Leave IP options alone.
  3895. +If the client is sending packets along an IP source route,
  3896. +send packets back along the same route.
  3897. +.TP
  3898. +.B \-O
  3899. +(Default.)
  3900. +Kill IP options.
  3901. +A client can still use source routing to connect and to send data,
  3902. +but packets will be sent back along the default route.
  3903. +.TP
  3904. +.B \-d
  3905. +(Default.)
  3906. +Delay sending data for a fraction of a second whenever the
  3907. +remote host is responding slowly,
  3908. +to make better use of the network.
  3909. +.TP
  3910. +.B \-D
  3911. +Never delay sending data;
  3912. +enable TCP_NODELAY.
  3913. +This is appropriate for interactive connections.
  3914. +.TP
  3915. +.B \-q
  3916. +Quiet.
  3917. +Do not print any messages.
  3918. +.TP
  3919. +.B \-Q
  3920. +(Default.)
  3921. +Print error messages.
  3922. +.TP
  3923. +.B \-v
  3924. +Verbose.
  3925. +Print all available messages.
  3926. +.SH "DATA-GATHERING OPTIONS"
  3927. +.TP
  3928. +.B \-p
  3929. +Paranoid.
  3930. +After looking up the remote host name,
  3931. +look up the IP addresses for that name,
  3932. +and make sure one of them matches
  3933. +.BR TCPREMOTEIP .
  3934. +If none of them do,
  3935. +unset
  3936. +.BR TCPREMOTEHOST .
  3937. +.TP
  3938. +.B \-P
  3939. +(Default.)
  3940. +Not paranoid.
  3941. +.TP
  3942. +.B \-h
  3943. +(Default.)
  3944. +Look up the remote host name and set
  3945. +.BR TCPREMOTEHOST .
  3946. +.TP
  3947. +.B \-H
  3948. +Do not look up the remote host name.
  3949. +.TP
  3950. +.B \-l\fIlocalname
  3951. +Do not look up the local host name;
  3952. +use
  3953. +.I localname
  3954. +for
  3955. +.BR TCPLOCALHOST .
  3956. +.TP
  3957. +.B \-r
  3958. +(Default.)
  3959. +Attempt to obtain
  3960. +.B TCPREMOTEINFO
  3961. +from the remote host.
  3962. +.TP
  3963. +.B \-R
  3964. +Do not attempt to obtain
  3965. +.B TCPREMOTEINFO
  3966. +from the remote host.
  3967. +.TP
  3968. +.B \-t\fItimeout
  3969. +Give up on the
  3970. +.B TCPREMOTEINFO
  3971. +connection attempt
  3972. +after
  3973. +.I timeout
  3974. +seconds. Default: 26.
  3975. +.SH "SEE ALSO"
  3976. +argv0(1),
  3977. +fixcr(1),
  3978. +recordio(1),
  3979. +tcpclient(1),
  3980. +tcprules(1),
  3981. +listen(2),
  3982. +tcp-environ(5)
  3983. diff -uNr ucspi-tcp-0.88.orig/tcpserver.c ucspi-tcp-0.88/tcpserver.c
  3984. --- ucspi-tcp-0.88.orig/tcpserver.c 2009-08-04 15:19:16.000000000 -0500
  3985. +++ ucspi-tcp-0.88/tcpserver.c 2009-08-04 17:45:59.000000000 -0500
  3986. @@ -7,6 +7,7 @@
  3987. #include "fmt.h"
  3988. #include "scan.h"
  3989. #include "ip4.h"
  3990. +#include "ip6.h"
  3991. #include "fd.h"
  3992. #include "exit.h"
  3993. #include "env.h"
  3994. @@ -28,6 +29,7 @@
  3995. #include "sig.h"
  3996. #include "dns.h"
  3997. +int forcev6 = 0;
  3998. int verbosity = 1;
  3999. int flagkillopts = 1;
  4000. int flagdelay = 1;
  4001. @@ -36,20 +38,21 @@
  4002. int flagremotehost = 1;
  4003. int flagparanoid = 0;
  4004. unsigned long timeout = 26;
  4005. +uint32 netif = 0;
  4006. static stralloc tcpremoteinfo;
  4007. uint16 localport;
  4008. char localportstr[FMT_ULONG];
  4009. -char localip[4];
  4010. -char localipstr[IP4_FMT];
  4011. +char localip[16];
  4012. +char localipstr[IP6_FMT];
  4013. static stralloc localhostsa;
  4014. char *localhost = 0;
  4015. uint16 remoteport;
  4016. char remoteportstr[FMT_ULONG];
  4017. -char remoteip[4];
  4018. -char remoteipstr[IP4_FMT];
  4019. +char remoteip[16];
  4020. +char remoteipstr[IP6_FMT];
  4021. static stralloc remotehostsa;
  4022. char *remotehost = 0;
  4023. @@ -96,12 +99,12 @@
  4024. if (ch < 33) ch = '?';
  4025. if (ch > 126) ch = '?';
  4026. if (ch == '%') ch = '?'; /* logger stupidity */
  4027. - if (ch == ':') ch = '?';
  4028. +/* if (ch == ':') ch = '?'; */
  4029. append(&ch);
  4030. }
  4031. cats("...");
  4032. }
  4033. -void env(char *s,char *t)
  4034. +void env(const char *s,const char *t)
  4035. {
  4036. if (!pathexec_env(s,t)) drop_nomem();
  4037. }
  4038. @@ -135,9 +138,16 @@
  4039. void doit(int t)
  4040. {
  4041. + int fakev4=0;
  4042. int j;
  4043. + uint32 scope_id;
  4044. - remoteipstr[ip4_fmt(remoteipstr,remoteip)] = 0;
  4045. + if (!forcev6 && ip6_isv4mapped(remoteip))
  4046. + fakev4=1;
  4047. + if (fakev4)
  4048. + remoteipstr[ip4_fmt(remoteipstr,remoteip+12)] = 0;
  4049. + else
  4050. + remoteipstr[ip6_fmt(remoteipstr,remoteip)] = 0;
  4051. if (verbosity >= 2) {
  4052. strnum[fmt_ulong(strnum,getpid())] = 0;
  4053. @@ -155,30 +165,40 @@
  4054. strerr_die2sys(111,DROP,"unable to print banner: ");
  4055. }
  4056. - if (socket_local4(t,localip,&localport) == -1)
  4057. + if (socket_local6(t,localip,&localport,&scope_id) == -1)
  4058. strerr_die2sys(111,DROP,"unable to get local address: ");
  4059. - localipstr[ip4_fmt(localipstr,localip)] = 0;
  4060. + if (fakev4)
  4061. + localipstr[ip4_fmt(localipstr,localip+12)] = 0;
  4062. + else
  4063. + localipstr[ip6_fmt(localipstr,localip)] = 0;
  4064. remoteportstr[fmt_ulong(remoteportstr,remoteport)] = 0;
  4065. if (!localhost)
  4066. - if (dns_name4(&localhostsa,localip) == 0)
  4067. + if (dns_name6(&localhostsa,localip) == 0)
  4068. if (localhostsa.len) {
  4069. if (!stralloc_0(&localhostsa)) drop_nomem();
  4070. localhost = localhostsa.s;
  4071. }
  4072. - env("PROTO","TCP");
  4073. + env("PROTO",fakev4?"TCP":"TCP6");
  4074. env("TCPLOCALIP",localipstr);
  4075. + localipstr[ip6_fmt(localipstr,localip)]=0;
  4076. + env("TCP6LOCALIP",localipstr);
  4077. +
  4078. env("TCPLOCALPORT",localportstr);
  4079. + env("TCP6LOCALPORT",localportstr);
  4080. env("TCPLOCALHOST",localhost);
  4081. + env("TCP6LOCALHOST",localhost);
  4082. + if (!fakev4 && scope_id)
  4083. + env("TCP6INTERFACE",socket_getifname(scope_id));
  4084. if (flagremotehost)
  4085. - if (dns_name4(&remotehostsa,remoteip) == 0)
  4086. + if (dns_name6(&remotehostsa,remoteip) == 0)
  4087. if (remotehostsa.len) {
  4088. if (flagparanoid)
  4089. - if (dns_ip4(&tmp,&remotehostsa) == 0)
  4090. - for (j = 0;j + 4 <= tmp.len;j += 4)
  4091. - if (byte_equal(remoteip,4,tmp.s + j)) {
  4092. + if (dns_ip6(&tmp,&remotehostsa) == 0)
  4093. + for (j = 0;j + 16 <= tmp.len;j += 16)
  4094. + if (byte_equal(remoteip,16,tmp.s + j)) {
  4095. flagparanoid = 0;
  4096. break;
  4097. }
  4098. @@ -188,15 +208,20 @@
  4099. }
  4100. }
  4101. env("TCPREMOTEIP",remoteipstr);
  4102. + remoteipstr[ip6_fmt(remoteipstr,remoteip)]=0;
  4103. + env("TCP6REMOTEIP",remoteipstr);
  4104. env("TCPREMOTEPORT",remoteportstr);
  4105. + env("TCP6REMOTEPORT",remoteportstr);
  4106. env("TCPREMOTEHOST",remotehost);
  4107. + env("TCP6REMOTEHOST",remotehost);
  4108. if (flagremoteinfo) {
  4109. - if (remoteinfo(&tcpremoteinfo,remoteip,remoteport,localip,localport,timeout) == -1)
  4110. + if (remoteinfo6(&tcpremoteinfo,remoteip,remoteport,localip,localport,timeout,netif) == -1)
  4111. flagremoteinfo = 0;
  4112. if (!stralloc_0(&tcpremoteinfo)) drop_nomem();
  4113. }
  4114. env("TCPREMOTEINFO",flagremoteinfo ? tcpremoteinfo.s : 0);
  4115. + env("TCP6REMOTEINFO",flagremoteinfo ? tcpremoteinfo.s : 0);
  4116. if (fnrules) {
  4117. int fdrules;
  4118. @@ -206,7 +231,15 @@
  4119. if (!flagallownorules) drop_rules();
  4120. }
  4121. else {
  4122. - if (rules(found,fdrules,remoteipstr,remotehost,flagremoteinfo ? tcpremoteinfo.s : 0) == -1) drop_rules();
  4123. + int fakev4=0;
  4124. + char* temp;
  4125. + if (!forcev6 && ip6_isv4mapped(remoteip))
  4126. + fakev4=1;
  4127. + if (fakev4)
  4128. + temp=remoteipstr+7;
  4129. + else
  4130. + temp=remoteipstr;
  4131. + if (rules(found,fdrules,temp,remotehost,flagremoteinfo ? tcpremoteinfo.s : 0) == -1) drop_rules();
  4132. close(fdrules);
  4133. }
  4134. }
  4135. @@ -240,7 +273,7 @@
  4136. {
  4137. strerr_warn1("\
  4138. tcpserver: usage: tcpserver \
  4139. -[ -1UXpPhHrRoOdDqQv ] \
  4140. +[ -461UXpPhHrRoOdDqQv ] \
  4141. [ -c limit ] \
  4142. [ -x rules.cdb ] \
  4143. [ -B banner ] \
  4144. @@ -249,6 +282,7 @@
  4145. [ -b backlog ] \
  4146. [ -l localname ] \
  4147. [ -t timeout ] \
  4148. +[ -I interface ] \
  4149. host port program",0);
  4150. _exit(100);
  4151. }
  4152. @@ -299,8 +333,8 @@
  4153. unsigned long u;
  4154. int s;
  4155. int t;
  4156. -
  4157. - while ((opt = getopt(argc,argv,"dDvqQhHrR1UXx:t:u:g:l:b:B:c:pPoO")) != opteof)
  4158. +
  4159. + while ((opt = getopt(argc,argv,"46dDvqQhHrR1UXx:t:u:g:l:b:B:c:I:pPoO")) != opteof)
  4160. switch(opt) {
  4161. case 'b': scan_ulong(optarg,&backlog); break;
  4162. case 'c': scan_ulong(optarg,&limit); break;
  4163. @@ -325,7 +359,10 @@
  4164. x = env_get("GID"); if (x) scan_ulong(x,&gid); break;
  4165. case 'u': scan_ulong(optarg,&uid); break;
  4166. case 'g': scan_ulong(optarg,&gid); break;
  4167. + case 'I': netif=socket_getifidx(optarg); break;
  4168. case '1': flag1 = 1; break;
  4169. + case '4': noipv6 = 1; break;
  4170. + case '6': forcev6 = 1; break;
  4171. case 'l': localhost = optarg; break;
  4172. default: usage();
  4173. }
  4174. @@ -337,8 +374,7 @@
  4175. hostname = *argv++;
  4176. if (!hostname) usage();
  4177. - if (str_equal(hostname,"")) hostname = "0.0.0.0";
  4178. - if (str_equal(hostname,"0")) hostname = "0.0.0.0";
  4179. + if (str_equal(hostname,"")) hostname = "0";
  4180. x = *argv++;
  4181. if (!x) usage();
  4182. @@ -348,7 +384,7 @@
  4183. se = getservbyname(x,"tcp");
  4184. if (!se)
  4185. strerr_die3x(111,FATAL,"unable to figure out port number for ",x);
  4186. - localport = ntohs(se->s_port);
  4187. + uint16_unpack_big((char*)&se->s_port,&localport);
  4188. }
  4189. if (!*argv) usage();
  4190. @@ -358,20 +394,26 @@
  4191. sig_catch(sig_term,sigterm);
  4192. sig_ignore(sig_pipe);
  4193. - if (!stralloc_copys(&tmp,hostname))
  4194. - strerr_die2x(111,FATAL,"out of memory");
  4195. - if (dns_ip4_qualify(&addresses,&fqdn,&tmp) == -1)
  4196. - strerr_die4sys(111,FATAL,"temporarily unable to figure out IP address for ",hostname,": ");
  4197. - if (addresses.len < 4)
  4198. - strerr_die3x(111,FATAL,"no IP address for ",hostname);
  4199. - byte_copy(localip,4,addresses.s);
  4200. + if (str_equal(hostname,"0")) {
  4201. + byte_zero(localip,sizeof localip);
  4202. + } else {
  4203. + if (!stralloc_copys(&tmp,hostname))
  4204. + strerr_die2x(111,FATAL,"out of memory");
  4205. + if (dns_ip6_qualify(&addresses,&fqdn,&tmp) == -1)
  4206. + strerr_die4sys(111,FATAL,"temporarily unable to figure out IP address for ",hostname,": ");
  4207. + if (addresses.len < 16)
  4208. + strerr_die3x(111,FATAL,"no IP address for ",hostname);
  4209. + byte_copy(localip,16,addresses.s);
  4210. + if (ip6_isv4mapped(localip))
  4211. + noipv6=1;
  4212. + }
  4213. - s = socket_tcp();
  4214. + s = socket_tcp6();
  4215. if (s == -1)
  4216. strerr_die2sys(111,FATAL,"unable to create socket: ");
  4217. - if (socket_bind4_reuse(s,localip,localport) == -1)
  4218. + if (socket_bind6_reuse(s,localip,localport,netif) == -1)
  4219. strerr_die2sys(111,FATAL,"unable to bind: ");
  4220. - if (socket_local4(s,localip,&localport) == -1)
  4221. + if (socket_local6(s,localip,&localport,&netif) == -1)
  4222. strerr_die2sys(111,FATAL,"unable to get local address: ");
  4223. if (socket_listen(s,backlog) == -1)
  4224. strerr_die2sys(111,FATAL,"unable to listen: ");
  4225. @@ -399,7 +441,7 @@
  4226. while (numchildren >= limit) sig_pause();
  4227. sig_unblock(sig_child);
  4228. - t = socket_accept4(s,remoteip,&remoteport);
  4229. + t = socket_accept6(s,remoteip,&remoteport,&netif);
  4230. sig_block(sig_child);
  4231. if (t == -1) continue;
  4232. diff -uNr ucspi-tcp-0.88.orig/timeoutconn.h ucspi-tcp-0.88/timeoutconn.h
  4233. --- ucspi-tcp-0.88.orig/timeoutconn.h 2009-08-04 15:19:16.000000000 -0500
  4234. +++ ucspi-tcp-0.88/timeoutconn.h 2009-08-04 17:45:59.000000000 -0500
  4235. @@ -2,7 +2,9 @@
  4236. #define TIMEOUTCONN_H
  4237. #include "uint16.h"
  4238. +#include "uint32.h"
  4239. extern int timeoutconn(int,char *,uint16,unsigned int);
  4240. +extern int timeoutconn6(int,char *,uint16,unsigned int,uint32);
  4241. #endif
  4242. diff -uNr ucspi-tcp-0.88.orig/timeoutconn6.c ucspi-tcp-0.88/timeoutconn6.c
  4243. --- ucspi-tcp-0.88.orig/timeoutconn6.c 1969-12-31 18:00:00.000000000 -0600
  4244. +++ ucspi-tcp-0.88/timeoutconn6.c 2009-08-04 17:45:59.000000000 -0500
  4245. @@ -0,0 +1,34 @@
  4246. +#include "ndelay.h"
  4247. +#include "socket.h"
  4248. +#include "iopause.h"
  4249. +#include "error.h"
  4250. +#include "timeoutconn.h"
  4251. +
  4252. +int timeoutconn6(int s,char ip[16],uint16 port,unsigned int timeout,uint32 netif)
  4253. +{
  4254. + struct taia now;
  4255. + struct taia deadline;
  4256. + iopause_fd x;
  4257. +
  4258. + if (socket_connect6(s,ip,port,netif) == -1) {
  4259. + if ((errno != error_wouldblock) && (errno != error_inprogress)) return -1;
  4260. + x.fd = s;
  4261. + x.events = IOPAUSE_WRITE;
  4262. + taia_now(&now);
  4263. + taia_uint(&deadline,timeout);
  4264. + taia_add(&deadline,&now,&deadline);
  4265. + for (;;) {
  4266. + taia_now(&now);
  4267. + iopause(&x,1,&deadline,&now);
  4268. + if (x.revents) break;
  4269. + if (taia_less(&deadline,&now)) {
  4270. + errno = error_timeout; /* note that connect attempt is continuing */
  4271. + return -1;
  4272. + }
  4273. + }
  4274. + if (!socket_connected(s)) return -1;
  4275. + }
  4276. +
  4277. + if (ndelay_off(s) == -1) return -1;
  4278. + return 0;
  4279. +}
  4280. diff -uNr ucspi-tcp-0.88.orig/tryip6.c ucspi-tcp-0.88/tryip6.c
  4281. --- ucspi-tcp-0.88.orig/tryip6.c 1969-12-31 18:00:00.000000000 -0600
  4282. +++ ucspi-tcp-0.88/tryip6.c 2009-08-04 17:45:59.000000000 -0500
  4283. @@ -0,0 +1,8 @@
  4284. +#include <sys/types.h>
  4285. +#include <sys/socket.h>
  4286. +#include <netinet/in.h>
  4287. +
  4288. +main() {
  4289. + struct sockaddr_in6 sa;
  4290. + sa.sin6_family = PF_INET6;
  4291. +}
  4292. diff -uNr ucspi-tcp-0.88.orig/usr/local/man/man1/tcpclient.1 ucspi-tcp-0.88/usr/local/man/man1/tcpclient.1
  4293. --- ucspi-tcp-0.88.orig/usr/local/man/man1/tcpclient.1 1969-12-31 18:00:00.000000000 -0600
  4294. +++ ucspi-tcp-0.88/usr/local/man/man1/tcpclient.1 2009-08-04 17:45:59.000000000 -0500
  4295. @@ -0,0 +1,173 @@
  4296. +.TH tcpclient 1
  4297. +.SH NAME
  4298. +tcpclient \- create an outgoing TCP connection
  4299. +.SH SYNOPSIS
  4300. +.B tcpclient
  4301. +[
  4302. +.B \-46hHrRdDqQv
  4303. +]
  4304. +[
  4305. +.B \-i\fIlocalip
  4306. +]
  4307. +[
  4308. +.B \-p\fIlocalport
  4309. +]
  4310. +[
  4311. +.B \-T\fItimeoutconn
  4312. +]
  4313. +[
  4314. +.B \-l\fIlocalname
  4315. +]
  4316. +[
  4317. +.B \-t\fItimeoutinfo
  4318. +]
  4319. +[
  4320. +.B \-I\fIinterface
  4321. +]
  4322. +.I host
  4323. +.I port
  4324. +.I program
  4325. +[
  4326. +.I arg ...
  4327. +]
  4328. +.SH DESCRIPTION
  4329. +.B tcpclient
  4330. +attempts to connect to a TCP server.
  4331. +If it is successful, it runs
  4332. +.I program
  4333. +with the given arguments,
  4334. +with descriptor 6 reading from the network
  4335. +and descriptor 7 writing to the network.
  4336. +
  4337. +The server's address is given by
  4338. +.I host
  4339. +and
  4340. +.IR port .
  4341. +.I host
  4342. +may be 0, referring to the local machine,
  4343. +or a dotted-decimal IP address,
  4344. +or a host name;
  4345. +if a host has several IP addresses,
  4346. +.B tcpclient
  4347. +tries each in turn.
  4348. +.I port
  4349. +may be a numeric port number
  4350. +or a port name.
  4351. +
  4352. +.B tcpclient
  4353. +sets up several environment variables,
  4354. +as described in
  4355. +.B tcp-environ(5).
  4356. +.SH OPTIONS
  4357. +.TP
  4358. +.B \-i\fIlocalip
  4359. +Use
  4360. +.I localip
  4361. +as the IP address for the local side of the connection;
  4362. +quit if
  4363. +.I localip
  4364. +is not available.
  4365. +.TP
  4366. +.B \-p\fIlocalport
  4367. +Use
  4368. +.I localport
  4369. +as the port number for the local side of the connection;
  4370. +quit if
  4371. +.I localport
  4372. +is not available.
  4373. +.TP
  4374. +.B \-I\fIinterface
  4375. +Use
  4376. +.I interface
  4377. +as the local network interface. This is only defined for IPv6 sockets
  4378. +and needed if you use link-local IPv6 addresses.
  4379. +.TP
  4380. +.B \-T\fItimeoutconn
  4381. +Give up on the
  4382. +connection attempt
  4383. +after
  4384. +.I timeoutconn
  4385. +seconds. Default: 60.
  4386. +This timeout applies to each IP address tried.
  4387. +.TP
  4388. +.B \-d
  4389. +(Default.)
  4390. +Delay sending data for a fraction of a second whenever the
  4391. +remote host is responding slowly,
  4392. +to make better use of the network.
  4393. +.TP
  4394. +.B \-D
  4395. +Never delay sending data;
  4396. +enable TCP_NODELAY.
  4397. +This is appropriate for interactive connections.
  4398. +.TP
  4399. +.B \-q
  4400. +Quiet.
  4401. +Do not print any messages.
  4402. +.TP
  4403. +.B \-Q
  4404. +(Default.)
  4405. +Print error messages.
  4406. +.TP
  4407. +.B \-v
  4408. +Verbose.
  4409. +Print all available messages.
  4410. +.SH "DATA-GATHERING OPTIONS"
  4411. +.TP
  4412. +.B \-h
  4413. +(Default.)
  4414. +Look up the remote host name for
  4415. +.BR TCPREMOTEHOST .
  4416. +.TP
  4417. +.B \-H
  4418. +Do not look up the remote host name;
  4419. +unset
  4420. +.BR TCPREMOTEHOST .
  4421. +.TP
  4422. +.B \-l\fIlocalname
  4423. +Do not look up the local host name;
  4424. +use
  4425. +.I localname
  4426. +for
  4427. +.BR TCPLOCALHOST .
  4428. +.TP
  4429. +.B \-r
  4430. +(Default.)
  4431. +Attempt to obtain
  4432. +.B TCPREMOTEINFO
  4433. +from the remote host.
  4434. +.TP
  4435. +.B \-R
  4436. +Do not attempt to obtain
  4437. +.B TCPREMOTEINFO
  4438. +from the remote host.
  4439. +.TP
  4440. +.B \-t\fItimeoutinfo
  4441. +Give up on the
  4442. +.B TCPREMOTEINFO
  4443. +connection attempt
  4444. +after
  4445. +.I timeoutinfo
  4446. +seconds. Default: 26.
  4447. +.TP
  4448. +.B \-4
  4449. +Fall back to IPv4 sockets. This is necessary for terminally broken
  4450. +systems like OpenBSD which will not let IPv6 sockets connect to
  4451. +V4-mapped IPv6 addresses. Please note that this also applies to DNS
  4452. +lookups, so you will have to use an DNS resolver with an IPv6 address to
  4453. +connect to IPv6 systems. Use \fBDNSCACHEIP\fR to set the DNS resolver
  4454. +IP dynamically.
  4455. +.TP
  4456. +.B \-6
  4457. +Force IPv6 mode in UCSPI environment variables, even for
  4458. +IPv4 connections. This will set \fB$PROTO\fR to \fBTCP6\fR and put
  4459. +IPv4-mapped IPv6 addresses in \fBTCPLOCALIP\fR and \fBTCPREMOTEIP\fR.
  4460. +.SH "SEE ALSO"
  4461. +date@(1),
  4462. +finger@(1),
  4463. +http@(1),
  4464. +mconnect(1),
  4465. +tcpcat(1),
  4466. +tcpserver(1),
  4467. +who@(1),
  4468. +tcp-environ(5)
  4469. diff -uNr ucspi-tcp-0.88.orig/usr/local/man/man1/tcpserver.1 ucspi-tcp-0.88/usr/local/man/man1/tcpserver.1
  4470. --- ucspi-tcp-0.88.orig/usr/local/man/man1/tcpserver.1 1969-12-31 18:00:00.000000000 -0600
  4471. +++ ucspi-tcp-0.88/usr/local/man/man1/tcpserver.1 2009-08-04 17:45:59.000000000 -0500
  4472. @@ -0,0 +1,266 @@
  4473. +.TH tcpserver 1
  4474. +.SH NAME
  4475. +tcpserver \- accept incoming TCP connections
  4476. +.SH SYNOPSIS
  4477. +.B tcpserver
  4478. +[
  4479. +.B \-146jpPhHrRoOdDqQv
  4480. +]
  4481. +[
  4482. +.B \-c\fIlimit
  4483. +]
  4484. +[
  4485. +.B \-x\fIrules.cdb
  4486. +]
  4487. +[
  4488. +.B \-B\fIbanner
  4489. +]
  4490. +[
  4491. +.B \-g\fIgid
  4492. +]
  4493. +[
  4494. +.B \-u\fIuid
  4495. +]
  4496. +[
  4497. +.B \-b\fIbacklog
  4498. +]
  4499. +[
  4500. +.B \-l\fIlocalname
  4501. +]
  4502. +[
  4503. +.B \-t\fItimeout
  4504. +]
  4505. +[
  4506. +.B \-I\fIinterface
  4507. +]
  4508. +.I host
  4509. +.I port
  4510. +.I program
  4511. +[
  4512. +.I arg ...
  4513. +]
  4514. +.SH DESCRIPTION
  4515. +.B tcpserver
  4516. +waits for connections from TCP clients.
  4517. +For each connection, it runs
  4518. +.I program
  4519. +with the given arguments,
  4520. +with descriptor 0 reading from the network
  4521. +and descriptor 1 writing to the network.
  4522. +
  4523. +The server's address is given by
  4524. +.I host
  4525. +and
  4526. +.IR port .
  4527. +.I host
  4528. +can be 0, allowing connections from any host;
  4529. +or a particular IP address,
  4530. +allowing connections only to that address;
  4531. +or a host name, allowing connections to the first IP address
  4532. +for that host.
  4533. +.I port
  4534. +may be a numeric port number
  4535. +or a port name.
  4536. +If
  4537. +.I port
  4538. +is 0,
  4539. +.B tcpserver
  4540. +will choose a free port.
  4541. +
  4542. +.B tcpserver
  4543. +sets up several environment variables,
  4544. +as described in
  4545. +.B tcp-environ(5).
  4546. +
  4547. +.B tcpserver
  4548. +exits when it receives SIGTERM.
  4549. +.SH "OPTIONS"
  4550. +.TP
  4551. +.B \-c\fIlimit
  4552. +Do not handle more than
  4553. +.I limit
  4554. +simultaneous connections.
  4555. +If there are
  4556. +.I limit
  4557. +simultaneous copies of
  4558. +.I program
  4559. +running, defer acceptance of a new connection
  4560. +until one copy finishes.
  4561. +.I limit
  4562. +must be a positive integer.
  4563. +Default: 40.
  4564. +.TP
  4565. +.B \-x\fIrules.cdb
  4566. +Follow the rules compiled into
  4567. +.I rules.cdb
  4568. +by
  4569. +.BR tcprules .
  4570. +These rules may specify setting environment variables
  4571. +or rejecting connections from bad sources.
  4572. +
  4573. +.B tcpserver
  4574. +does not read
  4575. +.I rules.cdb
  4576. +into memory;
  4577. +you can rerun
  4578. +.B tcprules
  4579. +to change
  4580. +.BR tcpserver 's
  4581. +behavior on the fly.
  4582. +.TP
  4583. +.B \-B\fIbanner
  4584. +Write
  4585. +.I banner
  4586. +to the network immediately after each connection is made.
  4587. +.B tcpserver
  4588. +writes
  4589. +.I banner
  4590. +before looking up
  4591. +.BR TCPREMOTEHOST ,
  4592. +before looking up
  4593. +.BR TCPREMOTEINFO ,
  4594. +and before checking
  4595. +.IR rules.cdb .
  4596. +
  4597. +This feature can be used to reduce latency in protocols
  4598. +where the client waits for a greeting from the server.
  4599. +.TP
  4600. +.B \-g\fIgid
  4601. +Switch group ID to
  4602. +.I gid
  4603. +after preparing to receive connections.
  4604. +.I gid
  4605. +must be a positive integer.
  4606. +.TP
  4607. +.B \-u\fIuid
  4608. +Switch user ID to
  4609. +.I uid
  4610. +after preparing to receive connections.
  4611. +.I uid
  4612. +must be a positive integer.
  4613. +.TP
  4614. +.B \-1
  4615. +After preparing to receive connections,
  4616. +print the local port number to standard output.
  4617. +.TP
  4618. +.B \-4
  4619. +Fall back to IPv4 sockets. This is necessary for terminally broken
  4620. +systems like OpenBSD which will not let IPv6 sockets connect to
  4621. +V4-mapped IPv6 addresses. Please note that this also applies to DNS
  4622. +lookups, so you will have to use an DNS resolver with an IPv6 address to
  4623. +accept IPv6 connections. Use \fBDNSCACHEIP\fR to set the DNS resolver
  4624. +IP dynamically.
  4625. +.TP
  4626. +.B \-6
  4627. +Force IPv6 mode in UCSPI environment variables, even for
  4628. +IPv4 connections. This will set \fB$PROTO\fR to \fBTCP6\fR and put
  4629. +IPv4-mapped IPv6 addresses in \fBTCPLOCALIP\fR and \fBTCPREMOTEIP\fR.
  4630. +.TP
  4631. +.B \-I\fIinterface
  4632. +Bind to the network interface
  4633. +.I interface
  4634. +("eth0" on Linux, for example). This is only defined and needed for
  4635. +IPv6 link-local addresses.
  4636. +.TP
  4637. +.B \-b\fIbacklog
  4638. +Allow up to
  4639. +.I backlog
  4640. +simultaneous SYN_RECEIVEDs.
  4641. +Default: 20.
  4642. +On some systems,
  4643. +.I backlog
  4644. +is silently limited to 5.
  4645. +See
  4646. +.BR listen (2)
  4647. +for more details.
  4648. +.TP
  4649. +.B \-o
  4650. +Leave IP options alone.
  4651. +If the client is sending packets along an IP source route,
  4652. +send packets back along the same route.
  4653. +.TP
  4654. +.B \-O
  4655. +(Default.)
  4656. +Kill IP options.
  4657. +A client can still use source routing to connect and to send data,
  4658. +but packets will be sent back along the default route.
  4659. +.TP
  4660. +.B \-d
  4661. +(Default.)
  4662. +Delay sending data for a fraction of a second whenever the
  4663. +remote host is responding slowly,
  4664. +to make better use of the network.
  4665. +.TP
  4666. +.B \-D
  4667. +Never delay sending data;
  4668. +enable TCP_NODELAY.
  4669. +This is appropriate for interactive connections.
  4670. +.TP
  4671. +.B \-q
  4672. +Quiet.
  4673. +Do not print any messages.
  4674. +.TP
  4675. +.B \-Q
  4676. +(Default.)
  4677. +Print error messages.
  4678. +.TP
  4679. +.B \-v
  4680. +Verbose.
  4681. +Print all available messages.
  4682. +.SH "DATA-GATHERING OPTIONS"
  4683. +.TP
  4684. +.B \-p
  4685. +Paranoid.
  4686. +After looking up the remote host name,
  4687. +look up the IP addresses for that name,
  4688. +and make sure one of them matches
  4689. +.BR TCPREMOTEIP .
  4690. +If none of them do,
  4691. +unset
  4692. +.BR TCPREMOTEHOST .
  4693. +.TP
  4694. +.B \-P
  4695. +(Default.)
  4696. +Not paranoid.
  4697. +.TP
  4698. +.B \-h
  4699. +(Default.)
  4700. +Look up the remote host name and set
  4701. +.BR TCPREMOTEHOST .
  4702. +.TP
  4703. +.B \-H
  4704. +Do not look up the remote host name.
  4705. +.TP
  4706. +.B \-l\fIlocalname
  4707. +Do not look up the local host name;
  4708. +use
  4709. +.I localname
  4710. +for
  4711. +.BR TCPLOCALHOST .
  4712. +.TP
  4713. +.B \-r
  4714. +(Default.)
  4715. +Attempt to obtain
  4716. +.B TCPREMOTEINFO
  4717. +from the remote host.
  4718. +.TP
  4719. +.B \-R
  4720. +Do not attempt to obtain
  4721. +.B TCPREMOTEINFO
  4722. +from the remote host.
  4723. +.TP
  4724. +.B \-t\fItimeout
  4725. +Give up on the
  4726. +.B TCPREMOTEINFO
  4727. +connection attempt
  4728. +after
  4729. +.I timeout
  4730. +seconds. Default: 26.
  4731. +.SH "SEE ALSO"
  4732. +argv0(1),
  4733. +fixcr(1),
  4734. +recordio(1),
  4735. +tcpclient(1),
  4736. +tcprules(1),
  4737. +listen(2),
  4738. +tcp-environ(5)
  4739. diff -uNr ucspi-tcp-0.88.orig/who@.1 ucspi-tcp-0.88/who@.1
  4740. --- ucspi-tcp-0.88.orig/who@.1 1969-12-31 18:00:00.000000000 -0600
  4741. +++ ucspi-tcp-0.88/who@.1 2009-08-04 17:45:59.000000000 -0500
  4742. @@ -0,0 +1,32 @@
  4743. +.TH who@ 1
  4744. +.SH NAME
  4745. +who@ \- print list of active users on a host
  4746. +.SH SYNTAX
  4747. +.B who@
  4748. +[
  4749. +.I host
  4750. +]
  4751. +.SH DESCRIPTION
  4752. +.B who@
  4753. +connects to TCP port 11 (Systat) on
  4754. +.I host
  4755. +and prints any data it receives.
  4756. +It removes CR and converts unprintable characters to a visible format.
  4757. +
  4758. +If
  4759. +.I host
  4760. +is not supplied,
  4761. +.B who@
  4762. +connects to the local host.
  4763. +
  4764. +Some computers respond to port 11 with a list of active users.
  4765. +For example, they may be running
  4766. +
  4767. +.EX
  4768. + tcpserver 0 11 who &
  4769. +.EE
  4770. +.SH "SEE ALSO"
  4771. +cat(1),
  4772. +delcr(1),
  4773. +tcpclient(1),
  4774. +tcpserver(1)