MCPcopy Create free account
hub / github.com/F-Stack/f-stack / ProxyEncodeTcpStream

Function ProxyEncodeTcpStream

freebsd/netinet/libalias/alias_proxy.c:285–376  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

283}
284
285static void
286ProxyEncodeTcpStream(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);

Callers 1

ProxyModifyFunction · 0.85

Calls 12

ip_nextFunction · 0.85
GetAckModifiedFunction · 0.85
snprintfFunction · 0.85
inet_ntoa_rFunction · 0.85
GetProxyAddressFunction · 0.85
GetProxyPortFunction · 0.85
strcatFunction · 0.85
SetAckModifiedFunction · 0.85
GetDeltaSeqOutFunction · 0.85
AddSeqFunction · 0.85
TcpChecksumFunction · 0.85
memcpyFunction · 0.50

Tested by

no test coverage detected