Newsgroup: it.comp.lang.c
Titolo: Compilazione

Vorrei compilare il seguente codice in ambiente Win2000.
Dove trovo le librerie tipo  netinet/in.h, netinet/udp.h, arpa/inet.h ......
#include<sys/types.h>
#include<sys/socket.h>
#include<netinet/in.h>
#include<netinet/udp.h>
#include<arpa/inet.h>
#include<sys/time.h>
#include<string.h>
#include<stdio.h>
#include<signal.h>
#include<unistd.h>
#include<stdlib.h>
#define BUFFER_SIZE 300
struct sockaddr sa;
struct sockaddr sf;
struct sockaddr *from;
struct sockaddr_in *p, *d;
int len;
int fd;
int sent,recvd;
unsigned long start_ip;
char pass[32];
char str[10];
FILE *logfile;
struct timeval minutetimeout;
int TIMEOUT;
int numhost=0, numfound=0;
double per;
u_char data2recv[BUFFER_SIZE];
u_char data2sent[62]={
  0x19, 0x73, 0x04, 0x17, 0x73, 0x30, 0x00, 0x01,
  0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x01, 0x02,
  0x01, 0x33, 0x01, 0x13, 0x01, 0x16, 0x04, 0x08,
  0x04, 0x15, 0x01, 0x0D, 0x01, 0x0E, 0x01, 0x14,
  0x40, 0x03, 0x40, 0x04, 0x01, 0x26, 0x01, 0x27,
  0x01, 0x28, 0x01, 0x30, 0x01, 0x44, 0x42, 0x05,
  0x42, 0x22, 0x04, 0x18, 0xFF, 0xFF, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00
  };
void func_alarm_telindus (int s) {
 close(fd);
 return;
}
void exitnow () {
 close(fd);
 exit(2);
}
int checktelindus (unsigned long ip) {
 int i=0;
 char *s;
 p=(struct sockaddr_in*)&sa;
 p->sin_family=AF_INET;
 p->sin_port=htons(9833);
 p->sin_addr.s_addr= htonl(ip);
 d=(struct sockaddr_in*)&sf;
 d->sin_family=AF_INET;
 d->sin_port=htons(9833);
 d->sin_addr.s_addr=INADDR_ANY;
 minutetimeout.tv_sec = TIMEOUT;
 minutetimeout.tv_usec = 0;
 bzero (data2recv, sizeof (data2recv));
 fd=socket(AF_INET,SOCK_DGRAM,0);
 bind (fd, (struct sockaddr*)d, sizeof (struct sockaddr));
 sent=sendto(fd,&data2sent,62,0,(struct sockaddr*)p,sizeof(struct
sockaddr));
 signal(SIGALRM, func_alarm_telindus);
 alarm(TIMEOUT);
 if (recvfrom(fd,data2recv,BUFFER_SIZE,0,from,&len)<=0) {
  alarm(0);
  signal(SIGALRM,SIG_DFL);
  bzero (data2recv, sizeof (data2recv));
  return(-1);
 }
 s=data2recv;
 while (i<5) {
  while ((*(s++)) != '\0');  i++;
 }
 if (*s == '\0') {
  printf ("pw vuota\n");
 } else {
  strncpy (pass, ++s, strlen(s) -3 );
  printf ("pw: = %s \n", pass);
 }
 alarm(0);
 signal(SIGALRM,SIG_DFL);
 return (0);
}
void usage (char *cmd) {
 printf ("\n%s ip\n", cmd);
 exit(1);
}
int main(int argc, char *argv[]) {
 if (argc != 2) usage(argv[0]);
 start_ip=inet_addr(argv[1]);
 signal(SIGINT, exitnow);
 signal(SIGTERM, exitnow);
 signal(SIGKILL, exitnow);
 signal(SIGQUIT, exitnow);
 checktelindus (ntohl(start_ip));
 return (0);
}
Ciao e grazie.

 Dove trovo le librerie tipo  netinet/in.h, netinet/udp.h, arpa/inet.h
......
non le trovi.
toglimi una curiosità.. è firmato noxious di olografix quel codice?
ciao
 sbirish

 Vorrei compilare il seguente codice in ambiente Win2000.
... pappa pronta..
<code>
#ifndef _WIN32
 #include<sys/types.h>
 #include <sys/socket.h>
 #include<netinet/in.h>
 #include<netinet/udp.h>
 #include<arpa/inet.h>
 #include<sys/time.h>
 #include<unistd.h>
#else
 #include <winsock2.h>
#endif
 #include<string.h>
 #include<stdio.h>
 #include<stdlib.h>
 #include<signal.h>
 #define BUFFER_SIZE 300
#ifndef _WIN32
 typedef int SocketType;
#else
 typedef SOCKET SocketType;
#endif
static const unsigned char data2send[]=
{
  0x19, 0x73, 0x04, 0x17, 0x73, 0x30, 0x00, 0x01,
  0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x01, 0x02,
  0x01, 0x33, 0x01, 0x13, 0x01, 0x16, 0x04, 0x08,
  0x04, 0x15, 0x01, 0x0D, 0x01, 0x0E, 0x01, 0x14,
  0x40, 0x03, 0x40, 0x04, 0x01, 0x26, 0x01, 0x27,
  0x01, 0x28, 0x01, 0x30, 0x01, 0x44, 0x42, 0x05,
  0x42, 0x22, 0x04, 0x18, 0xFF, 0xFF, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};
void print_and_abort(char* message)
{
        fprintf(stderr,message);
        exit(EXIT_FAILURE);
}
char* getpassword(char* passbuff)
{
        /*
        qui ci sono serie eventualità di buffer overflow.. occhio!
        */
        char* s;
        int i;
        s=passbuff;
        while (i<5)
        {
                while (*(s++));
                i++;
        }
        return (s==NULL)
                ? NULL
                : strdup(s+1);
}
void freepassword(char* password){ free(password); }
int checktelindus (unsigned long ip)
{
        unsigned char data2recv[BUFFER_SIZE];
        struct sockaddr sa;
        struct sockaddr sf;
        struct sockaddr *from;
        struct sockaddr_in *p, *d;
        SocketType fd;
        int len;
        char* password;
        p=(struct sockaddr_in*)&sa;
        p->sin_family=PF_INET;
        p->sin_port=htons(9833);
        p->sin_addr.s_addr= htonl(ip);
        d=(struct sockaddr_in*)&sf;
        d->sin_family=PF_INET;
        d->sin_port=htons(9833);
        d->sin_addr.s_addr=INADDR_ANY;
        memset (data2recv, 0 ,sizeof (data2recv));
        fd=socket(AF_INET,SOCK_DGRAM,0);
        printf(" -Binding..\r\n");
        if(bind (fd, (struct sockaddr*)d, sizeof (struct sockaddr))!=0)
                print_and_abort("Error in bind()\r\n");
        printf(" -Sending data..\r\n");
        if(sendto(fd,&data2send,sizeof(data2send),0,
                (struct sockaddr*)p,sizeof(struct sockaddr))
                <=0)
                print_and_abort("Error in sendto()\r\n");
        printf(" -Wating for data..\r\n");
        if (recvfrom(fd,data2recv,BUFFER_SIZE,0,from,&len)<=0)
                print_and_abort("Error in recvfrom()\r\n");
        password=getpassword(data2recv);
        printf(" **Got Password: ='%s'\r\n",password);
        freepassword(password);
        return 0;
}
int main(int argc, char *argv[])
{
#ifdef _WIN32
        WSADATA wsaData;
        if( WSAStartup (0x0101, &wsaData))
                print_and_abort("Cannot inizialize winsock\r\n");
#endif
        if (argc != 2)
                print_and_abort("Usage: checktelindus ip\r\n");
        return checktelindus (ntohl(inet_addr(argv[1])));
}
</code>
 sbirish

Prima di tutto grazie per l'interessamento.
E' imbarazzante il fatto che non riesco nemmeno a risolvere i problemi
secondari.
Compilando mi genera i seguenti errori (Visual studio 6).
Deleting intermediate files and output files for project 'Cpp1 - Win32
Debug'.
--------------------Configuration: Cpp1 - Win32 Debug--------------------
Compiling...
Cpp1.cpp
c:\documents and settings\apianzola\desktop\aaa\cpp1.cpp(102) : error C2664:
'sendto' : cannot convert parameter 2 from 'const unsigned char (*)[62]' to
'const char *'
        Types pointed to are unrelated; conversion requires
reinterpret_cast, C-style cast or function-style cast
c:\documents and settings\apianzola\desktop\aaa\cpp1.cpp(106) : error C2664:
'recvfrom' : cannot convert parameter 2 from 'unsigned char [300]' to 'char
*'
        Types pointed to are unrelated; conversion requires
reinterpret_cast, C-style cast or function-style cast
c:\documents and settings\apianzola\desktop\aaa\cpp1.cpp(110) : error C2664:
'getpassword' : cannot convert parameter 1 from 'unsigned char [300]' to
'char *'
        Types pointed to are unrelated; conversion requires
reinterpret_cast, C-style cast or function-style cast
Error executing cl.exe.
Cpp1.exe - 3 error(s), 0 warning(s)
Ciao.

 secondari.
compilalo come C non come C++
ciao
 Sbirish