aboutsummaryrefslogtreecommitdiff
path: root/Semestr 4
diff options
context:
space:
mode:
Diffstat (limited to 'Semestr 4')
-rw-r--r--Semestr 4/aisd/pracownia4/rozw2.cpp135
-rw-r--r--Semestr 4/ask/lista6/puzzle.c28
-rw-r--r--Semestr 4/ask/lista6/puzzle.s22
-rw-r--r--Semestr 4/ask/lista6/puzzle7.s29
-rw-r--r--Semestr 4/ask/lista6/puzzle8.c25
-rw-r--r--Semestr 4/ask/lista6/puzzle8.s30
-rw-r--r--Semestr 4/ask/lista6/test.c9
-rw-r--r--Semestr 4/ask/lista6/zad7.c18
-rw-r--r--Semestr 4/ask/materiały/x86-64-psABI-1.0.pdfbin0 -> 496280 bytes
-rw-r--r--Semestr 4/pstwo/kol1/FranciszekMalinkaKolokwium1.pdfbin0 -> 3170096 bytes
-rw-r--r--Semestr 4/sieci/pracownia2/router.c212
-rwxr-xr-xSemestr 4/sieci/pracownia2/udp_client.c33
-rwxr-xr-xSemestr 4/sieci/pracownia2/udp_server.c59
-rw-r--r--Semestr 4/sieci/pracownia3/p3.pdfbin0 -> 95110 bytes
-rw-r--r--Semestr 4/sieci/wyklady/lec3.pdfbin0 -> 8701267 bytes
-rw-r--r--Semestr 4/sieci/wyklady/lec4.pdfbin0 -> 5658130 bytes
-rw-r--r--Semestr 4/sieci/wyklady/lec5.pdfbin0 -> 4572488 bytes
-rw-r--r--Semestr 4/sieci/wyklady/lec6.pdfbin0 -> 3339096 bytes
18 files changed, 600 insertions, 0 deletions
diff --git a/Semestr 4/aisd/pracownia4/rozw2.cpp b/Semestr 4/aisd/pracownia4/rozw2.cpp
new file mode 100644
index 0000000..17562a9
--- /dev/null
+++ b/Semestr 4/aisd/pracownia4/rozw2.cpp
@@ -0,0 +1,135 @@
+#include <bits/stdc++.h>
+using namespace std;
+
+struct treap {
+ typedef long long T;
+ treap *left = nullptr;
+ treap *right = nullptr;
+ int rank, items = 1;
+ T value;
+ T sum;
+ bool rev = false;
+
+ treap(T val = T()) : rank(rand()), value(val), sum(val) {}
+
+ inline void update() {
+ if (rev) {
+ swap(left, right);
+ if (left) left->rev = !left->rev;
+ if (right) right->rev = !right->rev;
+ rev = false;
+ }
+ }
+};
+
+inline int items(treap *t) { return t ? t->items : 0; }
+inline int sum(treap *t) { return t ? t->sum : 0; }
+inline void recalc(treap *t) {
+ t->items = items(t->left) + items(t->right) + 1;
+ t->sum = sum(t->left) + sum(t->right) + t->value;
+}
+
+pair<treap*, treap*> split(treap *t, int k) {
+ if (!t) return {nullptr, nullptr};
+ t->update();
+ if (items(t->left) < k) {
+ auto p = split(t->right, k - items(t->left) - 1);
+ t->right = p.first;
+ recalc(t);
+ return {t, p.second};
+ }
+ else {
+ auto p = split(t->left, k);
+ t->right = p.first;
+ recalc(t);
+ return {p.first, t};
+ }
+}
+
+treap* merge(treap *a, treap *b) {
+ if (!a) return b;
+ if (!b) return a;
+ a->update();
+ b->update();
+ if (a->rank > b->rank) {
+ a->right = merge(a->right, b);
+ recalc(a);
+ return a;
+ }
+ else {
+ b->left = merge(a, b->left);
+ recalc(b);
+ return b;
+ }
+}
+
+treap::T select(treap *t, int k) {
+ if (!t) return treap::T();
+ t->update();
+ int i = items(t->left);
+ if (i == k) return t->value;
+ else if (i > k) return select(t->left, k);
+ else return select(t->right, k - i - 1);
+}
+
+treap *insert (treap *t, treap::T val, int k) {
+ auto p = split(t, k);
+ return merge(merge(p.first, new treap(val)), p.second);
+}
+
+treap *erase(treap *t, int k) {
+ auto p1 = split(t, k);
+ auto p2 = split(p1.second, 1);
+ return merge(p1.first, p2.second);
+}
+
+treap::T sum(treap *t, int l, int r) {
+ auto p1 = split(t, r);
+ auto p2 = split(p1.first, l);
+ return sum(p2.second);
+}
+
+void write(treap *t) {
+ if (!t) return;
+ t->update();
+ write(t->left);
+ cout << t->value << " ";
+ write(t->right);
+}
+void destroy(treap *t) {
+ if (!t) return;
+ destroy(t->left);
+ destroy(t->right);
+ delete t;
+}
+
+treap *t = 0;
+
+int main() {
+ int n;
+ scanf("%d", &n);
+ for (int i = 0; i < n; i++) {
+ char c;
+ scanf(" %c", &c);
+ if (c == 'I') {
+ int p, x;
+ scanf("%d%d", &p, &x);
+ t = insert(t, x, p);
+ }
+ if (c == 'D') {
+ int p;
+ scanf("%d", &p);
+ t = erase(t, p - 1);
+ }
+ if (c == 'S') {
+ int l, r;
+ scanf("%d%d", &l, &r);
+ printf("ans: %lld\n", sum(t, l, r));
+ }
+ cout << "Treap:\n";
+ write(t);
+ cout << "\n";
+ }
+
+ destroy(t);
+} \ No newline at end of file
diff --git a/Semestr 4/ask/lista6/puzzle.c b/Semestr 4/ask/lista6/puzzle.c
new file mode 100644
index 0000000..6a18d20
--- /dev/null
+++ b/Semestr 4/ask/lista6/puzzle.c
@@ -0,0 +1,28 @@
+```c=
+ 0: 55 pushq %rbp
+ 1: 48 89 e5 movq %rsp, %rbp
+ 4: 48 83 ec 10 subq $16, %rsp
+ 8: 48 89 e0 movq %rsp, %rax #wsk stosu to rax
+ b: 48 8d 0c fd 0f 00 00 00 leaq 15(,%rdi,8), %rcx #n * rozmiar longa + 15 do rcx (+15 to kwestia wyrównania/sufit)
+ 13: 48 83 e1 f0 andq $-16, %rcx #zerujemy ostatnie 4 bity
+ 17: 48 29 c8 subq %rcx, %rax #oblicz nowy wskaźnik stosu
+ 1a: 48 89 c4 movq %rax, %rsp #nowy wskaźnik wrzuć do rsp
+ 1d: 48 8d 4d f8 leaq -8(%rbp), %rcx
+ 21: 48 89 4c f8 f8 movq %rcx, -8(%rax,%rdi,8)
+ 26: 48 c7 45 f8 00 00 00 00 movq $0, -8(%rbp)
+ 2e: 48 85 ff testq %rdi, %rdi
+ 31: 7e 1d jle 29 <_aframe+0x50>
+ 33: 31 c9 xorl %ecx, %ecx
+ 35: 66 2e 0f 1f 84 00 00 00 00 00 nopw %cs:(%rax,%rax)
+ 3f: 90 nop
+ 40: 48 89 14 c8 movq %rdx, (%rax,%rcx,8)
+ 44: 48 ff c1 incq %rcx
+ 47: 48 39 cf cmpq %rcx, %rdi
+ 4a: 75 f4 jne -12 <_aframe+0x40>
+ 4c: 48 89 7d f8 movq %rdi, -8(%rbp)
+ 50: 48 8b 04 f0 movq (%rax,%rsi,8), %rax
+ 54: 48 8b 00 movq (%rax), %rax
+ 57: 48 89 ec movq %rbp, %rsp #powrót do poprzedniej ramki
+ 5a: 5d popq %rbp #wrzucenie do rbp poprzedniego adresu
+ 5b: c3 retq
+``` \ No newline at end of file
diff --git a/Semestr 4/ask/lista6/puzzle.s b/Semestr 4/ask/lista6/puzzle.s
new file mode 100644
index 0000000..3a39398
--- /dev/null
+++ b/Semestr 4/ask/lista6/puzzle.s
@@ -0,0 +1,22 @@
+ .globl puzzle
+
+ .text
+puzzle:
+ push %rbp # adres koncu ramki, callee-saved
+ xorl %eax, %eax # zeruje %rax
+ mov %rsi, %rbp # rbp := rsi, czyli rbp := p
+ push %rbx # rbx na stos, callee-saved
+ mov %rdi, %rbx # rbx := rdi, czyli rbx := n
+ sub $24, %rsp # rsp -= 24, czyli przesun rsp o 3 bajty w dół
+ test %rdi, %rdi # rdi == 0?, czyli n == 0?
+ jle .L1 # jesli tak, skocz do L1
+ lea 8(%rsp), %rsi # w p.w. rsi := rsp + 8
+ lea (%rdi,%rdi), %rdi # rdi := 2*rdi
+ call puzzle # wywolanie rekurencyjne puzzle
+ add 8(%rsp), %rax # rax := rax + *(rsp + 8)
+ add %rax, %rbx # rbx := rbx + rax
+.L1: mov %rbx, (%rbp) # *rbp := rbx, czyli *p := rbx
+ add $24, %rsp # rsp := rsp + 24 (przesun adres stacka o 3 bajty)
+ pop %rbx # przywracamy rbx
+ pop %rbp # przywracamy rbp
+ ret
diff --git a/Semestr 4/ask/lista6/puzzle7.s b/Semestr 4/ask/lista6/puzzle7.s
new file mode 100644
index 0000000..6d26961
--- /dev/null
+++ b/Semestr 4/ask/lista6/puzzle7.s
@@ -0,0 +1,29 @@
+ .global puzzle7
+
+ .text
+puzzle7:
+ movq %rsi, -40(%rsp)
+ movq %rdx, -32(%rsp)
+ movq %rcx, -24(%rsp)
+ movq %r8, -16(%rsp)
+ movq %r9, -8(%rsp)
+ movl $8, -72(%rsp)
+ leaq 8(%rsp), %rax
+ movq %rax, -64(%rsp)
+ leaq -48(%rsp), %rax
+ movq %rax, -56(%rsp)
+ movl $0, %eax
+ jmp .L2
+.L3: movq -64(%rsp), %rdx
+ leaq 8(%rdx), %rcx
+ movq %rcx, -64(%rsp)
+.L4: addq (%rdx), %rax
+.L2: subq $1, %rdi
+ js .L6
+ cmpl $47, -72(%rsp)
+ ja .L3
+ movl -72(%rsp), %edx
+ addq -56(%rsp), %rdx
+ addl $8, -72(%rsp)
+ jmp .L4
+.L6: ret
diff --git a/Semestr 4/ask/lista6/puzzle8.c b/Semestr 4/ask/lista6/puzzle8.c
new file mode 100644
index 0000000..4d65f9d
--- /dev/null
+++ b/Semestr 4/ask/lista6/puzzle8.c
@@ -0,0 +1,25 @@
+#include <limits.h>
+
+struct T {
+ long min;
+ long max;
+ long mean;
+};
+
+struct T puzzle8(long *a, long n);
+
+struct T decode(long *a, long n) {
+ long maks = LONG_MIN;
+ long mini = LONG_MAX;
+ long sum = 0;
+ for (int i = 0; i < n; i++) {
+ if (maks < a[i]) maks = a[i];
+ if (mini > a[i]) mini = a[i];
+ sum += a[i];
+ }
+ struct T ret;
+ ret.min = mini;
+ ret.max = maks;
+ ret.mean = sum / n;
+ return ret;
+} \ No newline at end of file
diff --git a/Semestr 4/ask/lista6/puzzle8.s b/Semestr 4/ask/lista6/puzzle8.s
new file mode 100644
index 0000000..cc3805d
--- /dev/null
+++ b/Semestr 4/ask/lista6/puzzle8.s
@@ -0,0 +1,30 @@
+# rdi - adres zwracanej struktury (niejawnie)
+# rsi - *a
+# rdx - n
+
+ .global puzzle8
+
+ .text
+puzzle8:
+ movq %rdx, %r11 # r11 := n
+ xorl %r10d, %r10d # r10 := 0
+ xorl %eax, %eax # rax := 0
+ movq $LONG_MIN, %r8 # r8 := 0x800...
+ movq $LONG_MAX, %r9 # r9 := 0x7ff...
+.L2: cmpq %r11, %r10 # if n <= r10
+ jge .L5 # then jump to L5, else
+ movq (%rsi,%r10,8), %rcx # rcx := a[r10]
+ cmpq %rcx, %r9 # if a[r10] < r9
+ cmovg %rcx, %r9 # then r9 = a[r10]
+ cmpq %rcx, %r8 # if a[r10] > r8
+ cmovl %rcx, %r8 # then r8 = a[r10]
+ addq %rcx, %rax # rax += a[r10]
+ incq %r10 # r10++
+ jmp .L2
+.L5: cqto # jeśli rax < 0 to niech rdx zaplonie
+ movq %r9, (%rdi) # rdi->0 := r9
+ idivq %r11 # podziel rax przez r11, efektywnie rax /= r11
+ movq %r8, 8(%rdi) # rdi->8 := r8
+ movq %rax, 16(%rdi) # rdi->16 := rax
+ movq %rdi, %rax # rax := rdi
+ ret \ No newline at end of file
diff --git a/Semestr 4/ask/lista6/test.c b/Semestr 4/ask/lista6/test.c
new file mode 100644
index 0000000..8a84ac2
--- /dev/null
+++ b/Semestr 4/ask/lista6/test.c
@@ -0,0 +1,9 @@
+#include <stdio.h>
+#include <stdint.h>
+
+int main() {
+ int32_t x = 0xc0000000;
+ int32_t y = x + x;
+
+ printf("%d, %d\n", x, y);
+} \ No newline at end of file
diff --git a/Semestr 4/ask/lista6/zad7.c b/Semestr 4/ask/lista6/zad7.c
new file mode 100644
index 0000000..9072504
--- /dev/null
+++ b/Semestr 4/ask/lista6/zad7.c
@@ -0,0 +1,18 @@
+#include <stdarg.h>
+#include <stdio.h>
+
+int wypisuj(int cnt, ...) {
+ va_list v;
+ va_start(v, cnt);
+ int sum = 0;
+ for (int i = 0; i < cnt; i++) {
+ sum += va_arg(v, int);
+ }
+ return sum;
+}
+
+int puzzle7(int cnt, ...);
+
+int main() {
+ printf("%d\n", puzzle7(10, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10));
+} \ No newline at end of file
diff --git a/Semestr 4/ask/materiały/x86-64-psABI-1.0.pdf b/Semestr 4/ask/materiały/x86-64-psABI-1.0.pdf
new file mode 100644
index 0000000..2a5a923
--- /dev/null
+++ b/Semestr 4/ask/materiały/x86-64-psABI-1.0.pdf
Binary files differ
diff --git a/Semestr 4/pstwo/kol1/FranciszekMalinkaKolokwium1.pdf b/Semestr 4/pstwo/kol1/FranciszekMalinkaKolokwium1.pdf
new file mode 100644
index 0000000..82c38f7
--- /dev/null
+++ b/Semestr 4/pstwo/kol1/FranciszekMalinkaKolokwium1.pdf
Binary files differ
diff --git a/Semestr 4/sieci/pracownia2/router.c b/Semestr 4/sieci/pracownia2/router.c
new file mode 100644
index 0000000..79754b3
--- /dev/null
+++ b/Semestr 4/sieci/pracownia2/router.c
@@ -0,0 +1,212 @@
+#include <stdio.h>
+#include <errno.h>
+#include <strings.h>
+#include <string.h>
+#include <netinet/ip.h>
+#include <arpa/inet.h>
+#include <stdint.h>
+#include <stdlib.h>
+#include <poll.h>
+#include <time.h>
+#include <unistd.h>
+
+#define SERVER_PORT 54321
+#define TURN_LEN_S 5
+#define TURN_LEN_MS (1000 * TURN_LEN_S)
+#define TURN_LEN_US (1000000 * TURN_LEN_S)
+#define NS_TO_MS(X) ((long)(X) / (long)1000000)
+#define S_TO_MS(X) ((long)(X) * (long)1000)
+
+struct router_addr {
+ struct in_addr addr;
+ uint16_t distance;
+ uint8_t netmask;
+};
+
+struct in_addr get_broadcast_address(struct router_addr ra) {
+ struct in_addr result = ra.addr;
+ /* bitshift by more than 31 is UB */
+ if (ra.netmask < 32) {
+ result.s_addr |= ~((1<<ra.netmask) - 1);
+ }
+ return result;
+}
+
+void pretty_print(struct router_addr ra) {
+ char ip_addr[20];
+ inet_ntop(AF_INET, &ra.addr, ip_addr, sizeof(ip_addr));
+ printf("%s/%d distance %d\n", ip_addr, ra.netmask, ra.distance);
+}
+
+/* converts string of IP with netmask in CIDR notation to router_addr */
+struct router_addr stora(char *str) {
+ struct router_addr result;
+ char addr[20];
+ size_t ip_preffix = strcspn(str, "/");
+
+ strncpy(addr, str, strlen(str));
+ addr[ip_preffix] = 0;
+ inet_pton(AF_INET, addr, &(result.addr));
+ result.netmask = atoi(str + ip_preffix + 1);
+ return result;
+}
+
+int get_socket() {
+ int sockfd = socket(AF_INET, SOCK_DGRAM, 0);
+ if (sockfd < 0) {
+ fprintf(stderr, "Socket error: %s\n", strerror(errno));
+ exit(EXIT_FAILURE);
+ }
+ return sockfd;
+}
+
+void bind_to_port(int sockfd, uint16_t port) {
+ struct sockaddr_in server_address;
+ bzero(&server_address, sizeof(server_address));
+ server_address.sin_family = AF_INET;
+ server_address.sin_port = htons(port);
+ server_address.sin_addr.s_addr = htonl(INADDR_ANY);
+ if (bind(sockfd, (struct sockaddr*)&server_address, sizeof(server_address)) < 0) {
+ fprintf(stderr, "Bind error: %s\n", strerror(errno));
+ exit(EXIT_FAILURE);
+ }
+
+ int broadcastPermission = 1;
+ setsockopt (sockfd, SOL_SOCKET, SO_BROADCAST, (void *)&broadcastPermission, sizeof(broadcastPermission));
+}
+
+uint16_t read_configuration(struct router_addr** networks) {
+ uint16_t n;
+ scanf("%hd", &n);
+ *networks = malloc(n * sizeof(struct router_addr));
+ for (int i = 0; i < n; i++) {
+ char addr[20];
+ char _dist[10];
+ uint16_t dist;
+ scanf(" %s %s %hd", addr, _dist, &dist);
+ (*networks)[i] = stora(addr);
+ (*networks)[i].distance = dist;
+ }
+ return n;
+}
+
+long get_time_interval(struct timespec start, struct timespec finish) {
+ return S_TO_MS(finish.tv_sec - start.tv_sec) + NS_TO_MS(finish.tv_nsec - start.tv_nsec);
+}
+
+int poll_modify_timeout(struct pollfd *fds, nfds_t nfd, int *timeout) {
+ if (*timeout < 0) {
+ fprintf(stderr, "poll_modify_timeout: timeout is negative.\n");
+ exit(EXIT_FAILURE);
+ }
+
+ struct timespec start;
+ clock_gettime(CLOCK_REALTIME, &start);
+ int result = poll(fds, nfd, *timeout);
+
+ if (result == -1) {
+ fprintf(stderr, "poll error: %s\n", strerror(errno));
+ exit(EXIT_FAILURE);
+ }
+ if (result == 0) {
+ *timeout = 0;
+ return 0;
+ }
+ struct timespec finish;
+ clock_gettime(CLOCK_REALTIME, &finish);
+ *timeout -= get_time_interval(start, finish);
+ printf("Timeout: %dms, time waiting: %ldms.\n", *timeout, get_time_interval(start, finish));
+ return result;
+}
+
+/* For debug purposes only */
+void recv_and_print(int sockfd, int networks_number, struct router_addr *networks) {
+ struct sockaddr_in sender;
+ socklen_t sender_len = sizeof(sender);
+ uint8_t buffer[IP_MAXPACKET + 1];
+ ssize_t datagram_len = recvfrom(sockfd, buffer, IP_MAXPACKET, 0,
+ (struct sockaddr*)&sender, &sender_len);
+ if (datagram_len < 0) {
+ fprintf(stderr, "recvfrom error: %s\n", strerror(errno));
+ exit(EXIT_FAILURE);
+ }
+ for (int i = 0; i < networks_number; i++) {
+ if (networks[i].addr.s_addr == sender.sin_addr.s_addr) {
+ return;
+ }
+ }
+
+ char sender_ip_str[20];
+ inet_ntop(AF_INET, &(sender.sin_addr), sender_ip_str, sizeof(sender_ip_str));
+ printf("Received UDP packet from IP address: %s, port %d\n",
+ sender_ip_str, ntohs(sender.sin_port));
+
+ buffer[datagram_len] = 0;
+ printf("%ld-byte message: +%s+\n", datagram_len, buffer);
+
+}
+
+void listen_for_routers(int sockfd, int timeout, int networks_number, struct router_addr *netowrks) {
+ printf("Listening for %dms.\n", timeout);
+ struct pollfd fds;
+ fds.fd = sockfd;
+ fds.events = POLLIN;
+ fds.revents = 0;
+ while (poll_modify_timeout(&fds, 1, &timeout)) {
+ printf("Poll returned, remaining timeout: %dms.\n", timeout);
+ recv_and_print(sockfd, networks_number, netowrks);
+ }
+ printf("Finished listening\n");
+}
+
+int send_distance_vector(int sockfd, struct in_addr network) {
+ struct sockaddr_in network_address;
+ bzero (&network_address, sizeof(network_address));
+ network_address.sin_family = AF_INET;
+ network_address.sin_port = htons(SERVER_PORT);
+ network_address.sin_addr = network;
+
+ char* message = "Hello server! My name is S1\n";
+ ssize_t message_len = strlen(message);
+ int result;
+
+ char addr[20];
+ inet_ntop(AF_INET, &network, addr, sizeof(addr));
+ printf("Sending datagram to %s\n", addr);
+ if ((result = sendto(sockfd, message, message_len, 0, (struct sockaddr*) &network_address, sizeof(network_address))) != message_len) {
+ fprintf(stderr, "sendto error: %s\n", strerror(errno));
+ // return EXIT_FAILURE;
+ }
+}
+
+void propagate_distance_vector(int sockfd, int networks_number, struct router_addr *networks) {
+ printf("Propagating distance vector\n");
+ for (int i = 0; i < networks_number; i++) {
+ struct in_addr broadcast_address = get_broadcast_address(networks[i]);
+ send_distance_vector(sockfd, broadcast_address);
+ }
+ printf("Distance vector propagated.\n");
+}
+
+void router_loop(int sockfd, int networks_number, struct router_addr *networks) {
+ printf("Starting the router loop...\n");
+ for (;;) {
+ listen_for_routers(sockfd, TURN_LEN_MS, networks_number, networks);
+ propagate_distance_vector(sockfd, networks_number, networks);
+ }
+}
+
+int main() {
+ struct router_addr* networks;
+ int n = read_configuration(&networks);
+ for (int i = 0; i < n; i++) {
+ pretty_print(networks[i]);
+ }
+
+ int sockfd = get_socket();
+ bind_to_port(sockfd, SERVER_PORT);
+ router_loop(sockfd, n, networks);
+
+ close(sockfd);
+ free(networks);
+} \ No newline at end of file
diff --git a/Semestr 4/sieci/pracownia2/udp_client.c b/Semestr 4/sieci/pracownia2/udp_client.c
new file mode 100755
index 0000000..5624484
--- /dev/null
+++ b/Semestr 4/sieci/pracownia2/udp_client.c
@@ -0,0 +1,33 @@
+#include <netinet/ip.h>
+#include <arpa/inet.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+#include <errno.h>
+
+int main()
+{
+ int sockfd = socket(AF_INET, SOCK_DGRAM, 0);
+ if (sockfd < 0) {
+ fprintf(stderr, "socket error: %s\n", strerror(errno));
+ return EXIT_FAILURE;
+ }
+
+ struct sockaddr_in server_address;
+ bzero (&server_address, sizeof(server_address));
+ server_address.sin_family = AF_INET;
+ server_address.sin_port = htons(54321);
+ inet_pton(AF_INET, "192.168.1.2", &server_address.sin_addr);
+
+ char* message = "Hello server!";
+ ssize_t message_len = strlen(message);
+ if (sendto(sockfd, message, message_len, 0, (struct sockaddr*) &server_address, sizeof(server_address)) != message_len) {
+ fprintf(stderr, "sendto error: %s\n", strerror(errno));
+ return EXIT_FAILURE;
+ }
+
+ close (sockfd);
+ return EXIT_SUCCESS;
+}
+
diff --git a/Semestr 4/sieci/pracownia2/udp_server.c b/Semestr 4/sieci/pracownia2/udp_server.c
new file mode 100755
index 0000000..b5ae6d1
--- /dev/null
+++ b/Semestr 4/sieci/pracownia2/udp_server.c
@@ -0,0 +1,59 @@
+#include <netinet/ip.h>
+#include <arpa/inet.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+#include <errno.h>
+
+int main()
+{
+ int sockfd = socket(AF_INET, SOCK_DGRAM, 0);
+ if (sockfd < 0) {
+ fprintf(stderr, "socket error: %s\n", strerror(errno));
+ return EXIT_FAILURE;
+ }
+
+ struct sockaddr_in server_address;
+ bzero (&server_address, sizeof(server_address));
+ server_address.sin_family = AF_INET;
+ server_address.sin_port = htons(54321);
+ server_address.sin_addr.s_addr = htonl(INADDR_ANY);
+ if (bind (sockfd, (struct sockaddr*)&server_address, sizeof(server_address)) < 0) {
+ fprintf(stderr, "bind error: %s\n", strerror(errno));
+ return EXIT_FAILURE;
+ }
+
+ for (;;) {
+
+ struct sockaddr_in sender;
+ socklen_t sender_len = sizeof(sender);
+ u_int8_t buffer[IP_MAXPACKET+1];
+
+ ssize_t datagram_len = recvfrom (sockfd, buffer, IP_MAXPACKET, 0, (struct sockaddr*)&sender, &sender_len);
+ if (datagram_len < 0) {
+ fprintf(stderr, "recvfrom error: %s\n", strerror(errno));
+ return EXIT_FAILURE;
+ }
+
+ char sender_ip_str[20];
+ inet_ntop(AF_INET, &(sender.sin_addr), sender_ip_str, sizeof(sender_ip_str));
+ printf ("Received UDP packet from IP address: %s, port: %d\n", sender_ip_str, ntohs(sender.sin_port));
+
+ buffer[datagram_len] = 0;
+ printf ("%ld-byte message: +%s+\n", datagram_len, buffer);
+
+ char* reply = "Thank you!";
+ ssize_t reply_len = strlen(reply);
+ if (sendto(sockfd, reply, reply_len, 0, (struct sockaddr*)&sender, sender_len) != reply_len) {
+ fprintf(stderr, "sendto error: %s\n", strerror(errno));
+ return EXIT_FAILURE;
+ }
+
+ fflush(stdout);
+ }
+
+ close (sockfd);
+ return EXIT_SUCCESS;
+}
+
diff --git a/Semestr 4/sieci/pracownia3/p3.pdf b/Semestr 4/sieci/pracownia3/p3.pdf
new file mode 100644
index 0000000..14f1261
--- /dev/null
+++ b/Semestr 4/sieci/pracownia3/p3.pdf
Binary files differ
diff --git a/Semestr 4/sieci/wyklady/lec3.pdf b/Semestr 4/sieci/wyklady/lec3.pdf
new file mode 100644
index 0000000..ae48ec2
--- /dev/null
+++ b/Semestr 4/sieci/wyklady/lec3.pdf
Binary files differ
diff --git a/Semestr 4/sieci/wyklady/lec4.pdf b/Semestr 4/sieci/wyklady/lec4.pdf
new file mode 100644
index 0000000..352b71d
--- /dev/null
+++ b/Semestr 4/sieci/wyklady/lec4.pdf
Binary files differ
diff --git a/Semestr 4/sieci/wyklady/lec5.pdf b/Semestr 4/sieci/wyklady/lec5.pdf
new file mode 100644
index 0000000..3a7b39b
--- /dev/null
+++ b/Semestr 4/sieci/wyklady/lec5.pdf
Binary files differ
diff --git a/Semestr 4/sieci/wyklady/lec6.pdf b/Semestr 4/sieci/wyklady/lec6.pdf
new file mode 100644
index 0000000..04975ce
--- /dev/null
+++ b/Semestr 4/sieci/wyklady/lec6.pdf
Binary files differ