Commit 3e38a153 authored by Chris's avatar Chris

introduction de l'ipv6

parent 7f954af3
......@@ -100,17 +100,30 @@ ZEND_FUNCTION(mail_php)
}
#endif
struct sockaddr_in serverSockAddr; /* Socket Address */
struct hostent *serverHostEnt; /* Host description */
in_addr_t hostAddr; /* Hostname address */
struct addrinfo hints, *servinfo, *p; /* Pour parcours des adresses */
int rv;
int port; // Port sur lequel se connecter
char portStr[6]; // Idem en format string
bzero(&serverSockAddr,sizeof(serverSockAddr));
/* IP address to long integer conversion */
/* hostAddr = inet_addr(server_name); */
memset(&hints, 0, sizeof(hints));
hints.ai_family = AF_UNSPEC;
hints.ai_socktype = SOCK_STREAM;
/* si le parametre du fichier de conf est none pour le port smtp, on lit l'argument */
if (strcmp(INI_STR("mail_php.smtp_port"),"none")==0) {
port=atoi(smtp_port); /* smtp port from parameter */
} else {
port=INI_INT("mail_php.smtp_port"); /* smtp port from ini */
}
// Copier le numero de port int en format string
sprintf(portStr, "%u",port);
/* si le parametre du fichier de conf est none pour le smtp, on lis l'argument */
if (strcmp(INI_STR("mail_php.smtp_server"),"none")==0) {
hostAddr = inet_addr(smtp_server);
// Smtp libre dans la fonction
if ((rv = getaddrinfo(smtp_server, portStr, &hints, &servinfo)) != 0) {
zend_printf("Gethost ERROR\n");
exit(0);
}
/* Si le serveur SMTP n'est pas force, on lis le parametre SSL */
if (strcmp(ssl_on,"1")==0) {
sslOn=1;
......@@ -118,7 +131,10 @@ ZEND_FUNCTION(mail_php)
sslOn=0;
}
} else {
hostAddr = inet_addr(INI_STR("mail_php.smtp_server"));
if ((rv = getaddrinfo(INI_STR("mail_php.smtp_server"), portStr, &hints, &servinfo)) != 0) {
zend_printf("Gethost ERROR\n");
exit(0);
}
/* Le ssl est pilote par le fichier de configuration */
if (INI_BOOL("mail_php.enable_ssl")) {
sslOn=1;
......@@ -127,42 +143,27 @@ ZEND_FUNCTION(mail_php)
}
}
if ( (in_addr_t)hostAddr != (in_addr_t)-1)
bcopy(&hostAddr,&serverSockAddr.sin_addr,sizeof(hostAddr));
else /* If a name is given */
{
serverHostEnt = gethostbyname(INI_STR("mail_php.smtp_server"));
/* si le parametre du fichier de conf est none pour le smtp, on lis l'argument */
if (strcmp(INI_STR("mail_php.smtp_server"),"none")==0) {
serverHostEnt = gethostbyname(smtp_server);
} else {
serverHostEnt = gethostbyname(INI_STR("mail_php.smtp_server"));
// On parcours toutes les adresses possibles pour ce serveur de mail
for (p=servinfo; p != NULL; p = p->ai_next) {
if ((to_server_socket = socket(p->ai_family, p->ai_socktype, p->ai_protocol)) == -1) {
// Erreur de socket
zend_printf("Sock error\n");
continue;
}
if (serverHostEnt == NULL) {
zend_printf("Gethost ERROR\n");
exit(0);
if (connect(to_server_socket, p->ai_addr, p->ai_addrlen) == -1) {
// Erreur de connexion
zend_printf("Connect error\n");
close(to_server_socket);
continue;
}
bcopy(serverHostEnt->h_addr,&serverSockAddr.sin_addr,serverHostEnt->h_length);
}
/* si le parametre du fichier de conf est none pour le port smtp, on lis l'argument */
if (strcmp(INI_STR("mail_php.smtp_port"),"none")==0) {
serverSockAddr.sin_port = htons(atoi(smtp_port)); /* smtp port from parameter */
} else {
serverSockAddr.sin_port = htons(INI_INT("mail_php.smtp_port")); /* smtp port from ini */
}
serverSockAddr.sin_family = AF_INET; /* AF_*** : INET=internet */
/* Socket Creation */
if ( (to_server_socket = socket(AF_INET,SOCK_STREAM,0)) < 0) {
zend_printf("Client socket creation issue\n");
exit(0);
// On est connecte
break;
}
/* Connection query */
if(connect(to_server_socket,(struct sockaddr *)&serverSockAddr,sizeof(serverSockAddr))<0) {
zend_printf("Connection timeout\n");
exit(0);
if (p == NULL) {
// On a pas reussi a se connecter
zend_printf("Client socket creation or connection issue\n");
exit(0);
}
/* Envoi du mail */
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment