Newsgroups: fj.questions.unix
Path: galaxy.trc.rwcp.or.jp!news.trc!imnet3!nspixp2!newsfeed1.dti.ad.jp!newsfeed2.dti.ad.jp!taurus!usenet
From: manmos@stellar.co.jp (Hideo "Sir MaNMOS" Morishita)
Subject: Re: How to get IP address
X-Nntp-Posting-Host: hydra
Content-Type: text/plain; charset=ISO-2022-JP
Message-ID: <squ3e4c74z7.fsf@stellar.co.jp>
Sender: usenet@stellar.co.jp
Organization: Stellar Craft, Inc. Osaka,Japan.
X-Newsreader: Gnus v5.4.66/Emacs 19.34
References: <MENDO.99Feb10131342@ishispa.ilab.ntt.co.jp> <m2emnxee0g.fsf@clotho.KU3G.org>
Mime-Version: 1.0 (generated by tm-edit 7.92)
Date: Fri, 12 Feb 1999 02:03:56 GMT
Lines: 74
Xref: galaxy.trc.rwcp.or.jp fj.questions.unix:9319
X-originally-archived-at: http://galaxy.rwcp.or.jp/text/cgi-bin/newsarticle2?ng=fj.questions.unix&nb=9319&hd=a
X-reformat-date: Mon, 18 Oct 2004 15:18:22 +0900
X-reformat-comment: Tabs were expanded into 4 column tabstops by the Galaxy's archiver. See http://katsu.watanabe.name/ancientfj/galaxy-format.html for more info.


Masahito Ohtsuka <negi@KU3G.org> writes:

> $B$*$*$D$+$G$9(B
> 
> >>>>> <MENDO.99Feb10131342@ishispa.ilab.ntt.co.jp> $B$N5-;v$G(B
> >>>>> mendo@ilab.ntt.co.jp (Masahiro Endo) $B$5$s$O=q$-$^$7$?(B
> 
> Endo> UNIX $B%^%7%s!J(B SUN SS20, Solaris 2.6 $B!K$G!"(B
> Endo> $B$=$N%^%7%s$N(B IP$B%"%I%l%9$r%7%9%F%`%3!<%k$GF~<j$9$kJ}K!$rCN$j$?$$$N$G$9$,!"(B
> Endo> $B$I$J$?$+!"$4B8$8$"$j$^$;$s$+!#(B
> 
> Endo> $B$h$m$7$/$*4j$$$7$^$9!#(B
> 
> $B$3$l$O(B irchat $B$KImB0$7$F$$$k(B dcc.c $B$r(B hack $B$9$k$H$-$K6lO+$7$?3P(B
> $B$($,$"$j$^$9!#(B
> 
> dcc $B$O(B gethostbyname() $B$G<+J,$N(B IP $B$r0z$$$F$$$k$s$G$9$,!$(BPPP $B@\(B
> $BB3Ey(B hostname $B$,@5<0$G$J$$>l9g$&$^$/$$$-$^$;$s!#(B
> 
> $B<+J,$O(B pppd $B$+$i(B IP $B%"%I%l%9$r65$($F$b$i$C$F$?$s$G$9$,!$:G?7HG$N(B
> irchat $BImB0(B dcc.c $B$G$O$&$^$$$3$H$d$C$F2r7h$7$F$$$^$9!#(B
> 
> $B$9$4$/4JC1$K=q$/$H(B
> 
> 1. $B%@%_!<$N%=%1%C%H:n$k(B
> 2. $B$I$C$+$K(B connect $B$9$k(B
> 3. getsockname() $B$9$k(B

$B$`$+!<$7$3$s$J%=!<%9$r=q$$$?!#(B

intsock;
structifconfifconf;
structifreqifreq,*ptr,*qtr;
intflag;
inti, hashsize, rtnum=0;

if ((sock = socket(AF_INET,SOCK_DGRAM,0)) == - 1) {
perror("socket");
exit(1);
}
qtr = ptr = malloc(sizeof(struct ifreq)*100);
ifconf.ifc_len = sizeof(struct ifreq)*100;
ifconf.ifc_req = ptr;
if (ioctl(sock,SIOCGIFCONF,&ifconf) == -1) {
perror("ioctl(SIOCGIFCONF)");
exit(1);
}
for (i = 0 ; i < ifconf.ifc_len/sizeof(struct ifreq) ; i++,ptr++ ) {
strcpy(ifreq.ifr_name,ptr->ifr_name);
if (ioctl(sock,SIOCGIFFLAGS,&ifreq) == -1) {
perror("ioctl(SIOCGIFFLAGS)");
exit(1);
}
flag = ifreq.ifr_flags;
if (ioctl(sock,SIOCGIFADDR,&ifreq) == -1) {
perror("ioctl(SIOCGIFDSTADDR)");
exit(1);
}
printf("%s %s\n",ptr->ifr_name,
   inet_ntoa(((struct sockaddr_in *)&ifreq.ifr_addr)->sin_addr),
   inet_ntoa(((struct sockaddr_in *)&ifreq.ifr_dstaddr)->sin_addr));
}
close(socket);

$B$=$N$^$^(Bcopy & paste$B$7$?$s$G!"JQ$JJQ?t$b$"$k$1$I$4$a$s$M!#(B
$B$?$7$+!"$=$l$J$j$KF0$$$?$O$:!#(B
NEXTSTEP$BMQ$@$1$I(BSolaris$B$G$b$=$&JQ$o$i$J$$$O$:!#(B

-- 
   ___     $B$o$7$O!";3?a?'$N$+$9$F!<$i$,Bg9%$-$G$N$%(B
 [[o o]]            $B$U$)$C$U$)$C$U$)(B
   'J'     $B?92<(B $B$*Be41MM(B $B#M#a#N#M#O#S(B $B1QIW!w%9%F%i%/%i%U%H(B
PGP Finger = CD EA D5 A8 AD B2 FE 7D  02 74 87 52 7C B7 39 37
