Hello,
I have just started in a process of writing a client that will
talk to an IMAP4 server. The below code is giving me an error
(Bad address) when i call read() for the first time.
I am not sure why. i can use telnet easily to talk to the imap4
server "aineldelb.com" at the port 143.
I can not do it with the code below. I am using TCP for the
connection. The code below is fairly simple and straight
forward. All i want to do with it really is just to get the
welcome message from the server. the rest of it is not
important. you will find the read() under a line
of //////////////////////////////s
Thank you for your help in advance.
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netdb.h>
#include <stdio.h>
#include <string.h>
#include <errno.h>
#define BUF_LEN 48
main(int argc, char *argv[])
{
int csd;
struct sockaddr_in server;
struct hostent *server_host;
int server_len;
int string_size;
short server_port;
int out_cnt, in_cnt;
char client_send_string[BUF_LEN];
char *server_reversed_string = " ";
int ret_code;
int terminate = 0;
char *host_name = "aineldelb.com";
server_host = gethostbyname(host_name);
server_port = 143;
csd = socket(PF_INET, SOCK_STREAM, 0);
if(csd < 0){
perror("While calling socket()");
exit(1);
}
server.sin_family = AF_INET;
memcpy(&server.sin_addr, server_host->h_addr_list[0],
server_host ->h_length);
server.sin_port = htons(server_port);
if(connect(csd, (void *)&server, sizeof(server)) == -1)
{
perror("While calling connect()");
exit(1);
}
////////////////////////// THIS IS THE READ THAT IS GIVING ME
PROBLEMS
in_cnt = read(csd, server_reversed_string, BUF_LEN);
if(in_cnt < 0)
{
perror("While calling read()");
exit(1);
}
}
________________________________________________
Get your own "800" number
Voicemail, fax, email, and a lot more
http://www.ureach.com/reg/tag
--
------------------------------------------------------------------
For information about this mailing list, and its archives, see:
http://www.washington.edu/imap/c-client-list.html
------------------------------------------------------------------