All pastes #245227 Raw Edit

Unnamed

public text v1 · immutable
#245227 ·published 2006-11-10 19:03 UTC
rendered paste body
int irc_recv_data(socket_t *sock)
{
    struct userdata *ptr = NULL;
	char *buffer = (char *)malloc(BUF);
	char tmp[30][BUF];
	int i, j, k, len;

	len = recv(*sock, buffer, BUF, 0);

	if(len > 0 || len != SOCKET_ERROR)
    {
        buffer[len]='\0';
    }
    else if(len < 0)
    {
        printf("[-] Can't recieve Data\n");
        return(-1);
    }

	for(i=0, j=0, k=0;i<=len;i++)
	{
	    if(buffer[i] == ':')
		{
		    while(buffer[j] != '!')
			{
			    tmp[k][j] = buffer[i];
			 	j++;
			}
			tmp[k][j]='\0';
			j=0;
			k++;
			i += j;
		}
		else if(buffer[i] == '!')
		{
		    while(buffer[j] != '@')
			{
			    tmp[k][j] = buffer[i];
			 	j++;
			}
			tmp[k][j]='\0';
			j=0;
			k++;
			i += j;
		}
		else if(buffer[i] == '!')
		{
		    while(buffer[j] != '@')
			{
			    tmp[k][j] = buffer[i];
			 	j++;
			}
			tmp[k][j]='\0';
			j=0;
			k++;
			i += j;
		}
		else if(buffer[i] == ' ')
		{
		    while(buffer[j] != ' ')
			{
			    tmp[k][j] = buffer[i];
			 	j++;
			}
			tmp[k][j]='\0';
			j=0;
			k++;
			i += j;
		}	
		else if(buffer[i] == ':' && i > 3)
		{
		    while(buffer[j] != '\n')
			{
			    tmp[k][j] = buffer[i];
			 	j++;
			}
			tmp[k][j]='\0';
			j=0;
			k++;
			i += j;
		}
	}

	if(root == NULL)
	{
	     if( ( root = (struct irc_userdata *) 
            malloc (sizeof(struct irc_userdata)) ) == NULL)
		 {
               printf("[-] Not enough Memory capacity\n");
			   return(-1); 
         }
		 strcpy(root->nick, tmp[0]);
		 strcpy(root->ident, tmp[1]);
		 strcpy(root->host, tmp[2]);
		 strcpy(root->to, tmp[4]);
		 root->next=NULL;
	}
	else
	{
	 	 ptr = root;
		 while(ptr->next != NULL)
		 {
		     ptr = ptr->next;
		 }
		 if( (zeiger->next = (struct irc_userdata *) 
		    malloc (sizeof(struct irc_userdata)) ) == NULL)
		{
		 	  printf("[-] Not enough Memory capacity\n");
			  return(-1);
		}
		strcpy(ptr->nick, tmp[0]);
		strcpy(ptr->ident, tmp[1]);
		strcpy(ptr->host, tmp[2]);
		strcpy(ptr->to, tmp[4]);
		ptr->next = NULL
	}

	if(ircopt.log == 1)
	{
	    bot_log(*sock, *ptr);
	}

	return EXIT_SUCCESS;
}