| 12
 3
 4
 5
 6
 7
 8
 9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 
 | #include <stdio.h>
#include <stdlib.h>
#include <string.h>
 
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <netdb.h>
#include <stdio.h>
#include <unistd.h>
 
void hostname_f(char *host);
void ip_f(const char *HostName, char *ipret);
void proxyAd_f(const char *ip, char *proxy);
 
int main()
{
    char *hostname_v = NULL;
    hostname_v = malloc(256);
    hostname_f(hostname_v); //
    printf("%s", hostname_v);
 
    char *ip_v = NULL;
    ip_v = malloc(256);
    ip_f(hostname_v, ip_v); //
    printf("%s", ip_v);
 
 
    free(hostname_v);
    free(ip_v);
 
    return 0;
}
 
 
void hostname_f(char *host)
{
    char hostname[256];
 
    if (gethostname(hostname, sizeof(hostname)-1) == 0){
        printf("\n(hostname_f : %s)\n", hostname);
    }
    else {
        fprintf(stderr, "La fonction gethostname a echoue.\n");
    }
    strcpy(host ,  hostname); //on change le contenu de host qui est un pointeur de hostname_v
}
 
void ip_f(const char *HostName, char *ipret)
{
    struct hostent * host;
    struct in_addr addr;
 
    if ((host = gethostbyname(HostName)) != NULL) {
        int i;
        for(i = 0; host->h_addr_list[i] != NULL; i++) {
            memcpy(&addr.s_addr, host->h_addr_list[i], sizeof(addr.s_addr));
            printf("\n(PrintIp : %s)\n", inet_ntoa(addr));
        }
    }
    else {
        printf("La fonction gethostbyname a echoue.\n");
    }
    strcpy(ipret, inet_ntoa(addr));
} | 
Partager