playing with some c code
This commit is contained in:
parent
428a26017f
commit
cc7e576a07
|
@ -0,0 +1,23 @@
|
||||||
|
// playing around with structs
|
||||||
|
// win 2024
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
15
webserver.c
15
webserver.c
|
@ -3,6 +3,8 @@
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <sys/socket.h>
|
#include <sys/socket.h>
|
||||||
|
|
||||||
|
#define PORT 8080
|
||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
int sockfd = socket(AF_INET, SOCK_STREAM, 0);
|
int sockfd = socket(AF_INET, SOCK_STREAM, 0);
|
||||||
if(sockfd == -1) {
|
if(sockfd == -1) {
|
||||||
|
@ -11,5 +13,18 @@ int main() {
|
||||||
}
|
}
|
||||||
printf("socket created successfully\n");
|
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;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue