Takt
23-10-2003, 03:37
/************************************************** *************************
main.cpp - description
-------------------
begin : Don Okt 23 01:32:08 CEST 2003
copyright : (C) 2003 by Oliver Herms
email : takt@excluded.org
************************************************** *************************/
/************************************************** *************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
************************************************** *************************/
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include <iostream.h>
#include <fstream.h>
#include <stdio.h>
#include <netinet/in.h>
#include <sys/socket.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <sys/signal.h>
#include <arpa/inet.h>
#include <time.h>
#define CONFIG "/etc/expopper.conf"
void sig_chld(int signo);
int main(int argc, char *argv[])
{
pid_t pid;
time_t istime;
ssize_t len;
int sockfd;
int connfd;
int maxclients;
int port;
int loglevel;
char logfile[1024];
struct sockaddr_in servaddr, cliaddr;
if(getuid() != 0 || getgid() != 0)
{
cout << "You need to be root...\n";
return -1;
}
ifstream fin(CONFIG);
if(!fin)
{
cout << "No Config file found! Get sure there is a expopper.conf in /etc!\n";
return -1;
}
while(!fin.eof())
{
fin >> port;
fin >> maxclients;
fin >> logfile;
fin >> loglevel;
}
fin.close();
if(loglevel != 0)
{
ofstream fout(logfile, ios::app);
if(!fout)
{
cout << "Couldn't write to log file! Do you need to chmod? \n";
return -1;
}
else
{
if(loglevel == 2)
{
istime = time(NULL);
fout << ctime(&istime) << "config file exists...\n";
fout << ctime(&istime) << "logfile access granetd...\n";
}
}
fout.close();
}
memset(&servaddr, '\0', sizeof(servaddr));
servaddr.sin_family = AF_INET; /* IP v4 */
servaddr.sin_port = htons(port);
servaddr.sin_addr.s_addr = htonl(INADDR_ANY);
sockfd = socket(AF_INET, SOCK_STREAM, 0);
if(sockfd < 0)
{
if(loglevel != 0)
{
ofstream fout(logfile, ios::app);
istime = time(NULL);
fout << ctime(&istime) << "Couldn't create socket!\n";
fout << ctime(&istime) << "expopper died!!\n";
fout.close();
}
return -1;
}
else
{
if(loglevel == 2)
{
ofstream fout(logfile, ios::app);
istime = time(NULL);
fout << ctime(&istime) << "Socket creation success!\n";
fout.close();
}
}
if(bind(sockfd, (struct sockaddr *)&servaddr, sizeof(servaddr)) < 0 && loglevel != 0)
{
istime = time(NULL);
ofstream fout(logfile, ios::app);
fout << ctime(&istime) << "Binding port " << port << " failed! maybe port " << port << " in use or not root?\n";
fout << ctime(&istime) << "expopper died!\n";
fout.close();
return -1;
}
else
{
if(loglevel == 2)
{
istime = time(NULL);
ofstream fout(logfile, ios::app);
fout << ctime(&istime) << "Binding port " << port << " success!\n";
fout.close();
}
}
listen(sockfd, maxclients);
len = sizeof(cliaddr);
signal(SIGCHLD, sig_chld);
while(1>0)
{
connfd = accept(sockfd, (struct sockaddr *)&cliaddr,&len);
if( (pid = fork()) == 0) /* ****EN */
{
close(sockfd);
/* pop3 routine... */
char banner[] = "This is eXcluded.org popper (pop3d) from www.excluded.org\n";
write(connfd, banner, strlen(banner));
if(loglevel != 0)
{
istime = time(NULL);
ofstream fout(logfile, ios::app);
fout << ctime(&istime) << inet_ntoa(cliaddr.sin_addr.s_addr) << " connected\n";
fout.close();
}
/* end of pop3 routine... */
exit(0);
}
}
close(sockfd);
return 0;
}
void sig_chld(int signo)
{
pid_t pid;
int stat;
pid=wait(&stat);
return;
}
Also, ich bin grade dabei mit nen pop3 server zu basteln. Soweit so gut, nur, jetzt bin ich beim loggen des conenctens angelangt. Will ntürlich die cliaddr "lesbar" machen, das macht man ja normal mit inet_ntoa(). So wie ich das da in meinem source habe.
Nur bekomme ich beim Compilieren folgende fehlerausgabe:
In file included from /usr/include/g++/backward/iostream.h:31,
from main.cpp:21:
/usr/include/g++/backward/backward_warning.h:32:2: warning: #warning This file includes at least one deprecated or antiquated header. Please consider using one of the 32 headers found in section 17.4.1.2 of the C++ standard. Examples include substituting the <X> header for the <X.h> header for C++ includes, or <sstream> instead of the deprecated header <strstream.h>. To disable this warning use -Wno-deprecated.
main.cpp: In function `int main(int, char**)':
main.cpp:143: warning: invalid conversion from `ssize_t*' to `socklen_t*'
main.cpp:155: error: conversion from `in_addr_t' to non-scalar type `in_addr'
requested
main.cpp:37: warning: unused parameter `int argc'
main.cpp:37: warning: unused parameter `char**argv'
main.cpp: In function `void sig_chld(int)':
main.cpp:170: warning: unused parameter `int signo'
gmake[2]: *** [main.o] Fehler 1
gmake[2]: Leaving directory `/home/taktloss/expopper/expopper'
gmake[1]: *** [all-recursive] Fehler 1
gmake[1]: Leaving directory `/home/taktloss/expopper'
gmake: *** [all] Fehler 2
*** failed ***
main.cpp:155: error: conversion from `in_addr_t' to non-scalar type `in_addr'
requested
Wie ist das jetzt zu verstehen und wie kann ich das lösen?
Ich bin am Ende meines Latein.
MfG. Taktloss
main.cpp - description
-------------------
begin : Don Okt 23 01:32:08 CEST 2003
copyright : (C) 2003 by Oliver Herms
email : takt@excluded.org
************************************************** *************************/
/************************************************** *************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
************************************************** *************************/
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include <iostream.h>
#include <fstream.h>
#include <stdio.h>
#include <netinet/in.h>
#include <sys/socket.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <sys/signal.h>
#include <arpa/inet.h>
#include <time.h>
#define CONFIG "/etc/expopper.conf"
void sig_chld(int signo);
int main(int argc, char *argv[])
{
pid_t pid;
time_t istime;
ssize_t len;
int sockfd;
int connfd;
int maxclients;
int port;
int loglevel;
char logfile[1024];
struct sockaddr_in servaddr, cliaddr;
if(getuid() != 0 || getgid() != 0)
{
cout << "You need to be root...\n";
return -1;
}
ifstream fin(CONFIG);
if(!fin)
{
cout << "No Config file found! Get sure there is a expopper.conf in /etc!\n";
return -1;
}
while(!fin.eof())
{
fin >> port;
fin >> maxclients;
fin >> logfile;
fin >> loglevel;
}
fin.close();
if(loglevel != 0)
{
ofstream fout(logfile, ios::app);
if(!fout)
{
cout << "Couldn't write to log file! Do you need to chmod? \n";
return -1;
}
else
{
if(loglevel == 2)
{
istime = time(NULL);
fout << ctime(&istime) << "config file exists...\n";
fout << ctime(&istime) << "logfile access granetd...\n";
}
}
fout.close();
}
memset(&servaddr, '\0', sizeof(servaddr));
servaddr.sin_family = AF_INET; /* IP v4 */
servaddr.sin_port = htons(port);
servaddr.sin_addr.s_addr = htonl(INADDR_ANY);
sockfd = socket(AF_INET, SOCK_STREAM, 0);
if(sockfd < 0)
{
if(loglevel != 0)
{
ofstream fout(logfile, ios::app);
istime = time(NULL);
fout << ctime(&istime) << "Couldn't create socket!\n";
fout << ctime(&istime) << "expopper died!!\n";
fout.close();
}
return -1;
}
else
{
if(loglevel == 2)
{
ofstream fout(logfile, ios::app);
istime = time(NULL);
fout << ctime(&istime) << "Socket creation success!\n";
fout.close();
}
}
if(bind(sockfd, (struct sockaddr *)&servaddr, sizeof(servaddr)) < 0 && loglevel != 0)
{
istime = time(NULL);
ofstream fout(logfile, ios::app);
fout << ctime(&istime) << "Binding port " << port << " failed! maybe port " << port << " in use or not root?\n";
fout << ctime(&istime) << "expopper died!\n";
fout.close();
return -1;
}
else
{
if(loglevel == 2)
{
istime = time(NULL);
ofstream fout(logfile, ios::app);
fout << ctime(&istime) << "Binding port " << port << " success!\n";
fout.close();
}
}
listen(sockfd, maxclients);
len = sizeof(cliaddr);
signal(SIGCHLD, sig_chld);
while(1>0)
{
connfd = accept(sockfd, (struct sockaddr *)&cliaddr,&len);
if( (pid = fork()) == 0) /* ****EN */
{
close(sockfd);
/* pop3 routine... */
char banner[] = "This is eXcluded.org popper (pop3d) from www.excluded.org\n";
write(connfd, banner, strlen(banner));
if(loglevel != 0)
{
istime = time(NULL);
ofstream fout(logfile, ios::app);
fout << ctime(&istime) << inet_ntoa(cliaddr.sin_addr.s_addr) << " connected\n";
fout.close();
}
/* end of pop3 routine... */
exit(0);
}
}
close(sockfd);
return 0;
}
void sig_chld(int signo)
{
pid_t pid;
int stat;
pid=wait(&stat);
return;
}
Also, ich bin grade dabei mit nen pop3 server zu basteln. Soweit so gut, nur, jetzt bin ich beim loggen des conenctens angelangt. Will ntürlich die cliaddr "lesbar" machen, das macht man ja normal mit inet_ntoa(). So wie ich das da in meinem source habe.
Nur bekomme ich beim Compilieren folgende fehlerausgabe:
In file included from /usr/include/g++/backward/iostream.h:31,
from main.cpp:21:
/usr/include/g++/backward/backward_warning.h:32:2: warning: #warning This file includes at least one deprecated or antiquated header. Please consider using one of the 32 headers found in section 17.4.1.2 of the C++ standard. Examples include substituting the <X> header for the <X.h> header for C++ includes, or <sstream> instead of the deprecated header <strstream.h>. To disable this warning use -Wno-deprecated.
main.cpp: In function `int main(int, char**)':
main.cpp:143: warning: invalid conversion from `ssize_t*' to `socklen_t*'
main.cpp:155: error: conversion from `in_addr_t' to non-scalar type `in_addr'
requested
main.cpp:37: warning: unused parameter `int argc'
main.cpp:37: warning: unused parameter `char**argv'
main.cpp: In function `void sig_chld(int)':
main.cpp:170: warning: unused parameter `int signo'
gmake[2]: *** [main.o] Fehler 1
gmake[2]: Leaving directory `/home/taktloss/expopper/expopper'
gmake[1]: *** [all-recursive] Fehler 1
gmake[1]: Leaving directory `/home/taktloss/expopper'
gmake: *** [all] Fehler 2
*** failed ***
main.cpp:155: error: conversion from `in_addr_t' to non-scalar type `in_addr'
requested
Wie ist das jetzt zu verstehen und wie kann ich das lösen?
Ich bin am Ende meines Latein.
MfG. Taktloss