summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/main.c18
1 files changed, 14 insertions, 4 deletions
diff --git a/src/main.c b/src/main.c
index 43d5b88..7254f90 100644
--- a/src/main.c
+++ b/src/main.c
@@ -1,11 +1,21 @@
+#include <netinet/in.h>
#include <stdio.h>
#include <sys/socket.h>
int main() {
- int server = socket(AF_INET, SOCK_STREAM, 0);
- if (server == -1) {
- perror("could not open socket");
- return 1;
+ struct sockaddr_in addr;
+ addr.sin_family = AF_INET; /* IPv4 */
+ addr.sin_port = htons(8000); /* Port */
+ addr.sin_addr.s_addr = INADDR_ANY; /* equals to 0.0.0.0 */
+ int sfd = socket(AF_INET, SOCK_STREAM, 0);
+ if (sfd == -1) {
+ perror("could not open socket");
+ return 1;
+ }
+ int bind_addr = bind(sfd, (struct sockaddr *)&addr, sizeof(addr));
+ if (bind_addr == -1) {
+ perror("could not bind socket");
+ return 1;
}
printf("hello world\n");
return 0;