C++如何read/split EPRT命令?

C++ How to read/split EPRT command?

我目前正在编写 C++ FTP 服务器,我想知道从客户端读取 EPRT 命令的最佳方式是什么。

<< DEBUG INFO. >>: the message from the CLIENT reads: 'EPRT |2|::1|58059|\r\n'                 
                                                             ^   ^   ^                     
                                                    Ip Version   |   |                   
                                                                 |   |                     
                                                    Ipv6 Address-    |               
                                                         Port Number-  

我尝试以多种方式使用 sscanf 函数,但我认为我做的不对。

// 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);

我应该以不同的方式存储 IP 地址和端口号吗?有任何想法吗? 谢谢

            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);

如果有人感兴趣