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
|
#include <winsock2.h> /*socket*/
#include <stdio.h> /*printf*/
#include <MYSQL/mysql.h>
#define __WIN__
#pragma comment(lib, "ws2_32.lib")
int main()
{
WSADATA WSAData;
WSAStartup(MAKEWORD(2,0), &WSAData);
SOCKET sock;
SOCKET csock;
SOCKADDR_IN sin;
SOCKADDR_IN csin;
char buffer[BUFSIZ];;
sin.sin_addr.s_addr = htonl(INADDR_ANY);
sin.sin_family = AF_INET;
sin.sin_port = htons(10000);
sock = socket(AF_INET,SOCK_STREAM,0);
bind(sock, (SOCKADDR *)&sin, sizeof(sin));
listen(sock,0);
while(1)
{
/* connection socket */
int sinsize = sizeof(csin);
csock = accept(sock, (SOCKADDR *)&csin, &sinsize);
memset(buffer, '\0', sizeof(buffer)); /*on vide le buffer*/
recv(csock, buffer, sizeof(buffer), 0);
char *pointeur;
char *separateur = { "-" }; // Le séparateur
char *code_appli= NULL;
char *type_serveur= NULL;
// premier appel,
pointeur = strtok( buffer, separateur );
code_appli = ("%s",pointeur);
while( pointeur != NULL )
{
// Cherche les autres separateur
pointeur = strtok( NULL, separateur );
if ( pointeur != NULL )
{
type_serveur = ("%s",pointeur);
}
}
//printf ("code appli: %s type serveur : %s\n",code_appli,type_serveur);
MYSQL *conn;
MYSQL_RES *res;
MYSQL_ROW row;
char *server = "localhost";
char *user = "thanks";
char *password = "thanks";
char *database = "atos";
conn = mysql_init(NULL);
/* Connect to database */
if (!mysql_real_connect(conn, server,
user, password, database, 0, NULL, 0)) {
fprintf(stderr, "%s\n", mysql_error(conn));
return(0);
}
if (mysql_query(conn, "SELECT C.IP_SERVEUR FROM comporter C INNER JOIN serveur S ON ((C.IP_SERVEUR = S.IP_SERVEUR AND S.TYPE_SERVEUR = type_serveur) AND C.CODE_APPLICATION = code_appli)"))
{
fprintf(stderr, "%s\n", mysql_error(conn));
system ("pause");
return(0);
}
res = mysql_use_result(conn);
while ((row = mysql_fetch_row(res)) != NULL)
{
// printf ("code appli: |%s| type serveur : |%s|\n",code_appli,type_serveur);
char *result = row[0];
printf("%s \n",result);
}
/* Release memory used to store results and close connection */
mysql_free_result(res);
mysql_close(conn);
}
} |
Partager