diff --git a/structs b/structs new file mode 100755 index 0000000..5057a9e Binary files /dev/null and b/structs differ diff --git a/structs.c b/structs.c new file mode 100644 index 0000000..8d62aad --- /dev/null +++ b/structs.c @@ -0,0 +1,23 @@ +// playing around with structs +// win 2024 + +#include + +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; }