Re: Print IP adress



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
.



Relevant Pages