* retriving a dhcp assigned ip @ 2003-03-22 20:42 Massimiliano Cialdi 2003-03-22 20:46 ` Jan-Benedict Glaw 2003-03-22 22:06 ` Flávio de Ayra Mendes 0 siblings, 2 replies; 3+ messages in thread From: Massimiliano Cialdi @ 2003-03-22 20:42 UTC (permalink / raw) To: linux-c-programming How can I retrive the ip address assigned to my host by a dhcp server? I think I need to use ioctl with SIOCGIFADDR parameter, but I don't know where the address is saved. thanks -- Massimiliano Cialdi cialdi@firenze.net m.cialdi@oksys.it cialdi@control.dsi.unifi.it ^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: retriving a dhcp assigned ip 2003-03-22 20:42 retriving a dhcp assigned ip Massimiliano Cialdi @ 2003-03-22 20:46 ` Jan-Benedict Glaw 2003-03-22 22:06 ` Flávio de Ayra Mendes 1 sibling, 0 replies; 3+ messages in thread From: Jan-Benedict Glaw @ 2003-03-22 20:46 UTC (permalink / raw) To: linux-c-programming [-- Attachment #1: Type: text/plain, Size: 765 bytes --] On Sat, 2003-03-22 21:42:16 +0100, Massimiliano Cialdi <cialdi@firenze.net> wrote in message <20030322214216.45bc5681.cialdi@firenze.net>: > How can I retrive the ip address assigned to my host by a dhcp server? > I think I need to use ioctl with SIOCGIFADDR parameter, but I don't know > where the address is saved. Look for a sample program that does the job. For example, "ifconfig" from the net-tools package fetches the IP address... MfG, JBG -- Jan-Benedict Glaw jbglaw@lug-owl.de . +49-172-7608481 "Eine Freie Meinung in einem Freien Kopf | Gegen Zensur | Gegen Krieg fuer einen Freien Staat voll Freier Bürger" | im Internet! | im Irak! ret = do_actions((curr | FREE_SPEECH) & ~(IRAQ_WAR_2 | DRM | TCPA)); [-- Attachment #2: Type: application/pgp-signature, Size: 189 bytes --] ^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: retriving a dhcp assigned ip 2003-03-22 20:42 retriving a dhcp assigned ip Massimiliano Cialdi 2003-03-22 20:46 ` Jan-Benedict Glaw @ 2003-03-22 22:06 ` Flávio de Ayra Mendes 1 sibling, 0 replies; 3+ messages in thread From: Flávio de Ayra Mendes @ 2003-03-22 22:06 UTC (permalink / raw) To: Massimiliano Cialdi; +Cc: linux-c-programming [-- Attachment #1: Type: text/plain, Size: 221 bytes --] Massimiliano Cialdi wrote: >How can I retrive the ip address assigned to my host by a dhcp server? >I think I need to use ioctl with SIOCGIFADDR parameter, but I don't know >where the address is saved. > >thanks > > > [-- Attachment #2: discoverip.c --] [-- Type: text/x-csrc, Size: 1203 bytes --] /* * Wed Mar 3 16:21:48 EST 1999 - * h4 <h4@locked.org> */ #include <stdio.h> #include <errno.h> #include <string.h> #include <sys/stat.h> /* socket() */ #include <sys/types.h> /* socket() */ #include <sys/ioctl.h> /* socket() */ #include <sys/socket.h> /* socket() */ #include <linux/if.h> /* ifreq */ #include <linux/in.h> /* sockaddr_in */ int main(int argc, char **argv) { struct sockaddr_in *sk8; struct ifreq r0x; int sockfd; if (argc != 2) { fprintf(stderr, "usage: %s <interface>\n", argv[0]); exit(1); } /* * linux/if.h * #define ifr_name ifr_ifrn.ifrn_name */ strncpy(r0x.ifr_name, argv[1], sizeof(r0x.ifr_name)); if ((sockfd = socket(AF_INET, SOCK_STREAM, IPPROTO_IP)) == -1) { fprintf(stderr, "socket(): %s\n", strerror(errno)); exit(1); } if (ioctl(sockfd, SIOCGIFADDR, &r0x) != 0) { fprintf(stderr, "ioctl(): %s\n", strerror(errno)); exit(1); } /* * linux/if.h * #define ifr_addr ifr_ifru.ifru_addr */ sk8 = (struct sockaddr_in *)&r0x.ifr_addr; fprintf(stdout, "interface : %s\n", r0x.ifr_name); fprintf(stdout, "address: %s\n", inet_ntoa(sk8->sin_addr.s_addr)); return(0); } ^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2003-03-22 22:06 UTC | newest] Thread overview: 3+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2003-03-22 20:42 retriving a dhcp assigned ip Massimiliano Cialdi 2003-03-22 20:46 ` Jan-Benedict Glaw 2003-03-22 22:06 ` Flávio de Ayra Mendes
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for NNTP newsgroup(s).