From a1250cb3345cd3b4bbec10e1cbe461b1843f9a25 Mon Sep 17 00:00:00 2001 From: Santiago Lo Coco Date: Fri, 5 Nov 2021 18:26:05 -0300 Subject: [PATCH] Add client (working with given server) Co-authored-by: Ezequiel Bellver Co-authored-by: Juan Barmasch --- .vscode/settings.json | 7 +++++++ Makefile | 24 ++++++++++++++++++++++++ client.c | 34 ++++++++++++++++++++++++++++++++++ client.o | Bin 0 -> 21304 bytes errors.c | 12 ++++++++++++ errors.o | Bin 0 -> 5824 bytes include/client.h | 17 +++++++++++++++++ include/errors.h | 10 ++++++++++ server.c | 0 server.o | Bin 0 -> 1256 bytes 10 files changed, 104 insertions(+) create mode 100644 .vscode/settings.json create mode 100644 Makefile create mode 100644 client.c create mode 100755 client.o create mode 100644 errors.c create mode 100644 errors.o create mode 100644 include/client.h create mode 100644 include/errors.h create mode 100644 server.c create mode 100644 server.o diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..aa45b88 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,7 @@ +{ + "files.associations": { + "error.h": "c", + "client.h": "c", + "errors.h": "c" + } +} \ No newline at end of file diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..c26f792 --- /dev/null +++ b/Makefile @@ -0,0 +1,24 @@ +CC = gcc +CCFLAGS = -Wall -std=c99 -pedantic -g + +OBJECTS = server.o errors.o client.o + +all: $(OBJECTS) + +server.o: server.c include/errors.h + $(CC) $(CCFLAGS) -c server.c +errors.o: errors.c include/errors.h + $(CC) $(CCFLAGS) -c errors.c +client.o: client.c errors.o + $(CC) $(CCFLAGS) client.c -o client.o errors.o + +clean: + rm -rf $(OBJECTS) + +test: + pvs-studio-analyzer trace -- make + pvs-studio-analyzer analyze + plog-converter -a '64:1,2,3;GA:1,2,3;OP:1,2,3' -t tasklist -o report.tasks PVS-Studio.log + cppcheck --quiet --enable=all --force --inconclusive . + +.PHONY: all clean test \ No newline at end of file diff --git a/client.c b/client.c new file mode 100644 index 0000000..187fb49 --- /dev/null +++ b/client.c @@ -0,0 +1,34 @@ +#include "include/client.h" + +int main(int argc, char *argv[]) { + int fd = 0; + struct sockaddr_in serv_addr; + + if ((fd = socket(AF_INET, SOCK_STREAM, 0)) < 0) { + printSystemError("User: socket()"); + } + + serv_addr.sin_family = AF_INET; + serv_addr.sin_port = htons(PORT); + serv_addr.sin_addr.s_addr = inet_addr(ADDRESS); + + if (connect(fd, (struct sockaddr *) &serv_addr, sizeof(serv_addr)) < 0) { + printSystemError("User: connect()"); + } + + char input[MAX_LEN] = {0}; + int readChars; + while ((readChars = read(STDIN_FILENO, input, MAX_LEN - 1)) != 0) { + if (readChars < 0) + printSystemError("User: read()"); + input[readChars] = '\0'; + + if (write(fd, input, readChars) < 0) { + printSystemError("User: write()"); + } + } + + close(fd); + + return EXIT_SUCCESS; +} diff --git a/client.o b/client.o new file mode 100755 index 0000000000000000000000000000000000000000..85bf82b578d9434b4b04751e11646a7e667790dd GIT binary patch literal 21304 zcmeHPdvH_NnLk(3wPXv+PrwFJWExUPVjBY?Kthmg3*=xP0h5qT$VHZ9TSb<zuM~(!CM>>LG9Vtd zn3W^Gl6{$#K(=vAq-_scI21;X;9s~UY1v=AL^w46_xH~&Cy8rqJ_=TP-8R_OAj^)!*R00+9qu1d0p2RYmwdQe4IxOEhsOcAFNfJZz{uVlW&xN8 zFE4=m3*gk6iSk)o0AEl5|7rpJrULj2z}+~^p$5Q2^`UVx5k9Q|{wi=c4s*Bz0Qt@w zsJkZ0e+}>|R?iN4goPTfEEx}O4X0RmFp^?@sdy~O2EvI%Ji&tTSS%b&F~dlv0>Q0D zuy3o;6Np4vA{+>@o`G~K$Re?D$_Ru)2`(pDG8KX`3r6F~Fbso(0i!1p3q&J#lZYV@ zq|6d2qdyRdv9Bc}sW2my#=#=Cva_SL&6wY`Fw4zvx{etgU8@ab8}5xHQ{hC{>b7V+ z7VZjkM=8(V{&-C0X$aK`6?vmA7#)_pACuBJ)qw1Pwi@rXkqAyjD|1mNt(t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Q^j^V4_La+pL6=f2U{A@WCUVU_k1+7a o8~<4lC%XQY0ykBW8y@lr`#GjWQ+06fHL?9kzp(Ey8JI-&UxdjfYXATM literal 0 HcmV?d00001 diff --git a/errors.c b/errors.c new file mode 100644 index 0000000..8752803 --- /dev/null +++ b/errors.c @@ -0,0 +1,12 @@ +#include "include/errors.h" + +void printError(char * string) { + fprintf(stderr, "%s", string); + fprintf(stderr, "\n"); + exit(EXIT_FAILURE); +} + +void printSystemError(char * string) { + perror(string); + exit(EXIT_FAILURE); +} \ No newline at end of file diff --git a/errors.o b/errors.o new file mode 100644 index 0000000000000000000000000000000000000000..a398c994aaa83376fedab9dd71412b046645c577 GIT binary patch literal 5824 zcmbuCdpwls9>CvmO;ogquxE;t)P!~miE$Y-8;Q_viD`y$*&4T*)+kxBM3LHRyHLtH z+p5myM0Y}xHg()~vzw!AYSrn&l8tR`=Y3{=kH%yA=bY#BnfG~q-{0-Iz0dp1=Nw;e zH3oyig+aMeZzW7Aify3OmN(gyF=a#r^Ku^XGM?%4a<&Zdb{HWIZwF_Hmve`g)9_d! zYRape>(vwKhMZNS6!O+sf8?m}dTW84snI@-sEw6ng`urYK5FiU+I>G;v>y)sc=;@& z8CDaDncI(UusyS@ndx)MWMpbavu8`KC%4qc-|L>?5pVhqgs8N^x)Hka}^0%13%rB`ca7gGE=+5n|@@ns__%&&T7HiP- z_8#LAq3ryP*gt+62+f+mq}uK7GrOmai~sKXpOxKp70K7kT*5;GgZk!~XG-EH9?2*# zQ_sIT&}UUi^>lF@r}X?Xvr;eas%^XxOE0qY?DWb*CNmay&HTe9(DQ2zccJ%R%HQe&)oIRa4)=Io=C=kNTV`+OcZ4$E&v}$Gz&G?fD6v?3L0~&u%X_`u{ZCBUv$~wmsA=df z=nm72PUtzSaouaxjooEg`!dS8)5GjrLRo`50~o#w@0tjL|8XL>-!4?`S^r_tq7S^; zmCyg}%`^S=N^`^PqEzP6)VvsrnEz~s@vAt(QOliI1wt)_luX*#Pkwfw9PI2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raDw0Vl zR)jz*pjbkQgks5Qgh;qCiXRgj8At2nZGljjDEe%ST97D+jS`J@*$@*e!Y*_k+(ei! zm&4=4Vo@xeGB!>sV$oOQ`4Xuhd_Blfu^U%}_t!*1!i+-y)m4qZ4-A{(vW3Qvn%EzY--BkV^82gN3cA!Q zs?jI*#{j)ws{Bo0Lh$_#+mrt2y;ar!n#l?eJ8(q(N50q}_aD8Ns`B$7enpr)ezblD^bh;v^;4A_c}7G2G#IcU_>%rQG$-GE +#include +#include +#include +#include +#include +#include "errors.h" + +#define MAX_ARGS 3 +#define MAX_LEN 100 +#define PORT 8080 +#define ADDRESS "127.0.0.1" + +#endif \ No newline at end of file diff --git a/include/errors.h b/include/errors.h new file mode 100644 index 0000000..7c44512 --- /dev/null +++ b/include/errors.h @@ -0,0 +1,10 @@ +#ifndef ERRORS_H +#define ERRORS_H + +#include +#include + +void printError(char * string); +void printSystemError(char * string); + +#endif \ No newline at end of file diff --git a/server.c b/server.c new file mode 100644 index 0000000..e69de29 diff --git a/server.o b/server.o new file mode 100644 index 0000000000000000000000000000000000000000..3282402a652c9fb458cc4bace5787cd3dccb4e7f GIT binary patch literal 1256 zcmbVJ%Syvg5S`TbYawn5ZlW6%OwytjD^#LEMGz~r?u3%YOIvIbNp7WG^=kw_!KI($ z)-TYRdZ)%~S5BDBoH^&@PLko-)p^b^fWv@e_(41cc*zXi(b$C*ScZ%1Thl9-&0^6m z+6B`JWiJwymWV{s2@v{8(600kOIB&$v|6T>%KJ)CE<-AkCz03zIPEwTPTGwFyqwGW z>4|gTIkl=&zuBX-YE^&>&pR@=@vI$n5KQ9^Cguz#&LIcJ8_hTjg)?h2^{Wy;4IiJs zh6Kh7f}IXR={K>;