Hi,
I've been working on modifying openvpn code for certain requirements I wanna 
implement and I'm running into a few problems which I hope someone in this 
mailing list could help me with or just give me some insight about them.

I tried to print out the ethernet and IP headers of the packets in the 
incoming_tun buffer. The methods that does the printing is mentioned below.
I run the modified openvpn code and established a VPN tunnel.. I established an 
FTP connection between machine A (running openvpn client and ftp client ) tun 
ip is 10.0.8.2 and machine B running FTP server whose IP is 10.0.0.2.

The printed packet info showed incorrect mac addresses, incorrect SRC and DEST 
IPs.The only thing that was printed correctly was the IP protocol. it's always 
showing 20 or 21.
What amazes me even more is the values of ih->saddr and ih->daddr has been 
uniquely different for every printed packet! I was expecting to only see to 
values representing those IPs only 10.0.8.2  and 10.0.0.2.
I don't know what I did wrong but if anyone can look at the code I wrote and 
see if I did anything wrong. 

Some RESULTS of RUNNING THE CODE:

ETHERNET PROTOCOL :[unknown protocol]
MAC SRC: 40:0:40:6:c1:f9
MAC DEST: 45:8:0:34:64:b3
Source IP using inet_ntop: 18.150.151.187
Source IP in decimal representation = 3147273746
Dest IP using inet_ntop: 187.250.128.17
Dest IP in decimal representation = 293665467
IP Protocol = 20

ETHERNET PROTOCOL :[unknown protocol]
MAC SRC: 40:0:40:6:ae:39
MAC DEST: 45:10:0:34:78:6b
Source IP using inet_ntop: 16.163.150.188
Source IP in decimal representation = 3163988752
Dest IP using inet_ntop: 19.77.128.16
Dest IP in decimal representation = 276843795
IP Protocol = 21



CODE:

process_incoming_tun (struct context *c)
{
....

 if (c->c2.buf.len > 0)
    {
        printipv4packet(&c->c2.buf); 
        .....

}


void printipv4packet(struct buffer *buf) 
{ 
    // PRINT ALL MAC LAYER INFORMATION
    const struct openvpn_ethhdr *eh;
    eh = (const struct openvpn_ethhdr *) BPTR (buf); 

    printf("\nETHERNET PROTOCOL :%s\n", ethProtcol2Ascii(eh->proto)); 
    printf("MAC SRC: %x:%x:%x:%x:%x:%x\n", eh->source[0], eh->source[1], 
eh->source[2], eh->source[3], eh->source[4], eh->source[5]); 
    printf("MAC DEST: %x:%x:%x:%x:%x:%x\n", eh->dest[0], eh->dest[1], 
eh->dest[2], eh->dest[3], eh->dest[4], eh->dest[5]); 

    // PRINT ALL IP LAYER INFORMATION (if applicable)

    if (BLEN (buf) >= (int)(sizeof (struct openvpn_ethhdr) + sizeof (struct 
openvpn_iphdr))) 
    {
        int ipPacketOffset = sizeof (struct openvpn_ethhdr); 
        const struct openvpn_iphdr *ih; 
        ih = (const struct openvpn_iphdr *) (BPTR (buf) + ipPacketOffset); 
        printf("SRC "); 
        char str[INET_ADDRSTRLEN];      
        inet_ntop(AF_INET, &ih->saddr, str, INET_ADDRSTRLEN);
        printf("Source IP using inet_ntop: %s\n", str);
        printf("Source IP in decimal representation = %u\n", ih->saddr);    
        printf("DEST "); 
        inet_ntop(AF_INET, &ih->daddr , str, INET_ADDRSTRLEN);
        printf("Dest IP using inet_ntop: %s\n", str);
        printf("Dest IP in decimal representation = %u\n", ih->daddr); 
        printf("IP Protocol = %u\n", ih->protocol); 
    } 
} 


I appreciate any insight!
Thank you
Abdullah


Reply via email to