PLEX86  x86- Virtual Machine (VM) Program
 Plex86  |  CVS  |  Mailing List  |  Download  |  Linux  |  Newsgroups

C program for getting IP address of standlone box with no sockets 7163


Your Ad Here

Your Ad Here

C program for getting IP address of standlone box with no sockets 7164
What? If you're going to call ifconfig, why not just use popen()? PA: I was just not aware of this function. Thanks for pointing it out. Unwilling to make system calls? Are you...

the Black Sun and said:

What? If you're going to call ifconfig, why not just use popen()?

FILE *FP; char buff1024;

FP=popen("-sbin-ifconfig bin-grep inetaddr","r"); if(!FP){ barf("popen(ifconfig) failed! Bailing out."); } while(fgets(buff,1024,FP)){ * parse data and do stuff with it * } pclose(FP);* continue program *

Unwilling to make system calls? Are you *sure* you know what you're doing? Maybe you should read the ifconfig source code as Peter T. Breuer suggested, so you can understand what it does. Generally, you *must* make system calls to do anything other than manipulate private-to-the-current-process data. read(), write(), open(), close(), and ioctl() are ... guess what, system calls. If your program doesn't use any system calls, it won't be able to do much. (Remember, the fopen() and fprintf() functions make system calls through the standard C library.)

Escaping backslash programming question
You'll need to create a new file anyway. If all you want to do is delete that line... mvtmp-tempfileetc-syslog.conf Will do it. :-) You might want to save the original syslog.conf file...

Um. Network interfaces on Linux always have names of some sort, like eth0, usb0, ppp0, lo, and so forth. If you meant "might not have a DNS name", then that's cool. gethostname() should always return a valid hostname or EFAULT-EINVAL though.

The solution that'd take the least amount of time for you is to popen() ifconfig and parse the data returned. (Remember, Laziness is one of the virtues.) There are other ways, of course, but why not make use of the nifty POSIX stuff that's available if it makes your job easier? HTH,

Linux Security 7166
If you run redhat-fedora there is a program system-config-securitylevel you can use to configure a firewall...

-- Matt GThere is no Darkness in Eternity-But only Light too dim for us to see Brainbench MVP for Linux Admin mail: TRAP + SPAN don't belong ----------------------------- penguins, is Tux." --MegaHAL



Your Ad Here

List | Previous | Next

C program for getting IP address of standlone box with no sockets 7164

Linux groups from Newsgroups

The #1 Usenet Provider on the Internet

C program for getting IP address of standlone box with no sockets 7162