I am currently writing a C++ FTP server and I was wondering what would be the best way to read the EPRT command from the client.
<< DEBUG INFO. >>: the message from the CLIENT reads: 'EPRT |2|::1|58059|\r\n'
^ ^ ^
Ip Version | |
| |
Ipv6 Address- |
Port Number-
I tried using the sscanf function in multiple ways but I don't think I'm doing it right.
// method one
int ipVersion;
char* portNum;
char* v6_addr;
int scanned_items = sscanf(receive_buffer, "EPRT |%d|%s|%s|", &ipVersion, &v6_addr,
&portNum);
// method two
int ipVersion;
char* portNum;
char v6_addr[3];
int scanned_items = sscanf(receive_buffer, "EPRT |%d|%s:%s:%s|%s|", &ipVersion,
&v6_addr[0], &v6_addr[1], &v6_addr[2], &portNum);
Should I be storing the IP address and port number differently. Any ideas? Thanks.
int ipVersion;
char ipv6_str[64], rest[47], port[12];
int scanned_items = sscanf(receive_buffer, "EPRT |%d|%s", &ipVersion, rest);
char *first = strchr(rest, '|');
*first = 0;
scanned_items = sscanf(rest, "%s", ipv6_str);
char *portT = first + 1;
char *second = strchr(portT, '|');
*second = 0;
scanned_items = sscanf(portT, "%s", port);
If anyone was interested