这是我的代码:
tmpip = get_public_ip();
pubip = strtok(tmpip, "\n");
sprintf(buffer, "220 FTPUtils Server [%s]", pubip);
len_string = strlen(buffer)+1;
if(send(newsockd, &len_string, sizeof(len_string), 0) < 0){
perror("Errore invio len buffer");
onexit(newsockd, sockd, 0, 2);
}
if(send(newsockd, buffer, len_string, 0) < 0){
perror("Errore durante l'invio");
onexit(newsockd, sockd, 0, 2);
}
pubip = NULL;
free(tmpip);
memset(buffer, 0, sizeof(buffer));
if(recv(newsockd, &len_string, sizeof(len_string), MSG_WAITALL) < 0){
perror("Errore ricezione len user buffer");
onexit(newsockd, sockd, 0, 2);
}
if(recv(newsockd, buffer, len_string, 0) < 0){
perror("Errore ricezione del nome utente");
onexit(newsockd, sockd, 0, 2);
}
user_string = strtok(buffer, " ");
username = strtok(NULL, "\n");
fprintf(stdout, "%s %s\n", user_string, username);
sprintf(saved_user, "%s", username);
memset(buffer, 0, sizeof(buffer));
if(recv(newsockd, &len_string, sizeof(len_string), MSG_WAITALL) < 0){
perror("Errore ricezione len pass buffer");
onexit(newsockd, sockd, 0, 2);
}
if(recv(newsockd, buffer, len_string, 0) < 0){
perror("Errore ricezione password");
onexit(newsockd, sockd, 0, 2);
}
pass_string = strtok(buffer, " ");
password = strtok(NULL, "\n");
fprintf(stdout, "%s %s\n", pass_string, password);
memset(buffer, 0, sizeof(buffer));
printf("%s %s\n", username, password);
我上次调试时遇到问题:它没有printf
打印到标准输出!为什么我的指针(用户名和密码)被清除了???
这很奇怪,因为 2完美地工作,但最后一个没有......fprintf
printf