- if (*portfwd_strptr == 'A' ||
- *portfwd_strptr == '4' ||
- *portfwd_strptr == '6')
- address_family = *portfwd_strptr++;
- if (*portfwd_strptr == 'L' ||
- *portfwd_strptr == 'R' ||
- *portfwd_strptr == 'D')
- type = *portfwd_strptr++;
-
- saddr[0] = '\0';
-
- n = 0;
- while (*portfwd_strptr && *portfwd_strptr != '\t') {
- if (*portfwd_strptr == ':') {
- /*
- * We've seen a colon in the middle of the
- * source port number. This means that
- * everything we've seen until now is the
- * source _address_, so we'll move it into
- * saddr and start sports from the beginning
- * again.
- */
- portfwd_strptr++;
- sports[n] = '\0';
- if (ssh->version == 1 && type == 'R') {
- logeventf(ssh, "SSH-1 cannot handle remote source address "
- "spec \"%s\"; ignoring", sports);
- } else
- strcpy(saddr, sports);
- n = 0;
- }
- if (n < lenof(sports)-1) sports[n++] = *portfwd_strptr++;
- }
- sports[n] = 0;
- if (type != 'D') {
- if (*portfwd_strptr == '\t')
- portfwd_strptr++;
- n = 0;
- while (*portfwd_strptr && *portfwd_strptr != ':') {
- if (n < lenof(host)-1) host[n++] = *portfwd_strptr++;
- }
- host[n] = 0;
- if (*portfwd_strptr == ':')
- portfwd_strptr++;
- n = 0;
- while (*portfwd_strptr) {
- if (n < lenof(dports)-1) dports[n++] = *portfwd_strptr++;
- }
- dports[n] = 0;
- portfwd_strptr++;
- dport = atoi(dports);
- dserv = 0;
- if (dport == 0) {
- dserv = 1;
- dport = net_service_lookup(dports);
- if (!dport) {
- logeventf(ssh, "Service lookup failed for destination"
- " port \"%s\"", dports);
- }
- }
+ if (*kp == 'A' || *kp == '4' || *kp == '6')
+ address_family = *kp++;
+ if (*kp == 'L' || *kp == 'R')
+ type = *kp++;
+
+ if ((kp2 = strchr(kp, ':')) != NULL) {
+ /*
+ * There's a colon in the middle of the source port
+ * string, which means that the part before it is
+ * actually a source address.
+ */
+ saddr = dupprintf("%.*s", (int)(kp2 - kp), kp);
+ sports = kp2+1;