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
|
/*
* Retrieve the UDP port to which requests
* must be sent.
* Return the port number or -1 if failed
*/
int getPort(char* path) {
FILE *fb;
char ligne[20];
char filename[50];
/* Build the filename */
strncpy(filename,path,sizeof(filename)-1);
strncat(filename,"/etc/.authServerPort",sizeof(filename)-1-strlen(path));
/* Retrieve the UDP port to which send the authentication request */
if ( (fb = fopen(filename,"r")) == NULL) {
/* Log the error message */
if ( DEBUG == 1 ) {
fprintf(logfile , "ERROR: Can not open port file: %s\n", strerror(errno));
fflush(logfile);
fclose(logfile);
}
return -1;
} else {
/* read the UDP port */
if (fgets(ligne,sizeof(ligne),fb) != NULL) {
return strtol(ligne,NULL,10);
fclose(fb);
fb = NULL;
} else {
/* Log the error message */
if (DEBUG == 1) {
fprintf(logfile , "ERROR: Can not read port file: %s\n", strerror(errno));
fflush(logfile);
fclose(logfile);
}
fclose(fb);
fb = NULL;
return -1;
}
}
} |
Partager