473,406 Members | 2,336 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

Program analysis (pseudocode if possible)

#include <err.h>
#include <stdlib.h>
#include <string.h>
#include <sys/ioctl.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <net/route.h>
#include <net/if.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <net/if_ether.h>
#include <net/if_dl.h>
#include <ifaddrs.h>
#include <stdio.h>

#include "ipschema.h"
#include "ssrv/sockaddr.h"

#ifndef lint
__RCSID("$Id: ethip.c 2314 2004-12-29 01:00:25Z dyoung $");
#endif

#define ETHIP "ethip"
#define WLANIP "wlanip"
#define RTMSGIP "rtip"
#define ETH6IP "eth6ip"
#define WLAN6IP "wlan6ip"

#define ENDSWITH(s, end) (strlen((s)) >= strlen((end)) && \
strcmp((s) + strlen((s)) - strlen((end)),
end) == 0)

void
usage(const char *proggie)
{
errx(EXIT_FAILURE, "Usage: %s <interface>", proggie);
}

int
main(int argc, char **argv)
{
char buf[100];
struct sockaddr_dl *sdl;
int masklen, rc;
struct sockaddr *iaddr;
struct ether_addr mac;
struct ifaddrs *ifap, *ifa_iter;
ab_to_ip_t ab_to_ip;

if (argc < 2)
usage(argv[0]);

if (ENDSWITH(argv[0], ETHIP)) {
ab_to_ip = ab_to_eth_ip;
} else if (ENDSWITH(argv[0], WLANIP)) {
ab_to_ip = ab_to_wlan_ip;
} else if (ENDSWITH(argv[0], RTMSGIP)) {
ab_to_ip = ab_to_routemsg_ip;
} else if (ENDSWITH(argv[0], ETH6IP)) {
ab_to_ip = ab_to_eth_ip6;
} else {
errx(EXIT_FAILURE, "%s: unimplemented.", argv[0]);
}

if (getifaddrs(&ifap) == -1)
err(EXIT_FAILURE, "ioctl");

for (ifa_iter = ifap; ifa_iter; ifa_iter = ifa_iter->ifa_next)
if (strcmp(ifa_iter->ifa_name, argv[1]) == 0)
break;

if (!ifa_iter)
errx(EXIT_FAILURE, "no such interface as %s", argv[1]);

for (ifa_iter = ifap; ifa_iter; ifa_iter = ifa_iter->ifa_next) {
if (strcmp(ifa_iter->ifa_name, argv[1]) != 0)
continue;
if (ifa_iter->ifa_addr->sa_family == AF_LINK)
break;
}

if (!ifa_iter)
errx(EXIT_FAILURE, "no link-level address for %s", argv[1]);

sdl = (struct sockaddr_dl *)ifa_iter->ifa_addr;

(void)memcpy(&mac, LLADDR(sdl), sizeof(mac));
masklen = mac_to_ip(&mac, ab_to_ip, &iaddr);
rc = sockaddr_snprintf(buf, sizeof(buf), "%a", iaddr);
if (rc == -1 || rc >= sizeof(buf))
errx(EXIT_FAILURE, "%s: sockaddr_snprintf", getprogname());
sockaddr_free(iaddr);
(void)printf("%s/%d\n", buf, masklen);

freeifaddrs(ifap);
return 0;
}

Jul 3 '06 #1
4 2007
Vusi wrote:
#include <err.h>
#include <stdlib.h>
#include <string.h>
#include <sys/ioctl.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <net/route.h>
#include <net/if.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <net/if_ether.h>
#include <net/if_dl.h>
#include <ifaddrs.h>
#include <stdio.h>

#include "ipschema.h"
#include "ssrv/sockaddr.h"

#ifndef lint
__RCSID("$Id: ethip.c 2314 2004-12-29 01:00:25Z dyoung $");
#endif

#define ETHIP "ethip"
#define WLANIP "wlanip"
#define RTMSGIP "rtip"
#define ETH6IP "eth6ip"
#define WLAN6IP "wlan6ip"

#define ENDSWITH(s, end) (strlen((s)) >= strlen((end)) && \
strcmp((s) + strlen((s)) - strlen((end)),
end) == 0)

void
usage(const char *proggie)
{
errx(EXIT_FAILURE, "Usage: %s <interface>", proggie);
}

int
main(int argc, char **argv)
{
char buf[100];
struct sockaddr_dl *sdl;
int masklen, rc;
struct sockaddr *iaddr;
struct ether_addr mac;
struct ifaddrs *ifap, *ifa_iter;
ab_to_ip_t ab_to_ip;

if (argc < 2)
usage(argv[0]);

if (ENDSWITH(argv[0], ETHIP)) {
ab_to_ip = ab_to_eth_ip;
} else if (ENDSWITH(argv[0], WLANIP)) {
ab_to_ip = ab_to_wlan_ip;
} else if (ENDSWITH(argv[0], RTMSGIP)) {
ab_to_ip = ab_to_routemsg_ip;
} else if (ENDSWITH(argv[0], ETH6IP)) {
ab_to_ip = ab_to_eth_ip6;
} else {
errx(EXIT_FAILURE, "%s: unimplemented.", argv[0]);
}

if (getifaddrs(&ifap) == -1)
err(EXIT_FAILURE, "ioctl");

for (ifa_iter = ifap; ifa_iter; ifa_iter = ifa_iter->ifa_next)
if (strcmp(ifa_iter->ifa_name, argv[1]) == 0)
break;

if (!ifa_iter)
errx(EXIT_FAILURE, "no such interface as %s", argv[1]);

for (ifa_iter = ifap; ifa_iter; ifa_iter = ifa_iter->ifa_next) {
if (strcmp(ifa_iter->ifa_name, argv[1]) != 0)
continue;
if (ifa_iter->ifa_addr->sa_family == AF_LINK)
break;
}

if (!ifa_iter)
errx(EXIT_FAILURE, "no link-level address for %s", argv[1]);

sdl = (struct sockaddr_dl *)ifa_iter->ifa_addr;

(void)memcpy(&mac, LLADDR(sdl), sizeof(mac));
masklen = mac_to_ip(&mac, ab_to_ip, &iaddr);
rc = sockaddr_snprintf(buf, sizeof(buf), "%a", iaddr);
if (rc == -1 || rc >= sizeof(buf))
errx(EXIT_FAILURE, "%s: sockaddr_snprintf", getprogname());
sockaddr_free(iaddr);
(void)printf("%s/%d\n", buf, masklen);

freeifaddrs(ifap);
return 0;
}
<pseudocode>

BEGIN PROGRAM
read_this('http://www.catb.org/~esr/faqs/smart-questions.html')
do_your_homework()
END PROGRAM

--
bruno desthuilliers
python -c "print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for
p in 'o****@xiludom.gro'.split('@')])"
Jul 3 '06 #3
"Bruno Desthuilliers" <on***@xiludom.growrote in message
news:44***********************@news.free.fr...
<snip>
<pseudocode>

BEGIN PROGRAM
read_this('http://www.catb.org/~esr/faqs/smart-questions.html')
do_your_homework()
if (cant_figure_it_out)
post_specific_question_on_relevant_newsgroup("comp .lang.c")
END PROGRAM

--
bruno desthuilliers
python -c "print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for
p in 'o****@xiludom.gro'.split('@')])"

Jul 3 '06 #4
Paul McGuire wrote:
"Bruno Desthuilliers" <on***@xiludom.growrote in message
news:44***********************@news.free.fr...
<snip>
>><pseudocode>

BEGIN PROGRAM
read_this('http://www.catb.org/~esr/faqs/smart-questions.html')
do_your_homework()

if (cant_figure_it_out)
BEGIN
post_specific_question_on_relevant_newsgroup("comp .lang.c")
answer =
post_specific_question_on_relevant_newsgroup("comp .lang.c")
assert answer == DO_YOUR_HOMEWORK
END IF
>>END PROGRAM

--
bruno desthuilliers
python -c "print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for
p in 'o****@xiludom.gro'.split('@')])"



--
bruno desthuilliers
python -c "print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for
p in 'o****@xiludom.gro'.split('@')])"
Jul 3 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Hung Jung Lu | last post by:
Hi, I have been looking into AOP (Aspect-Oriented Programming) for sometime, now. I frankly don't like the syntax of any of the approaches I have seen so far. I am kind playing around with some...
3
by: Ron Stephens | last post by:
I posted to my web site a fun little program called merlin.py today. Please keep in mind that I am a hobbyist and this is just a little hack, if you look at the code you will see that it is still...
8
by: bearophileHUGS | last post by:
The free wikipedia is adopting a standard pseudocode: http://en.wikipedia.org/wiki/Wikipedia_talk:Wikicode/Specification MShonle says something nice: I support the idea of wikicode. Basically I...
13
by: takashi | last post by:
Hi, I have a question. I am learning about how to use c++ language. I have attempted to make my own programs, using the knowledge that I have, but sometimes when I get stuck on writing a code, it...
22
by: edgrsprj | last post by:
PROPOSED EARTHQUAKE FORECASTING COMPUTER PROGRAM DEVELOPMENT EFFORT Posted July 11, 2005 My main earthquake forecasting Web page is: http://www.freewebz.com/eq-forecasting/Data.html ...
9
by: terry | last post by:
I am a programmer (cobol, peoplesoft, sqr, etc.) so I am familiar with programming logic, etc. but not very familiar with C. I need a C program in a study I'm doing. The program is fairly simple,...
9
by: Keith | last post by:
The bits get twiddled every now and then. Using gcc 3.2 and 3.4. To build: cc -o test test.c -lm ---------------- 8< test.c ------------------------ #include <stdio.h> #include <math.h> ...
2
by: Joah Senegal | last post by:
Hello all, I;m a beginner C++ and I;m trying to convert some pseudocode into C++. Its pseudo code of the peterson algorithm for N-processes. I almost converted the whole code. But the last...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.