From cc7e576a075188999aa3a229e9eb4ceb412f2265 Mon Sep 17 00:00:00 2001 From: winsdominoes Date: Tue, 14 May 2024 20:44:39 +0700 Subject: [PATCH] playing with some c code --- structs | Bin 0 -> 16008 bytes structs.c | 23 +++++++++++++++++++++++ webserver.c | 15 +++++++++++++++ 3 files changed, 38 insertions(+) create mode 100755 structs create mode 100644 structs.c diff --git a/structs b/structs new file mode 100755 index 0000000000000000000000000000000000000000..5057a9e7248cfa826190dd60bb7c64f9cceb3c4a GIT binary patch literal 16008 zcmeHOYit}>6~4Q9Ic*Xr{#m;>TQR_T2NG^WA&r%$?agyXQWi*t07di71pg>eGs~u?B<0#c+O`R7k|tcD0y3 z*QvE?KIwBcX6$hz$ZE>v=uBBB_#BeVTgjCg@?!>8kQgCL=FL`K;sH^CRB|57o5u#x zgR)J=2?=|(Ka0s!Ed5!PDR!U&>F4oKCL6U`O}5RHN2R|Zk>Ih)yt44h!h^ga{Xrt0 z91}jaOFVv%fTyN>R$RgAiOb4H=}~G)xZi8{e6~ra%sim z?gE#&NBW!XIvkMrLrQqn=1jV8TkGabsxgz!l|~vzwr^|P)*373V_S5`JT8k4o>RN` z9a7XxnK22YijEl_?XhjS*x7%zdcBewKfC_9#M9#oe|vlXix)neVjmtibJ&Lqw}&ah zI@cG_!9FG)FHp^3EHAmg&$67YEF%LS!Qv8N1wqoepIZJcv*0`$i;iG9MSv9qN#8)n z`Wm=$oT8WPKj!og9dibf=?npMN%|QrcuqE%&Jof-l5_^rxnw4N+*QMcbj}-4?8Vn< zo7%mnyQ9F(X@q}+l#m@ay5p?7a*CZBVAlYJSN8XwH&bJCq- zTx&Y=HHpx5noFM%eGl^KFtURr=3!}ddLiGTU4ku7rx)|pJs|qq-*|;CXHvrJye@9+z@cB>X>gt^d@WI?e7JvpUG?Gmc`1Y&KHSVZW4PtRd0wKN z7o0KN6KuQa!+E}kC5%8AfiMDL1i}b}5eOp?M&N%Nfxp$Sy={+Qud`3gdvCK+_E*bZ zv~tlN|5e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UtWP`1LLoWoxH+#dss;+l ztm~vo+3YA$e40a^-V9gs8)A`$`$#J(}%iK-AOR*aBvc~SnaMJ zs>%H)W#&czCsoWlL&;oQBX!|5v)g)7?>Xk!7+pLZP8 z+(s~SGsDc`aCnu96-TpPvX7)!Fmebr+W6oWhE*(=_uSZEt`r+CN@?27 zl1>TK-qGF2vq!rRC5uBUmKx1b7e;yoWBHO>D5mqd8Hz);f}2S)L2APpPsQ{wV^oa| z=1JvB(d}0;&mAF^rxSVS^;L58qi4SqxqR#RYbnw~({Mq(ju`d^_H;kqfZ?E(7gZr@f_iKN_ z^9&e&&-wZIo`tmFC^E=@itvBX+6Cjs`VJEPV|^DKf0FpTwgVsQKgcrKxbPS`&fsGm zmL`ms2H;~o35oS1x#+@e_{$eb;k6m~SdT&CF^ciS5Aw^z=d~VmtoI<}(phl)0;`i$ z;h2Jt^(SOm9MOO9{9hG*hxlPV3)$r3bIgML?-Rx`LHpJ34LNbF^Q9R*R@7O3n+`wU z5*{S_2S?1+Zr%v+4~PRK{Ac4&2KYyX0BM0J6750$EWjTV1LS02!hnZn%{ps3eptsq z;ynuf!Taae(m$@hvcyy5^P)oF`a%C4Rd|Ttk6Fe7*=p44XRv>>?wjVH7Cz*Us!US} z_J4(7N&~I#)x!HB_Du%;p+oZevfjtXy83h@fmGmUv}qmqhh*Tni}xn1cd-vvr^b?< z?>{c!;X3}1FpeMiSpQCLW^bkU*_oR81Rrufk^OuX7w;w`(T||j{-G}-GPi~PvHoii zKKg+__vJ53rGIg+n!tagikJ%ceu=r`cik=xj>y11PDWZ4SI3X%FTbB*?0)_vzgSVZ ZjgE|}V + +struct abc { + int x; + int y; + int z; +}; + +int main() { + struct abc a = {0, 1, 2}; + struct abc *ptr = &a; + + printf("Address of struct a: %p\n", ptr); + + printf("Address of x in struct a: %p\n", &a.x); + printf("Address of y in struct a: %p\n", &a.y); + printf("Address of z in struct a: %p:\n", &a.z); + + return 0; +} diff --git a/webserver.c b/webserver.c index 2bd4c95..4503532 100644 --- a/webserver.c +++ b/webserver.c @@ -3,6 +3,8 @@ #include #include +#define PORT 8080 + int main() { int sockfd = socket(AF_INET, SOCK_STREAM, 0); if(sockfd == -1) { @@ -11,5 +13,18 @@ int main() { } printf("socket created successfully\n"); + struct sockaddr_in host_addr; + int host_addrlen = sizeof(host_addr); + + host_addr.sin_family = AF_INET; + host_addr.sin_port = htons(PORT); + host_addr.sin_addr.s_addr = htonl(INADDR_ANY); + + if(bind(sockfd, (struct sockaddr *)&host_addr, host_addrlen) != 0) { + perror("webserver (bind)"); + return 1; + } + printf("socket successfully bound to address\n"); + return 0; }