open-iscsi / target-isns

Target-isns is an iSNS client for the Linux LIO iSCSI target
GNU General Public License v2.0
16 stars 19 forks source link

Handle IPv4 Addresses in network order #25

Closed gonzoleeman closed 9 years ago

gonzoleeman commented 9 years ago

NOTE: This issue was actually found by Olaf Kirch.

The code in src/isns.c:isns_get_ip() is automatically converting from network order to host order with this code:

   switch (l.ss.ss_family) {
    case AF_INET:
            addr = ((&l.s4)->sin_addr.s_addr);                     <=== this line

            ip[10] = ip[11] = 0xff;
            ip[15] = 0xff & (addr >> 24);
            ip[14] = 0xff & (addr >> 16);
            ip[13] = 0xff & (addr >> 8);
            ip[12] = 0xff & addr;
            break;

This worked fine on x86, but fails on big-endian architecture.

Instead, this code can be replaced with:

    switch (l.ss.ss_family) {
    case AF_INET:
            memcpy(ip + 12, &((&l.s4)->sin_addr), 4);
            break;

Which copies from network order to network order.

cvubrugier commented 9 years ago

Thank you Lee and Olaf! Indeed, I never tested target-isns on a big-endian architecture. I copied isns.c from IET and the same code is also present in tgt, so you may want to report the bug to these projects as well.

Could you write a patch and send me a pull request please? This way, you and Olaf will get proper attribution for your work.

Thanks again!

gonzoleeman commented 9 years ago

Oops! I missed a line in that pull request. Can you please cancel it? I'll submit a new one.

gonzoleeman commented 9 years ago

Updated pull request sent.

cvubrugier commented 9 years ago

Fixed by merging Lee's pull request https://github.com/cvubrugier/target-isns/pull/27