diff --git a/Email/.gitkeep b/Email/.gitkeep deleted file mode 100644 index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..0000000000000000000000000000000000000000 diff --git a/Email/Makefile b/Email/Makefile deleted file mode 100644 index a0ddb3507c0fb83c8f97bc51ff5471a98c6ebf94..0000000000000000000000000000000000000000 --- a/Email/Makefile +++ /dev/null @@ -1,21 +0,0 @@ -# Protocoale de comunicatii -# Laborator 11 - E-mail -# Makefile - -CFLAGS = -Wall -g - -IP_SERVER = 127.0.0.1 -NUME_FISIER = file.txt - -default: send_mail - -send_mail: send_mail.c - gcc $(CFLAGS) send_mail.c -o send_mail - -run: send_mail - ./send_mail ${IP_SERVER} ${NUME_FISIER} - -.PHONY: clean - -clean: - rm -f send_mail diff --git a/Email/file.txt b/Email/file.txt deleted file mode 100644 index c63f99db70349a989e08dbdd05f81f308d7b5039..0000000000000000000000000000000000000000 --- a/Email/file.txt +++ /dev/null @@ -1 +0,0 @@ -This is an attachment. diff --git a/Email/send_mail.c b/Email/send_mail.c deleted file mode 100644 index 2c2979b01700bc6e4468704b91681c0f77e91589..0000000000000000000000000000000000000000 --- a/Email/send_mail.c +++ /dev/null @@ -1,129 +0,0 @@ -/* - * Protocoale de comunicatii - * Laborator 11 - E-mail - * send_mail.c - */ - -#include <sys/socket.h> -#include <netinet/in.h> -#include <arpa/inet.h> -#include <unistd.h> -#include <sys/types.h> -#include <sys/stat.h> -#include <fcntl.h> -#include <stdlib.h> -#include <string.h> -#include <stdio.h> -#include <errno.h> - -#define SMTP_PORT 25 -#define MAXLEN 500 - -/** - * Citeste maxim maxlen octeti de pe socket-ul sockfd in - * buffer-ul vptr. Intoarce numarul de octeti cititi. - */ -ssize_t read_line(int sockd, void *vptr, size_t maxlen) -{ - ssize_t n, rc; - char c, *buffer; - - buffer = vptr; - - for (n = 1; n < maxlen; n++) { - if ((rc = read(sockd, &c, 1)) == 1) { - *buffer++ = c; - - if (c == '\n') { - break; - } - } else if (rc == 0) { - if (n == 1) { - return 0; - } else { - break; - } - } else { - if (errno == EINTR) { - continue; - } - - return -1; - } - } - - *buffer = 0; - return n; -} - -/** - * Trimite o comanda SMTP si asteapta raspuns de la server. Comanda - * trebuie sa fie in buffer-ul sendbuf. Sirul expected contine - * inceputul raspunsului pe care trebuie sa-l trimita serverul - * in caz de succes (de exemplu, codul 250). Daca raspunsul - * semnaleaza o eroare, se iese din program. - */ -void send_command(int sockfd, const char sendbuf[], char *expected) -{ - char recvbuf[MAXLEN]; - int nbytes; - char CRLF[2] = {13, 10}; - - printf("Trimit: %s\n", sendbuf); - write(sockfd, sendbuf, strlen(sendbuf)); - write(sockfd, CRLF, sizeof(CRLF)); - - nbytes = read_line(sockfd, recvbuf, MAXLEN - 1); - recvbuf[nbytes] = 0; - printf("Am primit: %s", recvbuf); - - if (strstr(recvbuf, expected) != recvbuf) { - printf("Am primit mesaj de eroare de la server!\n"); - exit(-1); - } -} - -int main(int argc, char **argv) { - int sockfd; - int port = SMTP_PORT; - struct sockaddr_in servaddr; - char server_ip[INET_ADDRSTRLEN]; - char sendbuf[MAXLEN]; - char recvbuf[MAXLEN]; - - if (argc != 3) { - printf("Utilizare: ./send_msg adresa_server nume_fisier\n"); - exit(-1); - } - - strncpy(server_ip, argv[1], INET_ADDRSTRLEN); - - // TODO 1: creati socket-ul TCP client - - // TODO 2: completati structura sockaddr_in cu - // portul si adresa IP ale serverului SMTP - - // TODO 3: conectati-va la server - - // se primeste mesajul de conectare de la server - read_line(sockfd, recvbuf, MAXLEN -1); - printf("Am primit: %s\n", recvbuf); - - // se trimite comanda de HELO - sprintf(sendbuf, "HELO localhost"); - send_command(sockfd, sendbuf, "250"); - - // TODO 4: trimiteti comanda de MAIL FROM - - // TODO 5: trimiteti comanda de RCPT TO - - // TODO 6: trimiteti comanda de DATA - - // TODO 7: trimiteti e-mail-ul (antete + corp + atasament) - - // TODO 8: trimiteti comanda de QUIT - - // TODO 9: inchideti socket-ul TCP client - - return 0; -} diff --git a/dns/.gitkeep b/dns/.gitkeep deleted file mode 100644 index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..0000000000000000000000000000000000000000 diff --git a/dns/Makefile b/dns/Makefile deleted file mode 100644 index 6aba007d48e54f4a0d32ca05d48c30a1c3aa7b60..0000000000000000000000000000000000000000 --- a/dns/Makefile +++ /dev/null @@ -1,14 +0,0 @@ -# Protocoale de comunicatii -# Laborator 11 - DNS -# Makefile - -CFLAGS = -Wall -g - -default: dns - -dns: dns.c - -.PHONY: clean - -clean: - rm -f dns diff --git a/dns/dns.c b/dns/dns.c deleted file mode 100644 index 3a689c79a13d323b4dc75724af0271cf684728c4..0000000000000000000000000000000000000000 --- a/dns/dns.c +++ /dev/null @@ -1,65 +0,0 @@ -// Protocoale de comunicatii -// Laborator 9 - DNS -// dns.c - -#include <stdlib.h> -#include <stdio.h> -#include <sys/types.h> -#include <unistd.h> -#include <string.h> -#include <sys/socket.h> -#include <netdb.h> -#include <arpa/inet.h> - -int usage(char* name) -{ - printf("Usage:\n\t%s -n <NAME>\n\t%s -a <IP>\n", name, name); - return 1; -} - -// Receives a name and prints IP addresses -void get_ip(char* name) -{ - int ret; - struct addrinfo hints, *result, *p; - - // TODO: set hints - - // TODO: get addresses - - // TODO: iterate through addresses and print them - - // TODO: free allocated data -} - -// Receives an address and prints the associated name and service -void get_name(char* ip) -{ - int ret; - struct sockaddr_in addr; - char host[1024]; - char service[20]; - - // TODO: fill in address data - - // TODO: get name and service - - // TODO: print name and service -} - -int main(int argc, char **argv) -{ - if (argc < 3) { - return usage(argv[0]); - } - - if (strncmp(argv[1], "-n", 2) == 0) { - get_ip(argv[2]); - } else if (strncmp(argv[1], "-a", 2) == 0) { - get_name(argv[2]); - } else { - return usage(argv[0]); - } - - return 0; -}