This patch from Fabio Ferrari <fabio.ferrari@digitro.com.br> enables
"broadcast +" for deriving the broadcast address automagically.
This commit is contained in:
parent
d9d75555ba
commit
48dfc56b4a
26
ifconfig.c
26
ifconfig.c
@ -15,7 +15,7 @@
|
|||||||
* Foundation; either version 2 of the License, or (at
|
* Foundation; either version 2 of the License, or (at
|
||||||
* your option) any later version.
|
* your option) any later version.
|
||||||
*
|
*
|
||||||
* $Id: ifconfig.c,v 1.10 2001/03/26 16:26:16 mjn3 Exp $
|
* $Id: ifconfig.c,v 1.11 2001/07/07 05:19:52 andersen Exp $
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@ -110,6 +110,8 @@
|
|||||||
#define A_NETMASK 0x20 /* Set if netmask (check for multiple sets). */
|
#define A_NETMASK 0x20 /* Set if netmask (check for multiple sets). */
|
||||||
#define A_SET_AFTER 0x40 /* Set a flag at the end. */
|
#define A_SET_AFTER 0x40 /* Set a flag at the end. */
|
||||||
#define A_COLON_CHK 0x80 /* Is this needed? See below. */
|
#define A_COLON_CHK 0x80 /* Is this needed? See below. */
|
||||||
|
#define A_HOSTNAME 0x100 /* Set if it is ip addr. */
|
||||||
|
#define A_BROADCAST 0x200 /* Set if it is broadcast addr. */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* These defines are for dealing with the A_CAST_TYPE field.
|
* These defines are for dealing with the A_CAST_TYPE field.
|
||||||
@ -139,12 +141,12 @@
|
|||||||
#define ARG_IRQ (A_ARG_REQ | A_MAP_UCHAR)
|
#define ARG_IRQ (A_ARG_REQ | A_MAP_UCHAR)
|
||||||
#define ARG_DSTADDR (A_ARG_REQ | A_CAST_HOST_COPY_RESOLVE)
|
#define ARG_DSTADDR (A_ARG_REQ | A_CAST_HOST_COPY_RESOLVE)
|
||||||
#define ARG_NETMASK (A_ARG_REQ | A_CAST_HOST_COPY_RESOLVE | A_NETMASK)
|
#define ARG_NETMASK (A_ARG_REQ | A_CAST_HOST_COPY_RESOLVE | A_NETMASK)
|
||||||
#define ARG_BROADCAST (A_ARG_REQ | A_CAST_HOST_COPY_RESOLVE | A_SET_AFTER)
|
#define ARG_BROADCAST (A_ARG_REQ | A_CAST_HOST_COPY_RESOLVE | A_SET_AFTER | A_BROADCAST)
|
||||||
#define ARG_HW (A_ARG_REQ | A_CAST_HOST_COPY_IN_ETHER)
|
#define ARG_HW (A_ARG_REQ | A_CAST_HOST_COPY_IN_ETHER)
|
||||||
#define ARG_POINTOPOINT (A_CAST_HOST_COPY_RESOLVE | A_SET_AFTER)
|
#define ARG_POINTOPOINT (A_CAST_HOST_COPY_RESOLVE | A_SET_AFTER)
|
||||||
#define ARG_KEEPALIVE (A_ARG_REQ | A_CAST_CHAR_PTR)
|
#define ARG_KEEPALIVE (A_ARG_REQ | A_CAST_CHAR_PTR)
|
||||||
#define ARG_OUTFILL (A_ARG_REQ | A_CAST_CHAR_PTR)
|
#define ARG_OUTFILL (A_ARG_REQ | A_CAST_CHAR_PTR)
|
||||||
#define ARG_HOSTNAME (A_CAST_HOST_COPY_RESOLVE | A_SET_AFTER | A_COLON_CHK)
|
#define ARG_HOSTNAME (A_CAST_HOST_COPY_RESOLVE | A_SET_AFTER | A_COLON_CHK | A_HOSTNAME)
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -160,7 +162,7 @@ struct arg1opt {
|
|||||||
struct options {
|
struct options {
|
||||||
const char *name;
|
const char *name;
|
||||||
const unsigned char flags;
|
const unsigned char flags;
|
||||||
const unsigned char arg_flags;
|
const unsigned int arg_flags;
|
||||||
const unsigned short selector;
|
const unsigned short selector;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -246,6 +248,7 @@ int ifconfig_main(int argc, char **argv)
|
|||||||
{
|
{
|
||||||
struct ifreq ifr;
|
struct ifreq ifr;
|
||||||
struct sockaddr_in sai;
|
struct sockaddr_in sai;
|
||||||
|
struct sockaddr_in sai_hostname, sai_netmask;
|
||||||
#ifdef BB_FEATURE_IFCONFIG_HW
|
#ifdef BB_FEATURE_IFCONFIG_HW
|
||||||
struct sockaddr sa;
|
struct sockaddr sa;
|
||||||
#endif
|
#endif
|
||||||
@ -256,8 +259,8 @@ int ifconfig_main(int argc, char **argv)
|
|||||||
int selector;
|
int selector;
|
||||||
char *p;
|
char *p;
|
||||||
char host[128];
|
char host[128];
|
||||||
unsigned char mask;
|
unsigned int mask;
|
||||||
unsigned char did_flags;
|
unsigned int did_flags;
|
||||||
|
|
||||||
goterr = 0;
|
goterr = 0;
|
||||||
did_flags = 0;
|
did_flags = 0;
|
||||||
@ -331,7 +334,7 @@ int ifconfig_main(int argc, char **argv)
|
|||||||
}
|
}
|
||||||
} else { /* got an arg so process it */
|
} else { /* got an arg so process it */
|
||||||
HOSTNAME:
|
HOSTNAME:
|
||||||
did_flags |= (mask & A_NETMASK);
|
did_flags |= (mask & (A_NETMASK|A_HOSTNAME));
|
||||||
if (mask & A_CAST_HOST_COPY) {
|
if (mask & A_CAST_HOST_COPY) {
|
||||||
#ifdef BB_FEATURE_IFCONFIG_HW
|
#ifdef BB_FEATURE_IFCONFIG_HW
|
||||||
if (mask & A_CAST_RESOLVE) {
|
if (mask & A_CAST_RESOLVE) {
|
||||||
@ -342,11 +345,20 @@ int ifconfig_main(int argc, char **argv)
|
|||||||
if (!strcmp(host, "default")) {
|
if (!strcmp(host, "default")) {
|
||||||
/* Default is special, meaning 0.0.0.0. */
|
/* Default is special, meaning 0.0.0.0. */
|
||||||
sai.sin_addr.s_addr = INADDR_ANY;
|
sai.sin_addr.s_addr = INADDR_ANY;
|
||||||
|
} else if ((!strcmp(host, "+")) && (mask & A_BROADCAST) &&
|
||||||
|
(did_flags & (A_NETMASK|A_HOSTNAME))) {
|
||||||
|
/* + is special, meaning broadcast is derived. */
|
||||||
|
sai.sin_addr.s_addr = (~sai_netmask.sin_addr.s_addr) |
|
||||||
|
(sai_hostname.sin_addr.s_addr & sai_netmask.sin_addr.s_addr);
|
||||||
} else if (inet_aton(host, &sai.sin_addr) == 0) {
|
} else if (inet_aton(host, &sai.sin_addr) == 0) {
|
||||||
/* It's not a dotted quad. */
|
/* It's not a dotted quad. */
|
||||||
++goterr;
|
++goterr;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
if(mask & A_HOSTNAME)
|
||||||
|
sai_hostname = sai;
|
||||||
|
if(mask & A_NETMASK)
|
||||||
|
sai_netmask = sai;
|
||||||
p = (char *) &sai;
|
p = (char *) &sai;
|
||||||
#ifdef BB_FEATURE_IFCONFIG_HW
|
#ifdef BB_FEATURE_IFCONFIG_HW
|
||||||
} else { /* A_CAST_HOST_COPY_IN_ETHER */
|
} else { /* A_CAST_HOST_COPY_IN_ETHER */
|
||||||
|
@ -15,7 +15,7 @@
|
|||||||
* Foundation; either version 2 of the License, or (at
|
* Foundation; either version 2 of the License, or (at
|
||||||
* your option) any later version.
|
* your option) any later version.
|
||||||
*
|
*
|
||||||
* $Id: ifconfig.c,v 1.10 2001/03/26 16:26:16 mjn3 Exp $
|
* $Id: ifconfig.c,v 1.11 2001/07/07 05:19:52 andersen Exp $
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@ -110,6 +110,8 @@
|
|||||||
#define A_NETMASK 0x20 /* Set if netmask (check for multiple sets). */
|
#define A_NETMASK 0x20 /* Set if netmask (check for multiple sets). */
|
||||||
#define A_SET_AFTER 0x40 /* Set a flag at the end. */
|
#define A_SET_AFTER 0x40 /* Set a flag at the end. */
|
||||||
#define A_COLON_CHK 0x80 /* Is this needed? See below. */
|
#define A_COLON_CHK 0x80 /* Is this needed? See below. */
|
||||||
|
#define A_HOSTNAME 0x100 /* Set if it is ip addr. */
|
||||||
|
#define A_BROADCAST 0x200 /* Set if it is broadcast addr. */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* These defines are for dealing with the A_CAST_TYPE field.
|
* These defines are for dealing with the A_CAST_TYPE field.
|
||||||
@ -139,12 +141,12 @@
|
|||||||
#define ARG_IRQ (A_ARG_REQ | A_MAP_UCHAR)
|
#define ARG_IRQ (A_ARG_REQ | A_MAP_UCHAR)
|
||||||
#define ARG_DSTADDR (A_ARG_REQ | A_CAST_HOST_COPY_RESOLVE)
|
#define ARG_DSTADDR (A_ARG_REQ | A_CAST_HOST_COPY_RESOLVE)
|
||||||
#define ARG_NETMASK (A_ARG_REQ | A_CAST_HOST_COPY_RESOLVE | A_NETMASK)
|
#define ARG_NETMASK (A_ARG_REQ | A_CAST_HOST_COPY_RESOLVE | A_NETMASK)
|
||||||
#define ARG_BROADCAST (A_ARG_REQ | A_CAST_HOST_COPY_RESOLVE | A_SET_AFTER)
|
#define ARG_BROADCAST (A_ARG_REQ | A_CAST_HOST_COPY_RESOLVE | A_SET_AFTER | A_BROADCAST)
|
||||||
#define ARG_HW (A_ARG_REQ | A_CAST_HOST_COPY_IN_ETHER)
|
#define ARG_HW (A_ARG_REQ | A_CAST_HOST_COPY_IN_ETHER)
|
||||||
#define ARG_POINTOPOINT (A_CAST_HOST_COPY_RESOLVE | A_SET_AFTER)
|
#define ARG_POINTOPOINT (A_CAST_HOST_COPY_RESOLVE | A_SET_AFTER)
|
||||||
#define ARG_KEEPALIVE (A_ARG_REQ | A_CAST_CHAR_PTR)
|
#define ARG_KEEPALIVE (A_ARG_REQ | A_CAST_CHAR_PTR)
|
||||||
#define ARG_OUTFILL (A_ARG_REQ | A_CAST_CHAR_PTR)
|
#define ARG_OUTFILL (A_ARG_REQ | A_CAST_CHAR_PTR)
|
||||||
#define ARG_HOSTNAME (A_CAST_HOST_COPY_RESOLVE | A_SET_AFTER | A_COLON_CHK)
|
#define ARG_HOSTNAME (A_CAST_HOST_COPY_RESOLVE | A_SET_AFTER | A_COLON_CHK | A_HOSTNAME)
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -160,7 +162,7 @@ struct arg1opt {
|
|||||||
struct options {
|
struct options {
|
||||||
const char *name;
|
const char *name;
|
||||||
const unsigned char flags;
|
const unsigned char flags;
|
||||||
const unsigned char arg_flags;
|
const unsigned int arg_flags;
|
||||||
const unsigned short selector;
|
const unsigned short selector;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -246,6 +248,7 @@ int ifconfig_main(int argc, char **argv)
|
|||||||
{
|
{
|
||||||
struct ifreq ifr;
|
struct ifreq ifr;
|
||||||
struct sockaddr_in sai;
|
struct sockaddr_in sai;
|
||||||
|
struct sockaddr_in sai_hostname, sai_netmask;
|
||||||
#ifdef BB_FEATURE_IFCONFIG_HW
|
#ifdef BB_FEATURE_IFCONFIG_HW
|
||||||
struct sockaddr sa;
|
struct sockaddr sa;
|
||||||
#endif
|
#endif
|
||||||
@ -256,8 +259,8 @@ int ifconfig_main(int argc, char **argv)
|
|||||||
int selector;
|
int selector;
|
||||||
char *p;
|
char *p;
|
||||||
char host[128];
|
char host[128];
|
||||||
unsigned char mask;
|
unsigned int mask;
|
||||||
unsigned char did_flags;
|
unsigned int did_flags;
|
||||||
|
|
||||||
goterr = 0;
|
goterr = 0;
|
||||||
did_flags = 0;
|
did_flags = 0;
|
||||||
@ -331,7 +334,7 @@ int ifconfig_main(int argc, char **argv)
|
|||||||
}
|
}
|
||||||
} else { /* got an arg so process it */
|
} else { /* got an arg so process it */
|
||||||
HOSTNAME:
|
HOSTNAME:
|
||||||
did_flags |= (mask & A_NETMASK);
|
did_flags |= (mask & (A_NETMASK|A_HOSTNAME));
|
||||||
if (mask & A_CAST_HOST_COPY) {
|
if (mask & A_CAST_HOST_COPY) {
|
||||||
#ifdef BB_FEATURE_IFCONFIG_HW
|
#ifdef BB_FEATURE_IFCONFIG_HW
|
||||||
if (mask & A_CAST_RESOLVE) {
|
if (mask & A_CAST_RESOLVE) {
|
||||||
@ -342,11 +345,20 @@ int ifconfig_main(int argc, char **argv)
|
|||||||
if (!strcmp(host, "default")) {
|
if (!strcmp(host, "default")) {
|
||||||
/* Default is special, meaning 0.0.0.0. */
|
/* Default is special, meaning 0.0.0.0. */
|
||||||
sai.sin_addr.s_addr = INADDR_ANY;
|
sai.sin_addr.s_addr = INADDR_ANY;
|
||||||
|
} else if ((!strcmp(host, "+")) && (mask & A_BROADCAST) &&
|
||||||
|
(did_flags & (A_NETMASK|A_HOSTNAME))) {
|
||||||
|
/* + is special, meaning broadcast is derived. */
|
||||||
|
sai.sin_addr.s_addr = (~sai_netmask.sin_addr.s_addr) |
|
||||||
|
(sai_hostname.sin_addr.s_addr & sai_netmask.sin_addr.s_addr);
|
||||||
} else if (inet_aton(host, &sai.sin_addr) == 0) {
|
} else if (inet_aton(host, &sai.sin_addr) == 0) {
|
||||||
/* It's not a dotted quad. */
|
/* It's not a dotted quad. */
|
||||||
++goterr;
|
++goterr;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
if(mask & A_HOSTNAME)
|
||||||
|
sai_hostname = sai;
|
||||||
|
if(mask & A_NETMASK)
|
||||||
|
sai_netmask = sai;
|
||||||
p = (char *) &sai;
|
p = (char *) &sai;
|
||||||
#ifdef BB_FEATURE_IFCONFIG_HW
|
#ifdef BB_FEATURE_IFCONFIG_HW
|
||||||
} else { /* A_CAST_HOST_COPY_IN_ETHER */
|
} else { /* A_CAST_HOST_COPY_IN_ETHER */
|
||||||
|
Loading…
x
Reference in New Issue
Block a user