Welcome to HBH! If you have tried to register and didn't get a verification email, please using the following link to resend the verification email.
haviong trouble in C with IRC.
i am trying to make a small VERY VERY basic IRC client…… it is console based and i am trying to get it to send() and recv()…..i get the the first send and the first recv…..but the then it stops and when i press return it says segmentation fault……i don't know why. I use memset to free the msg and buf arrays…..but it doesnt do any good. Here is my source.
––––––––––––––––––––––irc.c–––––––––––––––––––––––––––––––––– #include "prog.h" #include <string.h> #include <stdio.h> #include <stdlib.h> #include <errno.h>
int main(int argc, char *argv[]) { int sockfd, data; char buf[30000]; char *name, *msg; struct hostent *host; struct sockaddr_in addr;
name= argv[2];
if(argc < 2)
{
printf("Usage: irc [server_hostname]\n");
exit(1);
}
if((host = gethostbyname(argv[1])) == NULL)
{
printf("ERROR: could not resolve host\n");
exit(1);
}
if((sockfd = socket(PF_INET, SOCK_STREAM, 0)) == -1)
{
printf("ERROR: could not connect to server\n");
exit(1);
}
addr.sin_family = AF_INET;
addr.sin_port = htons(IRC_PORT);
addr.sin_addr = *((struct in_addr *)host->h_addr);
memset(addr.sin_zero, '\0', sizeof addr.sin_zero);
if(connect(sockfd, (struct sockaddr *)&addr, sizeof addr) == -1)
{
printf("ERROR: could not connect()");
exit(1);
}
send(sockfd, ("/nick %s",name), MAXDATASIZE-1, 0);
while(msg != "exit")
{
printf("Welcome to %s\n\n",argv[1]);
scanf("|>: %s", msg);
send(sockfd, msg, sizeof(msg-1), 0);
memset(msg, 0, sizeof msg);
recv(sockfd, buf, MAXDATASIZE-1, 0);
printf("%s",buf);
memset(buf, 0, sizeof buf);
}
close(sockfd);
return 0;
}