1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149
|
#include <winsock2.h>
#include <stdlib.h>
#include <conio.h>
#include <stdio.h>
#include <string.h>
#define host "smtp.unimi.it"
#define portm 25
#define host1 "mailserver.unimi.it"
#define port1 110
/* Macro definitions */
#define TABLELEN 63
#define BUFFFERLEN 128
#define ENCODERLEN 4
#define ENCODEROPLEN 0
#define ENCODERBLOCKLEN 3
#define PADDINGCHAR '='
#define BASE64CHARSET "ABCDEFGHIJKLMNOPQRSTUVWXYZ"\
"abcdefghijklmnopqrstuvwxyz"\
"0123456789"\
"+/";
/* Function prototypes */
int Base64Encode(char *input, char *output, int oplen);
int encodeblock(char *input, char *output, int oplen);
int Base64Decode(char *input, char *output, int oplen);
int decodeblock(char *input, char *output, int oplen);
/*programma esempio per codificare con base 64 una parola da una stringa*/
bool GetMailAddress(bool sendrequest, struct sockaddr_in &ip4addr)
{
const char* host = (sendrequest ? sendinfo.name : readnfo.name);
unsigned short port = (sendrequest ? sendinfo.port : readinfo.port);
if (struct hostent* hent = gethostbyname(host))
{
if (hent->h_addrtype == AF_INET && hent->h_length == sizeof(unsigned short))
{
addr.sin_family = AF_INET;
addr.sin_port = htons(port);
addr.sin_addr = *(unsigned short*)hent->h_addr;
return true;
}
}
/*
int main(void) {
int rc = 0;
char input[BUFFFERLEN + 1] = "";
char encodedoutput[BUFFFERLEN + 1] = "";
char decodedoutput[BUFFFERLEN + 1] = "";
printf("Enter a string: \n");
scanf("%s", input);
rc = Base64Encode(input, encodedoutput, BUFFFERLEN);
printf("Base64 Encoded value: %s\n", encodedoutput);
rc = Base64Decode(encodedoutput, decodedoutput, BUFFFERLEN);
printf("Base64 Decoded value: %s", decodedoutput);
getch();
return rc;
}
*/
int main()
{
fflush(stdin);
fflush(stdout);
WORD AS; //WORD -> unsigned short int
WSADATA WData;
SOCKET s;
/*variabili client smtp*/
char answer[256]="";
int rc= 0;
char sendp [BUFFFERLEN + 1]= ""; /* indirizzo email password*/
char sendp1[BUFFFERLEN+1]=""; /*indirizzo email mittente*/
char sendp2[BUFFFERLEN+1]=""; /*indirizzo email destinatario*/
char encodedoutput[BUFFFERLEN + 1] = ""; /*variabile con indirizzo email password con base 64*/
char msped[BUFFFERLEN+1]=""; /*messaggio mandato*/
struct MailHostInfo
{
char name[64];
unsigned short port;
};
const MailHostInfo sendinfo = { "xxxxxxxxx.com", 24 };
const MailHostInfo readnfo = { "xxxxxxxxx.com", 110 };
/*variabili per pop3*/
SOCKET s1;
char answer1[4290]="";
char sendpop1[256]=""; /* indirizzo email password*/
char answer2[4096]="";
char leg='a'; /*risposta per la lettura di una email*/
int rin=1;
int i;
char str[]="\r\n.\r\n";
/*variabili condivise*/
char in='a'; /*risposta iniziale*/
int port=0;
char rit='s';
system("cls");
//system("Pause");
AS = MAKEWORD(2, 0);
if (WSAStartup(AS, &WData) != 0) //inizializza in WSAStartup
{
printf("error cant initialize WinSock2\n");
WSACleanup(); //si pulisce con WSACleanup
return 1;
}
while (rit=='s')
{
port=0;
printf("Benvenuto, se vuoi mandare una email scrivi a,\r\nse vuoi leggere una email scrivi b\r\n");
fflush(stdin);
scanf("%c",&in);
struct sockaddr_in addr;
if (GetMailAddress((in == 'a'), addr)
{
std::clog << "cannot find host name" << std::endl;
return 1;
}
/*memcpy(h_addr,he->h_addr,sizeof(he->h_addr));*/
switch (in)
{
case 'a':
s = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP); //viene costruita la socket
if (s <0)
{printf("la socket non funziona /r/n");
return 1;}
|