Welcome to Linux Forums!

With a comprehensive Linux Forum, information on various types of Linux software and many Linux Reviews articles, we have all the knowledge you need a click away, or accessible via our knowledgeable members.

Linux Forum ArticlesLinux ForumsLinux Forum DownloadsLinux Hosts
Home|Register|FAQ|Member List|Calendar|Unanswered Posts|Forum Rules|Today's Posts|Advanced Search|
SEARCH FOR IN
Go Back   Linux Forums > GNU Linux Zone > Linux Networking
Reload this Page ppp0 link IP
Linux Forums
Linux Forums
Welcome To The Linux Forums!
Welcome to Linux Forums. We pride ourselves in being one of the largest Linux communities on the web, we encourage you to REGISTER on our forums and participate in the community. There are over 150,000 members ready to answer your questions. JOINING US today will allow you to make new posts, get support, send messages to other members and submit downloads to our downloads directory and many other great features!

Linux Networking Hardware/Software related, Modems, Internet connection sharing, IPTables etc.

Reply
 
Thread Tools Display Modes
Old 04-18-2007   #1 (permalink)
lovlin
Just Joined!
 
Join Date: Aug 2006
Posts: 76
ppp0 link IP

Hi all,
can anyone tell me how to extract the IP address next to P-t-P: i.e.203.55.228.22 in the below output ?????? and store that value in a charecter array in C program ????


ppp0 Link encap:Point-to-Point Protocol
inet addr:203.205.69.144 P-t-P:203.55.228.22 Mask:255.255.255.255
UP POINTOPOINT RUNNING NOARP MULTICAST MTU:1492 Metric:1
RX packets:3976232 errors:0 dropped:0 overruns:0 frame:0
TX packets:3082369 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:3
RX bytes:3954209505 (3.6 GiB) TX bytes:575598726 (548.9 Mi
B)

thanks...
lovlin is offline   Reply With Quote
Old 04-18-2007   #2 (permalink)
dilbert
Linux Newbie
 
dilbert's Avatar
 
Join Date: Sep 2006
Location: Yorkshire, GB
Posts: 215
I got those code snippets for reading the MAC address. Shouldn't be a great deal to change it to read the IP address. UCHAR is "unsigned char".

The first code snippet seems to be what you're looking for. The second one is writing it in a shell variable. Just here for completeness.

================================================
writing into C array
================================================

Code:
#define ENET_ADDR_SIZE            6

static int get_eth_mac_address( int eth_port )
{
    FILE *get_mac;
    char mac_string[ENET_ADDR_SIZE * 3 + 1];
    // int i;
    
    switch (eth_port)
    {
        case 0:
            get_mac = popen("ifconfig eth0 | grep HWaddr | awk '{print $5}'", "r");
            break;
        case 2:
            get_mac = popen("ifconfig eth2 | grep HWaddr | awk '{print $5}'", "r");
            break;
        default:
            printf("Error: ethernet port not supported\n");
            return -1;
    }

    printf("Reading MAC address from eth0\n");

    while (fgets(mac_string, sizeof(mac_string), get_mac))
    {
        fprintf(stdout, "%s", mac_string);
    }

    Mac[0] = (UCHAR) strtol(&mac_string[0], NULL, 16);
    Mac[1] = (UCHAR) strtol(&mac_string[3], NULL, 16);
    Mac[2] = (UCHAR) strtol(&mac_string[6], NULL, 16);
    Mac[3] = (UCHAR) strtol(&mac_string[9], NULL, 16);
    Mac[4] = (UCHAR) strtol(&mac_string[12], NULL, 16);
    Mac[5] = (UCHAR) strtol(&mac_string[15], NULL, 16);

    /*
    for (i=0; i < ENET_ADDR_SIZE; i++)
    {
        printf("%02x ", Mac[i]);
    } 
    printf("\n");
    */
    return 0;

}

================================================
writing into shell variable
================================================


Code:
            printf("MAC address from eth2\n");
            system("MAC_ETH2=`ifconfig eth2 | grep HWaddr | awk '{print $5}'`");
            system("echo $MAC_ETH2");
__________________
Bus Error: Passengers dumped. Hech gap yo'q.
dilbert is offline   Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off




All times are GMT. The time now is 05:14 AM.




© 2000 - 2008 - All Rights Reserved - Property of  MAS Media

Content Relevant URLs by vBSEO 3.0.0