Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8169107
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T20:44:53+00:00 2026-06-06T20:44:53+00:00

I am writing a Java interposer (using LD_PRELOAD method) that modifies the recipient information

  • 0

I am writing a Java interposer (using LD_PRELOAD method) that modifies the recipient information in network communication system calls (connect/sendto).

Whenever Java tries to connect to another socket, I modify the intended recipient IP and port. Java uses IPv4-mapped-IPv6 addresses. So, I need to extract the IPv4 part of it. I achieve this using the method prescribed by Nicolas Bachschmidt at link.

The problem I am facing is that for every IPv4-mapped-IPv6 address, the result string (IPv4 part) I obtain is always 0.0.0.1. Instead it should be 10.0.0.1 (for ::ffff:10.0.0.1). I have tried this with different IP addresses. The result is always the same.

Two things I would like to mention that I think may be related:

  1. When I tested the same program a month ago on my local network (that has 192.168.1.XXX IP addresses), the program worked correctly. Point being (I don’t think) there is any problem with code. To verify this, I asked a question on stackoverflow to convert IPv4-mapped-IPv6 addresses to IPv4, the link of which is mentioned earlier).

  2. I am trying to test this program now on my university network (that has 10.XXX.XXX.XXX IP addresses) and VirtualBox (NAT mode that also gives 10.XXX.XXX.XXX addresses). However, I have tried to connect to 10.0.0.1 and 12.0.0.1 in these cases. Both give 0.0.0.1.

What am I doing wrong?

UPDATE: In Java, socket connection is done by the usual method:

Socket conn = new Socket("10.0.0.1", 50021);

The code to interpose this connect() system call is as follows:

int connect(int fd, const struct sockaddr *sk, socklen_t sl)
{
    struct sockaddr_in      *lsk_in  = (struct sockaddr_in *)  sk;
    struct sockaddr_in6     *lsk_in6 = (struct sockaddr_in6 *) sk;

    struct sockaddr_in      addr4;

    unsigned int            len;
    int                     nbytes, oport, tport, ret, i;
    char                    ip_address[30];
    char                    buffer[1024];   
    char                    tempBuffer[1024];   

    if((lsk_in->sin_family == AF_INET) || (lsk_in->sin_family == AF_INET6))
    {
        if(lsk_in->sin_family == AF_INET)
        {
            oport = ntohs(lsk_in->sin_port);
            memcpy(&addr4.sin_addr.s_addr, &lsk_in->sin_addr.s_addr, sizeof(addr4.sin_addr.s_addr));
        }
        else if(lsk_in->sin_family == AF_INET6)
        {
            oport = ntohs(lsk_in6->sin6_port);

            //This is where the problem is. I always get 0.0.0.1
            memcpy(&addr4.sin_addr.s_addr, lsk_in6->sin6_addr.s6_addr+12, sizeof(addr4.sin_addr.s_addr)); 
        }

        memset(buffer, '\0', sizeof(buffer));
        sprintf(buffer, "%s%c%s%c%i", NAT_VM_CONNECT_RULE, NAT_VM_DELIMITER, (char *)inet_ntoa(addr4.sin_addr), NAT_VM_DELIMITER, oport);

        nbytes = send(sock, buffer, strlen(buffer), 0);
        if(DEBUG_MODE)
            fprintf(stdout, "[LD_INTERPOSER] Sent[%s]\n", buffer);

        memset(buffer, '\0', sizeof(buffer));
        nbytes = recv(sock, buffer, sizeof(buffer), 0);

        fprintf(stderr, "[LD_INTERPOSER] Received CONNECT [%s]\n", buffer);

        memset(ip_address, '\0', sizeof(ip_address));
        int pos = strrchr(buffer, NAT_VM_DELIMITER) - buffer;

        strncpy(ip_address, buffer, pos);
        ip_address[pos] = '\0';
        tport = atoi(buffer + pos + 1);

        if(lsk_in->sin_family == AF_INET)
        {
            lsk_in->sin_addr.s_addr = inet_addr(ip_address + 7);
            lsk_in->sin_port = htons(tport);
        }
        else if(lsk_in->sin_family == AF_INET6)
        {
            inet_pton(AF_INET6, ip_address, &(lsk_in6->sin6_addr));
            lsk_in6->sin6_port = htons(tport);
        }

        fprintf(stderr, "[LD_INTERPOSER] IP[%s], Port[%d] for VM[%s]\n", ip_address, tport, vm_ip);
    }

    return real_connect(fd, sk, sl);
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T20:44:55+00:00Added an answer on June 6, 2026 at 8:44 pm

    Thanks to @ugoren hex dump technique (in comments), I was able to figure out that the IPv6 structure itself contained a 0.0.0.1 address. I realized that the problem may be due to different JDKs. The Java project was built using OpenJDK 7 while the PC I was using had OpenJDK 6. When I updated the JDK to version 7, the error disappeared. However, it has landed me to another error which is documented at a new stackoverflow question which I am still unable to resolve.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm writing java application that is using both SQLite and MySQL using JDBC. Are
I need help in writing java code that can connect to a remote UNIX
Sometimes while writing Java in Eclipse, I write code that generates warnings. A common
I am writing a Java program which automatically plugs information into a website, which
I am writing a Java client/server GUI application using sockets and here is the
I am writing java code where i need to get some information from a
If writing a Java unit test with mocking using JMock, should we use Mockery
I'm writing a Java programm, according to MVC model. So the problem is that
I am writing a java program that gets the rainfall for each month. It's
I'm writing a java socket app that allows a client to communicate with a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.