TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Making http clients for use with netcat-like programs, part 1 of 2

1 pointsby textmodealmost 7 years ago
part 1 of 2<p><pre><code> # make config parser (yy018) # source code for 018.l is below flex -8iCrfa 018.l; cc -static -o yy018 lex.yy.c; # create a config (hh1) # format is name: &quot;value&quot; # no indent, must be left-justified cat &gt; hh1 httpVersion=&quot;1.0&quot; Host: &quot;&quot; Connection: &quot;close&quot; User-Agent: &quot;CERN-LineMode&#x2F;2.15 libwww&#x2F;2.17b3&quot; ^D </code></pre> save as &quot;018.l&quot;<p><pre><code> #define jmp (yy_start) = 1 + 2 * #define se setenv #define g getenv #define X(x) fputs(x,stdout) #define Y(x,y) fprintf(stdout,x,y) #define Y2(x,y) fprintf(stderr,x,y) xxyy() { se(&quot;value&quot;,yytext,1); Y(&quot;\40\40\40if(0==se(\&quot;%s\&quot;,&quot;,g(&quot;name&quot;)); Y(&quot;%s,0))&quot;,g(&quot;value&quot;)); Y(&quot;p(\&quot;%s: %%s\\r\\n\&quot;,&quot;,g(&quot;name&quot;)); Y(&quot;g(\&quot;%s\&quot;));\n&quot;,g(&quot;name&quot;)); } int lineno=1; %s xa xb xc xd %% \n lineno++; ^[\40\11]+ { Y2(&quot;yy018: error: remove %d &quot;,yyleng); Y2(&quot;leading spaces&#x2F;tabs from line %d\n&quot;,lineno); yyterminate(); } ^&quot;Referer&quot;[: ] jmp xb; ^&quot;Host&quot;[: ] se(&quot;name&quot;,&quot;Host&quot;,1);jmp xc; ^[^\40\11\&quot;:\n]* se(&quot;name&quot;,yytext,1);jmp xa; &lt;xa&gt;[\&quot;][^\&quot;]*[\&quot;] { if(yyleng&gt;2)xxyy(); else if(yyleng==2&amp;&amp;yytext[0]==&#x27;\&quot;&#x27;&amp;&amp;yytext[1]==&#x27;\&quot;&#x27;) { se(&quot;value&quot;,yytext,1); Y(&quot;\40\40\40if(g(\&quot;%s\&quot;))&quot;,g(&quot;name&quot;)); Y(&quot;p(\&quot;%s: %%s\\r\\n\&quot;,&quot;,g(&quot;name&quot;)); Y(&quot;g(\&quot;%s\&quot;));\n&quot;,g(&quot;name&quot;)); }} &lt;xc&gt;[\&quot;][^\&quot;]*[\&quot;] xxyy(); &lt;xb&gt;[\&quot;][^\&quot;:]*[\&quot;] { if(!g(&quot;Referer&quot;)){ X(&quot;\40\40\40p(\&quot;Referer: %s\&quot;,g(\&quot;Scheme\&quot;));&quot;); X(&quot;p(\&quot;%s\&quot;,g(\&quot;Host\&quot;));&quot;); X(&quot;if(0==path)puts(\&quot;\\r\&quot;);\n&quot;); X(&quot;if(1==path)p(\&quot;%s\\r\\n\&quot;,g(\&quot;Path\&quot;));\n&quot;); }} \n|. %% int main(){ yylex();} int yywrap(){}</code></pre>

no comments

no comments