backend/epson2.c, added network scanner autodiscovery

merge-requests/1/head
Alessandro Zummo 2007-12-26 11:34:17 +00:00
rodzic 5655e0886f
commit 4cf7b16449
4 zmienionych plików z 58 dodań i 0 usunięć

Wyświetl plik

@ -1,3 +1,6 @@
2007-12-26 Alessandro Zummo <a.zummo@towertech.it>
* backend/epson2.c, added network scanner autodiscovery
2007-12-26 Alessandro Zummo <a.zummo@towertech.it>
* sanei/sanei_udp.c, added udp support functions

Wyświetl plik

@ -393,6 +393,7 @@ libsane-epson2.la: ../sanei/sanei_scsi.lo
libsane-epson2.la: ../sanei/sanei_usb.lo
libsane-epson2.la: ../sanei/sanei_pio.lo
libsane-epson2.la: ../sanei/sanei_tcp.lo
libsane-epson2.la: ../sanei/sanei_udp.lo
libsane-fujitsu.la: ../sanei/sanei_config2.lo
libsane-fujitsu.la: ../sanei/sanei_constrain_value.lo
libsane-fujitsu.la: ../sanei/sanei_scsi.lo

Wyświetl plik

@ -58,6 +58,7 @@
#include <sane/sanei_usb.h>
#include <sane/sanei_pio.h>
#include <sane/sanei_tcp.h>
#include <sane/sanei_udp.h>
#include <sane/sanei_backend.h>
#include <sane/sanei_config.h>
@ -570,6 +571,50 @@ close_scanner(Epson_Scanner * s)
return;
}
static void
epson2_network_discovery(void)
{
fd_set rfds;
int nfds, fd, len;
SANE_Status status;
char *ip, *query = "EPSONP\x00\xff\x00\x00\x00\x00\x00\x00\x00";
u_char buf[76];
struct timeval to;
status = sanei_udp_open_broadcast(&fd);
if (status != SANE_STATUS_GOOD)
return;
sanei_udp_write_broadcast(fd, 3289, (u_char *) query, 15);
DBG(5, "%s, sent discovery packet\n", __func__);
to.tv_sec = 1;
to.tv_usec = 0;
FD_ZERO(&rfds);
FD_SET(fd, &rfds);
if (select(fd + 1, &rfds, NULL, NULL, &to) > 0) {
while((len = sanei_udp_recvfrom(fd, buf, 76, &ip)) == 76) {
DBG(5, " response from %s\n", ip);
/* minimal check, protocol unknown */
if (strncmp(buf, "EPSON", 5) == 0)
attach_one_net(ip);
}
}
DBG(5, "%s, end\n", __func__);
sanei_udp_close(fd);
}
/*
* open_scanner()
*
@ -855,6 +900,12 @@ attach(const char *name, Epson_Device * *devp, int type)
if (dev->connection == SANE_EPSON_NET) {
unsigned char buf[5];
if (strncmp(name, "autodiscovery", 13) == 0) {
epson2_network_discovery();
status = SANE_STATUS_INVAL;
goto free;
}
status = sanei_tcp_open(name, 1865, &s->fd);
if (status != SANE_STATUS_GOOD) {
DBG(1, "%s: %s open failed: %s\n", __func__,

Wyświetl plik

@ -21,4 +21,7 @@ usb
# usb 0x4b8 0x110
# Network
#
# net 192.168.1.123
net autodiscovery