| 283 | } |
| 284 | |
| 285 | static void |
| 286 | ProxyEncodeTcpStream(struct alias_link *lnk, |
| 287 | struct ip *pip, |
| 288 | int maxpacketsize) |
| 289 | { |
| 290 | int slen; |
| 291 | char buffer[40]; |
| 292 | struct tcphdr *tc; |
| 293 | char addrbuf[INET_ADDRSTRLEN]; |
| 294 | |
| 295 | /* Compute pointer to tcp header */ |
| 296 | tc = (struct tcphdr *)ip_next(pip); |
| 297 | |
| 298 | /* Don't modify if once already modified */ |
| 299 | |
| 300 | if (GetAckModified(lnk)) |
| 301 | return; |
| 302 | |
| 303 | /* Translate destination address and port to string form */ |
| 304 | snprintf(buffer, sizeof(buffer) - 2, "[DEST %s %d]", |
| 305 | inet_ntoa_r(GetProxyAddress(lnk), INET_NTOA_BUF(addrbuf)), |
| 306 | (u_int) ntohs(GetProxyPort(lnk))); |
| 307 | |
| 308 | /* Pad string out to a multiple of two in length */ |
| 309 | slen = strlen(buffer); |
| 310 | switch (slen % 2) { |
| 311 | case 0: |
| 312 | strcat(buffer, " \n"); |
| 313 | slen += 2; |
| 314 | break; |
| 315 | case 1: |
| 316 | strcat(buffer, "\n"); |
| 317 | slen += 1; |
| 318 | } |
| 319 | |
| 320 | /* Check for packet overflow */ |
| 321 | if ((int)(ntohs(pip->ip_len) + strlen(buffer)) > maxpacketsize) |
| 322 | return; |
| 323 | |
| 324 | /* Shift existing TCP data and insert destination string */ |
| 325 | { |
| 326 | int dlen; |
| 327 | int hlen; |
| 328 | char *p; |
| 329 | |
| 330 | hlen = (pip->ip_hl + tc->th_off) << 2; |
| 331 | dlen = ntohs(pip->ip_len) - hlen; |
| 332 | |
| 333 | /* Modify first packet that has data in it */ |
| 334 | |
| 335 | if (dlen == 0) |
| 336 | return; |
| 337 | |
| 338 | p = (char *)pip; |
| 339 | p += hlen; |
| 340 | |
| 341 | bcopy(p, p + slen, dlen); |
| 342 | memcpy(p, buffer, slen); |
no test coverage detected