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

help getting IP address in c code


Your Ad Here

Your Ad Here

...

For user level programs there should virtually *never* be a need to include from theusr-include-linux directory. But there are some tricks to learn about how to avoid it too. Here is the correct list of includes:

#define GNUSOURCE

The define is needed *only* if you enable ISO-ANSI C Standard compliance of the compiler on the command line. Hence, with this command line it is not required,

gcc -O2 -Wall -W foo.c

Which is probably the most minimal command line you should ever use. With this command line, which is probably more appropriate, the define above would be required,

gcc -O2 -Wall -W -std=c99 foo.c

Seeusr-include-features.h for more information about the possible defines that might be useful.

Dual network configuration
On 28 Jun 2006, in the Usenet newsgroup comp.os.linux.networking, in article newsgroup comp.os.linux.misc in article Please don't multi-post. This article...

Incidentally, it is handy to have a generic Makefile to allow testing just about anything with the simple "make" command. Mine invokes the compiler like this,

gcc -ggdb -O2 -std=c99 -pedantic -Wall -W -Wcast-align -Wcast-qual -Wmissing-prototypes -Wshadow -Wnested-externs -Wstrict-prototypes -Waggregate-return -Wpointer-arith -c foo.c

Ubuntu Synaptic repository problem
I am currently running Breezy on my laptop - it's a bit of a limited machine (156 MB RAM, 450 MHz processor, 4 GB HDD) so I'm...

There is little point in not letting the compiler catch your mistakes, before they are a real problem.

Here are a couple variations on that code, which may or may not be interesting to you,

int main(void) { int fd; struct ifreq ifr;

* Define POINTER as non-zero to use a pointer here. *

#define POINTER 0 #if POINTER struct sockaddrin *saddr = (struct sockaddrin *) &ifr.ifraddr; #else struct sockaddrin saddr = *((struct sockaddrin *)(&(ifr.ifraddr))); #endif

strcpy(ifr.ifrname,"eth0");

if (-1 == (fd = socket(PFINET,SOCKSTREAM,0))) { perror("socket()"); return EXITFAILURE; }

if (-1 == (ioctl(fd, SIOCGIFADDR, &ifr))) { perror("ioctl SIOGIFADDR"); return EXITFAILURE; }

#if POINTER #else printf("-n%s : %s-n", ifr.ifrname, inetntoa(saddr.sinaddr)); #endif

return EXITSUCCESS; }

--



Your Ad Here

List | Previous | Next

Dual network configuration

Linux groups from Newsgroups

The #1 Usenet Provider on the Internet

netkittelnet compile fail. `exit' undeclared in main.cc