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 2 of 2

2 pointsby textmodeabout 4 years ago
<p><pre><code> # make new http client (yy025) # hh2 is an #include in 025.l below yy018 &lt; ua.txt &gt; hh2; flex -8iCrfa 025.l; # cpp -P 025.l|less; cc -Wall -std=c89 -static -o yy025 lex.yy.c; save as &quot;025.l&quot;: int yy_get_next_buffer(); int fileno(FILE *); int setenv (const char *, const char *, int); int dprintf(int, const char *__restrict, ...); #define httpMethod &quot;GET&quot; #define httpVersion &quot;1.1&quot; #define Host &quot;&quot; #define jmp BEGIN #define Y(x,y) fprintf(stdout,x,y) int count,path,ka; int httpheaders(){ setenv(&quot;httpMethod&quot;,httpMethod,0);Y(&quot;%s &quot;,getenv(&quot;httpMethod&quot;)); Y(&quot;%s HTTP&#x2F;&quot;,getenv(&quot;Path&quot;)); setenv(&quot;httpVersion&quot;,httpVersion,0);Y(&quot;%s\r\n&quot;,getenv(&quot;httpVersion&quot;)); #include &quot;hh2&quot; fputs(&quot;\r\n&quot;,stdout); return 0;} int keepaliveclose(){setenv(&quot;Connection&quot;,&quot;close&quot;,1);return 0;} %option nounput %s xa xb xc xa &quot;http:&#x2F;&#x2F;&quot;|&quot;https:&#x2F;&#x2F;&quot; xb [-A-Za-z0-9.:]* xc [^#&#x27;|&lt;&gt; \r\n]* %% ^{xa} count++;setenv(&quot;Scheme&quot;,yytext,0);jmp xa; &lt;xa&gt;{xb} setenv(&quot;Host&quot;,yytext,1);if(!getenv(&quot;Host&quot;))setenv(&quot;Host&quot;,Host,0);jmp xb; &lt;xb&gt;\n path=0;setenv(&quot;Path&quot;,&quot;&#x2F;&quot;,0);httpheaders();jmp 0; &lt;xb&gt;{xc} path=1;setenv(&quot;Path&quot;,yytext,1);httpheaders();jmp 0; .|\n %% int main(){input();yylex();if(!getenv(&quot;nokac&quot;)){if(count&gt;1){keepaliveclose();httpheaders();};}return 0;} int yywrap(){dprintf(6,&quot;%s&quot;,getenv(&quot;Host&quot;));return 0;}</code></pre>

1 comment

textmodealmost 4 years ago
Corrections:<p>&#x2F;int main&#x2F;{s&#x2F;input();&#x2F;&#x2F;;s&#x2F;return 0&#x2F;exit(0)&#x2F;;};&#x2F;int yywrap&#x2F;s&#x2F;return 0&#x2F;exit(0)&#x2F;;&#x2F;%option&#x2F;s&#x2F;$&#x2F; noinput&#x2F;