Support Forums
Get Local IP [C++] - Printable Version

+- Support Forums (https://www.supportforums.net)
+-- Forum: Categories (https://www.supportforums.net/forumdisplay.php?fid=87)
+--- Forum: Coding Support Forums (https://www.supportforums.net/forumdisplay.php?fid=18)
+---- Forum: Programming with C++ (https://www.supportforums.net/forumdisplay.php?fid=20)
+---- Thread: Get Local IP [C++] (/showthread.php?tid=10995)

Pages: 1 2


Get Local IP [C++] - wchar_t - 08-06-2010

Code:
char *GetMyIP()
{
    static char        ip[16];
    SOCKADDR        sa;
    int                sas = sizeof(sa);

    memset(&sa, 0, sizeof(sa));
    getsockname(sock, &sa, &sas);

    sprintf(ip, "%d.%d.%d.%d", (BYTE)sa.sa_data[2], (BYTE)sa.sa_data[3], (BYTE)sa.sa_data[4], (BYTE)sa.sa_data[5]);

    return (ip);
}

A Usefull Code I Used in a medi sharing application.


RE: Get Local IP [C++] - wat - 09-20-2010

Better not use this in any multi-threaded apps, people...


RE: Get Local IP [C++] - haphazard - 10-27-2010

Not to be disrespectful; and thanks for sharing but.
what wat said...


RE: Get Local IP [C++] - Arеs - 11-01-2010

I started C++ I might learn this soon.


RE: Get Local IP [C++] - the_legend_nl - 11-05-2010

thanks man. just started c++ a while ago this.


RE: Get Local IP [C++] - HeY? - 11-05-2010

Looks nice Smile
Will use it once I learn C++ a bit more Smile


RE: Get Local IP [C++] - SlimDeath - 11-15-2010

Nice share mate,i may add it in my folder for later use. Thank you.


RE: Get Local IP [C++] - Bursihido - 12-13-2010

Oh cool Share. Thanks


RE: Get Local IP [C++] - Volkov - 02-06-2011

Nice share..
you might want to give credits ;)


RE: Get Local IP [C++] - w00pz - 02-09-2011

nice share dude Smile
I am new to C++ so this is good to mess around with and learn something Smile