Continued working on retrieving IP address from message

master
Aadhavan Srinivasan 2 years ago
parent eefe9fbf1b
commit 67466ade6e

@ -66,6 +66,14 @@ int main() {
} else { } else {
if (dest_address[i] == NULL) { if (dest_address[i] == NULL) {
dest_address[i] = fetch_address(buffer); dest_address[i] = fetch_address(buffer);
if (dest_address[i] == NULL) {
printf("Invalid message format\n");
exit(241);
}
if (check_ip_ver(dest_address[i]) == -1) {
printf("Invalid address: %s\n",dest_address[i]);
exit(242);
}
} }

@ -4,14 +4,12 @@
char* fetch_address(char* message) { char* fetch_address(char* message) {
char* token = malloc (sizeof(char) * strlen(message)); char* token = malloc (sizeof(char) * strlen(message));
token = strtok(message," "); token = strtok(message," \n");
if (strcmp(token,"TO:") == 0) { if (strcmp(token,"TO:") == 0) {
token = strtok(NULL,""); token = strtok(NULL," \n");
} else {
return NULL;
} }
if (check_ip_ver(token) == -1) {
return NULL;
} else {
return token; return token;
} }
}

Loading…
Cancel
Save