Linux-Development-Sys Digest #326, Volume #8      Wed, 6 Dec 00 04:13:13 EST

Contents:
  Problem with Realtek "rtl8139(a/b/c)" driver (H�kan Waara)
  Basic Kernel Stuff- memory management (Tony Lawrence)
  Re: plip on thinkpads - broke since 2.2.14 (Jerry McBride)
  JOB OP: SCSI driver developer ([EMAIL PROTECTED])
  Re: How to make a BIOS call in Linux ("Joshua Schaeffer")
  Re: kernel header problems ("Lee Ho")
  Getting eth0 device information in C or perl. ("Joel Pobar")
  Re: How to make a BIOS call in Linux ([EMAIL PROTECTED])
  Why is ramdisk always 4 MB? (John Kelly)
  Re: Getting eth0 device information in C or perl. ([EMAIL PROTECTED])
  Re: Why is ramdisk always 4 MB? (John Kelly)
  Re: How to make a BIOS call in Linux (Josef Moellers)
  Re: Getting eth0 device information in C or perl. (michael scott frank)
  Re: Remapping memory in the kernel space (Arne Driescher)
  Re: c++ in kernel and linker problems ("O.Petzold")
  Re: Please help: NT to Linux port ("Andrew Voznytsa")
  Re: kernel header problems ("O.Petzold")
  Re: Getting eth0 device information in C or perl. ("Quiney, Philip 
[HAL02:HH00:EXCH]")

----------------------------------------------------------------------------

Crossposted-To: 
alt.comp.linux,alt.os.linux,alt.os.linux.mandrake,comp.os.linux.networking
Subject: Problem with Realtek "rtl8139(a/b/c)" driver
From: [EMAIL PROTECTED] (H�kan Waara)
Date: Tue, 05 Dec 2000 22:13:33 GMT

Hey. I installed Linux mandrake yesterday. When I boot, the networking card 
(eth0) fails to connect to the DHCP server. Also, zope fails to shutdown 
correctly.

So, I went to www.realtek.com.tw and looked for the right driver 
("rtl8139(a/b/c)"). What I found was an open-sourced driver, 8139too. But 
the only thing I could download was the source; no compiled driver.

Does someone have "8139too" installed and can email me it or can someone 
compile it (http://www.sourceforge.net/gkernel/) and then send it over?

Thanks in advance! (Please use email only)

--
H�kan Waara

------------------------------

From: Tony Lawrence <[EMAIL PROTECTED]>
Subject: Basic Kernel Stuff- memory management
Date: Tue, 05 Dec 2000 17:08:48 -0500

I'm looking for some pointers to basic kernel stuff, starting
with memory management: how the descriptor and paging tables are
set up, etc.   I've bought O'Reilly's "Understanding the Linux
Kernel" and Moshe Bar's "Linux Internals"- I find those not
exactly baffling, but less than fully illuminating.  

I don't feel I'm really ready to start asking questions here: too
much amorphous gel floating around in my head; I'd like to nail
things down just a little more before asking moronic questions.

I've looked about the web, but so far all I find is very
incomplete stuff, old stuff that knows it is outdated.  From what
I can see, it looks like things have changed radically since most
of that stuff was written, and is about to change again with 2.4
I'm hoping for something comprehensive that covers the evolution
of Linux's memory management from then to now- maybe too much to
hope for..

Any useful pointers, web or hard copy, appreciated.


-- 
Tony Lawrence ([EMAIL PROTECTED])
SCO/Linux articles, help, book reviews, tests, 
job listings and more : http://www.pcunix.com

------------------------------

From: [EMAIL PROTECTED] (Jerry McBride)
Crossposted-To: comp.os.linux.portable
Subject: Re: plip on thinkpads - broke since 2.2.14
Date: Tue, 05 Dec 2000 23:01:08 GMT

In article <[EMAIL PROTECTED]>,
robert w hall <[EMAIL PROTECTED]> wrote:
>plip, which I use extensively to network my old laptop and desktop
>together, got broke in kernel 2.2.14 (due to a FIFO error I recollect).
>It was ostensibly fixed in 2.2.15 and beyond, and these later versions
>work fine on my 686 desktop; but plip in all these later versions  fails
>to run on my laptop (a 755ce stinkpad). When pinged from the desktop, I
>only get back a series of plip transmit timeout errors.
>
>I've also tried plip in the successive slack network-install boot-disks
>as they've been produced, and these have also failed to network after
>2.2.13.
>
>Anyone know the possible root cause of this problem? (It can't just be
>finger trouble, I claim - the setup & config files are unchanged between
>working and non-working builds).
>

I don't know the exact problem. However I can backup what you claim. Moving to
2.2.16 has "fixed" everything, that was wrong, with plip.

--
*******************************************************************************
>         Explore the galaxy--meet new alien races--blow them away!           <
*******************************************************************************
>        5:30pm  up 1 days, 20:13:19, load: 24 processes, 82 threads.         <
*******************************************************************************
* NetRexx - The onramp to the Internet - http://www2.hursley.ibm.com/netrexx  *
*******************************************************************************
*                             ICQ# 76727806                                   *
*******************************************************************************
*                    Registered Linux User Number 185956                      *
*******************************************************************************

------------------------------

From: [EMAIL PROTECTED]
Subject: JOB OP: SCSI driver developer
Date: Tue, 05 Dec 2000 23:07:21 GMT

We are a red hot startup company based in Santa Clara, CA.
We are looking for engineers with experience in developing
or maintaining  SCSI driver preferably in Linux environment.
The ideal candidate must  have worked for at least 3 years
in kernel space of Linux or any other UNIX flavor OS with
at least two years in SCSI driver.

Please send your resume to [EMAIL PROTECTED]

Subbu


Sent via Deja.com http://www.deja.com/
Before you buy.

------------------------------

From: "Joshua Schaeffer" <[EMAIL PROTECTED]>
Subject: Re: How to make a BIOS call in Linux
Date: Tue, 05 Dec 2000 23:34:24 GMT

Why does the boot loader or APM even need to bother with BIOS in the first
place?

"Joe Pfeiffer" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]...
> [EMAIL PROTECTED] writes:
>
> > Does any body know how to make a BIOS call in linux or point me to an
> > example in the linux src code? I searched through the linix source code
> > for "bios' or "BIOS" but did not come up w/ anything useful.
>
> This is the sort of answer I personally find extremely annoying, but:
>
> You almost certainly don't want to do it.  Only a vanishingly small
> number of system-style programs, like the boot loader or APM, have any
> need to ever look at the BIOS.




------------------------------

From: "Lee Ho" <[EMAIL PROTECTED]>
Subject: Re: kernel header problems
Date: Wed, 06 Dec 2000 00:51:24 GMT


O.Petzold Writes:
># g++ -I/usr/include/linux -W -Wall -D__KERNEL__ -c t.cc


append compiler option -DMODULE

*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*
Lee, Ho. Software Engineer, Embedded Linux Dep, LinuxOne
Mail : [EMAIL PROTECTED] (work), [EMAIL PROTECTED] (personal)
Homepage : http://flyduck.com, http://linuxkernel.to




------------------------------

From: "Joel Pobar" <[EMAIL PROTECTED]>
Crossposted-To: 
aus.computers.linux,comp.os.linux.development.apps,comp.os.linux.networking,linux.dev.apps,linux.dev.c-programming,linux.dev.net
Subject: Getting eth0 device information in C or perl.
Date: Wed, 6 Dec 2000 12:15:31 +1000

Hey all,

I need to get the IP address from eth0 in a C or Perl program. I was
wondering if there are any functions that can be called to obtain this
information.

Thanks in advance.
Regards,
Joel Pobar.



------------------------------

From: [EMAIL PROTECTED]
Subject: Re: How to make a BIOS call in Linux
Date: Wed, 06 Dec 2000 02:34:31 GMT

"Joshua Schaeffer" <[EMAIL PROTECTED]> writes:
> Why does the boot loader or APM even need to bother with BIOS in the
> first place?

.. Because it's BIOS that loads them into place; there needs to be
some very basic "bootstrap" portion of the code that takes the
hand-off.

-- 
(concatenate 'string "cbbrowne" "@hex.net") <http://www.ntlug.org/~cbbrowne/>
As usual,  this being  a 1.3.x release,  I haven't even  compiled this
kernel yet.   So if it works,  you should be  doubly impressed. (Linus
Torvalds, announcing kernel 1.3.3 on the linux-kernel mailing list.)

------------------------------

From: John Kelly <[EMAIL PROTECTED]>
Subject: Why is ramdisk always 4 MB?
Date: Tue, 05 Dec 2000 21:13:02 -0700

I've compiled 2.2.16 on RH7 with modular ramdisk support, and booted the
image with ramdisk=56000 (on
a machine with 256MB RAM).  I do an insmod rd rd_size=56000, and get a
success message in /var/log/messages.

mkfs -t ext2 /dev/ramdisk succeeds, and says that 56000 blocks were
found,

mount /dev/ramdisk /mnt/ramdisk works.
df -k /dev/ramdisk shows about 56MB availible,

BUT.....

if I copy more than 4MB into the ram fs, I always get a disk full
message.

What am I doing wrong?

=jk




------------------------------

From: [EMAIL PROTECTED]
Subject: Re: Getting eth0 device information in C or perl.
Date: Wed, 06 Dec 2000 05:42:06 -0000

In comp.os.linux.development.system Joel Pobar <[EMAIL PROTECTED]> wrote:

| I need to get the IP address from eth0 in a C or Perl program. I was
| wondering if there are any functions that can be called to obtain this
| information.

The function is ioctl(), one of the most poorly documented system
functions in UNIX, primarily due to the fact that it has so much
capability compared to what little "man ioctl" says about it. 
One way you can see what ioctl symbols to check for is to do
"strace ifconfig eth0", then go look for those symbols in the .c
files in the Linux kernel for exact details on what you have to
give in arguments, and what you can get back.

-- 
=================================================================
| Phil Howard - KA9WGN |   Dallas   | http://linuxhomepage.com/ |
| [EMAIL PROTECTED] | Texas, USA | http://phil.ipal.org/     |
=================================================================

------------------------------

From: John Kelly <[EMAIL PROTECTED]>
Subject: Re: Why is ramdisk always 4 MB?
Date: Tue, 05 Dec 2000 23:16:00 -0700

Never mind.  The problem was inodes, not disk size.

-jk


John Kelly wrote:

> I've compiled 2.2.16 on RH7 with modular ramdisk support, and booted the
> image with ramdisk=56000 (on
> a machine with 256MB RAM).  I do an insmod rd rd_size=56000, and get a
> success message in /var/log/messages.
>
> mkfs -t ext2 /dev/ramdisk succeeds, and says that 56000 blocks were
> found,
>
> mount /dev/ramdisk /mnt/ramdisk works.
> df -k /dev/ramdisk shows about 56MB availible,
>
> BUT.....
>
> if I copy more than 4MB into the ram fs, I always get a disk full
> message.
>
> What am I doing wrong?
>
> =jk


------------------------------

From: Josef Moellers <[EMAIL PROTECTED]>
Subject: Re: How to make a BIOS call in Linux
Date: Wed, 06 Dec 2000 08:03:59 +0100

Joshua Schaeffer wrote:
> =

> Why does the boot loader or APM even need to bother with BIOS in the fi=
rst
> place?

The boot loader, for one, cannot support all possible disk
controllers/host-adapters. Even if you somehow managed to configure your
boot loader to use a specific driver, the first stage loader must fit
into a 512 byte block (the master boot record, MBR) and even the most
rudimentary SCSI driver needs more than that. Besides ... the boot
loader runs in real mode as does the BIOS and the BIOS knows how to
access the boot device, so why bother with a driver of your own when
it's already there!

As to the APM code, I don't know, but I'll make an educated guess: the
APM is a fairly recent development and, as such, the APM BIOS is
available in a protected mode version. Also, I guess, it's highly
vendor-specific, so rather than write several versions of APM code,
Linux can very well use the APM BIOS.

-- =

Josef M=F6llers (Pinguinpfleger bei FSC)
        If failure had no penalty success would not be a prize (T.  Pratchett)

------------------------------

From: michael scott frank <[EMAIL PROTECTED]>
Crossposted-To: 
comp.os.linux.development.apps,comp.os.linux.networking,linux.dev.apps,linux.dev.c-programming,linux.dev.net,aus.computers.linux
Subject: Re: Getting eth0 device information in C or perl.
Date: Tue, 5 Dec 2000 23:37:00 -0800

If you want to do it in C, you use the ioctl SIOCGIFADDR.  Here's a small
program i wrote a while ago, modified a bit for what you need.  Its a bit
of work to do it the 'real' way, as you can see.  the ifreq struct is
particularily nasty, if you look at how it is defined in the headers.  If
you are interested in this stuff like i am tho, you should definitely pick
up "UNIX network programming" by W. Richard Stevens.  it is _the_ book on
the subject, and has an excellent chapter on network related ioctls.

#include <stdio.h>
#include <sys/socket.h>
#include <sys/ioctl.h>
#include <netinet/in.h>
#include <net/if.h>

int main(void) {
        int fd;
        struct sockaddr_in *addr_ptr;
        struct ifreq interface;
        char IP[INET_ADDRSTRLEN];

        /* tells ioctl which interface to query */
        strcpy(interface.ifr_name, "eth0");     

        /* need a socket to use ioctl */
        fd = socket(AF_INET, SOCK_DGRAM, 0);

        /* get interface ip address */
        if (ioctl(fd, SIOCGIFADDR, &interface) < 0) {
                perror("ERROR (ioctl (SIOCGIFADDR))");
                exit(1);
        }

        /* kinda ugly, but this allows us to use inet_ntop */
        addr_ptr = (struct sockaddr_in *) &interface.ifr_addr;

        /* INET protocol family */
        addr_ptr->sin_family = AF_INET; 

        /* copy ip address */
        inet_ntop(AF_INET, &addr_ptr->sin_addr, IP, INET_ADDRSTRLEN);   

        /* print it */
        printf("IP of eth0: %s\n", IP);
        exit(0);
}




=========================  .~.
Michael Frank              /v\
[EMAIL PROTECTED]  // \\
======================== /(   )\
                          ^`~'^

On Wed, 6 Dec 2000, Joel Pobar wrote:

> Hey all,
> 
> I need to get the IP address from eth0 in a C or Perl program. I was
> wondering if there are any functions that can be called to obtain this
> information.
> 
> Thanks in advance.
> Regards,
> Joel Pobar.
> 
> 
> 


------------------------------

From: Arne Driescher <[EMAIL PROTECTED]>
Subject: Re: Remapping memory in the kernel space
Date: Wed, 06 Dec 2000 09:15:34 +0100

David Zada wrote:
> 
> Hi !
> 
> How can i map my memory in the linux, to allocate  a region of memory in
> specific address that i decide , that any others process can't overwrite
> this region of memory  ? ( i know in the other O.S you just give order to
> the linker to save some region of memory for you in specific
> address , i wonder if there any way in linux to do it ).
> I must to notify that this allocation done in my module , and i want that
> this allocation will be in the kernel space memory
> 
> Sincerely,
> David

Dear David,

your question is not much to the point. 
1) What kind of memory are you talking about?
   Normal RAM, I/O-memory from some device
2) If it is real memory, how much memory do you need?
3) What do you want to do with the memory? 
   (normal buffer for internal use or DMA transfer)

Try to answer this questions and perhaps someone can
help you.

-Arne

------------------------------

From: "O.Petzold" <[EMAIL PROTECTED]>
Subject: Re: c++ in kernel and linker problems
Date: Wed, 06 Dec 2000 09:35:57 +0100

Mathias Waack wrote:

> "O.Petzold" <[EMAIL PROTECTED]> writes:
>
> > I try to write C++ for a linux kernel module, since I use the same
> > code for the real app und the module. The problem is, I can't use
> > exceptions and rtti, so I have to emulate this. The first I use a
> > global flag, the 2nd - no idea. Well, I have now linking problems - I
>
> The 2nd was solved (before the "invention" of rtti) by a virtual method
> int type() in each class. This method must be overloaded in each subclass
> and you should use uniq type-ids in your application.

like this ?:
class A {
    A();
    ~A();
    virtual int type() { return unique_id; }
};

So I can use dynamic_cast and typeid (typeinfo.h) ?

>
>
> > Further more I use in the source char *p = new(nothrow) char[39]
> > if(!p) {
> >     THROW(std::bad_alloc); }
>
> Hmm, if you use std::bad_alloc in kernel code, you must IMHO link
> your module statically with the libstdc++. Bad idea I think...

So the symbols are defined in the libstdc++. I agree with you staticaly
linking
is not a good idea.

> > The nothrow symbol is defined inside header new with extern const
> > nothrow_t nothrow;
>
> Thats a declaration, not a definition. Are you sure that nothrow is
> defined somewhere?

Yes, in my code - see above:
char* p = new(nothrow) char[39];
With this I can proof on (!p) for user and kernel space. The other way could

be in user space:
try {
    char* p = new char[39]; }
catch(std::bad_alloc) {
    ...}
and to use global flags for kernel space.

> > That's all what I found. How can I write the
> > classes nothrow, exception and bad_alloc so that I don't get linker
> > errors ?
>
> Try to declare your own bad_alloc class first.

No use of the c++ includes from kernel space?, so I have to write my own
kernel libstc++ ? For new/delete there isn't a problem for me but, for
exceptions
yes - it's like to have a look in the engine room 8).
Does exist a small one here ?

Thanks    Olaf


------------------------------

From: "Andrew Voznytsa" <[EMAIL PROTECTED]>
Subject: Re: Please help: NT to Linux port
Date: Wed, 6 Dec 2000 10:21:55 +0200

I never did it, but I know some things which can help you,
It's not very hard but it also I not very easy,

in two words:

1. you should install sig. handler;
2. when handler will be called, it should call __throw(); (this functions
generates throw, sources is in <gcc root>/gcc/libgcc2.c, also in this file
is implementation of all exception handling machinery);
3. exception will be handled by appropriate catch block or
terminate_handler() if block was not found;

reds,

Andrew

"Carlos Portela" <[EMAIL PROTECTED]> wrote in message
news:90iikl$tno$[EMAIL PROTECTED]...
> Thanks to all who replied to my post.
>
> As someone indicated in his/her response the protection violations that I
am
> trying to catch are generated by bad programming and the proposed solution
> is to fix the code that generates them.  In a perfect world I would agree
> 100% with that proposal but when you have hundreds of thousands of lines
of
> code written by several programmers over years of work it is nearly
> impossible to cover all the possibilities and in this particular case
> recovering from the violation, freeing resources, etc is very easy.
>
> Although catching exceptions for this purpose is not pretty nor perfect it
> does allow the product to continue to operate reliably 24 x 7 and the
client
> side is informed of the situation immediately. The truth is we very seldom
> see one of these exceptions but it surely is nice to catch them and
> gracefully recover when they occur.
>
> Once again I thank all who replied to my post.  If you have any further
> ideas about how I can implement something like this please let me know.
>
> Carlos
>
> Karl Heyes wrote in message <90h910$6ti$[EMAIL PROTECTED]>...
> >In article <90gah5$1ab0$[EMAIL PROTECTED]>, "Carlos Portela"
> ><[EMAIL PROTECTED]> wrote:
> >
> >>
> >>
> >> This code is not being used to catch normal exceptions thrown by the
> >> code underneath but instead it is being used to catch memory
> >> protection violations and other exceptions generated by Windows.
> >>
> >> My question is:
> >>
> >> Is this behaviour of the try-catch pair available in Linux?  If not
> >> then, can you suggest an alternate implementation?  In other words,
> >> how can I obtain control if the code I called (in this case
> >> CallSomeFunction) screws up?
> >>
> >
> >The code follows the C++ standard so yes it will work as long as you
> >have an uptodate G++, most distros usually will have at least egcs
> >1.1.2 which seems to be fine for exceptions that I've used.  There
> >may be cases where it may have problems though, haven't seen any!.
> >The recent versions are 2.95.2.  and some class that as out of date,
> >but I suspect that you will be ok.
> >
> >karl.
>
>



------------------------------

From: "O.Petzold" <[EMAIL PROTECTED]>
Subject: Re: kernel header problems
Date: Wed, 06 Dec 2000 09:57:50 +0100

>

Thanks Mathias and Lee. Here is the small piece of code:

#ifdef __cplusplus
extern "C" {
#endif

#  define new new_
#  define virtual virtual_

#  include <linux/config.h>
#  include <linux/types.h>  // size_t
#  include <stddef.h>           // size_t

#  include <linux/mm.h>    // GFP_KERNEL
#  include <linux/slab.h>   // kmalloc
#  include <linux/vmalloc.h> // vmalloc

#  include <linux/time.h>

#  undef new
#  undef virtual

#ifdef __cplusplus
}
#endif

void test() {}

# gcc -I/usr/src/linux/include -D__KERNEL__ -DMODULE -c mem.cc
In file included from /usr/src/linux/include/linux/sched.h:23,
                 from /usr/src/linux/include/linux/mm.h:4,
                 from mem.cc:12:
/usr/src/linux/include/linux/signal.h: In function `void
sigfillset(sigset_t *)':
/usr/src/linux/include/linux/signal.h:159: warning: assignment of negative
value `-1' to `long unsigned int'
/usr/src/linux/include/linux/signal.h:160: warning: assignment of negative
value `-1' to `long unsigned int'
/usr/src/linux/include/linux/signal.h: In function `void
siginitset(sigset_t *, long unsigned int)':
/usr/src/linux/include/linux/signal.h:193: parse error before `}'
/usr/src/linux/include/linux/signal.h: In function `void
siginitsetinv(sigset_t *, long unsigned int)':
/usr/src/linux/include/linux/signal.h:203: warning: assignment of negative
value `-1' to `long unsigned int'
/usr/src/linux/include/linux/signal.h:205: parse error before `}'

the g++ have the same errors ! Patching the headers should be not
the solution (kernel 2.2.17).

--- /usr/src/linux/include/linux/signal.h~      Tue Dec  5 13:47:23 2000
+++ /usr/src/linux/include/linux/signal.h       Wed Dec  6 10:33:30 2000
@@ -156,8 +156,8 @@
        default:
                memset(set, -1, sizeof(sigset_t));
                break;
-       case 2: set->sig[1] = -1;
-       case 1: set->sig[0] = -1;
+       case 2: set->sig[1] = (long unsigned int)-1;
+       case 1: set->sig[0] = (long unsigned int)-1;
                break;
        }
 }
@@ -189,7 +189,7 @@
                memset(&set->sig[1], 0, sizeof(long)*(_NSIG_WORDS-1));
                break;
        case 2: set->sig[1] = 0;
-       case 1:
+       case 1: return;
        }
 }

@@ -200,8 +200,8 @@
        default:
                memset(&set->sig[1], -1, sizeof(long)*(_NSIG_WORDS-1));
                break;
-       case 2: set->sig[1] = -1;
-       case 1:
+       case 2: set->sig[1] = (long unsigned int)-1;
+       case 1: return;
        }
 }

It's interesting to have the same errors with gcc and g++! Compiling the
kernel with
-Wall gives more - don't try -W 8) :
# gcc -Wall -I/usr/src/linux/include -D__KERNEL__ -DMODULE -c mem.cc
In file included from mem.cc:12:
/usr/src/linux/include/linux/mm.h: In function `int
expand_stack(vm_area_struct *, long unsigned int)':
/usr/src/linux/include/linux/mm.h:359: warning: comparison between signed
and unsigned
/usr/src/linux/include/linux/mm.h:362: warning: comparison between signed
and unsigned

Is this in 2.4.x as well ? Should I send this to the kernel mailing list ?

Thanks    Olaf



------------------------------

From: "Quiney, Philip [HAL02:HH00:EXCH]" <[EMAIL PROTECTED]>
Crossposted-To: 
aus.computers.linux,comp.os.linux.development.apps,comp.os.linux.networking,linux.dev.apps,linux.dev.c-programming,linux.dev.net
Subject: Re: Getting eth0 device information in C or perl.
Date: Wed, 06 Dec 2000 08:29:35 +0000

Joel Pobar wrote:
> 
> Hey all,
> 
> I need to get the IP address from eth0 in a C or Perl program. I was
> wondering if there are any functions that can be called to obtain this
> information.
> 
> Thanks in advance.
> Regards,
> Joel Pobar.
Hi,

The following code wil get this information.....(it ain't pretty but
does work ;-))

#include <unistd.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <linux/sockios.h>
#include <netinet/in.h>
#include <net/if.h>
#include <arpa/inet.h>
#include <stdio.h>
#include <string.h>


static int get_info(char *interface)
{
    char *f_name = "get_info";
    int fd;
    struct ifreq req;
    struct sockaddr_in *this_addr = (struct sockaddr_in *)&req.ifr_addr;
    struct sockaddr_in address;
    struct sockaddr_in netmask;


    fd = socket(AF_INET, SOCK_DGRAM, 0);
    if(fd<0)
    {
        perror("get_info: socket");
        return 1;
    }

    strcpy(req.ifr_name, interface);

    /* Interface is valid if we get an ifindex */
    if (ioctl(fd, SIOCGIFINDEX, &req) < 0)
    {
        printf("%s: unknown iface %s\n", f_name, interface);
        close(fd);
        return 1;
    }

    /* Get the interface address */
    if(ioctl(fd, SIOCGIFADDR, &req) < 0)
    {
        printf("%s: ioctl failed\n", f_name);
        close(fd);
        return 1;
    }

    address.sin_addr = this_addr->sin_addr;

    /* Get the interface netmask */
    if(ioctl(fd, SIOCGIFNETMASK, &req) < 0)
    {
        printf("%s: ioctl failed\n", f_name);
        close(fd);
        return 1;
    }

    netmask.sin_addr = this_addr->sin_addr;

    /* Done with socket so close it */
    close(fd);

    /*
     * Watch inet_ntoa - it won't work with multiple calls in a printf
as it
     * returns a pointer to a static buffer which gets overwritten
     */
    printf("Interface %s Address %s Netmask ", interface,
           inet_ntoa(address.sin_addr));
    printf("%s\n", inet_ntoa(netmask.sin_addr));

    return 0;
}


int main(int argc, char *argv[])
{
    if(argc <= 1)
    {
        printf("Useage: %s <interface> - where <interface> is name of",
               " device (eg eth0 or eth0,eth1,..,)\n", argv[0]);
        return 0;
    }

    get_info(argv[1]);
    return 0;
}


Regards

Phil Q

-- 

Phil Quiney                             CSIP Demonstrator
[EMAIL PROTECTED]              Nortel Networks,
Telephone: +44 (0)1279 402363           London Rd, Harlow,
Fax:       +44 (0)1279 402885           Essex CM17 9NA,
                                        United Kingdom.

"This message may contain information proprietary to Northern 
Telecom so any unauthorised disclosure, copying or distribution
of its contents is strictly prohibited."

------------------------------


** FOR YOUR REFERENCE **

The service address, to which questions about the list itself and requests
to be added to or deleted from it should be directed, is:

    Internet: [EMAIL PROTECTED]

You can send mail to the entire list (and comp.os.linux.development.system) via:

    Internet: [EMAIL PROTECTED]

Linux may be obtained via one of these FTP sites:
    ftp.funet.fi                                pub/Linux
    tsx-11.mit.edu                              pub/linux
    sunsite.unc.edu                             pub/Linux

End of Linux-Development-System Digest
******************************

Reply via email to