LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 03-16-2010, 01:46 PM   #1
devnull10
Member
 
Registered: Jan 2010
Location: Lancashire
Distribution: Slackware Stable
Posts: 572

Rep: Reputation: 120Reputation: 120
Simple socket programming in C


Hi,
I am looking to be able to connect to an IRC server in a C program. I have followed some instructions from an old book I have however it doesn't seem to be working. I've tried connecting to localhost on my ssh port and it still doesn't want to work.
This is what I have so far as a piece of skeleton test code:

Code:
#include<sys/types.h>
#include<stdio.h>
#include<stdlib.h>
#include<sys/socket.h>
#include<unistd.h>
#include<netinet/in.h>
#include<arpa/inet.h>

int main(int argc, char **argv) {
  int sockfd;
  int len;
  struct sockaddr_in address;
  int result;
  
  sockfd=socket(AF_INET,SOCK_STREAM,0);
  address.sin_family = AF_INET;
  address.sin_addr.s_addr=inet_addr("194.1.163.1");
  address.sin_port=6667;
  len=sizeof(address);
  
  result=connect(sockfd,(struct sockaddr *)&address, len);
  
  if (result==-1) {
   fprintf(stderr,"Error: Couldn't connect to server\n"); 
   exit(-1);
  }
  
    
  return 0;
}
Could someone please tell me where I'm going wrong!?

Cheers,

[edit]
Btw, the address is an efnet one.
 
Old 03-16-2010, 03:29 PM   #2
jf.argentino
Member
 
Registered: Apr 2008
Location: Toulon (France)
Distribution: FEDORA CORE
Posts: 493

Rep: Reputation: 50
take a look there
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Socket programming simple question: thefountainhead100 Programming 2 03-14-2008 04:00 AM
Help me ... about Socket programming.. rajsun Programming 2 04-24-2005 04:50 PM
socket programming???? harbir Linux - Networking 2 07-05-2004 02:52 AM
Socket Programming perdesiz Linux - Software 2 10-06-2003 12:15 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 07:19 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration