Print IP adress

Do you have a question? Post it now! No Registration Necessary

Translate This Thread From English to

Threaded View
hi all,

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 .how can
my pc recognise the board and generate the ip adress.Is there any
function or program are to be used .answers should be appreciated.

with regards

Re: Print IP adress

Quoted text here. Click to load it


Re: Print IP adress
Quoted text here. Click to load it

I assume that your setup consists of  a switch connected to the
network with a DHCP server
somewhere, the Blackfin board and your computer; I also assume that
gets its IP settings through DHCP.

You could run wireshark or tcpdump on your linux box and watch the
DHCP broadcast traffic to your board when you power it up. You could
see all traffic if you placed both your computer and the board on a
simple hub---a useful thing to have, and I keep a couple of old hubs
around for just this purpose.

Re: Print IP adress

Quoted text here. Click to load it

You may either use ifconfig or the following piece of code
(exchange "eth0" for the device in use):

#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);

  for(i=0; i<4;i++) {
    printf("%s%d", dot,
        (unsigned char) myifr.ifr_ifru.ifru_addr.sa_data[2+i]);

A MAC-Address query is very simular


                       This APT has Super Cow Powers.
                    (apt-get --help on debian woody)

We've slightly trimmed the long signature. Click to see the full one.

Site Timeline