ifaddrs.h header check and increase backend version number

merge-requests/1/head
Nicolas Martin 2008-10-18 22:26:57 +00:00
rodzic 5633288e36
commit f573865c33
7 zmienionych plików z 129 dodań i 93 usunięć

Wyświetl plik

@ -108,8 +108,8 @@ typedef u_int32_t uint32_t;
/** \name Version of the driver */
/**@{*/
#define PIXMA_VERSION_MAJOR 0
#define PIXMA_VERSION_MINOR 14
#define PIXMA_VERSION_BUILD 5
#define PIXMA_VERSION_MINOR 15
#define PIXMA_VERSION_BUILD 0
/**@}*/
/** \name Error codes */

Wyświetl plik

@ -45,29 +45,48 @@
/*
* Standard types etc
*/
#ifdef HAVE_STDLIB_H
#include <stdlib.h>
#endif
#ifdef HAVE_STRING_H
#include <string.h>
#endif
#include <unistd.h>
#include <stdio.h>
#include <stdint.h>
#include <sys/types.h>
#include <sys/timeb.h>
#ifdef HAVE_STDINT_H
/* #include <stdint.h> */
#endif
#ifdef HAVE_SYS_TYPES_H
/* #include <sys/types.h> */
#endif
#ifdef HAVE_SYS_TIME_H
/* #include <sys/timeb.h> */
#endif
/*
* networking stuff
*/
#include <sys/socket.h>
#include <netinet/in.h>
#include <netinet/tcp.h>
#include <arpa/inet.h>
#include <netdb.h>
#ifdef HAVE_SYS_SOCKET_H
/* #include <sys/socket.h> */
#endif
#ifdef HAVE_NETINET_IN_H
/* #include <netinet/in.h> */
#endif
#include <netinet/tcp.h>
#include <arpa/inet.h>
#include <netdb.h>
#include <net/if.h>
#ifdef HAVE_IFADDRS_H
#include <ifaddrs.h>
#include <sys/select.h>
#endif
#ifdef HAVE_SYS_SELSECT_H
// #include <sys/select.h>
#endif
#include <errno.h>
#include <fcntl.h>
#ifdef HAVE_FCNTL_H
#include <fcntl.h>
#endif
#include "pixma_bjnp_private.h"
#include "pixma_bjnp.h"
#include "pixma_rename.h"
@ -524,7 +543,7 @@ parse_scanner_address (char *resp_buf, char *address, char *serial)
}
int
bjnp_send_broadcast (struct ifaddrs *interface, struct BJNP_command cmd,
bjnp_send_broadcast (struct in_addr broadcast_addr, struct BJNP_command cmd,
int size)
{
/*
@ -532,37 +551,10 @@ bjnp_send_broadcast (struct ifaddrs *interface, struct BJNP_command cmd,
*/
struct sockaddr_in sendaddr;
struct sockaddr_in broadaddr;
int sockfd;
int broadcast = 1;
int numbytes;
/* check first if interface is IPv4 capable, if not, skip it */
if (interface->ifa_addr->sa_family != AF_INET)
{
/* not an IPv4 address */
PDBG (pixma_dbg (LOG_DEBUG, "%s is not IPv4 capable, skipping...\n",
interface->ifa_name));
return -1;
}
memcpy (&sendaddr, interface->ifa_addr, sizeof (struct sockaddr));
if (sendaddr.sin_addr.s_addr == htonl (INADDR_LOOPBACK))
{
/* skip loopback interface */
PDBG (pixma_dbg (LOG_DEBUG, "%s has loopback address, skipping...\n",
interface->ifa_name));
return -1;
}
PDBG (pixma_dbg (LOG_INFO, "%s is IPv4 capable, sending broadcast..\n",
interface->ifa_name));
if ((sockfd = socket (PF_INET, SOCK_DGRAM, IPPROTO_UDP)) == -1)
{
PDBG (pixma_dbg
@ -585,6 +577,7 @@ bjnp_send_broadcast (struct ifaddrs *interface, struct BJNP_command cmd,
/* Bind to local address, let OS select local address and port */
sendaddr.sin_family = AF_INET;
sendaddr.sin_port = htons (0);
sendaddr.sin_addr.s_addr = htonl (INADDR_ANY);
memset (sendaddr.sin_zero, '\0', sizeof sendaddr.sin_zero);
@ -601,13 +594,11 @@ bjnp_send_broadcast (struct ifaddrs *interface, struct BJNP_command cmd,
/* set address to send packet to */
memcpy (&broadaddr, interface->ifa_broadaddr, sizeof (struct sockaddr));
sendaddr.sin_family = AF_INET;
sendaddr.sin_port = htons (BJNP_PORT_SCAN);
/* usebroadcast address of interface */
sendaddr.sin_addr.s_addr = broadaddr.sin_addr.s_addr;
sendaddr.sin_addr = broadcast_addr;
memset (sendaddr.sin_zero, '\0', sizeof sendaddr.sin_zero);
@ -813,8 +804,8 @@ bjnp_write (int devno, const SANE_Byte * buf, size_t count)
sizeof (struct BJNP_command) + count));
if ((sent_bytes =
write (device[devno].fd, &bjnp_buf,
sizeof (struct BJNP_command) + count)) <
send (device[devno].fd, &bjnp_buf,
sizeof (struct BJNP_command) + count, 0)) <
(ssize_t) (sizeof (struct BJNP_command) + count))
{
/* return result from write */
@ -859,7 +850,7 @@ bjnp_send_read_request (int devno)
sizeof (struct BJNP_command));
if ((sent_bytes =
write (device[devno].fd, &bjnp_buf, sizeof (struct BJNP_command))) < 0)
send (device[devno].fd, &bjnp_buf, sizeof (struct BJNP_command), 0)) < 0)
{
/* return result from write */
terrno = errno;
@ -917,8 +908,8 @@ bjnp_recv_header (int devno)
/* get response header */
if ((recv_bytes =
read (fd, (char *) &resp_buf,
sizeof (struct BJNP_command))) != sizeof (struct BJNP_command))
recv (fd, (char *) &resp_buf,
sizeof (struct BJNP_command), 0)) != sizeof (struct BJNP_command))
{
terrno = errno;
PDBG (pixma_dbg (LOG_CRIT,
@ -990,7 +981,7 @@ bjnp_recv_data (int devno, SANE_Byte * buffer, size_t * len)
return SANE_STATUS_IO_ERROR;
}
if ((recv_bytes = read (fd, buffer, *len)) < 0)
if ((recv_bytes = recv (fd, buffer, *len, 0)) < 0)
{
terrno = errno;
PDBG (pixma_dbg (LOG_CRIT,
@ -1142,8 +1133,6 @@ sanei_bjnp_find_devices (SANE_Status (*attach_bjnp)
struct BJNP_command cmd;
int num_scanners = 0;
char resp_buf[2048];
struct ifaddrs *interfaces;
struct ifaddrs *interface;
int socket_fd[BJNP_SOCK_MAX];
int no_sockets;
int i;
@ -1158,6 +1147,12 @@ sanei_bjnp_find_devices (SANE_Status (*attach_bjnp)
int result;
int dev_no;
char serial[13];
#ifdef HAVE_IFADDRS_H
struct ifaddrs *interfaces;
struct ifaddrs *interface;
#else
struct in_addr broadcast;
#endif
PDBG (pixma_dbg (LOG_INFO, "sanei_bjnp_find_devices:\n"));
@ -1166,32 +1161,70 @@ sanei_bjnp_find_devices (SANE_Status (*attach_bjnp)
* Returns: number of scanners found
*/
FD_ZERO (&fdset);
set_cmd (-1, &cmd, CMD_UDP_DISCOVER, 0);
#ifdef HAVE_IFADDRS_H
getifaddrs (&interfaces);
interface = interfaces;
FD_ZERO (&fdset);
set_cmd (-1, &cmd, CMD_UDP_DISCOVER, 0);
for (no_sockets = 0; (no_sockets < BJNP_SOCK_MAX) && (interface != NULL);)
{
/* send broadcast packet to each suitable interface */
if ((socket_fd[no_sockets] =
bjnp_send_broadcast (interface, cmd, sizeof (cmd))) != -1)
{
if (socket_fd[no_sockets] > last_socketfd)
{
/* track highest used socket for use in select */
last_socketfd = socket_fd[no_sockets];
}
FD_SET (socket_fd[no_sockets], &fdset);
no_sockets++;
}
if ((interface->ifa_addr->sa_family != AF_INET) ||
(((struct sockaddr_in *)interface->ifa_addr)->sin_addr.s_addr == htonl (INADDR_LOOPBACK)))
{
/* not an IPv4 address */
PDBG (pixma_dbg (LOG_DEBUG, "%s is not a valid IPv4 interface, skipping...\n",
interface->ifa_name));
}
else
{
PDBG (pixma_dbg (LOG_INFO, "%s is IPv4 capable, sending broadcast..\n",
interface->ifa_name));
if ((socket_fd[no_sockets] =
bjnp_send_broadcast (((struct sockaddr_in *) interface->ifa_broadaddr)->sin_addr,
cmd, sizeof (cmd))) != -1)
{
if (socket_fd[no_sockets] > last_socketfd)
{
/* track highest used socket for use in select */
last_socketfd = socket_fd[no_sockets];
}
FD_SET (socket_fd[no_sockets], &fdset);
no_sockets++;
}
}
interface = interface->ifa_next;
}
freeifaddrs (interfaces);
#else
/* we have no easy way to find interfaces with their broadcast addresses, use global broadcast */
no_sockets = 0;
broadcast.s_addr = INADDR_BROADCAST;
if ((socket_fd[no_sockets] =
bjnp_send_broadcast (broadcast,
cmd, sizeof (cmd))) != -1)
{
if (socket_fd[no_sockets] > last_socketfd)
{
/* track highest used socket for use in select */
last_socketfd = socket_fd[no_sockets];
}
FD_SET (socket_fd[no_sockets], &fdset);
no_sockets++;
}
#endif
/* wait for up to 1 second for a UDP response */
timeout.tv_sec = 1;

Wyświetl plik

@ -53,7 +53,9 @@
#include "../include/sane/sane.h"
#include "pixma.h"
#ifdef HAVE_STDLIB_H
#include <stdlib.h> /* for size_t */
#endif
/** Initialize sanei_bjnp.
*

Wyświetl plik

@ -226,7 +226,7 @@ int udp_command (const int dev_no, char *command, int cmd_len, char *response,
int resp_len);
int get_scanner_id (const int dev_no, char *model, char *IEEE1284_id);
void parse_scanner_address (char *resp_buf, char *name, char *serial);
int bjnp_send_broadcast (struct ifaddrs *interface, struct BJNP_command cmd,
int bjnp_send_broadcast (struct in_addr broadcast_addr, struct BJNP_command cmd,
int size);
int split_uri (const char *devname, char *method, char *hostname, int *port,
char *args);

49
configure vendored
Wyświetl plik

@ -8674,6 +8674,7 @@ fi
for ac_header in fcntl.h unistd.h libc.h sys/dsreq.h sys/select.h \
@ -8687,7 +8688,7 @@ for ac_header in fcntl.h unistd.h libc.h sys/dsreq.h sys/select.h \
IOKit/cdb/IOSCSILib.h IOKit/scsi/SCSICommandOperationCodes.h \
IOKit/scsi-commands/SCSICommandOperationCodes.h \
windows.h be/kernel/OS.h be/drivers/USB_scanner.h limits.h sys/ioctl.h asm/types.h\
netinet/in.h tiffio.h
netinet/in.h tiffio.h ifaddrs.h
do
as_ac_Header=`echo "ac_cv_header_$ac_header" | $as_tr_sh`
if { as_var=$as_ac_Header; eval "test \"\${$as_var+set}\" = set"; }; then
@ -12644,7 +12645,7 @@ ia64-*-hpux*)
;;
*-*-irix6*)
# Find out which ABI we are using.
echo '#line 12647 "configure"' > conftest.$ac_ext
echo '#line 12648 "configure"' > conftest.$ac_ext
if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5
(eval $ac_compile) 2>&5
ac_status=$?
@ -15087,11 +15088,11 @@ else
-e 's:.*FLAGS}\{0,1\} :&$lt_compiler_flag :; t' \
-e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \
-e 's:$: $lt_compiler_flag:'`
(eval echo "\"\$as_me:15090: $lt_compile\"" >&5)
(eval echo "\"\$as_me:15091: $lt_compile\"" >&5)
(eval "$lt_compile" 2>conftest.err)
ac_status=$?
cat conftest.err >&5
echo "$as_me:15094: \$? = $ac_status" >&5
echo "$as_me:15095: \$? = $ac_status" >&5
if (exit $ac_status) && test -s "$ac_outfile"; then
# The compiler can only warn and ignore the option if not recognized
# So say no if there are warnings other than the usual output.
@ -15355,11 +15356,11 @@ else
-e 's:.*FLAGS}\{0,1\} :&$lt_compiler_flag :; t' \
-e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \
-e 's:$: $lt_compiler_flag:'`
(eval echo "\"\$as_me:15358: $lt_compile\"" >&5)
(eval echo "\"\$as_me:15359: $lt_compile\"" >&5)
(eval "$lt_compile" 2>conftest.err)
ac_status=$?
cat conftest.err >&5
echo "$as_me:15362: \$? = $ac_status" >&5
echo "$as_me:15363: \$? = $ac_status" >&5
if (exit $ac_status) && test -s "$ac_outfile"; then
# The compiler can only warn and ignore the option if not recognized
# So say no if there are warnings other than the usual output.
@ -15459,11 +15460,11 @@ else
-e 's:.*FLAGS}\{0,1\} :&$lt_compiler_flag :; t' \
-e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \
-e 's:$: $lt_compiler_flag:'`
(eval echo "\"\$as_me:15462: $lt_compile\"" >&5)
(eval echo "\"\$as_me:15463: $lt_compile\"" >&5)
(eval "$lt_compile" 2>out/conftest.err)
ac_status=$?
cat out/conftest.err >&5
echo "$as_me:15466: \$? = $ac_status" >&5
echo "$as_me:15467: \$? = $ac_status" >&5
if (exit $ac_status) && test -s out/conftest2.$ac_objext
then
# The compiler can only warn and ignore the option if not recognized
@ -17767,7 +17768,7 @@ else
lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
lt_status=$lt_dlunknown
cat > conftest.$ac_ext <<EOF
#line 17770 "configure"
#line 17771 "configure"
#include "confdefs.h"
#if HAVE_DLFCN_H
@ -17867,7 +17868,7 @@ else
lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
lt_status=$lt_dlunknown
cat > conftest.$ac_ext <<EOF
#line 17870 "configure"
#line 17871 "configure"
#include "confdefs.h"
#if HAVE_DLFCN_H
@ -20207,11 +20208,11 @@ else
-e 's:.*FLAGS}\{0,1\} :&$lt_compiler_flag :; t' \
-e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \
-e 's:$: $lt_compiler_flag:'`
(eval echo "\"\$as_me:20210: $lt_compile\"" >&5)
(eval echo "\"\$as_me:20211: $lt_compile\"" >&5)
(eval "$lt_compile" 2>conftest.err)
ac_status=$?
cat conftest.err >&5
echo "$as_me:20214: \$? = $ac_status" >&5
echo "$as_me:20215: \$? = $ac_status" >&5
if (exit $ac_status) && test -s "$ac_outfile"; then
# The compiler can only warn and ignore the option if not recognized
# So say no if there are warnings other than the usual output.
@ -20311,11 +20312,11 @@ else
-e 's:.*FLAGS}\{0,1\} :&$lt_compiler_flag :; t' \
-e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \
-e 's:$: $lt_compiler_flag:'`
(eval echo "\"\$as_me:20314: $lt_compile\"" >&5)
(eval echo "\"\$as_me:20315: $lt_compile\"" >&5)
(eval "$lt_compile" 2>out/conftest.err)
ac_status=$?
cat out/conftest.err >&5
echo "$as_me:20318: \$? = $ac_status" >&5
echo "$as_me:20319: \$? = $ac_status" >&5
if (exit $ac_status) && test -s out/conftest2.$ac_objext
then
# The compiler can only warn and ignore the option if not recognized
@ -21881,11 +21882,11 @@ else
-e 's:.*FLAGS}\{0,1\} :&$lt_compiler_flag :; t' \
-e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \
-e 's:$: $lt_compiler_flag:'`
(eval echo "\"\$as_me:21884: $lt_compile\"" >&5)
(eval echo "\"\$as_me:21885: $lt_compile\"" >&5)
(eval "$lt_compile" 2>conftest.err)
ac_status=$?
cat conftest.err >&5
echo "$as_me:21888: \$? = $ac_status" >&5
echo "$as_me:21889: \$? = $ac_status" >&5
if (exit $ac_status) && test -s "$ac_outfile"; then
# The compiler can only warn and ignore the option if not recognized
# So say no if there are warnings other than the usual output.
@ -21985,11 +21986,11 @@ else
-e 's:.*FLAGS}\{0,1\} :&$lt_compiler_flag :; t' \
-e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \
-e 's:$: $lt_compiler_flag:'`
(eval echo "\"\$as_me:21988: $lt_compile\"" >&5)
(eval echo "\"\$as_me:21989: $lt_compile\"" >&5)
(eval "$lt_compile" 2>out/conftest.err)
ac_status=$?
cat out/conftest.err >&5
echo "$as_me:21992: \$? = $ac_status" >&5
echo "$as_me:21993: \$? = $ac_status" >&5
if (exit $ac_status) && test -s out/conftest2.$ac_objext
then
# The compiler can only warn and ignore the option if not recognized
@ -24187,11 +24188,11 @@ else
-e 's:.*FLAGS}\{0,1\} :&$lt_compiler_flag :; t' \
-e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \
-e 's:$: $lt_compiler_flag:'`
(eval echo "\"\$as_me:24190: $lt_compile\"" >&5)
(eval echo "\"\$as_me:24191: $lt_compile\"" >&5)
(eval "$lt_compile" 2>conftest.err)
ac_status=$?
cat conftest.err >&5
echo "$as_me:24194: \$? = $ac_status" >&5
echo "$as_me:24195: \$? = $ac_status" >&5
if (exit $ac_status) && test -s "$ac_outfile"; then
# The compiler can only warn and ignore the option if not recognized
# So say no if there are warnings other than the usual output.
@ -24455,11 +24456,11 @@ else
-e 's:.*FLAGS}\{0,1\} :&$lt_compiler_flag :; t' \
-e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \
-e 's:$: $lt_compiler_flag:'`
(eval echo "\"\$as_me:24458: $lt_compile\"" >&5)
(eval echo "\"\$as_me:24459: $lt_compile\"" >&5)
(eval "$lt_compile" 2>conftest.err)
ac_status=$?
cat conftest.err >&5
echo "$as_me:24462: \$? = $ac_status" >&5
echo "$as_me:24463: \$? = $ac_status" >&5
if (exit $ac_status) && test -s "$ac_outfile"; then
# The compiler can only warn and ignore the option if not recognized
# So say no if there are warnings other than the usual output.
@ -24559,11 +24560,11 @@ else
-e 's:.*FLAGS}\{0,1\} :&$lt_compiler_flag :; t' \
-e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \
-e 's:$: $lt_compiler_flag:'`
(eval echo "\"\$as_me:24562: $lt_compile\"" >&5)
(eval echo "\"\$as_me:24563: $lt_compile\"" >&5)
(eval "$lt_compile" 2>out/conftest.err)
ac_status=$?
cat out/conftest.err >&5
echo "$as_me:24566: \$? = $ac_status" >&5
echo "$as_me:24567: \$? = $ac_status" >&5
if (exit $ac_status) && test -s out/conftest2.$ac_objext
then
# The compiler can only warn and ignore the option if not recognized

Wyświetl plik

@ -147,7 +147,7 @@ AC_CHECK_HEADERS(fcntl.h unistd.h libc.h sys/dsreq.h sys/select.h \
IOKit/cdb/IOSCSILib.h IOKit/scsi/SCSICommandOperationCodes.h \
IOKit/scsi-commands/SCSICommandOperationCodes.h \
windows.h be/kernel/OS.h be/drivers/USB_scanner.h limits.h sys/ioctl.h asm/types.h\
netinet/in.h tiffio.h)
netinet/in.h tiffio.h ifaddrs.h)
AC_CHECK_HEADERS([asm/io.h],,,[#include <sys/types.h>])
AC_CHECK_HEADERS([io/cam/cam.h],,,[#include <io/common/iotypes.h>])

Wyświetl plik

@ -11,7 +11,7 @@
; See doc/descriptions.txt for details.
:backend "pixma" ; name of backend
:version "0.14.5" ; version of backend (or "unmaintained")
:version "0.15.0" ; version of backend (or "unmaintained")
:manpage "sane-pixma" ; name of manpage (if it exists)
:url "http://home.arcor.de/wittawat/pixma/" ; 0.13.1 backend's web page
:url "http://mp610.blogspot.com/" ; 0.14.4 backend's web page