From: Grant Edwards <grant.b.edwards@gmail.com>
To: ecos-discuss@sources.redhat.com
Subject: [ECOS] Question about unused 'netmask' var in bootp_support.c
Date: Fri, 02 Mar 2012 17:53:00 -0000 [thread overview]
Message-ID: <jir1ei$avu$1@dough.gmane.org> (raw)
I'm working on clearing up some compiler warnings, and one of them is
a warning that the variable 'netmask' is set but never referenced in
bootp_support.c init_net(). The variable in question (netmask) is
declared at line 452, set at line 484, and never referenced (not even
conditionally).
Can I just remove the declaration of netmask at line 452, and remove
line 484 entirely? Or is this an actual bug because netmask is
supposed to be used for something?
[net/common/current/src/bootp_support.c]
443 // [Re]initialize the network interface with the info passed from BOOTP
444 cyg_bool_t
445 init_net(const char *intf, struct bootp *bp)
446 {
447 struct sockaddr_in *addrp;
448 struct ifreq ifr;
449 int s=-1;
450 int one = 1;
451 struct ecos_rtentry route;
452 struct in_addr netmask, gateway;
453 unsigned int length;
454 int retcode = false;
455
456 s = socket(AF_INET, SOCK_DGRAM, 0);
457 if (s < 0) {
458 perror("socket");
459 goto out;
460 }
461
462 if (setsockopt(s, SOL_SOCKET, SO_BROADCAST, &one, sizeof(one))) {
463 perror("setsockopt");
464 goto out;
465 }
466
467 addrp = (struct sockaddr_in *) &ifr.ifr_addr;
468 memset(addrp, 0, sizeof(*addrp));
469 addrp->sin_family = AF_INET;
470 addrp->sin_len = sizeof(*addrp);
471 addrp->sin_port = 0;
472 addrp->sin_addr = bp->bp_yiaddr; // The address BOOTP gave us
473
474 // Must do this temporarily with default route and netmask so that
475 // [sub]netmask can be set.
476 strcpy(ifr.ifr_name, intf);
477 if (ioctl(s, SIOCSIFADDR, &ifr)) {
478 perror("SIOCIFADDR");
479 goto out;
480 }
481
482 length = sizeof(addrp->sin_addr);
483 if (get_bootp_option(bp, TAG_SUBNET_MASK, &addrp->sin_addr,&length)) {
484 netmask = addrp->sin_addr;
485 if (ioctl(s, SIOCSIFNETMASK, &ifr)) {
486 perror("SIOCSIFNETMASK");
487 goto out;
488 }
489 // Must do this again so that [sub]netmask (and so default route)
490 // is taken notice of.
491 addrp->sin_addr = bp->bp_yiaddr; // The address BOOTP gave us
492 if (ioctl(s, SIOCSIFADDR, &ifr)) {
493 perror("SIOCIFADDR 2");
494 goto out;
495 }
496 }
497
498 length = sizeof(addrp->sin_addr);
499 if (get_bootp_option(bp, TAG_IP_BROADCAST, &addrp->sin_addr,&length)) {
500 if (ioctl(s, SIOCSIFBRDADDR, &ifr)) {
501 perror("SIOCSIFBRDADDR");
502 goto out;
503 }
504 // Do not re-set the IFADDR after this; doing *that* resets the
505 // BRDADDR to the default!
506 }
507
508 ifr.ifr_flags = IFF_UP | IFF_BROADCAST | IFF_RUNNING;
509 if (ioctl(s, SIOCSIFFLAGS, &ifr)) {
510 perror("SIOCSIFFLAGS");
511 goto out;
512 }
513
514 // Set up routing
515 length = sizeof(addrp->sin_addr);
516 if (get_bootp_option(bp, TAG_GATEWAY, &gateway,&length)) {
517 // ...and it's a nonzero address...
518 if ( 0 != gateway.s_addr ) {
519 memset(&route, 0, sizeof(route));
520 addrp->sin_family = AF_INET;
521 addrp->sin_port = 0;
522 addrp->sin_len = sizeof(*addrp);
523 addrp->sin_addr.s_addr = 0; // Use 0,0,GATEWAY for the default route
524 memcpy(&route.rt_dst, addrp, sizeof(*addrp));
525 addrp->sin_addr.s_addr = 0;
526 memcpy(&route.rt_genmask, addrp, sizeof(*addrp));
527 addrp->sin_addr = gateway;
528 memcpy(&route.rt_gateway, addrp, sizeof(*addrp));
529
530 route.rt_dev = ifr.ifr_name;
531 route.rt_flags = RTF_UP|RTF_GATEWAY;
532 route.rt_metric = 0;
533
534 if (ioctl(s, SIOCADDRT, &route)) {
535 diag_printf("Route - dst: %s",
536 inet_ntoa(((struct sockaddr_in *)&route.rt_dst)->sin_addr));
537 diag_printf(", mask: %s",
538 inet_ntoa(((struct sockaddr_in *)&route.rt_genmask)->sin_addr));
539 diag_printf(", gateway: %s\n",
540 inet_ntoa(((struct sockaddr_in *)&route.rt_gateway)->sin_addr));
541 if (errno != EEXIST) {
542 perror("SIOCADDRT 3");
543 goto out;
544 }
545 }
546 }
547 }
548 retcode = true;
549
550 #ifdef CYGINT_ISO_DNS
551 {
552 #define MAX_IP_ADDR_LEN 16
553 char buf[BP_MAX_OPTION_LEN+1];
554 memset(buf,0,sizeof(buf));
555 length = sizeof(buf);
556 if (get_bootp_option(bp, TAG_DOMAIN_NAME, buf, &length)) {
557 setdomainname(buf, length);
558 }
559 length = sizeof(buf);
560 if (get_bootp_option(bp, TAG_DOMAIN_SERVER, buf, &length)) {
561 cyg_dns_res_init((struct in_addr *)buf);
562 }
563 }
564 #endif
565
566 #ifdef CYGNUM_NET_SNTP_UNICAST_MAXDHCP
567 {
568 struct in_addr dhcp_addrs[CYGNUM_NET_SNTP_UNICAST_MAXDHCP];
569
570 /* Removed any previously registered addresses */
571 cyg_sntp_set_servers(NULL, 0);
572
573 /* See if we received any NTP servers from DHCP */
574 length = sizeof(dhcp_addrs);
575 if (get_bootp_option(bp, TAG_NTP_SERVER, &dhcp_addrs[0], &length))
576 {
577 static struct sockaddr ntp_servers[CYGNUM_NET_SNTP_UNICAST_MAXDHCP];
578 struct servent *service;
579 cyg_uint32 num;
580
581 /* See how many addresses we got. The length should always
582 * be a multiple of 4, but cut off any extra bytes and
583 * use what we got.
584 */
585 length /= sizeof(struct in_addr);
586
587 /* Fill out a sockaddr array for the NTP client */
588 service = getservbyname("ntp", "udp");
589 CYG_CHECK_DATA_PTR(service, "NTP service not found.");
590 memset(&ntp_servers[0], 0, sizeof(ntp_servers));
591 for (num = 0; num < length; num++)
592 {
593 struct sockaddr_in *saddr = (struct sockaddr_in *)&ntp_servers[num];
594
595 saddr->sin_len = sizeof(*saddr);
596 saddr->sin_family = AF_INET;
597 saddr->sin_port = service->s_port; /* Already network-endian */
598 saddr->sin_addr = dhcp_addrs[num]; /* Already network-endian */
599 }
600
601 /* Configure the client with the array */
602 cyg_sntp_set_servers(&ntp_servers[0], num);
603 }
604 }
605 #endif /* CYGNUM_NET_SNTP_UNICAST_MAXDHCP */
606 out:
607 if (s != -1)
608 close(s);
609 return retcode;
610 }
--
Before posting, please read the FAQ: http://ecos.sourceware.org/fom/ecos
and search the list archive: http://ecos.sourceware.org/ml/ecos-discuss
next reply other threads:[~2012-03-02 17:53 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-03-02 17:53 Grant Edwards [this message]
2012-03-08 8:39 ` Lange, Bert
2012-03-08 15:03 ` [ECOS] " Grant Edwards
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='jir1ei$avu$1@dough.gmane.org' \
--to=grant.b.edwards@gmail.com \
--cc=ecos-discuss@sources.redhat.com \
/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
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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 read-only IMAP folder(s) and NNTP newsgroup(s).