src/irc.c
changeset 6 7eb12be31bb5
parent 5 7c7fc8906920
child 9 aff6726b8b87
equal deleted inserted replaced
5:7c7fc8906920 6:7eb12be31bb5
    32 {
    32 {
    33     struct hostent *he;
    33     struct hostent *he;
    34     char *ip;
    34     char *ip;
    35     struct sockaddr_in ca;
    35     struct sockaddr_in ca;
    36     int csocket;
    36     int csocket;
    37     FILE *stream;
    37     FILE *stream = NULL;
    38 
    38 
    39     he = gethostbyname (server);
    39     he = gethostbyname (server);
    40     if (he == NULL) {
    40     if (he == NULL) {
    41         perror ("GETHOSTBYNAME");
    41         perror ("GETHOSTBYNAME");
    42         return NULL;
    42         return NULL;
    60 
    60 
    61     /*
    61     /*
    62      * rw mode,but many seek errors ...
    62      * rw mode,but many seek errors ...
    63      */
    63      */
    64 #ifdef NETBSD
    64 #ifdef NETBSD
    65     /* BEGIN OF STREAM */
    65     /*
       
    66      * BEGIN OF STREAM
       
    67      */
    66     stream = fdopen (csocket, "r+");
    68     stream = fdopen (csocket, "r+");
    67 #else
    69 #else
    68     /* END OF STREAM */
    70     /*
       
    71      * END OF STREAM
       
    72      */
    69     stream = fdopen (csocket, "a+");
    73     stream = fdopen (csocket, "a+");
    70 #endif
    74 #endif
    71     csocket = fileno(stream);
    75     csocket = fileno (stream);
    72 
    76 
    73     printf ("Using filedescriptor %d for stream operations\n", csocket);
    77     printf ("Using filedescriptor %d for stream operations\n", csocket);
    74     return stream;
    78     return stream;
    75 }
    79 }
    76 
    80 
    77 int irc_login (FILE * stream, char *nick, char *password)
    81 int irc_login (FILE * stream, char *server, char *nick, char *password)
    78 {
    82 {
    79     MSG message;
    83     MSG message;
    80     char msg[513];
    84     char msg[513];
    81     char *user;
    85     char *user;
    82     struct passwd *pwd = NULL;
    86     struct passwd *pwd = NULL;
    83 
    87 
    84     if ((user = getenv ("USER")) != NULL)
    88     if ((user = getenv ("USER")) != NULL)
    85         if ((pwd = getpwnam (user)) == NULL)
    89         if ((pwd = getpwnam (user)) == NULL)
    86             return IRC_GENERAL_ERROR;
    90             return IRC_GENERAL_ERROR;
    87 
    91 
    88     if (strlen (password) == 0)
    92     if (password == NULL)
    89         return IRC_LOGIN_ERROR;
    93         return IRC_LOGIN_ERROR;
    90 
    94 
    91     if (stream == NULL)
    95     if (stream == NULL)
    92         return IRC_GENERAL_ERROR;
    96         return IRC_GENERAL_ERROR;
    93 
    97 
    94     fprintf (stream, "NICK %s\r\n", nick);
    98     fprintf (stream, "NICK %s\r\n", nick);
    95 
    99 
    96     fprintf (stream, "USER %s 0 irc.freenode.net %s\r\n", user, pwd->pw_gecos);
   100     fprintf (stream, "USER %s 0 %s %s\r\n", user, server, pwd->pw_gecos);
    97 
   101 
    98     fprintf (stream, "PRIVMSG NICKSERV :IDENTIFY %s\r\n", password);
   102     fprintf (stream, "PRIVMSG NICKSERV :IDENTIFY %s\r\n", password);
    99 
   103 
   100     for (;;) {
   104     for (;;) {
   101         fgets (msg, 512, stream);
   105         fgets (msg, 512, stream);