summaryrefslogtreecommitdiff
path: root/connecting.c
diff options
context:
space:
mode:
authoroskar <[email protected]>2024-05-22 20:11:10 +0200
committeroskar <[email protected]>2024-05-22 20:11:10 +0200
commit330c22b13e46f3ba51d5c2775235da2276dca8a0 (patch)
treee960aa230ed1ecfd9f144e9aae0b16c353443f78 /connecting.c
networking learning
Diffstat (limited to 'connecting.c')
-rw-r--r--connecting.c36
1 files changed, 36 insertions, 0 deletions
diff --git a/connecting.c b/connecting.c
new file mode 100644
index 0000000..fe9b99e
--- /dev/null
+++ b/connecting.c
@@ -0,0 +1,36 @@
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <netdb.h>
+#include <stdio.h>
+#include <string.h>
+#include <stdint.h>
+#include <unistd.h>
+#include <stdbool.h>
+#include <fcntl.h>
+#include <stdlib.h>
+#include <arpa/inet.h>
+#include <netinet/in.h>
+
+int main () {
+
+ int sockfd;
+ struct addrinfo *res;
+ struct addrinfo hints;
+ memset(&hints, 0, sizeof(hints));
+ hints.ai_family = AF_INET;
+ hints.ai_socktype = SOCK_STREAM;
+ int result = getaddrinfo("192.168.1.18", "62000", &hints, &res);
+ if (result != 0) {
+ exit(0);
+ }
+
+ sockfd = socket(res->ai_family, res->ai_socktype, res->ai_protocol);
+ int connect_res = connect(sockfd, res->ai_addr, res->ai_addrlen);
+ if (connect_res == -1) {
+ fprintf(stderr, "connect_res: -1\n");
+ exit(1);
+ }
+
+
+ return 0;
+}