Re: Print IP adress
- From: Sven Geggus <usenet@xxxxxxxxxxxxxxxxxxxxx>
- Date: Fri, 26 Oct 2007 19:45:02 +0000 (UTC)
ashu <aswinikg@xxxxxxxxx> wrote:
I am new to blackfin561 in ethernet application I have connected my
board(BF561) to my pc in linux environment through the network, I need
to get ip adress of my board which is connected to the switch
You may either use ifconfig or the following piece of code
(exchange "eth0" for the device in use):
--cut--
#include <sys/socket.h>
#include <sys/ioctl.h>
#include <netinet/in.h>
#include <net/if.h>
#include <stdio.h>
int main(int argc, char **argv) {
struct ifreq myifr;
struct hostent *h;
int i;
char *dot;
sprintf(myifr.ifr_ifrn.ifrn_name,"%s", "eth0");
/* get IP address and write to nameip */
ioctl(socket(AF_INET, SOCK_DGRAM, IPPROTO_IP), SIOCGIFADDR, &myifr);
dot="";
for(i=0; i<4;i++) {
printf("%s%d", dot,
(unsigned char) myifr.ifr_ifru.ifru_addr.sa_data[2+i]);
dot=".";
}
printf("\n");
return(0);
}
--cut--
A MAC-Address query is very simular
Sven
--
This APT has Super Cow Powers.
(apt-get --help on debian woody)
/me is giggls@ircnet, http://sven.gegg.us/ on the Web
.
- References:
- Print IP adress
- From: ashu
- Print IP adress
- Prev by Date: Re: Print IP adress
- Next by Date: "Instant on" PDA like Linux web pad or tablet PC
- Previous by thread: Re: Print IP adress
- Next by thread: kexec/Kdump for linux
- Index(es):
Relevant Pages
|