diff --git a/ChangeLog b/ChangeLog index 5a8292218..ad20d6617 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,6 @@ +2007-12-26 Alessandro Zummo + * backend/epson2.c, added network scanner autodiscovery + 2007-12-26 Alessandro Zummo * sanei/sanei_udp.c, added udp support functions diff --git a/backend/Makefile.in b/backend/Makefile.in index 635b2f229..652698714 100644 --- a/backend/Makefile.in +++ b/backend/Makefile.in @@ -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 diff --git a/backend/epson2.c b/backend/epson2.c index ee14527b8..5dc77944d 100644 --- a/backend/epson2.c +++ b/backend/epson2.c @@ -58,6 +58,7 @@ #include #include #include +#include #include #include @@ -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__, diff --git a/backend/epson2.conf.in b/backend/epson2.conf.in index 4a81ef1ee..a99648785 100644 --- a/backend/epson2.conf.in +++ b/backend/epson2.conf.in @@ -21,4 +21,7 @@ usb # usb 0x4b8 0x110 # Network +# # net 192.168.1.123 +net autodiscovery +