Date: Tue, 18 Jul 2000 15:45:35 -0400 From: Matt Gostick <matt@virtualservice.com> To: Drew Sanford <drew@planetwe.com>, questions@freebsd.org Subject: Re: Mailing IP changes Message-ID: <3974B3DF.93D5901F@virtualservice.com> References: <3974A0A5.F4632A9A@planetwe.com>
next in thread | previous in thread | raw e-mail | index | archive | help
I took a quick glance at this piece of code after I sent it and noticed
why it didn't work for all interfaces :) It's fixed now.
#include <stdio.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/ioctl.h>
#include <netinet/in.h>
#include <net/if.h>
int main (int argc, char **argv) {
int sock_fd;
struct ifreq ifr;
struct in_addr ip;
/* open a socket for the ioctl calls */
if ((sock_fd = socket(AF_INET, SOCK_DGRAM, 0)) == -1) {
perror("socket");
return -1;
}
/* make the ioctl call */
strcpy(ifr.ifr_name, argv[1]);
if (ioctl(sock_fd, SIOCGIFADDR, &ifr) == -1) {
perror("ioctl(SIOCGIFADDR)");
return -1;
}
ip = (struct in_addr) (((struct sockaddr_in *)
&ifr.ifr_addr)->sin_addr);
/* close the socket */
close(sock_fd);
/* print the ip address */
printf("%s\n", inet_ntoa(ip));
/* success */
return 0;
}
Drew Sanford wrote:
>
> Hi,
> I'd like to know if anyone has a good way of emailing a machines IP
> address to themselves when the machine (connected via PPP) has to
> reconnect and is assigned a new IP. What is the most sensible way to do
> this?
>
> --
> Drew Sanford
> Systems Administrator
> Planetwe.com
> Email: drew@planetwe.com
>
> To Unsubscribe: send mail to majordomo@FreeBSD.org
> with "unsubscribe freebsd-questions" in the body of the message
--
Matt Gostick <matt@virtualservice.com>
To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-questions" in the body of the message
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?3974B3DF.93D5901F>
