From: Aleksandr Blohin <sass@uustoll.ee> To: mandrake-russian@altlinux.ru Subject: [mdk-re] Re: [mdk-re] Linux Programming: получить список адресов Date: Fri Mar 1 21:36:14 2002 Message-ID: <20020301203012.5beacc71.sass@uustoll.ee> (raw) In-Reply-To: <20020301143434.GA6242@darkstar.core.uslugionline.ru> [-- Attachment #1: Type: text/plain, Size: 759 bytes --] On Fri, 1 Mar 2002 17:34:34 +0300 Mikhail Nikitin <mouse@uslugionline.ru> wrote: MN> Здравствуйте господа! MN> Пишется некоторая программа на С++ (исп. libCommmonC++). MN> Есть некоторое желание получить список всех текущих IP-адресов (и, MN> желательно, девайсов, не глядя в /proc/net/dev). MN> Как бы это дело обстряпать получше? MN> (варианты с С, Perl, awk, etc.. не предлагать ;-) MN> Михаил MN> -- MN> UNIX is very user friendly. MN> It's just very selective about who its friends are. MN> _______________________________________________ MN> Mandrake-russian mailing list MN> Mandrake-russian@altlinux.ru MN> http://altlinux.ru/mailman/listinfo/mandrake-russian -- Best regards AB -- ... In nomine Altli, et Ctrli, et Spititus Deli, Reset! [-- Attachment #2: localaddr.c --] [-- Type: text/plain, Size: 1322 bytes --] # include <stdio.h> # include <stdlib.h> # include <errno.h> # include <unistd.h> # include <sys/types.h> # include <sys/socket.h> # include <net/if.h> # include <sys/ioctl.h> # include <netinet/in.h> # include <arpa/inet.h> int main(int argc, char* argv[]){ struct ifconf ifc; struct ifreq *ifr, ifrcopy; int flags; char *buf, *ptr; int len; int sockfd; struct sockaddr_in *sad; sockfd = socket(AF_INET,SOCK_DGRAM,0); if ( sockfd == -1 ) { perror ("socket"); return 1; } len = 100 * sizeof(struct ifreq); buf = malloc(len); ifc.ifc_len = len; ifc.ifc_buf = buf; if ( ioctl(sockfd, SIOCGIFCONF, &ifc ) == -1) { if ( errno != EINVAL ) { perror("ioctl"); return 2; } else printf("not all interfaces fit in buf\n"); } for (ptr = buf; ptr < buf + ifc.ifc_len; ){ ifr = (struct ifreq *)ptr; # if 1 ptr += sizeof (ifr->ifr_name) + sizeof(struct sockaddr); # else ptr += sizeof (ifr->ifr_name) + ifr->ifr_addr.sa_len; # endif ifrcopy = *ifr; ioctl(sockfd,SIOCGIFFLAGS,&ifrcopy); flags = ifrcopy.ifr_flags; if ( (flags & IFF_UP) == 0 ) continue; /* interface is down */ sad = (struct sockaddr_in *)(&ifr->ifr_addr); printf("%s %s\n", ifr->ifr_name, inet_ntoa( sad->sin_addr) ); } return 0; }
next prev parent reply other threads:[~2002-03-01 21:36 UTC|newest] Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top 2002-03-01 17:26 Mikhail Nikitin 2002-03-01 17:53 ` Sergey Vlasov 2002-03-01 18:15 ` Mikhail Nikitin 2002-03-01 21:36 ` Aleksandr Blohin [this message] 2002-03-02 12:52 ` [mdk-re] " Mikhail Nikitin
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20020301203012.5beacc71.sass@uustoll.ee \ --to=sass@uustoll.ee \ --cc=mandrake-russian@altlinux.ru \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: link
ALT Linux Community general discussions This inbox may be cloned and mirrored by anyone: git clone --mirror http://lore.altlinux.org/community/0 community/git/0.git # If you have public-inbox 1.1+ installed, you may # initialize and index your mirror using the following commands: public-inbox-init -V2 community community/ http://lore.altlinux.org/community \ mandrake-russian@linuxteam.iplabs.ru community@lists.altlinux.org community@lists.altlinux.ru community@lists.altlinux.com public-inbox-index community Example config snippet for mirrors. Newsgroup available over NNTP: nntp://lore.altlinux.org/org.altlinux.lists.community AGPL code for this site: git clone https://public-inbox.org/public-inbox.git