Results 1 to 2 of 2
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 ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
- 04-18-2007 #1Just 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 MiB)
thanks...
- 04-18-2007 #2
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.


Reply With Quote
