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

2 pointsby textmodeabout 4 years ago
<p><pre><code> # make config parser (yy018) # source code for 018.l is below flex -8iCrfa 018.l; cc -Wall -std=c89 -static -o yy018 lex.yy.c; # create a config (ua.txt) # format is name: &quot;value&quot; # no indent, must be left-justified cat &gt; ua.txt 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 save as &quot;018.l&quot; int setenv (const char *, const char *, int); int fileno(FILE *); #define jmp (yy_start) = 1 + 2 * #define X(x) fputs(x,stdout) #define Y(x,y) fprintf(stdout,x,y) #define Y2(x,y) fprintf(stderr,x,y) int xxyy() { setenv(&quot;value&quot;,yytext,1); Y(&quot;\40\40\40if(0==setenv(\&quot;%s\&quot;,&quot;,getenv(&quot;name&quot;)); Y(&quot;%s,0))&quot;,getenv(&quot;value&quot;)); Y(&quot;Y(\&quot;%s: %%s\\r\\n\&quot;,&quot;,getenv(&quot;name&quot;)); Y(&quot;getenv(\&quot;%s\&quot;));\n&quot;,getenv(&quot;name&quot;)); return 0; } int lineno=1; %option noinput nounput noyywrap %s xa xc %% \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;Host&quot;[: ] setenv(&quot;name&quot;,&quot;Host&quot;,1);jmp xc; ^[^\40\11\&quot;:\n]* setenv(&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;) { setenv(&quot;value&quot;,yytext,1); Y(&quot;\40\40\40if(getenv(\&quot;%s\&quot;))&quot;,getenv(&quot;name&quot;)); Y(&quot;Y(\&quot;%s: %%s\\r\\n\&quot;,&quot;,getenv(&quot;name&quot;)); Y(&quot;getenv(\&quot;%s\&quot;));\n&quot;,getenv(&quot;name&quot;)); };} &lt;xc&gt;[\&quot;][^\&quot;]*[\&quot;] xxyy(); \n|. %% int main(){yylex();return 0;}</code></pre>

no comments

no comments