rem: if ((l = del_lump (&msg->add_rm,pmatch.rm_so + off + (pos - (begin + pmatch.rm_so)),oldlen, 0)) == 0)
add: if ((l = del_lump (msg,pmatch.rm_so + off + (pos - (begin + pmatch.rm_so)),oldlen, 0)) == 0)
context: sdp_mangle_ip (struct sip_msg *msg, char *oldip, char *newip){	int i, oldContentLength, newContentLength, diff, oldlen,len,off,ret,needToDealocate;	unsigned int mask, address, locatedIp;	struct lump *l;	regmatch_t pmatch;	regex_t *re;	char *s, *pos,*begin,*key;	char buffer[16];	/* 123.456.789.123\0 */#ifdef DEBUG	fprintf (stdout,"---START--------MANGLE IP-----------------\n");#endif		key = IP_REGEX;	/*	 * Checking if msg has a payload	 */	if (msg == NULL)		{		LOG(L_ERR,"ERROR: sdp_mangle_ip: Received NULL for msg\n");		return -1;		}        parse_headers(msg,HDR_CONTENTLENGTH,0);        oldContentLength = get_content_length(msg);        	if (oldContentLength <= 0)		{		LOG(L_ERR,"ERROR: sdp_mangle_ip: Received <= for Content-Length\n");		return -2;		}	/* checking oldip */	if (oldip == NULL)		{		LOG(L_ERR,"ERROR: sdp_mangle_ip: Received NULL for oldip\n");		return -3;		}	/* checking newip */	if (newip == NULL)		{		LOG(L_ERR,"ERROR: sdp_mangle_ip: Received NULL for newip\n");		return -4;		}	i = parse_ip_netmask (oldip, &pos, &mask);	if (i == -1)	{		/* invalid value for the netmask specified in oldip */		LOG(L_ERR,"ERROR: sdp_mangle_ip: invalid value for the netmask specified in oldip\n");		return -5;	}	else	{		i = parse_ip_address (pos, &address);		if (pos != NULL) free (pos);		if (i == 0)			{			LOG(L_ERR,"ERROR: sdp_mangle_ip: invalid value for the ip specified in oldip\n");			return -6;	/* parse error in ip */			}	}	/* now we have in address/netmask binary values */	begin = get_body(msg);//msg->buf + msg->first_line.len;	// inlocuiesc cu begin = getbody */	ret = -1;	len = strlen (newip);	/* try to use precompiled expressions */	needToDealocate = 0;	if (ipExpression != NULL) 		{		re = ipExpression;#ifdef DEBUG		fprintf(stdout,"Using PRECOMPILED expression for ip ...\n");#endif		}		else /* we are not using precompiled expressions */			{			re = pkg_malloc(sizeof(regex_t));			if (re == NULL)				{				LOG(L_ERR,"ERROR: sdp_mangle_ip: Unable to allocate re\n");				return -7;				}			needToDealocate = 1;			if ((regcomp (re, key, REG_EXTENDED)) != 0)				{				LOG(L_ERR,"ERROR: sdp_mangle_ip: Unable to compile %s \n",key);				return -8;				}#ifdef DEBUG		fprintf(stdout,"Using ALLOCATED expression for ip ...\n");#endif			}	diff = 0;	while ((begin < msg->buf + msg->len) && (regexec (re, begin, 1, &pmatch, 0) == 0))	{		off = begin - msg->buf;		if (pmatch.rm_so == -1)		{			LOG (L_ERR,"ERROR: sdp_mangler_ip: offset unknown\n");			return -9;		}	#ifdef STRICT_CHECK		pmatch.rm_eo --; /* return with one space,\n,\r */#endif			/*                 for BSD and Solaris we avoid memrchr                pos = (char *) memrchr (begin + pmatch.rm_so, ' ',pmatch.rm_eo - pmatch.rm_so);                 */                pos = begin+pmatch.rm_eo;                do pos--; while (*pos != ' '); /* we should find ' ' because we matched c=IN IP4 ip */		pos++;		/* jumping over space */		oldlen = (pmatch.rm_eo - pmatch.rm_so) - (pos - (begin + pmatch.rm_so));	/* ip length */		if (oldlen > 15)		{			LOG(L_WARN,"WARNING: sdp_mangle_ip: Silent fail because oldlen > 15\n");#ifdef STRICT_CHECK			return -10;#else 			goto continue2;	/* silent fail return -10; invalid ip format ,probably like 1000.3.12341.2 */#endif					}		buffer[0] = '\0';		strncat ((char *) buffer, pos, oldlen);			buffer[oldlen] = '\0';		i = parse_ip_address (buffer, &locatedIp);		if (i == 0)		{			LOG(L_WARN,"WARNING: sdp_mangle_ip: Silent fail on parsing matched address \n");			#ifdef STRICT_CHECK			return -11;#else 			goto continue2;	#endif		}		if (same_net (locatedIp, address, mask) == 0)		{			LOG(L_WARN,"WARNING: sdp_mangle_ip: Silent fail because matched address is not in network\n");#ifdef DEBUG		fprintf(stdout,"Extracted ip is %s and not mangling \n",buffer);#endif			goto continue2;	/* not in the same net, skiping */		}#ifdef DEBUG		fprintf(stdout,"Extracted ip is %s and mangling to %s\n",buffer,newip);#endif		/* replacing ip */		/* deleting old ip */		if ((l = del_lump (&msg->add_rm,pmatch.rm_so + off + (pos - (begin + pmatch.rm_so)),oldlen, 0)) == 0)		{			LOG (L_ERR,"ERROR: sdp_mangle_ip: del_lump failed\n");			return -12;		}		s = pkg_malloc (len);		if (s == 0)		{			LOG (L_ERR,"ERROR: sdp_mangle_ip: mem. allocation failure\n");			return -13;		}		memcpy (s, newip, len);		if (insert_new_lump_after (l, s, len, 0) == 0)		{			LOG (L_ERR, "ERROR: sdp_mangle_ip: could not insert new lump\n");			pkg_free (s);			return -14;		}		diff = diff + len /*new length */  - oldlen;		/* new cycle */		ret++;continue2:		begin = begin + pmatch.rm_eo;	}			/* while */	if (needToDealocate)	{	regfree (re);		/* if I am going to use precompiled expressions to be removed */	pkg_free(re);#ifdef DEBUG		fprintf(stdout,"Dealocating expression for ip ...\n");#endif	}		if (diff != 0)	{		newContentLength = oldContentLength + diff;		patch_content_length (msg, newContentLength);	}#ifdef DEBUG	fprintf (stdout,"---END--------MANGLE IP-----------------\n");#endif	return ret+2;}