#4 patch to make findalldevs() work under AIX 4.3

open
Wim Lewis
None
5
2004-04-21
2003-02-03
Martin McGreal
No

Most of the changes in this patch are to provide more
verbose error messages when a problem occurs in
findalldevs(). It's obviously a total hack (using tmpstr and
snprintf), but unfortunately SWIG doesn't accept variable
argument functions. Really there are only two parts to
this patch that are needed to make findalldevs() work
under AIX 4.3, they are commented appropriately.

Discussion

  • Martin McGreal
    Martin McGreal
    2003-02-03

    Logged In: YES
    user_id=703727

    Only in pylibpcap-0.4.new: pcap.pyc
    diff -Bbru pylibpcap-0.4.old/pcap_interface.c pylibpcap-
    0.4.new/pcap_interface.c
    --- pylibpcap-0.4.old/pcap_interface.c Fri Jun 14 00:20:42
    2002
    +++ pylibpcap-0.4.new/pcap_interface.c Sat Jan 25 23:49:27
    2003
    @@ -321,6 +321,8 @@
    PyObject *out, *addrlist, *addrlist2, *tmp;
    struct sockaddr_in *addr;
    int status, i;
    +#define TMPSTRLEN 256
    + char tmpstr[TMPSTRLEN];

    status = pcap_findalldevs(&if_head, ebuf);

    @@ -342,9 +344,16 @@

    /* addr */

    + /* AIX 4.3.3 gives us more information than we care
    about. */
    if (addr_current->addr) {
    - if (addr_current->addr->sa_family!=AF_INET)
    - throw_exception(-1,"unknown address family");
    + if (addr_current->addr->sa_family == AF_LINK)
    + continue;
    +
    + if (addr_current->addr->sa_family!=AF_INET) {
    + snprintf(tmpstr, TMPSTRLEN, "Interface %s has an
    unknown address type (%d).",
    + if_current->description, addr_current->addr-
    >sa_family);
    + throw_exception(-1, tmpstr);
    + }

    addr=(struct sockaddr_in *)(addr_current->addr);
    PyList_Append(addrlist2,\ @@ -357,8 +366,12 @@
    /* netmask */

    if (addr_current->netmask) {
    - if (addr_current->netmask->sa_family!=AF_INET)
    - throw_exception(-1,"unknown address family");
    + /* Under AIX 4.3.3 the netmask address is listed as
    AF_UNSPEC. */
    + if ((addr_current->netmask->sa_family!=AF_INET) &&
    (addr_current->netmask->sa_family!=AF_UN
    SPEC)) {
    + snprintf(tmpstr, TMPSTRLEN, "Interface %s has an
    unknown netmask address type (%d).",
    + if_current->description, addr_current->addr-
    >sa_family);
    + throw_exception(-1,tmpstr);
    + }

    addr=(struct sockaddr_in *)(addr_current->netmask);
    PyList_Append(addrlist2,\ @@ -371,8 +384,11 @@
    /* broadaddr */

    if (addr_current->broadaddr) {
    - if (addr_current->broadaddr->sa_family!=AF_INET)
    - throw_exception(-1,"unknown address family");
    + if (addr_current->broadaddr->sa_family!=AF_INET) {
    + snprintf(tmpstr, TMPSTRLEN, "Interface %s has an
    unknown broadcast address type (%d).",
    + if_current->description, addr_current->addr-
    >sa_family);
    + throw_exception(-1,tmpstr);
    + }

    addr=(struct sockaddr_in *)(addr_current->broadaddr);
    PyList_Append(addrlist2,\ @@ -385,8 +401,10 @@
    /* dstaddr */

    if (addr_current->dstaddr) {
    - if (addr_current->dstaddr->sa_family!=AF_INET)
    - throw_exception(-1,"unknown address family");
    + if (addr_current->dstaddr->sa_family!=AF_INET) {
    + snprintf(tmpstr, TMPSTRLEN, "Interface %s has an
    unknown destination address type (%d).",
    + if_current->description, addr_current->addr-
    >sa_family);
    + }

    addr=(struct sockaddr_in *)(addr_current->dstaddr);
    PyList_Append(addrlist2,\ diff -Bbru pylibpcap-0.4.old/setup.py pylibpcap-
    0.4.new/setup.py
    --- pylibpcap-0.4.old/setup.py Fri Jun 14 02:36:30 2002
    +++ pylibpcap-0.4.new/setup.py Sat Jan 25 22:55:27 2003
    @@ -98,6 +98,7 @@

    ["pcap.c","pcap_interface.c","exception.c","error.c"],
    include_dirs=["/usr/local/include"],
    extra_objects=[],
    + library_dirs=["/usr/local/lib"],
    libraries=["pcap",],
    )
    ],

     
  • Martin McGreal
    Martin McGreal
    2003-02-03

    Logged In: YES
    user_id=703727

    Only in pylibpcap-0.4.new: pcap.pyc
    diff -Bbru pylibpcap-0.4.old/pcap_interface.c pylibpcap-
    0.4.new/pcap_interface.c
    --- pylibpcap-0.4.old/pcap_interface.c Fri Jun 14 00:20:42
    2002
    +++ pylibpcap-0.4.new/pcap_interface.c Sat Jan 25 23:49:27
    2003
    @@ -321,6 +321,8 @@
    PyObject *out, *addrlist, *addrlist2, *tmp;
    struct sockaddr_in *addr;
    int status, i;
    +#define TMPSTRLEN 256
    + char tmpstr[TMPSTRLEN];

    status = pcap_findalldevs(&if_head, ebuf);

    @@ -342,9 +344,16 @@

    /* addr */

    + /* AIX 4.3.3 gives us more information than we care
    about. */
    if (addr_current->addr) {
    - if (addr_current->addr->sa_family!=AF_INET)
    - throw_exception(-1,"unknown address family");
    + if (addr_current->addr->sa_family == AF_LINK)
    + continue;
    +
    + if (addr_current->addr->sa_family!=AF_INET) {
    + snprintf(tmpstr, TMPSTRLEN, "Interface %s has an
    unknown address type (%d).",
    + if_current->description, addr_current->addr-
    >sa_family);
    + throw_exception(-1, tmpstr);
    + }

    addr=(struct sockaddr_in *)(addr_current->addr);
    PyList_Append(addrlist2,\ @@ -357,8 +366,12 @@
    /* netmask */

    if (addr_current->netmask) {
    - if (addr_current->netmask->sa_family!=AF_INET)
    - throw_exception(-1,"unknown address family");
    + /* Under AIX 4.3.3 the netmask address is listed as
    AF_UNSPEC. */
    + if ((addr_current->netmask->sa_family!=AF_INET) &&
    (addr_current->netmask->sa_family!=AF_UN
    SPEC)) {
    + snprintf(tmpstr, TMPSTRLEN, "Interface %s has an
    unknown netmask address type (%d).",
    + if_current->description, addr_current->addr-
    >sa_family);
    + throw_exception(-1,tmpstr);
    + }

    addr=(struct sockaddr_in *)(addr_current->netmask);
    PyList_Append(addrlist2,\ @@ -371,8 +384,11 @@
    /* broadaddr */

    if (addr_current->broadaddr) {
    - if (addr_current->broadaddr->sa_family!=AF_INET)
    - throw_exception(-1,"unknown address family");
    + if (addr_current->broadaddr->sa_family!=AF_INET) {
    + snprintf(tmpstr, TMPSTRLEN, "Interface %s has an
    unknown broadcast address type (%d).",
    + if_current->description, addr_current->addr-
    >sa_family);
    + throw_exception(-1,tmpstr);
    + }

    addr=(struct sockaddr_in *)(addr_current->broadaddr);
    PyList_Append(addrlist2,\ @@ -385,8 +401,10 @@
    /* dstaddr */

    if (addr_current->dstaddr) {
    - if (addr_current->dstaddr->sa_family!=AF_INET)
    - throw_exception(-1,"unknown address family");
    + if (addr_current->dstaddr->sa_family!=AF_INET) {
    + snprintf(tmpstr, TMPSTRLEN, "Interface %s has an
    unknown destination address type (%d).",
    + if_current->description, addr_current->addr-
    >sa_family);
    + }

    addr=(struct sockaddr_in *)(addr_current->dstaddr);
    PyList_Append(addrlist2,\ diff -Bbru pylibpcap-0.4.old/setup.py pylibpcap-
    0.4.new/setup.py
    --- pylibpcap-0.4.old/setup.py Fri Jun 14 02:36:30 2002
    +++ pylibpcap-0.4.new/setup.py Sat Jan 25 22:55:27 2003
    @@ -98,6 +98,7 @@

    ["pcap.c","pcap_interface.c","exception.c","error.c"],
    include_dirs=["/usr/local/include"],
    extra_objects=[],
    + library_dirs=["/usr/local/lib"],
    libraries=["pcap",],
    )
    ],

     
  • Martin McGreal
    Martin McGreal
    2003-02-03

    Logged In: YES
    user_id=703727

    Only in pylibpcap-0.4.new: pcap.pyc
    diff -Bbru pylibpcap-0.4.old/pcap_interface.c pylibpcap-
    0.4.new/pcap_interface.c
    --- pylibpcap-0.4.old/pcap_interface.c Fri Jun 14 00:20:42
    2002
    +++ pylibpcap-0.4.new/pcap_interface.c Sat Jan 25 23:49:27
    2003
    @@ -321,6 +321,8 @@
    PyObject *out, *addrlist, *addrlist2, *tmp;
    struct sockaddr_in *addr;
    int status, i;
    +#define TMPSTRLEN 256
    + char tmpstr[TMPSTRLEN];

    status = pcap_findalldevs(&if_head, ebuf);

    @@ -342,9 +344,16 @@

    /* addr */

    + /* AIX 4.3.3 gives us more information than we care
    about. */
    if (addr_current->addr) {
    - if (addr_current->addr->sa_family!=AF_INET)
    - throw_exception(-1,"unknown address family");
    + if (addr_current->addr->sa_family == AF_LINK)
    + continue;
    +
    + if (addr_current->addr->sa_family!=AF_INET) {
    + snprintf(tmpstr, TMPSTRLEN, "Interface %s has an
    unknown address type (%d).",
    + if_current->description, addr_current->addr-
    >sa_family);
    + throw_exception(-1, tmpstr);
    + }

    addr=(struct sockaddr_in *)(addr_current->addr);
    PyList_Append(addrlist2,\ @@ -357,8 +366,12 @@
    /* netmask */

    if (addr_current->netmask) {
    - if (addr_current->netmask->sa_family!=AF_INET)
    - throw_exception(-1,"unknown address family");
    + /* Under AIX 4.3.3 the netmask address is listed as
    AF_UNSPEC. */
    + if ((addr_current->netmask->sa_family!=AF_INET) &&
    (addr_current->netmask->sa_family!=AF_UN
    SPEC)) {
    + snprintf(tmpstr, TMPSTRLEN, "Interface %s has an
    unknown netmask address type (%d).",
    + if_current->description, addr_current->addr-
    >sa_family);
    + throw_exception(-1,tmpstr);
    + }

    addr=(struct sockaddr_in *)(addr_current->netmask);
    PyList_Append(addrlist2,\ @@ -371,8 +384,11 @@
    /* broadaddr */

    if (addr_current->broadaddr) {
    - if (addr_current->broadaddr->sa_family!=AF_INET)
    - throw_exception(-1,"unknown address family");
    + if (addr_current->broadaddr->sa_family!=AF_INET) {
    + snprintf(tmpstr, TMPSTRLEN, "Interface %s has an
    unknown broadcast address type (%d).",
    + if_current->description, addr_current->addr-
    >sa_family);
    + throw_exception(-1,tmpstr);
    + }

    addr=(struct sockaddr_in *)(addr_current->broadaddr);
    PyList_Append(addrlist2,\ @@ -385,8 +401,10 @@
    /* dstaddr */

    if (addr_current->dstaddr) {
    - if (addr_current->dstaddr->sa_family!=AF_INET)
    - throw_exception(-1,"unknown address family");
    + if (addr_current->dstaddr->sa_family!=AF_INET) {
    + snprintf(tmpstr, TMPSTRLEN, "Interface %s has an
    unknown destination address type (%d).",
    + if_current->description, addr_current->addr-
    >sa_family);
    + }

    addr=(struct sockaddr_in *)(addr_current->dstaddr);
    PyList_Append(addrlist2,\ diff -Bbru pylibpcap-0.4.old/setup.py pylibpcap-
    0.4.new/setup.py
    --- pylibpcap-0.4.old/setup.py Fri Jun 14 02:36:30 2002
    +++ pylibpcap-0.4.new/setup.py Sat Jan 25 22:55:27 2003
    @@ -98,6 +98,7 @@

    ["pcap.c","pcap_interface.c","exception.c","error.c"],
    include_dirs=["/usr/local/include"],
    extra_objects=[],
    + library_dirs=["/usr/local/lib"],
    libraries=["pcap",],
    )
    ],

     
  • Wim Lewis
    Wim Lewis
    2004-04-21

    • assigned_to: nobody --> wiml